Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check to verify that catalystInstance is active before getJSModule #1050

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@

public class JsIOHelper {
public boolean sendEventToJS(String eventName, Bundle data, ReactContext reactContext) {
if (reactContext != null) {
sendEventToJS(eventName, Arguments.fromBundle(data), reactContext);
return true;
}
return false;
return sendEventToJS(eventName, Arguments.fromBundle(data), reactContext);
}

public boolean sendEventToJS(String eventName, WritableMap data, ReactContext reactContext) {
if (reactContext != null) {
if (reactContext != null && reactContext.hasActiveCatalystInstance()) {
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, data);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ protected void refreshToken() {
protected void sendTokenToJS() {
final ReactInstanceManager instanceManager = ((ReactApplication) mAppContext).getReactNativeHost().getReactInstanceManager();
final ReactContext reactContext = instanceManager.getCurrentReactContext();
Bundle tokenMap = new Bundle();
tokenMap.putString("deviceToken", sToken);
// mJsIOHelper is safe now when context is null or react instance is not active
mJsIOHelper.sendEventToJS(TOKEN_RECEIVED_EVENT_NAME, tokenMap, reactContext);

// Note: Cannot assume react-context exists cause this is an async dispatched service.
if (reactContext != null && reactContext.hasActiveCatalystInstance()) {
Bundle tokenMap = new Bundle();
tokenMap.putString("deviceToken", sToken);
mJsIOHelper.sendEventToJS(TOKEN_RECEIVED_EVENT_NAME, tokenMap, reactContext);
}
}
}