Skip to content

Commit d0ea897

Browse files
committed
Use locationInWindow
1 parent be7ec70 commit d0ea897

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactSurfaceView.kt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,24 @@ public class ReactSurfaceView(context: Context?, internal val surface: ReactSurf
5050

5151
private val viewportOffset: Point
5252
get() {
53-
val locationOnScreen = IntArray(2)
54-
getLocationOnScreen(locationOnScreen)
53+
val locationInWindow = IntArray(2)
54+
getLocationInWindow(locationInWindow)
5555

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.
56+
if (!isEdgeToEdgeFeatureFlagOn) {
57+
// When not in edge-to-edge mode, subtract the top system bar insets so the offset is
58+
// relative to the content area (below the status bar / cutout).
6659
ViewCompat.getRootWindowInsets(this)?.apply {
6760
val insets =
6861
getInsets(
6962
WindowInsetsCompat.Type.statusBars() or WindowInsetsCompat.Type.displayCutout()
7063
)
7164

72-
locationOnScreen[0] += insets.left
73-
locationOnScreen[1] += insets.top
65+
locationInWindow[0] -= insets.left
66+
locationInWindow[1] -= insets.top
7467
}
7568
}
7669

77-
return Point(locationOnScreen[0], locationOnScreen[1])
70+
return Point(locationInWindow[0], locationInWindow[1])
7871
}
7972

8073
init {

0 commit comments

Comments
 (0)