From 48bf59c85e12469964ef3faf6a0df72d0fcc7329 Mon Sep 17 00:00:00 2001 From: Nicola Corti Date: Mon, 28 Jul 2025 15:11:35 -0700 Subject: [PATCH] Use `by lazy(LazyThreadSafetyMode.NONE)` for RNTester (#52886) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- .../react/uiapp/RNTesterApplication.kt | 137 +++++++++--------- 1 file changed, 69 insertions(+), 68 deletions(-) diff --git a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt index d3bf047cced..b7eeb1ccbb3 100644 --- a/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt +++ b/packages/rn-tester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.kt @@ -41,82 +41,83 @@ internal class RNTesterApplication : Application(), ReactApplication { @Deprecated( "You should not use ReactNativeHost directly in the New Architecture. Use ReactHost instead.", replaceWith = ReplaceWith("reactHost")) - override val reactNativeHost: ReactNativeHost by lazy { - object : DefaultReactNativeHost(this) { - public override fun getJSMainModuleName(): String = BuildConfig.JS_MAIN_MODULE_NAME + override val reactNativeHost: ReactNativeHost by + lazy(LazyThreadSafetyMode.NONE) { + object : DefaultReactNativeHost(this) { + public override fun getJSMainModuleName(): String = BuildConfig.JS_MAIN_MODULE_NAME - public override fun getBundleAssetName(): String = BuildConfig.BUNDLE_ASSET_NAME + public override fun getBundleAssetName(): String = BuildConfig.BUNDLE_ASSET_NAME - override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG + override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG - public override fun getPackages(): List { - return listOf( - MainReactPackage(), - PopupMenuPackage(), - object : BaseReactPackage() { - override fun getModule( - name: String, - reactContext: ReactApplicationContext - ): NativeModule? = - when { - SampleTurboModule.NAME == name -> SampleTurboModule(reactContext) - SampleLegacyModule.NAME == name -> SampleLegacyModule(reactContext) - else -> null - } + public override fun getPackages(): List { + return listOf( + MainReactPackage(), + PopupMenuPackage(), + object : BaseReactPackage() { + override fun getModule( + name: String, + reactContext: ReactApplicationContext + ): NativeModule? = + when { + SampleTurboModule.NAME == name -> SampleTurboModule(reactContext) + SampleLegacyModule.NAME == name -> SampleLegacyModule(reactContext) + else -> null + } - // Note: Specialized annotation processor for @ReactModule isn't configured in OSS - // yet. For now, hardcode this information, though it's not necessary for most - // modules. - override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = - ReactModuleInfoProvider { - mapOf( - SampleTurboModule.NAME to - ReactModuleInfo( - SampleTurboModule.NAME, - "SampleTurboModule", - canOverrideExistingModule = false, - needsEagerInit = false, - isCxxModule = false, - isTurboModule = true), - SampleLegacyModule.NAME to - ReactModuleInfo( - SampleLegacyModule.NAME, - "SampleLegacyModule", - canOverrideExistingModule = false, - needsEagerInit = false, - isCxxModule = false, - isTurboModule = false)) - } - }, - object : ReactPackage, ViewManagerOnDemandReactPackage { - override fun getViewManagerNames(reactContext: ReactApplicationContext) = - listOf("RNTMyNativeView", "RNTMyLegacyNativeView", "RNTReportFullyDrawnView") + // Note: Specialized annotation processor for @ReactModule isn't configured in OSS + // yet. For now, hardcode this information, though it's not necessary for most + // modules. + override fun getReactModuleInfoProvider(): ReactModuleInfoProvider = + ReactModuleInfoProvider { + mapOf( + SampleTurboModule.NAME to + ReactModuleInfo( + SampleTurboModule.NAME, + "SampleTurboModule", + canOverrideExistingModule = false, + needsEagerInit = false, + isCxxModule = false, + isTurboModule = true), + SampleLegacyModule.NAME to + ReactModuleInfo( + SampleLegacyModule.NAME, + "SampleLegacyModule", + canOverrideExistingModule = false, + needsEagerInit = false, + isCxxModule = false, + isTurboModule = false)) + } + }, + object : ReactPackage, ViewManagerOnDemandReactPackage { + override fun getViewManagerNames(reactContext: ReactApplicationContext) = + listOf("RNTMyNativeView", "RNTMyLegacyNativeView", "RNTReportFullyDrawnView") - override fun createViewManagers( - reactContext: ReactApplicationContext - ): List> = - listOf( - MyNativeViewManager(), - MyLegacyViewManager(reactContext), - ReportFullyDrawnViewManager()) + override fun createViewManagers( + reactContext: ReactApplicationContext + ): List> = + listOf( + MyNativeViewManager(), + MyLegacyViewManager(reactContext), + ReportFullyDrawnViewManager()) - override fun createViewManager( - reactContext: ReactApplicationContext, - viewManagerName: String - ): ViewManager<*, out ReactShadowNode<*>>? = - when (viewManagerName) { - "RNTMyNativeView" -> MyNativeViewManager() - "RNTMyLegacyNativeView" -> MyLegacyViewManager(reactContext) - "RNTReportFullyDrawnView" -> ReportFullyDrawnViewManager() - else -> null - } - }) + override fun createViewManager( + reactContext: ReactApplicationContext, + viewManagerName: String + ): ViewManager<*, out ReactShadowNode<*>>? = + when (viewManagerName) { + "RNTMyNativeView" -> MyNativeViewManager() + "RNTMyLegacyNativeView" -> MyLegacyViewManager(reactContext) + "RNTReportFullyDrawnView" -> ReportFullyDrawnViewManager() + else -> null + } + }) + } + + override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED + } } - override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - } - } - override val reactHost: ReactHost get() = DefaultReactHost.getDefaultReactHost(applicationContext, reactNativeHost)