Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix android insets #49531

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading