Skip to content

Commit e06b8db

Browse files
donyuMartin Konicek
authored and
Martin Konicek
committed
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
1 parent 5144bf0 commit e06b8db

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java

+21
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,21 @@
5656
*/
5757
public class ReactRootView extends SizeMonitoringFrameLayout implements RootView {
5858

59+
/**
60+
* Listener interface for react root view events
61+
*/
62+
public interface ReactRootViewEventListener {
63+
/**
64+
* Called when the react context is attached to a ReactRootView.
65+
*/
66+
void onAttachedToReactInstance(ReactRootView rootView);
67+
}
68+
5969
private @Nullable ReactInstanceManager mReactInstanceManager;
6070
private @Nullable String mJSModuleName;
6171
private @Nullable Bundle mLaunchOptions;
6272
private @Nullable CustomGlobalLayoutListener mCustomGlobalLayoutListener;
73+
private @Nullable ReactRootViewEventListener mRootViewEventListener;
6374
private int mRootViewTag;
6475
private boolean mWasMeasured = false;
6576
private boolean mIsAttachedToInstance = false;
@@ -224,6 +235,16 @@ public void unmountReactApplication() {
224235
}
225236
}
226237

238+
public void onAttachedToReactInstance() {
239+
if (mRootViewEventListener != null) {
240+
mRootViewEventListener.onAttachedToReactInstance(this);
241+
}
242+
}
243+
244+
public void setEventListener(ReactRootViewEventListener eventListener) {
245+
mRootViewEventListener = eventListener;
246+
}
247+
227248
/* package */ String getJSModuleName() {
228249
return Assertions.assertNotNull(mJSModuleName);
229250
}

ReactAndroid/src/main/java/com/facebook/react/XReactInstanceManagerImpl.java

+1
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ private void attachMeasuredRootViewToInstance(
810810
appParams.putDouble("rootTag", rootTag);
811811
appParams.putMap("initialProps", initialProps);
812812
catalystInstance.getJSModule(AppRegistry.class).runApplication(jsAppModuleName, appParams);
813+
rootView.onAttachedToReactInstance();
813814
Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE);
814815
}
815816

0 commit comments

Comments
 (0)