add removeReactInstanceEventListener and call it from onDestroy

Reviewed By: zahanm

Differential Revision: D2937547

fb-gh-sync-id: 95461fdada8ac86d2c4174dae7023c97a3101e2e
shipit-source-id: 95461fdada8ac86d2c4174dae7023c97a3101e2e
This commit is contained in:
Felix Oghina 2016-02-16 12:13:16 -08:00 committed by facebook-github-bot-6
parent f74981ac32
commit 07a5f4407f
2 changed files with 14 additions and 1 deletions

View File

@ -136,6 +136,11 @@ public abstract class ReactInstanceManager {
*/
public abstract void addReactInstanceEventListener(ReactInstanceEventListener listener);
/**
* Remove a listener previously added with {@link #addReactInstanceEventListener}.
*/
public abstract void removeReactInstanceEventListener(ReactInstanceEventListener listener);
@VisibleForTesting
public abstract @Nullable ReactContext getCurrentReactContext();

View File

@ -15,7 +15,10 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import android.app.Activity;
@ -110,7 +113,7 @@ import static com.facebook.react.bridge.ReactMarkerConstants.*;
private String mSourceUrl;
private @Nullable Activity mCurrentActivity;
private final Collection<ReactInstanceEventListener> mReactInstanceEventListeners =
new ConcurrentLinkedQueue<>();
Collections.synchronizedSet(new HashSet<ReactInstanceEventListener>());
private volatile boolean mHasStartedCreatingInitialContext = false;
private final UIImplementationProvider mUIImplementationProvider;
private final MemoryPressureRouter mMemoryPressureRouter;
@ -599,6 +602,11 @@ import static com.facebook.react.bridge.ReactMarkerConstants.*;
mReactInstanceEventListeners.add(listener);
}
@Override
public void removeReactInstanceEventListener(ReactInstanceEventListener listener) {
mReactInstanceEventListeners.remove(listener);
}
@VisibleForTesting
@Override
public @Nullable ReactContext getCurrentReactContext() {