Skip to content

Commit 48bf59c

Browse files
cortinicofacebook-github-bot
authored andcommitted
Use by lazy(LazyThreadSafetyMode.NONE) for RNTester (#52886)
Summary: Pull Request resolved: #52886 RNTester was using just a plain `by lazy{}` which gets flagged by our internal linter over and over. This fixes it. Changelog: [Internal] [Changed] - Reviewed By: mdvacca Differential Revision: D79094496 fbshipit-source-id: 856864bf8b5e4ec1254d1793dba9e97377696408
1 parent 4718b35 commit 48bf59c

File tree

1 file changed

+75
-74
lines changed

1 file changed

+75
-74
lines changed

packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt

Lines changed: 75 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -41,82 +41,83 @@ internal class RNTesterApplication : Application(), ReactApplication {
4141
@Deprecated(
4242
"You should not use ReactNativeHost directly in the New Architecture. Use ReactHost instead.",
4343
replaceWith = ReplaceWith("reactHost"))
44-
override val reactNativeHost: ReactNativeHost by lazy {
45-
object : DefaultReactNativeHost(this) {
46-
public override fun getJSMainModuleName(): String = BuildConfig.JS_MAIN_MODULE_NAME
47-
48-
public override fun getBundleAssetName(): String = BuildConfig.BUNDLE_ASSET_NAME
49-
50-
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
51-
52-
public override fun getPackages(): List<ReactPackage> {
53-
return listOf(
54-
MainReactPackage(),
55-
PopupMenuPackage(),
56-
object : BaseReactPackage() {
57-
override fun getModule(
58-
name: String,
59-
reactContext: ReactApplicationContext
60-
): NativeModule? =
61-
when {
62-
SampleTurboModule.NAME == name -> SampleTurboModule(reactContext)
63-
SampleLegacyModule.NAME == name -> SampleLegacyModule(reactContext)
64-
else -> null
65-
}
66-
67-
// Note: Specialized annotation processor for @ReactModule isn't configured in OSS
68-
// yet. For now, hardcode this information, though it's not necessary for most
69-
// modules.
70-
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider =
71-
ReactModuleInfoProvider {
72-
mapOf(
73-
SampleTurboModule.NAME to
74-
ReactModuleInfo(
75-
SampleTurboModule.NAME,
76-
"SampleTurboModule",
77-
canOverrideExistingModule = false,
78-
needsEagerInit = false,
79-
isCxxModule = false,
80-
isTurboModule = true),
81-
SampleLegacyModule.NAME to
82-
ReactModuleInfo(
83-
SampleLegacyModule.NAME,
84-
"SampleLegacyModule",
85-
canOverrideExistingModule = false,
86-
needsEagerInit = false,
87-
isCxxModule = false,
88-
isTurboModule = false))
89-
}
90-
},
91-
object : ReactPackage, ViewManagerOnDemandReactPackage {
92-
override fun getViewManagerNames(reactContext: ReactApplicationContext) =
93-
listOf("RNTMyNativeView", "RNTMyLegacyNativeView", "RNTReportFullyDrawnView")
94-
95-
override fun createViewManagers(
96-
reactContext: ReactApplicationContext
97-
): List<ViewManager<*, *>> =
98-
listOf(
99-
MyNativeViewManager(),
100-
MyLegacyViewManager(reactContext),
101-
ReportFullyDrawnViewManager())
102-
103-
override fun createViewManager(
104-
reactContext: ReactApplicationContext,
105-
viewManagerName: String
106-
): ViewManager<*, out ReactShadowNode<*>>? =
107-
when (viewManagerName) {
108-
"RNTMyNativeView" -> MyNativeViewManager()
109-
"RNTMyLegacyNativeView" -> MyLegacyViewManager(reactContext)
110-
"RNTReportFullyDrawnView" -> ReportFullyDrawnViewManager()
111-
else -> null
112-
}
113-
})
44+
override val reactNativeHost: ReactNativeHost by
45+
lazy(LazyThreadSafetyMode.NONE) {
46+
object : DefaultReactNativeHost(this) {
47+
public override fun getJSMainModuleName(): String = BuildConfig.JS_MAIN_MODULE_NAME
48+
49+
public override fun getBundleAssetName(): String = BuildConfig.BUNDLE_ASSET_NAME
50+
51+
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
52+
53+
public override fun getPackages(): List<ReactPackage> {
54+
return listOf(
55+
MainReactPackage(),
56+
PopupMenuPackage(),
57+
object : BaseReactPackage() {
58+
override fun getModule(
59+
name: String,
60+
reactContext: ReactApplicationContext
61+
): NativeModule? =
62+
when {
63+
SampleTurboModule.NAME == name -> SampleTurboModule(reactContext)
64+
SampleLegacyModule.NAME == name -> SampleLegacyModule(reactContext)
65+
else -> null
66+
}
67+
68+
// Note: Specialized annotation processor for @ReactModule isn't configured in OSS
69+
// yet. For now, hardcode this information, though it's not necessary for most
70+
// modules.
71+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider =
72+
ReactModuleInfoProvider {
73+
mapOf(
74+
SampleTurboModule.NAME to
75+
ReactModuleInfo(
76+
SampleTurboModule.NAME,
77+
"SampleTurboModule",
78+
canOverrideExistingModule = false,
79+
needsEagerInit = false,
80+
isCxxModule = false,
81+
isTurboModule = true),
82+
SampleLegacyModule.NAME to
83+
ReactModuleInfo(
84+
SampleLegacyModule.NAME,
85+
"SampleLegacyModule",
86+
canOverrideExistingModule = false,
87+
needsEagerInit = false,
88+
isCxxModule = false,
89+
isTurboModule = false))
90+
}
91+
},
92+
object : ReactPackage, ViewManagerOnDemandReactPackage {
93+
override fun getViewManagerNames(reactContext: ReactApplicationContext) =
94+
listOf("RNTMyNativeView", "RNTMyLegacyNativeView", "RNTReportFullyDrawnView")
95+
96+
override fun createViewManagers(
97+
reactContext: ReactApplicationContext
98+
): List<ViewManager<*, *>> =
99+
listOf(
100+
MyNativeViewManager(),
101+
MyLegacyViewManager(reactContext),
102+
ReportFullyDrawnViewManager())
103+
104+
override fun createViewManager(
105+
reactContext: ReactApplicationContext,
106+
viewManagerName: String
107+
): ViewManager<*, out ReactShadowNode<*>>? =
108+
when (viewManagerName) {
109+
"RNTMyNativeView" -> MyNativeViewManager()
110+
"RNTMyLegacyNativeView" -> MyLegacyViewManager(reactContext)
111+
"RNTReportFullyDrawnView" -> ReportFullyDrawnViewManager()
112+
else -> null
113+
}
114+
})
115+
}
116+
117+
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
118+
}
114119
}
115120

116-
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
117-
}
118-
}
119-
120121
override val reactHost: ReactHost
121122
get() = DefaultReactHost.getDefaultReactHost(applicationContext, reactNativeHost)
122123

0 commit comments

Comments
 (0)