useSafeAreaInsets on Android returns 0 for top

See original GitHub issue

Hi, I’m using

"react-native-safe-area-context": "3.0.7"
"react-native": "0.62.2"
"expo": "38.0.8"

and when I call const insets = useSafeAreaInsets(); on Android it returns 0 for top inset, on iOS it returns correct number. I packed everything into

<SafeAreaProvider initialMetrics={initialWindowMetrics}>
<SafeAreaView style={styles.safeAreaStyle}>

on top level of navigation.

Am I doing something wrong or is this a bug?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:10
  • Comments:17

github_iconTop GitHub Comments

4reactions
fahad86commented, Jan 21, 2022

using import {initialWindowMetrics} from 'react-native-safe-area-context';

initialWindowMetrics.insets

worked out for my use-case

2reactions
choiblescommented, Jul 22, 2020

Hey, could be wrong with my fix, but I noticed that the insets object for this library doesn’t seem to take into account the Android status bar height in the top property of the insets object.

I got around this by adding StatusBar.currentHeight (don’t forget to import {StatusBar} from 'react-native';) to the top inset if the app is running on Android.

Hope that helps.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SafeAreaContext - Expo Documentation
You use the useSafeAreaInsets hook to get the insets in the form of { top: number, right: number, bottom: number: number, left: number...
Read more >
react-native-safe-area-context - npm
useSafeAreaInsets. Returns the safe area insets of the nearest provider. This allows manipulating the inset values from JavaScript. Note that ...
Read more >
react-native-safe-area-context useSafeAreaInsets JavaScript ...
function Transaction(props) { const insets = useSafeAreaInsets(); return <_Transaction ... top: 0, left: 0, bottom: 0, right: 0 }} /> </View> ) }...
Read more >
Supporting safe areas | React Navigation
<Text>This is top text. ... return ( <NavigationContainer> <Stack.Navigator initialRouteName="Home" screenOptions={{ ... const insets = useSafeAreaInsets();
Read more >
react-native-safe-area-context.useSafeAreaInsets JavaScript ...
... ({ animatedValue }) => { const insets = useSafeAreaInsets(); const headerHeight = animatedValue.interpolate({ inputRange: [0, HEADER_HEIGHT + insets.top], ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found