Skip to content

Commit 04d84f8

Browse files
committed
Fix measureInWindow on Android
1 parent 27a6185 commit 04d84f8

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import com.facebook.react.uimanager.JSKeyDispatcher
2727
import com.facebook.react.uimanager.JSPointerDispatcher
2828
import com.facebook.react.uimanager.JSTouchDispatcher
2929
import com.facebook.react.uimanager.common.UIManagerType
30+
import com.facebook.react.views.view.isEdgeToEdge
3031
import com.facebook.systrace.Systrace
3132
import java.util.Objects
3233
import kotlin.math.max
@@ -47,16 +48,19 @@ public class ReactSurfaceView(context: Context?, private val surface: ReactSurfa
4748

4849
private val viewportOffset: Point
4950
get() {
50-
val locationOnScreen = IntArray(2)
51-
getLocationOnScreen(locationOnScreen)
51+
val locationInWindow = IntArray(2)
52+
getLocationInWindow(locationInWindow)
5253

53-
// we need to subtract visibleWindowCoords - to subtract possible window insets, split
54-
// screen or multi window
55-
val visibleWindowFrame = Rect()
56-
getWindowVisibleDisplayFrame(visibleWindowFrame)
57-
locationOnScreen[0] -= visibleWindowFrame.left
58-
locationOnScreen[1] -= visibleWindowFrame.top
59-
return Point(locationOnScreen[0], locationOnScreen[1])
54+
if (!isEdgeToEdge) {
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
61+
}
62+
63+
return Point(locationInWindow[0], locationInWindow[1])
6064
}
6165

6266
init {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/RootViewUtil.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import android.graphics.Rect
1212
import android.view.View
1313
import androidx.annotation.UiThread
1414
import com.facebook.infer.annotation.Assertions
15+
import com.facebook.react.views.view.isEdgeToEdge
1516

1617
public object RootViewUtil {
1718
/** Returns the root view of a given view in a react application. */
@@ -34,12 +35,15 @@ public object RootViewUtil {
3435
val locationInWindow = IntArray(2)
3536
v.getLocationInWindow(locationInWindow)
3637

37-
// we need to subtract visibleWindowCoords - to subtract possible window insets, split
38-
// screen or multi window
39-
val visibleWindowFrame = Rect()
40-
v.getWindowVisibleDisplayFrame(visibleWindowFrame)
41-
locationInWindow[0] -= visibleWindowFrame.left
42-
locationInWindow[1] -= visibleWindowFrame.top
38+
if (!isEdgeToEdge) {
39+
// When not in edge-to-edge mode, subtract the visible window frame to get the offset
40+
// relative to the content area (below the status bar).
41+
val visibleWindowFrame = Rect()
42+
v.getWindowVisibleDisplayFrame(visibleWindowFrame)
43+
locationInWindow[0] -= visibleWindowFrame.left
44+
locationInWindow[1] -= visibleWindowFrame.top
45+
}
46+
4347
return Point(locationInWindow[0], locationInWindow[1])
4448
}
4549
}

0 commit comments

Comments
 (0)