1 package com.community.fabrictester;
2 
3 import android.os.Build;
4 import android.os.Bundle;
5 
6 import com.facebook.react.ReactActivity;
7 import com.facebook.react.ReactActivityDelegate;
8 import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
9 import com.facebook.react.defaults.DefaultReactActivityDelegate;
10 
11 import expo.modules.ReactActivityDelegateWrapper;
12 
13 public class MainActivity extends ReactActivity {
14   @Override
onCreate(Bundle savedInstanceState)15   protected void onCreate(Bundle savedInstanceState) {
16     // Set the theme to AppTheme BEFORE onCreate to support
17     // coloring the background, status bar, and navigation bar.
18     // This is required for expo-splash-screen.
19     setTheme(R.style.AppTheme);
20     super.onCreate(null);
21   }
22 
23   /**
24    * Returns the name of the main component registered from JavaScript.
25    * This is used to schedule rendering of the component.
26    */
27   @Override
getMainComponentName()28   protected String getMainComponentName() {
29     return "main";
30   }
31 
32   /**
33    * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
34    * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
35    * (aka React 18) with two boolean flags.
36    */
37   @Override
createReactActivityDelegate()38   protected ReactActivityDelegate createReactActivityDelegate() {
39     return new ReactActivityDelegateWrapper(this, BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, new DefaultReactActivityDelegate(
40         this,
41         getMainComponentName(),
42         // If you opted-in for the New Architecture, we enable the Fabric Renderer.
43         DefaultNewArchitectureEntryPoint.getFabricEnabled()));
44   }
45 
46   /**
47    * Align the back button behavior with Android S
48    * where moving root activities to background instead of finishing activities.
49    * @see <a href="https://developer.android.com/reference/android/app/Activity#onBackPressed()">onBackPressed</a>
50    */
51   @Override
invokeDefaultOnBackPressed()52   public void invokeDefaultOnBackPressed() {
53     if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
54       if (!moveTaskToBack(false)) {
55         // For non-root activities, use the default implementation to finish them.
56         super.invokeDefaultOnBackPressed();
57       }
58       return;
59     }
60 
61     // Use the default back button implementation on Android S
62     // because it's doing more than {@link Activity#moveTaskToBack} in fact.
63     super.invokeDefaultOnBackPressed();
64   }
65 }
66