-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from pixielabs/android
Android Native Reporter
- Loading branch information
Showing
13 changed files
with
238 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
|
||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.reactlibrary"> | ||
package="com.cavynativereporter"> | ||
|
||
</manifest> | ||
|
57 changes: 57 additions & 0 deletions
57
android/src/main/java/com/cavynativereporter/RNCavyNativeReporterModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
|
||
package com.cavynativereporter; | ||
|
||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.ReadableMap; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
// Android Bridge Module that exposes Cavy test reports to native code. | ||
public class RNCavyNativeReporterModule extends ReactContextBaseJavaModule { | ||
|
||
private final ReactApplicationContext reactContext; | ||
|
||
public RNCavyNativeReporterModule(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
this.reactContext = reactContext; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "CavyNativeReporter"; | ||
} | ||
|
||
public static ReadableMap cavyReport = null; | ||
// Initialize a CountDownLatch with a count of one as a simple gate. | ||
// The thread calling `waitForReport` will wait at `latch.await` until the | ||
// thread called `reporter` opens the gate with `latch.countdown`. | ||
final static CountDownLatch latch = new CountDownLatch(1); | ||
|
||
// This method is exposed to JS through React Native NativeModules. | ||
// | ||
// Sets the report as a class variable so we can access it later and opens | ||
// the latch gate (see note on CountDownLatch above). | ||
// | ||
// `report` - the Cavy test report. | ||
@ReactMethod | ||
public void reporter(ReadableMap report) { | ||
cavyReport = report; | ||
latch.countDown(); | ||
} | ||
|
||
// Class method that waits for the cavyReport to be available (see note on | ||
// CountDownLatch above). | ||
// | ||
// `seconds` - integer representing the number of seconds the latch should | ||
// wait for the report from Cavy before timing out. | ||
public static void waitForReport(int seconds) throws Exception { | ||
if (cavyReport != null) { | ||
return; | ||
} else { | ||
latch.await(seconds, TimeUnit.SECONDS); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
android/src/main/java/com/reactlibrary/RNCavyNativeReporterModule.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.