No Description

MainActivity.java 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package com.censusproject;
  2. import android.os.Build;
  3. import android.os.Bundle;
  4. import com.facebook.react.ReactActivity;
  5. import com.facebook.react.ReactActivityDelegate;
  6. import com.facebook.react.ReactRootView;
  7. import expo.modules.ReactActivityDelegateWrapper;
  8. public class MainActivity extends ReactActivity {
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11. // Set the theme to AppTheme BEFORE onCreate to support
  12. // coloring the background, status bar, and navigation bar.
  13. // This is required for expo-splash-screen.
  14. setTheme(R.style.AppTheme);
  15. super.onCreate(null);
  16. }
  17. /**
  18. * Returns the name of the main component registered from JavaScript.
  19. * This is used to schedule rendering of the component.
  20. */
  21. @Override
  22. protected String getMainComponentName() {
  23. return "main";
  24. }
  25. /**
  26. * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and
  27. * you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer
  28. * (Paper).
  29. */
  30. @Override
  31. protected ReactActivityDelegate createReactActivityDelegate() {
  32. return new ReactActivityDelegateWrapper(this, BuildConfig.IS_NEW_ARCHITECTURE_ENABLED,
  33. new MainActivityDelegate(this, getMainComponentName())
  34. );
  35. }
  36. /**
  37. * Align the back button behavior with Android S
  38. * where moving root activities to background instead of finishing activities.
  39. * @see <a href="https://developer.android.com/reference/android/app/Activity#onBackPressed()">onBackPressed</a>
  40. */
  41. @Override
  42. public void invokeDefaultOnBackPressed() {
  43. if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.R) {
  44. if (!moveTaskToBack(false)) {
  45. // For non-root activities, use the default implementation to finish them.
  46. super.invokeDefaultOnBackPressed();
  47. }
  48. return;
  49. }
  50. // Use the default back button implementation on Android S
  51. // because it's doing more than {@link Activity#moveTaskToBack} in fact.
  52. super.invokeDefaultOnBackPressed();
  53. }
  54. public static class MainActivityDelegate extends ReactActivityDelegate {
  55. public MainActivityDelegate(ReactActivity activity, String mainComponentName) {
  56. super(activity, mainComponentName);
  57. }
  58. @Override
  59. protected ReactRootView createRootView() {
  60. ReactRootView reactRootView = new ReactRootView(getContext());
  61. // If you opted-in for the New Architecture, we enable the Fabric Renderer.
  62. reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED);
  63. return reactRootView;
  64. }
  65. @Override
  66. protected boolean isConcurrentRootEnabled() {
  67. // If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18).
  68. // More on this on https://reactjs.org/blog/2022/03/29/react-v18.html
  69. return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
  70. }
  71. }
  72. }