Implement onViewAppear by creating a new EventListener on ReactRootView listening for when it's attached to a RN Instance

Reviewed By: AaaChiuuu

Differential Revision: D4269272

fbshipit-source-id: 6dd54f8ab7befebd54e82ef355119ba302b9bfe5
This commit is contained in:
Don Yu
2016-12-07 09:49:51 -08:00
committed by Facebook Github Bot
parent 7f8c2985a8
commit bfe551d2d1
2 changed files with 22 additions and 0 deletions

View File

@@ -56,10 +56,21 @@ import com.facebook.react.uimanager.events.EventDispatcher;
*/
public class ReactRootView extends SizeMonitoringFrameLayout implements RootView {
/**
* Listener interface for react root view events
*/
public interface ReactRootViewEventListener {
/**
* Called when the react context is attached to a ReactRootView.
*/
void onAttachedToReactInstance(ReactRootView rootView);
}
private @Nullable ReactInstanceManager mReactInstanceManager;
private @Nullable String mJSModuleName;
private @Nullable Bundle mLaunchOptions;
private @Nullable CustomGlobalLayoutListener mCustomGlobalLayoutListener;
private @Nullable ReactRootViewEventListener mRootViewEventListener;
private int mRootViewTag;
private boolean mWasMeasured = false;
private boolean mIsAttachedToInstance = false;
@@ -224,6 +235,16 @@ public class ReactRootView extends SizeMonitoringFrameLayout implements RootView
}
}
public void onAttachedToReactInstance() {
if (mRootViewEventListener != null) {
mRootViewEventListener.onAttachedToReactInstance(this);
}
}
public void setEventListener(ReactRootViewEventListener eventListener) {
mRootViewEventListener = eventListener;
}
/* package */ String getJSModuleName() {
return Assertions.assertNotNull(mJSModuleName);
}