Skip to content

Commit 6915cc9

Browse files
zoontekbartlomiejbloniarz
authored andcommitted
feature: Detect edge-to-edge and set isStatusBarTranslucentAndroid / isNavigationBarTranslucentAndroid (#6732)
## Summary Similar to [the PR](software-mansion/react-native-screens#2464) I opened on the `react-native-screens` repository (I highly recommend to read the discussion there to understand the motivation behind this), this PR detects if the user enabled edge-to-edge and act accordingly: `useAnimatedKeyboard` are ignored, set to `true` automatically. If those are set, a warning is logged: > `isStatusBarTranslucentAndroid` and `isNavigationBarTranslucentAndroid` values are ignored when `using react-native-edge-to-edge` It at some point [this proposal](facebook/react-native#47554) lands in core, `react-native-is-edge-to-edge` will be updated to support both the library and the core edge-to-edge flag, making the transition seamless for the users. ## Test plan - Install [react-native-edge-to-edge](https://github.com/zoontek/react-native-edge-to-edge) in the example app. - Don't set `isStatusBarTranslucentAndroid` / `isNavigationBarTranslucentAndroid`, or set them to something else than `true` --------- Co-authored-by: Bartłomiej Błoniarz <bartlomiej.bloniarz@swmansion.com>
1 parent 117655b commit 6915cc9

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

packages/react-native-reanimated/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
"@babel/plugin-transform-unicode-regex": "^7.0.0-0",
9090
"@babel/preset-typescript": "^7.16.7",
9191
"convert-source-map": "^2.0.0",
92-
"invariant": "^2.2.4"
92+
"invariant": "^2.2.4",
93+
"react-native-is-edge-to-edge": "1.1.6"
9394
},
9495
"peerDependencies": {
9596
"@babel/core": "^7.0.0-0",

packages/react-native-reanimated/src/core.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
'use strict';
2+
import {
3+
controlEdgeToEdgeValues,
4+
isEdgeToEdge,
5+
} from 'react-native-is-edge-to-edge';
6+
27
import type {
38
AnimatedKeyboardOptions,
49
LayoutAnimationBatchItem,
@@ -23,6 +28,7 @@ export { createWorkletRuntime, runOnRuntime } from './runtimes';
2328
export { makeShareable, makeShareableCloneRecursive } from './shareables';
2429
export { executeOnUIRuntimeSync, runOnJS, runOnUI } from './threads';
2530

31+
const EDGE_TO_EDGE = isEdgeToEdge();
2632
const SHOULD_BE_USE_WEB = shouldBeUseWeb();
2733

2834
/** @returns `true` in Reanimated 3, doesn't exist in Reanimated 2 or 1 */
@@ -112,12 +118,21 @@ export function subscribeForKeyboardEvents(
112118
global.__flushAnimationFrame(now);
113119
global.__frameTimestamp = undefined;
114120
}
121+
122+
if (__DEV__) {
123+
controlEdgeToEdgeValues({
124+
isStatusBarTranslucentAndroid: options.isStatusBarTranslucentAndroid,
125+
isNavigationBarTranslucentAndroid:
126+
options.isNavigationBarTranslucentAndroid,
127+
});
128+
}
129+
115130
return ReanimatedModule.subscribeForKeyboardEvents(
116131
makeShareableCloneRecursive(
117132
handleAndFlushAnimationFrame as WorkletFunction
118133
),
119-
options.isStatusBarTranslucentAndroid ?? false,
120-
options.isNavigationBarTranslucentAndroid ?? false
134+
EDGE_TO_EDGE || (options.isStatusBarTranslucentAndroid ?? false),
135+
EDGE_TO_EDGE || (options.isNavigationBarTranslucentAndroid ?? false)
121136
);
122137
}
123138

packages/react-native-reanimated/src/hook/useAnimatedKeyboard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import {
2222
*/
2323
export function useAnimatedKeyboard(
2424
options: AnimatedKeyboardOptions = {
25-
isStatusBarTranslucentAndroid: false,
26-
isNavigationBarTranslucentAndroid: false,
25+
isStatusBarTranslucentAndroid: undefined,
26+
isNavigationBarTranslucentAndroid: undefined,
2727
}
2828
): AnimatedKeyboardInfo {
2929
const ref = useRef<AnimatedKeyboardInfo | null>(null);

yarn.lock

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17591,6 +17591,16 @@ __metadata:
1759117591
languageName: node
1759217592
linkType: hard
1759317593

17594+
"react-native-is-edge-to-edge@npm:1.1.6":
17595+
version: 1.1.6
17596+
resolution: "react-native-is-edge-to-edge@npm:1.1.6"
17597+
peerDependencies:
17598+
react: ">=18.2.0"
17599+
react-native: ">=0.73.0"
17600+
checksum: 10/4e07c1e34c01c8d50fd7c1d0460db06f6f0515197405230386a8ffb950cb724b10743af032310d1384df0a90059bfb8992ba2d93344ce86315315f0493feccc2
17601+
languageName: node
17602+
linkType: hard
17603+
1759417604
"react-native-macos@npm:^0.75.13":
1759517605
version: 0.75.16
1759617606
resolution: "react-native-macos@npm:0.75.16"
@@ -17736,6 +17746,7 @@ __metadata:
1773617746
react-native: "npm:0.77.0"
1773717747
react-native-builder-bob: "npm:0.33.1"
1773817748
react-native-gesture-handler: "npm:2.22.0"
17749+
react-native-is-edge-to-edge: "npm:1.1.6"
1773917750
react-native-web: "npm:0.19.11"
1774017751
react-test-renderer: "npm:18.2.0"
1774117752
shelljs: "npm:^0.8.5"

0 commit comments

Comments
 (0)