Permalink
Browse files

Implement onViewAppear by creating a new EventListener on ReactRootVi…

…ew listening for when it's attached to a RN Instance

Reviewed By: AaaChiuuu

Differential Revision: D4269272

fbshipit-source-id: 6dd54f8ab7befebd54e82ef355119ba302b9bfe5
  • Loading branch information...
1 parent 5144bf0 commit e06b8db79d36183ef393a3fbbba0040d034c9ee6 @donyu donyu committed with mkonicek Dec 7, 2016
@@ -56,10 +56,21 @@
*/
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 void unmountReactApplication() {
}
}
+ public void onAttachedToReactInstance() {
+ if (mRootViewEventListener != null) {
+ mRootViewEventListener.onAttachedToReactInstance(this);
+ }
+ }
+
+ public void setEventListener(ReactRootViewEventListener eventListener) {
+ mRootViewEventListener = eventListener;
+ }
+
/* package */ String getJSModuleName() {
return Assertions.assertNotNull(mJSModuleName);
}
@@ -810,6 +810,7 @@ private void attachMeasuredRootViewToInstance(
appParams.putDouble("rootTag", rootTag);
appParams.putMap("initialProps", initialProps);
catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
+ rootView.onAttachedToReactInstance();
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
}

0 comments on commit e06b8db

Please sign in to comment.