Skip to content

Commit

Permalink
fix: extract Android specific safe area logic and simplify safe area …
Browse files Browse the repository at this point in the history
…components/hooks
  • Loading branch information
chrispader committed Nov 27, 2024
1 parent dbcaad9 commit b011c91
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 64 deletions.
43 changes: 0 additions & 43 deletions src/components/SafeAreaConsumer/index.android.tsx

This file was deleted.

8 changes: 5 additions & 3 deletions src/components/SafeAreaConsumer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ function SafeAreaConsumer({children}: SafeAreaConsumerProps) {

return (
<SafeAreaInsetsContext.Consumer>
{(insets) => {
const {paddingTop, paddingBottom} = StyleUtils.getSafeAreaPadding(insets ?? undefined);
{(safeAreaInsets) => {
const insets = StyleUtils.getSafeAreaInsets(safeAreaInsets);
const {paddingTop, paddingBottom} = StyleUtils.getSafeAreaPadding(insets);

return children({
paddingTop,
paddingBottom,
insets: insets ?? undefined,
insets,
safeAreaPaddingBottomStyle: {paddingBottom},
});
}}
Expand Down
File renamed without changes.
15 changes: 0 additions & 15 deletions src/hooks/useSafeAreaInsets/index.android.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/hooks/useStyledSafeAreaInsets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// eslint-disable-next-line no-restricted-imports
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import useSafeAreaInsets from './useSafeAreaInsets';
import useStyleUtils from './useStyleUtils';

/**
Expand Down
3 changes: 3 additions & 0 deletions src/styles/utils/getSafeAreaInsets/defaultInsets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const defaultInsets = {top: 0, bottom: 0, left: 0, right: 0};

export default defaultInsets;
18 changes: 18 additions & 0 deletions src/styles/utils/getSafeAreaInsets/index.android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type {EdgeInsets} from 'react-native-safe-area-context';
import StatusBar from '@libs/StatusBar';
import defaultInsets from './defaultInsets';

/**
* On Android we want to use the StatusBar height rather than the top safe area inset.
* @returns
*/
function getSafeAreaInsets(safeAreaInsets: EdgeInsets | null): EdgeInsets {
const insets = safeAreaInsets ?? defaultInsets;

return {
...insets,
top: StatusBar.currentHeight ?? insets.top,
};
}

export default getSafeAreaInsets;
13 changes: 13 additions & 0 deletions src/styles/utils/getSafeAreaInsets/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type {EdgeInsets} from 'react-native-safe-area-context';
import defaultInsets from './defaultInsets';

/**
* Noop on web and iOS. This utility function is only needed on Android.
* @returns
*/
function getSafeAreaInsets(safeAreaInsets: EdgeInsets | null): EdgeInsets {
const insets = safeAreaInsets ?? defaultInsets;
return insets;
}

export default getSafeAreaInsets;
2 changes: 2 additions & 0 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import createTooltipStyleUtils from './generators/TooltipStyleUtils';
import getContextMenuItemStyles from './getContextMenuItemStyles';
import getHighResolutionInfoWrapperStyle from './getHighResolutionInfoWrapperStyle';
import getNavigationModalCardStyle from './getNavigationModalCardStyles';
import getSafeAreaInsets from './getSafeAreaInsets';
import getSignInBgStyles from './getSignInBgStyles';
import {compactContentContainerStyles} from './optionRowStyles';
import positioning from './positioning';
Expand Down Expand Up @@ -1205,6 +1206,7 @@ const staticStyleUtils = {
getModalPaddingStyles,
getOuterModalStyle,
getPaymentMethodMenuWidth,
getSafeAreaInsets,
getSafeAreaMargins,
getSafeAreaPadding,
getSignInWordmarkWidthStyle,
Expand Down
2 changes: 1 addition & 1 deletion src/styles/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default {
mobileResponsiveWidthBreakpoint: 800,
tabletResponsiveWidthBreakpoint: 1024,
iosSafeAreaInsetsPercentage: 0.7,
androidSafeAreaInsetsPercentage: 1.3,
androidSafeAreaInsetsPercentage: 1.2,
sideBarWidth: 375,
pdfPageMaxWidth: 992,
tooltipzIndex: 10050,
Expand Down

0 comments on commit b011c91

Please sign in to comment.