Skip to content

Commit 7df29cd

Browse files
cortinicofacebook-github-bot
authored andcommitted
Move from from accidental template/ folder on root. (#36704)
Summary: Pull Request resolved: facebook/react-native#36704 Following up to #36696, I accidentally failed a rebase and had files commited on the wrong folder. I'm updating them here to use `packages/react-native/template`. Changelog: [Internal] [Changed] - Move from from accidental template/ folder on root Reviewed By: cipolleschi Differential Revision: D44502966 fbshipit-source-id: d408f38884444c4ecc03852b1d145bf2e89df672 Original-Commit: facebook/react-native@688df2f
1 parent eca4f65 commit 7df29cd

File tree

4 files changed

+157
-0
lines changed

4 files changed

+157
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.helloworld
9+
10+
import android.content.Context
11+
import com.facebook.flipper.android.AndroidFlipperClient
12+
import com.facebook.flipper.android.utils.FlipperUtils
13+
import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin
14+
import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin
15+
import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin
16+
import com.facebook.flipper.plugins.inspector.DescriptorMapping
17+
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin
18+
import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor
19+
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin
20+
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin
21+
import com.facebook.react.ReactInstanceEventListener
22+
import com.facebook.react.ReactInstanceManager
23+
import com.facebook.react.bridge.ReactContext
24+
import com.facebook.react.modules.network.NetworkingModule
25+
26+
/**
27+
* Class responsible of loading Flipper inside your React Native application. This is the debug
28+
* flavor of it. Here you can add your own plugins and customize the Flipper setup.
29+
*/
30+
object ReactNativeFlipper {
31+
fun initializeFlipper(context: Context, reactInstanceManager: ReactInstanceManager) {
32+
if (FlipperUtils.shouldEnableFlipper(context)) {
33+
val client = AndroidFlipperClient.getInstance(context)
34+
client.addPlugin(InspectorFlipperPlugin(context, DescriptorMapping.withDefaults()))
35+
client.addPlugin(DatabasesFlipperPlugin(context))
36+
client.addPlugin(SharedPreferencesFlipperPlugin(context))
37+
client.addPlugin(CrashReporterPlugin.getInstance())
38+
val networkFlipperPlugin = NetworkFlipperPlugin()
39+
NetworkingModule.setCustomClientBuilder { builder ->
40+
builder.addNetworkInterceptor(FlipperOkhttpInterceptor(networkFlipperPlugin))
41+
}
42+
client.addPlugin(networkFlipperPlugin)
43+
client.start()
44+
45+
// Fresco Plugin needs to ensure that ImagePipelineFactory is initialized
46+
// Hence we run if after all native modules have been initialized
47+
val currentReactContext = reactInstanceManager.currentReactContext
48+
if (currentReactContext == null) {
49+
reactInstanceManager.addReactInstanceEventListener(
50+
object : ReactInstanceEventListener {
51+
override fun onReactContextInitialized(context: ReactContext) {
52+
reactInstanceManager.removeReactInstanceEventListener(this)
53+
context.runOnNativeModulesQueueThread { client.addPlugin(FrescoFlipperPlugin()) }
54+
}
55+
})
56+
} else {
57+
client.addPlugin(FrescoFlipperPlugin())
58+
}
59+
}
60+
}
61+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.helloworld
9+
10+
import com.facebook.react.ReactActivity
11+
import com.facebook.react.ReactActivityDelegate
12+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
13+
import com.facebook.react.defaults.DefaultReactActivityDelegate
14+
15+
class MainActivity : ReactActivity() {
16+
17+
/**
18+
* Returns the name of the main component registered from JavaScript. This is used to schedule
19+
* rendering of the component.
20+
*/
21+
override fun getMainComponentName(): String = "HelloWorld"
22+
23+
/**
24+
* Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
25+
* which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
26+
*/
27+
override fun createReactActivityDelegate(): ReactActivityDelegate =
28+
DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.helloworld
9+
10+
import android.app.Application
11+
import com.facebook.react.PackageList
12+
import com.facebook.react.ReactApplication
13+
import com.facebook.react.ReactNativeHost
14+
import com.facebook.react.ReactPackage
15+
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
16+
import com.facebook.react.defaults.DefaultReactNativeHost
17+
import com.facebook.soloader.SoLoader
18+
19+
class MainApplication : Application(), ReactApplication {
20+
21+
private val reactNativeHost: ReactNativeHost =
22+
object : DefaultReactNativeHost(this) {
23+
override fun getPackages(): List<ReactPackage> {
24+
// Packages that cannot be autolinked yet can be added manually here, for example:
25+
// packages.add(new MyReactNativePackage());
26+
return PackageList(this).packages
27+
}
28+
override fun getJSMainModuleName(): String = "index"
29+
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
30+
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
31+
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
32+
}
33+
34+
override fun getReactNativeHost(): ReactNativeHost = reactNativeHost
35+
36+
override fun onCreate() {
37+
super.onCreate()
38+
SoLoader.init(this, false)
39+
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
40+
// If you opted-in for the New Architecture, we load the native entry point for this app.
41+
load()
42+
}
43+
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
44+
}
45+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.helloworld
9+
10+
import android.content.Context
11+
import com.facebook.react.ReactInstanceManager
12+
13+
/**
14+
* Class responsible of loading Flipper inside your React Native application. This is the release
15+
* flavor of it so it's empty as we don't want to load Flipper.
16+
*/
17+
object ReactNativeFlipper {
18+
@Suppress("UNUSED_PARAMETER")
19+
fun initializeFlipper(context: Context, reactInstanceManager: ReactInstanceManager) {
20+
// Do nothing as we don't want to initialize Flipper on Release.
21+
}
22+
}

0 commit comments

Comments
 (0)