Skip to content

Commit

Permalink
Implement onViewAppear by creating a new EventListener on ReactRootVi…
Browse files Browse the repository at this point in the history
…ew listening for when it's attached to a RN Instance

Reviewed By: AaaChiuuu

Differential Revision: D4269272

fbshipit-source-id: 6dd54f8ab7befebd54e82ef355119ba302b9bfe5
  • Loading branch information
donyu authored and Martin Konicek committed Dec 12, 2016
1 parent 5144bf0 commit e06b8db
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit e06b8db

Please sign in to comment.