-
-
Notifications
You must be signed in to change notification settings - Fork 527
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Allow Reanimated Screen to check large header (#1915)
## Description It looks that on Reanimated Screen we didn't check if on iOS there's large header enabled, which led to the wrong initial values, when user was using *at least* ReanimatedScreenProvider. This feature fixes that by adding an ability to get screen descriptor by Reanimated Screen, which contains an information if user has enabled `headerLargeTitle` prop. ## Changes - Changed the `useReanimatedTransitionProgress` leftover inside the `useReanimatedHeaderHeight` file - Created new hook `useScreenInfo` that provides an information about the route view which is being used by ReanimatedNativeStackScreen (this hook is not meant to be public [at least for now] - that's why I didn't exported it) - Moved the implementation of getStatusBarHeight to the separate file ## Screenshots / GIFs ### Before <img width="995" alt="image" src="https://github.com/software-mansion/react-native-screens/assets/23281839/244782fb-8ef0-433e-b84f-7a7159f800d9"> ### After <img width="996" alt="image" src="https://github.com/software-mansion/react-native-screens/assets/23281839/2114196c-1528-409a-8c04-0e6d1d9cc7c7"> ## Test code and steps to reproduce Add to `Test42` ReanimatedScreenProvider and enable `headerLargeTitle` prop for the `Home` screen. ## Checklist - [X] Included code example that can be used to test this change - [X] Updated TS types - [ ] Ensured that CI passes
- Loading branch information
Showing
5 changed files
with
48 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Rect } from 'react-native-safe-area-context'; | ||
import { Platform } from 'react-native'; | ||
|
||
export default function getStatusBarHeight( | ||
topInset: number, | ||
dimensions: Rect, | ||
isStatusBarTranslucent: boolean | ||
) { | ||
if (Platform.OS === 'ios') { | ||
// It looks like some iOS devices don't have strictly set status bar height to 44. | ||
// Thus, if the top inset is higher than 50, then the device should have a dynamic island. | ||
// On models with Dynamic Island the status bar height is smaller than the safe area top inset by 5 pixels. | ||
// See https://developer.apple.com/forums/thread/662466 for more details about status bar height. | ||
const hasDynamicIsland = topInset > 50; | ||
return hasDynamicIsland ? topInset - 5 : topInset; | ||
} else if (Platform.OS === 'android') { | ||
// On Android we should also rely on frame's y-axis position, as topInset is 0 on visible status bar. | ||
return isStatusBarTranslucent ? topInset : dimensions.y; | ||
} | ||
|
||
return topInset; | ||
} |
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