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

Fix crash for AccessToken tracker #699

Merged
merged 1 commit into from Jan 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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