@@ -15,6 +15,8 @@ import android.graphics.Rect
1515import android.view.KeyEvent
1616import android.view.MotionEvent
1717import android.view.View
18+ import androidx.core.view.ViewCompat
19+ import androidx.core.view.WindowInsetsCompat
1820import com.facebook.common.logging.FLog
1921import com.facebook.react.ReactRootView
2022import com.facebook.react.bridge.ReactContext
@@ -48,19 +50,31 @@ public class ReactSurfaceView(context: Context?, internal val surface: ReactSurf
4850
4951 private val viewportOffset: Point
5052 get() {
51- val locationInWindow = IntArray (2 )
52- getLocationInWindow(locationInWindow )
53+ val locationOnScreen = IntArray (2 )
54+ getLocationOnScreen(locationOnScreen )
5355
54- if (! isEdgeToEdgeFeatureFlagOn) {
55- // When not in edge-to-edge mode, subtract the visible window frame to get the offset
56- // relative to the content area (below the status bar).
57- val visibleWindowFrame = Rect ()
58- getWindowVisibleDisplayFrame(visibleWindowFrame)
59- locationInWindow[0 ] - = visibleWindowFrame.left
60- locationInWindow[1 ] - = visibleWindowFrame.top
56+ // we need to subtract visibleWindowCoords - to subtract possible window insets, split
57+ // screen or multi window
58+ val visibleWindowFrame = Rect ()
59+ getWindowVisibleDisplayFrame(visibleWindowFrame)
60+ locationOnScreen[0 ] - = visibleWindowFrame.left
61+ locationOnScreen[1 ] - = visibleWindowFrame.top
62+
63+ if (isEdgeToEdgeFeatureFlagOn) {
64+ // In edge-to-edge mode the viewport spans the full window, so add the top system bar
65+ // insets back to convert the content-area offset above into a window-relative offset.
66+ ViewCompat .getRootWindowInsets(this )?.apply {
67+ val insets =
68+ getInsets(
69+ WindowInsetsCompat .Type .statusBars() or WindowInsetsCompat .Type .displayCutout()
70+ )
71+
72+ locationOnScreen[0 ] + = insets.left
73+ locationOnScreen[1 ] + = insets.top
74+ }
6175 }
6276
63- return Point (locationInWindow [0 ], locationInWindow [1 ])
77+ return Point (locationOnScreen [0 ], locationOnScreen [1 ])
6478 }
6579
6680 init {
0 commit comments