Skip to content

Commit

Permalink
Merge pull request #5 from DispatcherInc/fix/catalyst-instance-crash
Browse files Browse the repository at this point in the history
Try fix the Catalyst instance crash
  • Loading branch information
gunters63 committed Mar 22, 2016
2 parents d799c5c + e717be0 commit 1eaf9fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions android/src/main/java/com/dispatcher/rnbranch/RNBranchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,22 @@ private Branch.BranchLinkShareListener init(Callback callback) {
}

public void sendRNEvent(String eventName, @Nullable WritableMap params) {
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
// This should avoid the crash in getJSModule() at startup
// Todo: It would be even better to wait until the catalyst instance has became available, but its not clear
// how to do that.
// See also: https://github.com/walmartreact/react-native-orientation-listener/issues/8
// We also wait 100ms here before sending the event so the catalyst instance should be available.

try {
Thread.sleep(100);
if (getReactApplicationContext().hasActiveCatalystInstance()) {
getReactApplicationContext()
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
}

private static Object getReadableMapObjectForKey(ReadableMap readableMap, String key) {
Expand Down Expand Up @@ -368,4 +381,4 @@ private static WritableArray convertJsonToArray(JSONArray jsonArray) throws JSON
}
return array;
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-branch",
"version": "0.0.9",
"version": "0.0.10",
"description": "Native Wrapper around Branch Metrics native SDKs",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 1eaf9fc

Please sign in to comment.