@@ -3,12 +3,14 @@ package com.multiplemodals
33import android.view.ViewGroup
44import com.facebook.react.bridge.WritableMap
55import com.facebook.react.bridge.WritableNativeMap
6+ import com.facebook.react.uimanager.PixelUtil
67import com.facebook.react.uimanager.ReactStylesDiffMap
78import com.facebook.react.uimanager.StateWrapper
89import com.facebook.react.uimanager.ViewGroupManager
910import com.facebook.react.uimanager.ViewManagerDelegate
1011import com.facebook.react.viewmanagers.RNTModalViewManagerDelegate
1112import com.facebook.react.viewmanagers.RNTModalViewManagerInterface
13+ import com.multiplemodals.library.ModalHostHelper
1214import com.multiplemodals.library.OnSizeComputedListener
1315import kotlin.math.roundToInt
1416
@@ -19,6 +21,15 @@ abstract class RNTModalViewManagerSpec<T : ViewGroup> : ViewGroupManager<T>(), R
1921 return mDelegate
2022 }
2123
24+ private fun computeViewSize (view : RNTModalView ) {
25+ val modalSize = ModalHostHelper .getModalHostSize(view.context)
26+
27+ view.onSizeComputedListener?.onSizeComputed(
28+ modalSize.x,
29+ modalSize.y,
30+ )
31+ }
32+
2233 override fun updateState (
2334 view : T ,
2435 props : ReactStylesDiffMap ,
@@ -34,20 +45,20 @@ abstract class RNTModalViewManagerSpec<T : ViewGroup> : ViewGroupManager<T>(), R
3445 }
3546 }
3647
37- view.onSizeComputedListener = OnSizeComputedListener { _, widthDip, heightDip ->
38- val nextWidthDip = widthDip .roundToInt()
39- val nextHeightDip = heightDip .roundToInt()
48+ view.onSizeComputedListener = OnSizeComputedListener { widthPx, heightPx ->
49+ val nextWidthDip = PixelUtil .toDIPFromPixel(widthPx.toFloat()) .roundToInt()
50+ val nextHeightDip = PixelUtil .toDIPFromPixel(heightPx.toFloat()) .roundToInt()
4051
4152 // Comparing props prevents infinite update cycle
4253 if (currentWidthDip != nextWidthDip || currentHeightDip != nextHeightDip) {
4354 val newStateData: WritableMap = WritableNativeMap ()
44- newStateData.putDouble(" screenWidth" , widthDip .toDouble())
45- newStateData.putDouble(" screenHeight" , heightDip .toDouble())
55+ newStateData.putDouble(" screenWidth" , nextWidthDip .toDouble())
56+ newStateData.putDouble(" screenHeight" , nextHeightDip .toDouble())
4657 stateWrapper.updateState(newStateData)
4758 }
4859 }
4960
50- view.requestViewSizeComputation( )
61+ computeViewSize(view )
5162 view.show()
5263 }
5364
0 commit comments