diff --git a/packages/react-native/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.java b/packages/react-native/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.java deleted file mode 100644 index 595dd5831c3..00000000000 --- a/packages/react-native/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - *

This source code is licensed under the MIT license found in the LICENSE file in the root - * directory of this source tree. - */ -package com.helloworld; - -import android.content.Context; -import com.facebook.flipper.android.AndroidFlipperClient; -import com.facebook.flipper.android.utils.FlipperUtils; -import com.facebook.flipper.core.FlipperClient; -import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; -import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; -import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; -import com.facebook.flipper.plugins.inspector.DescriptorMapping; -import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; -import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; -import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; -import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; -import com.facebook.react.ReactInstanceEventListener; -import com.facebook.react.ReactInstanceManager; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.modules.network.NetworkingModule; -import okhttp3.OkHttpClient; - -/** - * Class responsible of loading Flipper inside your React Native application. This is the debug - * flavor of it. Here you can add your own plugins and customize the Flipper setup. - */ -public class ReactNativeFlipper { - public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { - if (FlipperUtils.shouldEnableFlipper(context)) { - final FlipperClient client = AndroidFlipperClient.getInstance(context); - - client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); - client.addPlugin(new DatabasesFlipperPlugin(context)); - client.addPlugin(new SharedPreferencesFlipperPlugin(context)); - client.addPlugin(CrashReporterPlugin.getInstance()); - - NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); - NetworkingModule.setCustomClientBuilder( - new NetworkingModule.CustomClientBuilder() { - @Override - public void apply(OkHttpClient.Builder builder) { - builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); - } - }); - client.addPlugin(networkFlipperPlugin); - client.start(); - - // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized - // Hence we run if after all native modules have been initialized - ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); - if (reactContext == null) { - reactInstanceManager.addReactInstanceEventListener( - new ReactInstanceEventListener() { - @Override - public void onReactContextInitialized(ReactContext reactContext) { - reactInstanceManager.removeReactInstanceEventListener(this); - reactContext.runOnNativeModulesQueueThread( - new Runnable() { - @Override - public void run() { - client.addPlugin(new FrescoFlipperPlugin()); - } - }); - } - }); - } else { - client.addPlugin(new FrescoFlipperPlugin()); - } - } - } -} diff --git a/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.kt b/packages/react-native/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.kt similarity index 97% rename from template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.kt rename to packages/react-native/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.kt index a3658a497ef..5cea7f83005 100644 --- a/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.kt +++ b/packages/react-native/template/android/app/src/debug/java/com/helloworld/ReactNativeFlipper.kt @@ -1,9 +1,10 @@ -/** +/* * Copyright (c) Meta Platforms, Inc. and affiliates. * - * This source code is licensed under the MIT license found in the LICENSE file in the root - * directory of this source tree. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ + package com.helloworld import android.content.Context diff --git a/packages/react-native/template/android/app/src/main/java/com/helloworld/MainActivity.java b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainActivity.java deleted file mode 100644 index 1e9c1d94cc7..00000000000 --- a/packages/react-native/template/android/app/src/main/java/com/helloworld/MainActivity.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.helloworld; - -import com.facebook.react.ReactActivity; -import com.facebook.react.ReactActivityDelegate; -import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; -import com.facebook.react.defaults.DefaultReactActivityDelegate; - -public class MainActivity extends ReactActivity { - - /** - * Returns the name of the main component registered from JavaScript. This is used to schedule - * rendering of the component. - */ - @Override - protected String getMainComponentName() { - return "HelloWorld"; - } - - /** - * Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link - * DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React - * (aka React 18) with two boolean flags. - */ - @Override - protected ReactActivityDelegate createReactActivityDelegate() { - return new DefaultReactActivityDelegate( - this, - getMainComponentName(), - // If you opted-in for the New Architecture, we enable the Fabric Renderer. - DefaultNewArchitectureEntryPoint.getFabricEnabled()); - } -} diff --git a/template/android/app/src/main/java/com/helloworld/MainActivity.kt b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainActivity.kt similarity index 81% rename from template/android/app/src/main/java/com/helloworld/MainActivity.kt rename to packages/react-native/template/android/app/src/main/java/com/helloworld/MainActivity.kt index d7a3dee1a87..07c47370090 100644 --- a/template/android/app/src/main/java/com/helloworld/MainActivity.kt +++ b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainActivity.kt @@ -1,3 +1,10 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + package com.helloworld import com.facebook.react.ReactActivity diff --git a/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.java b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.java deleted file mode 100644 index 3227c9e9699..00000000000 --- a/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.helloworld; - -import android.app.Application; -import com.facebook.react.PackageList; -import com.facebook.react.ReactApplication; -import com.facebook.react.ReactNativeHost; -import com.facebook.react.ReactPackage; -import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint; -import com.facebook.react.defaults.DefaultReactNativeHost; -import com.facebook.soloader.SoLoader; -import java.util.List; - -public class MainApplication extends Application implements ReactApplication { - - private final ReactNativeHost mReactNativeHost = - new DefaultReactNativeHost(this) { - @Override - public boolean getUseDeveloperSupport() { - return BuildConfig.DEBUG; - } - - @Override - protected List getPackages() { - @SuppressWarnings("UnnecessaryLocalVariable") - List packages = new PackageList(this).getPackages(); - // Packages that cannot be autolinked yet can be added manually here, for example: - // packages.add(new MyReactNativePackage()); - return packages; - } - - @Override - protected String getJSMainModuleName() { - return "index"; - } - - @Override - protected boolean isNewArchEnabled() { - return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; - } - - @Override - protected Boolean isHermesEnabled() { - return BuildConfig.IS_HERMES_ENABLED; - } - }; - - @Override - public ReactNativeHost getReactNativeHost() { - return mReactNativeHost; - } - - @Override - public void onCreate() { - super.onCreate(); - SoLoader.init(this, /* native exopackage */ false); - if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - // If you opted-in for the New Architecture, we load the native entry point for this app. - DefaultNewArchitectureEntryPoint.load(); - } - ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); - } -} diff --git a/template/android/app/src/main/java/com/helloworld/MainApplication.kt b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt similarity index 88% rename from template/android/app/src/main/java/com/helloworld/MainApplication.kt rename to packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt index 6ca847e0e0b..75193c30424 100644 --- a/template/android/app/src/main/java/com/helloworld/MainApplication.kt +++ b/packages/react-native/template/android/app/src/main/java/com/helloworld/MainApplication.kt @@ -1,3 +1,10 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + package com.helloworld import android.app.Application diff --git a/packages/react-native/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.java b/packages/react-native/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.java deleted file mode 100644 index b5103644047..00000000000 --- a/packages/react-native/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.java +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - *

This source code is licensed under the MIT license found in the LICENSE file in the root - * directory of this source tree. - */ -package com.helloworld; - -import android.content.Context; -import com.facebook.react.ReactInstanceManager; - -/** - * Class responsible of loading Flipper inside your React Native application. This is the release - * flavor of it so it's empty as we don't want to load Flipper. - */ -public class ReactNativeFlipper { - public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { - // Do nothing as we don't want to initialize Flipper on Release. - } -} diff --git a/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.kt b/packages/react-native/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.kt similarity index 90% rename from template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.kt rename to packages/react-native/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.kt index e9b640550e3..486e6cd14f4 100644 --- a/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.kt +++ b/packages/react-native/template/android/app/src/release/java/com/helloworld/ReactNativeFlipper.kt @@ -1,9 +1,10 @@ -/** +/* * Copyright (c) Meta Platforms, Inc. and affiliates. * - * This source code is licensed under the MIT license found in the LICENSE file in the root - * directory of this source tree. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ + package com.helloworld import android.content.Context