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

Commit

Permalink
Fix crash for AccessToken tracker (#699)
Browse files Browse the repository at this point in the history
This PR fixes Crash when handling access token by tracking access token when react context is ready
  • Loading branch information
chakrihacker authored Jan 30, 2020
1 parent cfee77a commit 2294213
Showing 1 changed file with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,7 @@ public class FBAccessTokenModule extends ReactContextBaseJavaModule {
public static final String CHANGE_EVENT_NAME = "fbsdk.accessTokenDidChange";

private final ReactApplicationContext mReactContext;
private final AccessTokenTracker 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));
}
};
private AccessTokenTracker accessTokenTracker;

public FBAccessTokenModule(ReactApplicationContext reactContext) {
super(reactContext);
Expand All @@ -62,6 +55,26 @@ public String getName() {
return NAME;
}

@Override
public void initialize() {
super.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));
}
};

}

@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
accessTokenTracker.stopTracking();
}

/**
* Get {@link AccessToken} of the current session.
* @param callback Use callback to pass the current access token back to JS.
Expand Down

0 comments on commit 2294213

Please sign in to comment.