@@ -87,6 +87,7 @@ public interface ReactRootViewEventListener {
87
87
private boolean mWasMeasured = false ;
88
88
private int mWidthMeasureSpec = MeasureSpec .makeMeasureSpec (0 , MeasureSpec .UNSPECIFIED );
89
89
private int mHeightMeasureSpec = MeasureSpec .makeMeasureSpec (0 , MeasureSpec .UNSPECIFIED );
90
+ private @ Nullable Runnable mJSEntryPoint ;
90
91
91
92
public ReactRootView (Context context ) {
92
93
super (context );
@@ -379,42 +380,69 @@ public void setAppProperties(@Nullable Bundle appProperties) {
379
380
UiThreadUtil .assertOnUiThread ();
380
381
mAppProperties = appProperties ;
381
382
if (getRootViewTag () != 0 ) {
382
- runApplication ();
383
+ invokeJSEntryPoint ();
383
384
}
384
385
}
385
386
386
387
/**
387
388
* Calls into JS to start the React application. Can be called multiple times with the
388
389
* same rootTag, which will re-render the application from the root.
389
390
*/
390
- /* package */ void runApplication () {
391
- Systrace .beginSection (TRACE_TAG_REACT_JAVA_BRIDGE , "ReactRootView.runApplication" );
392
- try {
393
- if (mReactInstanceManager == null || !mIsAttachedToInstance ) {
394
- return ;
395
- }
391
+ /*package */ void invokeJSEntryPoint () {
392
+ if (mJSEntryPoint == null ) {
393
+ defaultJSEntryPoint ();
394
+ } else {
395
+ mJSEntryPoint .run ();
396
+ }
397
+ }
396
398
397
- ReactContext reactContext = mReactInstanceManager .getCurrentReactContext ();
398
- if (reactContext == null ) {
399
- return ;
400
- }
399
+ /**
400
+ * Set a custom entry point for invoking JS. By default, this is AppRegistry.runApplication
401
+ * @param jsEntryPoint
402
+ */
403
+ public void setJSEntryPoint (Runnable jsEntryPoint ) {
404
+ mJSEntryPoint = jsEntryPoint ;
405
+ }
401
406
402
- CatalystInstance catalystInstance = reactContext .getCatalystInstance ();
407
+ public void invokeDefaultJSEntryPoint (@ Nullable Bundle appProperties ) {
408
+ UiThreadUtil .assertOnUiThread ();
409
+ if (appProperties != null ) {
410
+ mAppProperties = appProperties ;
411
+ }
412
+ defaultJSEntryPoint ();
413
+ }
403
414
404
- WritableNativeMap appParams = new WritableNativeMap ();
405
- appParams .putDouble ("rootTag" , getRootViewTag ());
406
- @ Nullable Bundle appProperties = getAppProperties ();
407
- if (appProperties != null ) {
408
- appParams .putMap ("initialProps" , Arguments .fromBundle (appProperties ));
409
- }
415
+ /**
416
+ * Calls the default entry point into JS which is AppRegistry.runApplication()
417
+ */
418
+ private void defaultJSEntryPoint () {
419
+ Systrace .beginSection (TRACE_TAG_REACT_JAVA_BRIDGE , "ReactRootView.runApplication" );
420
+ try {
421
+ if (mReactInstanceManager == null || !mIsAttachedToInstance ) {
422
+ return ;
423
+ }
410
424
411
- mShouldLogContentAppeared = true ;
425
+ ReactContext reactContext = mReactInstanceManager .getCurrentReactContext ();
426
+ if (reactContext == null ) {
427
+ return ;
428
+ }
412
429
413
- String jsAppModuleName = getJSModuleName ();
414
- catalystInstance .getJSModule (AppRegistry .class ).runApplication (jsAppModuleName , appParams );
415
- } finally {
416
- Systrace .endSection (TRACE_TAG_REACT_JAVA_BRIDGE );
417
- }
430
+ CatalystInstance catalystInstance = reactContext .getCatalystInstance ();
431
+
432
+ WritableNativeMap appParams = new WritableNativeMap ();
433
+ appParams .putDouble ("rootTag" , getRootViewTag ());
434
+ @ Nullable Bundle appProperties = getAppProperties ();
435
+ if (appProperties != null ) {
436
+ appParams .putMap ("initialProps" , Arguments .fromBundle (appProperties ));
437
+ }
438
+
439
+ mShouldLogContentAppeared = true ;
440
+
441
+ String jsAppModuleName = getJSModuleName ();
442
+ catalystInstance .getJSModule (AppRegistry .class ).runApplication (jsAppModuleName , appParams );
443
+ } finally {
444
+ Systrace .endSection (TRACE_TAG_REACT_JAVA_BRIDGE );
445
+ }
418
446
}
419
447
420
448
/**
0 commit comments