-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #32335 from margelo/@chrispader/fix-status-bar-saf…
…e-area Fix: New Status bar causes wrong safe area insets (cherry picked from commit d7366c6)
- Loading branch information
Showing
17 changed files
with
191 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/components/CustomStatusBar/updateStatusBarAppearance/index.android.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import StatusBar from '@libs/StatusBar'; | ||
import UpdateStatusBarAppearanceProps from './types'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export default function updateStatusBarAppearance({statusBarStyle}: UpdateStatusBarAppearanceProps) { | ||
StatusBar.setBackgroundColor('transparent'); | ||
StatusBar.setTranslucent(true); | ||
if (statusBarStyle) { | ||
StatusBar.setBarStyle(statusBarStyle, true); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/components/CustomStatusBar/updateStatusBarAppearance/index.ios.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import StatusBar from '@libs/StatusBar'; | ||
import UpdateStatusBarAppearanceProps from './types'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export default function updateStatusBarAppearance({statusBarStyle}: UpdateStatusBarAppearanceProps) { | ||
if (!statusBarStyle) { | ||
return; | ||
} | ||
StatusBar.setBarStyle(statusBarStyle, true); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/components/CustomStatusBar/updateStatusBarAppearance/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import StatusBar from '@libs/StatusBar'; | ||
import UpdateStatusBarAppearanceProps from './types'; | ||
|
||
export default function updateStatusBarAppearance({backgroundColor, statusBarStyle}: UpdateStatusBarAppearanceProps) { | ||
if (backgroundColor) { | ||
StatusBar.setBackgroundColor(backgroundColor, true); | ||
} | ||
if (statusBarStyle) { | ||
StatusBar.setBarStyle(statusBarStyle, true); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/components/CustomStatusBar/updateStatusBarAppearance/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {StatusBarStyle} from '@styles/styles'; | ||
|
||
type UpdateStatusBarAppearanceProps = { | ||
backgroundColor?: string; | ||
statusBarStyle?: StatusBarStyle; | ||
}; | ||
|
||
export default UpdateStatusBarAppearanceProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
// eslint-disable-next-line no-restricted-imports | ||
import {SafeAreaInsetsContext} from 'react-native-safe-area-context'; | ||
import StatusBar from '@libs/StatusBar'; | ||
import * as StyleUtils from '@styles/StyleUtils'; | ||
import SafeAreaConsumerProps from './types'; | ||
|
||
/** | ||
* 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. | ||
*/ | ||
function SafeAreaConsumer({children}: SafeAreaConsumerProps) { | ||
return ( | ||
<SafeAreaInsetsContext.Consumer> | ||
{(insets) => { | ||
const insetsWithDefault = insets ?? { | ||
top: 0, | ||
bottom: 0, | ||
left: 0, | ||
right: 0, | ||
}; | ||
|
||
const androidInsets = { | ||
...insetsWithDefault, | ||
top: StatusBar.currentHeight ?? insetsWithDefault.top, | ||
}; | ||
|
||
const {paddingTop, paddingBottom} = StyleUtils.getSafeAreaPadding(androidInsets ?? undefined); | ||
return children({ | ||
paddingTop, | ||
paddingBottom, | ||
insets: androidInsets ?? undefined, | ||
safeAreaPaddingBottomStyle: {paddingBottom}, | ||
}); | ||
}} | ||
</SafeAreaInsetsContext.Consumer> | ||
); | ||
} | ||
|
||
SafeAreaConsumer.displayName = 'SafeAreaConsumer'; | ||
|
||
export default SafeAreaConsumer; |
18 changes: 3 additions & 15 deletions
18
src/components/SafeAreaConsumer.tsx → src/components/SafeAreaConsumer/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {DimensionValue} from 'react-native'; | ||
import {EdgeInsets} from 'react-native-safe-area-context'; | ||
|
||
type ChildrenProps = { | ||
paddingTop?: DimensionValue; | ||
paddingBottom?: DimensionValue; | ||
insets?: EdgeInsets; | ||
safeAreaPaddingBottomStyle: { | ||
paddingBottom?: DimensionValue; | ||
}; | ||
}; | ||
|
||
type SafeAreaConsumerProps = { | ||
children: React.FC<ChildrenProps>; | ||
}; | ||
|
||
export default SafeAreaConsumerProps; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// eslint-disable-next-line no-restricted-imports | ||
import {EdgeInsets, useSafeAreaInsets as useSafeAreaInsetsInternal} from 'react-native-safe-area-context'; | ||
import StatusBar from '@libs/StatusBar'; | ||
|
||
function useSafeAreaInsets(): EdgeInsets { | ||
const insets = useSafeAreaInsetsInternal(); | ||
|
||
return { | ||
...insets, | ||
top: StatusBar.currentHeight ?? insets.top, | ||
}; | ||
} | ||
|
||
export default useSafeAreaInsets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* eslint-disable no-restricted-imports */ | ||
import {useSafeAreaInsets} from 'react-native-safe-area-context'; | ||
|
||
export default useSafeAreaInsets; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters