Fix new arch example not render in RNTester (#39810)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39810 Two issues will be fixed: - Bridgeless has lazy view manager loading by default so the React Package that provides view managers must implement ViewManagerOnDemandReactPackage, we might could refactor the design of package classes later - ThemedReactContext should **NOT** be used directly to call function ```getJSModule```, since it doesn't overrides ```getJSModule``` for Bridgeless, we can use it's internal variable ```meactApplicationContext``` which should be an instance of BridgelessReactContext Reviewed By: cortinico Differential Revision: D49912656 fbshipit-source-id: a0bdd717612398e8d7a6f36d36dba241a3b06bd7
This commit is contained in:
Родитель
9fee99040d
Коммит
48dcfa1718
|
@ -14,6 +14,7 @@ import com.facebook.react.JSEngineResolutionAlgorithm
|
|||
import com.facebook.react.ReactPackage
|
||||
import com.facebook.react.ReactPackageTurboModuleManagerDelegate
|
||||
import com.facebook.react.TurboReactPackage
|
||||
import com.facebook.react.ViewManagerOnDemandReactPackage
|
||||
import com.facebook.react.bridge.JSBundleLoader
|
||||
import com.facebook.react.bridge.NativeModule
|
||||
import com.facebook.react.bridge.ReactApplicationContext
|
||||
|
@ -108,7 +109,7 @@ class RNTesterReactHostDelegate internal constructor(context: Context) : ReactHo
|
|||
}
|
||||
}
|
||||
},
|
||||
object : ReactPackage {
|
||||
object : ViewManagerOnDemandReactPackage, ReactPackage {
|
||||
override fun createNativeModules(
|
||||
reactContext: ReactApplicationContext
|
||||
): List<NativeModule> = emptyList()
|
||||
|
@ -117,6 +118,22 @@ class RNTesterReactHostDelegate internal constructor(context: Context) : ReactHo
|
|||
reactContext: ReactApplicationContext
|
||||
): List<ViewManager<*, *>> =
|
||||
listOf(MyNativeViewManager(), MyLegacyViewManager(reactContext))
|
||||
|
||||
override fun getViewManagerNames(
|
||||
reactContext: ReactApplicationContext
|
||||
): Collection<String> =
|
||||
listOf(MyNativeViewManager.REACT_CLASS, MyLegacyViewManager.REACT_CLASS)
|
||||
|
||||
override fun createViewManager(
|
||||
reactContext: ReactApplicationContext,
|
||||
viewManagerName: String
|
||||
): ViewManager<*, *>? {
|
||||
return when (viewManagerName) {
|
||||
MyNativeViewManager.REACT_CLASS -> MyNativeViewManager()
|
||||
MyLegacyViewManager.REACT_CLASS -> MyLegacyViewManager(reactContext)
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ internal class MyLegacyViewManager(reactContext: ReactApplicationContext) :
|
|||
|
||||
override fun getName(): String = REACT_CLASS
|
||||
|
||||
override fun createViewInstance(reactContext: ThemedReactContext): MyNativeView =
|
||||
MyNativeView(reactContext).apply { setBackgroundColor(Color.RED) }
|
||||
override fun createViewInstance(themedReactContext: ThemedReactContext): MyNativeView =
|
||||
MyNativeView(themedReactContext).apply { setBackgroundColor(Color.RED) }
|
||||
|
||||
@ReactProp(name = ViewProps.OPACITY, defaultFloat = 1f)
|
||||
override fun setOpacity(view: MyNativeView, opacity: Float) {
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
|
||||
package com.facebook.react.uiapp.component
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.GradientDrawable
|
||||
import android.view.View
|
||||
|
@ -15,13 +14,15 @@ import com.facebook.react.bridge.Arguments
|
|||
import com.facebook.react.bridge.ReactContext
|
||||
import com.facebook.react.bridge.WritableArray
|
||||
import com.facebook.react.bridge.WritableMap
|
||||
import com.facebook.react.uimanager.ThemedReactContext
|
||||
import com.facebook.react.uimanager.UIManagerHelper
|
||||
import com.facebook.react.uimanager.events.Event
|
||||
import com.facebook.react.uimanager.events.RCTEventEmitter
|
||||
|
||||
class MyNativeView(context: Context) : View(context) {
|
||||
class MyNativeView(context: ThemedReactContext) : View(context) {
|
||||
private var currentColor = 0
|
||||
private var background: GradientDrawable = GradientDrawable()
|
||||
private var reactContext: ReactContext = context.getReactApplicationContext()
|
||||
|
||||
override fun setBackgroundColor(color: Int) {
|
||||
if (color != currentColor) {
|
||||
|
@ -51,7 +52,6 @@ class MyNativeView(context: Context) : View(context) {
|
|||
Color.colorToHSV(color, hsv)
|
||||
event.putMap("backgroundColor", backgroundColor)
|
||||
|
||||
val reactContext = context as ReactContext
|
||||
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, "onColorChanged", event)
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче