Skip to content

Commit

Permalink
Merge pull request #49531 from margelo/@perunt/top-safe-area-notifica…
Browse files Browse the repository at this point in the history
…tion

Fix android insets

(cherry picked from commit 8e5fc88)

(CP triggered by AndrewGable)
  • Loading branch information
puneetlath authored and OSBotify committed Sep 24, 2024
1 parent fb7d357 commit 06b41bf
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/components/SafeAreaConsumer/index.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import useStyleUtils from '@hooks/useStyleUtils';
import StatusBar from '@libs/StatusBar';
import type SafeAreaConsumerProps from './types';

const defaultInsets = {top: 0, bottom: 0, left: 0, right: 0};

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

const androidInsets = {
...insetsWithDefault,
top: StatusBar.currentHeight ?? insetsWithDefault.top,
...safeInsets,
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
top: StatusBar.currentHeight || safeInsets.top,
};

const {paddingTop, paddingBottom} = StyleUtils.getSafeAreaPadding(androidInsets ?? undefined);
const {paddingTop, paddingBottom} = StyleUtils.getSafeAreaPadding(androidInsets);

return children({
paddingTop,
paddingBottom,
insets: androidInsets ?? undefined,
insets: androidInsets,
safeAreaPaddingBottomStyle: {paddingBottom},
});
}}
Expand Down

0 comments on commit 06b41bf

Please sign in to comment.