Skip to content

Commit 06b41bf

Browse files
puneetlathOSBotify
authored andcommitted
Merge pull request #49531 from margelo/@perunt/top-safe-area-notification
Fix android insets (cherry picked from commit 8e5fc88) (CP triggered by AndrewGable)
1 parent fb7d357 commit 06b41bf

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

src/components/SafeAreaConsumer/index.android.tsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import useStyleUtils from '@hooks/useStyleUtils';
55
import StatusBar from '@libs/StatusBar';
66
import type SafeAreaConsumerProps from './types';
77

8+
const defaultInsets = {top: 0, bottom: 0, left: 0, right: 0};
9+
810
/**
911
* This component is a light wrapper around the SafeAreaInsetsContext.Consumer. There are several places where we
1012
* may need not just the insets, but the computed styles so we save a few lines of code with this.
@@ -15,23 +17,20 @@ function SafeAreaConsumer({children}: SafeAreaConsumerProps) {
1517
return (
1618
<SafeAreaInsetsContext.Consumer>
1719
{(insets) => {
18-
const insetsWithDefault = insets ?? {
19-
top: 0,
20-
bottom: 0,
21-
left: 0,
22-
right: 0,
23-
};
20+
const safeInsets = insets ?? defaultInsets;
2421

2522
const androidInsets = {
26-
...insetsWithDefault,
27-
top: StatusBar.currentHeight ?? insetsWithDefault.top,
23+
...safeInsets,
24+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
25+
top: StatusBar.currentHeight || safeInsets.top,
2826
};
2927

30-
const {paddingTop, paddingBottom} = StyleUtils.getSafeAreaPadding(androidInsets ?? undefined);
28+
const {paddingTop, paddingBottom} = StyleUtils.getSafeAreaPadding(androidInsets);
29+
3130
return children({
3231
paddingTop,
3332
paddingBottom,
34-
insets: androidInsets ?? undefined,
33+
insets: androidInsets,
3534
safeAreaPaddingBottomStyle: {paddingBottom},
3635
});
3736
}}

0 commit comments

Comments
 (0)