Skip to content

Commit e48a27c

Browse files
committed
fix(mobile): patch react-native-screens 4.19.0 to fix Android header inset
react-native-screens 4.19.0 (PR #3240) changed CustomToolbar to use ancestor-propagated insets instead of rootWindowInsets. This conflicts with react-native-keyboard-controller's rootView inset listener, which modifies insets before they reach the toolbar, causing the Android header to be too short (missing status bar height). Apply upstream fix from software-mansion/react-native-screens#3500: read the top inset directly from the DecorView instead of relying on ancestor-propagated insets which may have been consumed earlier. This patch can be removed once #3500 is merged and released upstream.
1 parent cc2d9ad commit e48a27c

3 files changed

Lines changed: 78 additions & 18 deletions

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"pnpm": {
4040
"patchedDependencies": {
4141
"xcode@3.0.1": "patches/xcode@3.0.1.patch",
42-
"playwright-extra@4.3.6": "patches/playwright-extra@4.3.6.patch"
42+
"playwright-extra@4.3.6": "patches/playwright-extra@4.3.6.patch",
43+
"react-native-screens@4.19.0": "patches/react-native-screens@4.19.0.patch"
4344
}
4445
}
4546
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
diff --git a/android/src/main/java/com/swmansion/rnscreens/CustomToolbar.kt b/android/src/main/java/com/swmansion/rnscreens/CustomToolbar.kt
2+
index 0ecc2fc36e20daf13b3ca1be077bbc476d6cf814..97bc6188e0aa57bbc0934b5080f7a929e0aa5c92 100644
3+
--- a/android/src/main/java/com/swmansion/rnscreens/CustomToolbar.kt
4+
+++ b/android/src/main/java/com/swmansion/rnscreens/CustomToolbar.kt
5+
@@ -4,13 +4,16 @@ import android.annotation.SuppressLint
6+
import android.content.Context
7+
import android.os.Build
8+
import android.view.Choreographer
9+
+import android.view.View
10+
import android.view.WindowInsets
11+
import android.view.WindowManager
12+
import androidx.appcompat.widget.Toolbar
13+
import androidx.core.view.WindowInsetsCompat
14+
+import com.facebook.react.bridge.ReactContext
15+
import com.facebook.react.modules.core.ReactChoreographer
16+
import com.facebook.react.uimanager.ThemedReactContext
17+
import com.swmansion.rnscreens.utils.InsetsCompat
18+
+import com.swmansion.rnscreens.utils.getDecorViewTopInset
19+
import com.swmansion.rnscreens.utils.resolveInsetsOrZero
20+
import kotlin.math.max
21+
22+
@@ -139,13 +142,33 @@ open class CustomToolbar(
23+
0,
24+
)
25+
26+
+ var maybeTopLevelDecorView: View? = null
27+
+ if (context is ReactContext) {
28+
+ val reactContext = context as ReactContext
29+
+ maybeTopLevelDecorView =
30+
+ requireNotNull(
31+
+ reactContext.currentActivity?.window?.decorView,
32+
+ ) { "[RNScreens] DecorView is required for applying inset correction, but was null." }
33+
+ }
34+
+
35+
+ // The top inset from DecorView is currently used in both Screen and ScreenDummyLayoutHelper
36+
+ // to manually apply layout adjustments. To ensure consistent behavior between Screen and Toolbar,
37+
+ // we should preferably handle the top inset here. Relying on unhandledInsets may be unreliable,
38+
+ // as they could already have been consumed earlier in the layout process.
39+
+ val topInset =
40+
+ if (maybeTopLevelDecorView != null) {
41+
+ getDecorViewTopInset(maybeTopLevelDecorView)
42+
+ } else {
43+
+ max(cutoutInsets.top, if (shouldApplyTopInset) systemBarInsets.top else 0)
44+
+ }
45+
+
46+
// We want to handle display cutout always, no matter the HeaderConfig prop values.
47+
// If there are no cutout displays, we want to apply the additional padding to
48+
// respect the status bar.
49+
val verticalInsets =
50+
InsetsCompat.of(
51+
0,
52+
- max(cutoutInsets.top, if (shouldApplyTopInset) systemBarInsets.top else 0),
53+
+ topInset,
54+
0,
55+
max(cutoutInsets.bottom, 0),
56+
)

pnpm-lock.yaml

Lines changed: 20 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)