Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ abstract class GenerateEntryPointTask : DefaultTask() {
import android.content.Context;
import android.content.res.Resources;

import com.facebook.react.ReactApplication;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger;
import com.facebook.react.views.view.WindowUtilKt;
Expand All @@ -82,9 +83,21 @@ abstract class GenerateEntryPointTask : DefaultTask() {
*
* The `loadReactNative(this)` method invocation should be called inside the
* application onCreate otherwise the app won't load correctly.
*
* `loadReactNative(this, true)` additionally starts the ReactHost right away, so the
* React instance (JS runtime, TurboModules, bundle evaluation) is created on the
* ReactHost background thread while the first Activity is being created, instead of
* only once that Activity starts its surface. This makes the first React content
* appear earlier at the cost of a slightly later first (empty) frame, and it creates
* the React instance for every process start, including ones that never show an
* Activity (e.g. a headless task or a push service).
*/
public class ReactNativeApplicationEntryPoint {
public static void loadReactNative(Context context) {
loadReactNative(context, false);
}

public static void loadReactNative(Context context, boolean startReactHost) {
SoLoader.init(context, OpenSourceMergedSoMapping.INSTANCE);

if ({{packageName}}.BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
Expand All @@ -94,6 +107,10 @@ abstract class GenerateEntryPointTask : DefaultTask() {
if ({{packageName}}.BuildConfig.IS_EDGE_TO_EDGE_ENABLED) {
WindowUtilKt.setEdgeToEdgeFeatureFlagOn();
}

if (startReactHost && context instanceof ReactApplication) {
((ReactApplication) context).getReactHost().start();
}
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class GenerateEntryPointTaskTest {
import android.content.Context;
import android.content.res.Resources;

import com.facebook.react.ReactApplication;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.common.annotations.internal.LegacyArchitectureLogger;
import com.facebook.react.views.view.WindowUtilKt;
Expand All @@ -65,9 +66,21 @@ class GenerateEntryPointTaskTest {
*
* The `loadReactNative(this)` method invocation should be called inside the
* application onCreate otherwise the app won't load correctly.
*
* `loadReactNative(this, true)` additionally starts the ReactHost right away, so the
* React instance (JS runtime, TurboModules, bundle evaluation) is created on the
* ReactHost background thread while the first Activity is being created, instead of
* only once that Activity starts its surface. This makes the first React content
* appear earlier at the cost of a slightly later first (empty) frame, and it creates
* the React instance for every process start, including ones that never show an
* Activity (e.g. a headless task or a push service).
*/
public class ReactNativeApplicationEntryPoint {
public static void loadReactNative(Context context) {
loadReactNative(context, false);
}

public static void loadReactNative(Context context, boolean startReactHost) {
SoLoader.init(context, OpenSourceMergedSoMapping.INSTANCE);

if (com.facebook.react.BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
Expand All @@ -77,6 +90,10 @@ class GenerateEntryPointTaskTest {
if (com.facebook.react.BuildConfig.IS_EDGE_TO_EDGE_ENABLED) {
WindowUtilKt.setEdgeToEdgeFeatureFlagOn();
}

if (startReactHost && context instanceof ReactApplication) {
((ReactApplication) context).getReactHost().start();
}
}
}
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ internal class RNTesterApplication : Application(), ReactApplication {
// Must run before loadReactNative so E2E-provided system properties are readable by the
// feature flag overrides applied during React Native startup.
FBRNTesterEndToEndHelper.initializeConfig(this)
loadReactNative(this)
// Start the ReactHost right away so the React instance is created while the first Activity
// is being created.
loadReactNative(this, true)
}
}
Loading