Skip to content

Commit

Permalink
feat: migrate to StateWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
WoLewicki committed Jun 27, 2024
1 parent 7dfed31 commit 536b096
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ import androidx.annotation.UiThread
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.WritableMap
import com.facebook.react.bridge.WritableNativeMap
import com.facebook.react.uimanager.FabricViewStateManager
import com.facebook.react.uimanager.PixelUtil
import com.facebook.react.uimanager.StateWrapper
import kotlin.math.abs

abstract class FabricEnabledViewGroup constructor(
abstract class FabricEnabledViewGroup(
context: ReactContext?,
) : ViewGroup(context),
FabricViewStateManager.HasFabricViewStateManager {
private val mFabricViewStateManager: FabricViewStateManager = FabricViewStateManager()
) : ViewGroup(context) {
private var mStateWrapper: StateWrapper? = null

private var lastSetWidth = 0f
private var lastSetHeight = 0f

override fun getFabricViewStateManager(): FabricViewStateManager = mFabricViewStateManager
fun setStateWrapper(wrapper: StateWrapper?) {
mStateWrapper = wrapper
}

protected fun updateScreenSizeFabric(
width: Int,
Expand Down Expand Up @@ -48,14 +49,11 @@ abstract class FabricEnabledViewGroup constructor(

lastSetWidth = realWidth
lastSetHeight = realHeight

mFabricViewStateManager.setState {
val map: WritableMap = WritableNativeMap()
map.putDouble("frameWidth", realWidth.toDouble())
map.putDouble("frameHeight", realHeight.toDouble())
map.putDouble("contentOffsetX", 0.0)
map.putDouble("contentOffsetY", headerHeight)
map
}
val map: WritableMap = WritableNativeMap()
map.putDouble("frameWidth", realWidth.toDouble())
map.putDouble("frameHeight", realHeight.toDouble())
map.putDouble("contentOffsetX", 0.0)
map.putDouble("contentOffsetY", headerHeight)
mStateWrapper?.updateState(map)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ open class ScreenViewManager :
): Any? {
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// fabricViewStateManager should never be null in Fabric. The null check is only for Paper's empty impl.
view.fabricViewStateManager?.setStateWrapper(stateWrapper)
view.setStateWrapper(stateWrapper)
}
return super.updateState(view, props, stateWrapper)
}
Expand Down

0 comments on commit 536b096

Please sign in to comment.