Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,7 +109,7 @@ class RNTesterReactHostDelegate internal constructor(context: Context) : ReactHo
}
}
},
object : ReactPackage {
object : ViewManagerOnDemandReactPackage, ReactPackage {
override fun createNativeModules(
reactContext: ReactApplicationContext
): List<NativeModule> = emptyList()
Expand All @@ -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
}
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@

package com.facebook.react.uiapp.component

import android.content.Context
import android.graphics.Color
import android.graphics.drawable.GradientDrawable
import android.view.View
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) {
Expand Down Expand Up @@ -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)
}

Expand Down