Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Avoid app crashing on access token change (#744)
Browse files Browse the repository at this point in the history
The access token change event is broadcasted from AccessTokenTracker
during app start, even before the react-native has fully initialized.
This results in a RuntimeException while trying to retrive the
JSModule from context. This is just a safe escape hatch to avoid app
crashing. A more robust solution might be deferring the change event
after the react-native initializes.
  • Loading branch information
syaau committed May 18, 2020
1 parent fdccd6a commit 9d6d0c0
Showing 1 changed file with 9 additions and 3 deletions.
Expand Up @@ -61,9 +61,15 @@ public void initialize() {
accessTokenTracker = new AccessTokenTracker() {
@Override
protected void onCurrentAccessTokenChanged(AccessToken oldAccessToken, AccessToken currentAccessToken) {
mReactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(CHANGE_EVENT_NAME, currentAccessToken == null ? null : Utility.accessTokenToReactMap(currentAccessToken));
try {
mReactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(CHANGE_EVENT_NAME, currentAccessToken == null ? null : Utility.accessTokenToReactMap(currentAccessToken));
} catch (RuntimeException ex) {
// It is possible that the react context might not have initialized when this
// event is broadcasted from AccessTokenTracker, so rather than crashing with
// an error message, ignoring the change
}
}
};

Expand Down

0 comments on commit 9d6d0c0

Please sign in to comment.