react-native-safe-area-context icon indicating copy to clipboard operation
react-native-safe-area-context copied to clipboard

Does not respect hidden StatusBar

Open AdamGerthel opened this issue 5 years ago • 16 comments

I just installed this package in order to fix notch problems on my app. However, I immediately stumbled upon a problem: The inset values don't make sense to me. I'm getting top: 20 on an iPhone 7, but the iPhone 7 doesn't have any notches or unsafe areas. At the same time, a Sony Xperia phone that I'm testing with, also without any notches, has top: 0. See below:

Screenshot 2019-11-09 at 13 47 58

What are the values based upon? Is there a way for me to be able to foresee these differences so that I can work around them? I would've expected that this library provided the size of the actual unsafe areas, and not to add seemingly arbitrary additional values.

Update Ok, so I'm guessing the 20 additional pixels stem from the status bar. But why is this automatically added, and how come it's only added on iOS? The status bar is hidden in my app on both Android and iOS, so I can't really just subtract those 20px in a very convenient way.. I'm doing it this way now, but feels like a hack: paddingTop: Platform.OS === 'ios' ? insets.top - 20 : insets.top

AdamGerthel avatar Nov 09 '19 12:11 AdamGerthel

@AdamGerthel What version of iOS is on the phone? We polyfill the safe area api on older iOS versions that don't support it but it might not take status bar visibility in consideration. Also can you confirm if it also happens on a more recent iOS version (iOS 12 / 13)?

janicduplessis avatar Nov 09 '19 19:11 janicduplessis

@janicduplessis The iPhone is running 13.1.2. react-native-safe-area-context is on ~0.3.6 (installed via expo install react-native-safe-area-context since I'm using Expo).

AdamGerthel avatar Nov 09 '19 22:11 AdamGerthel

Ok I can repro in snack, I'll have a look. https://snack.expo.io/@janic/restless-carrot

janicduplessis avatar Nov 10 '19 01:11 janicduplessis

I think the issue is fixed now, I cannot reproduce locally, I think expo is doing a release soon I'll check to make sure this library gets updated.

janicduplessis avatar Nov 10 '19 02:11 janicduplessis

@janicduplessis I'm not sure I follow, the issue is reproducible in your snack (using react-native-safe-area-context 0.6.0), but you're saying the issue has already been fixed? Are you saying that this is an Expo-specific issue?

AdamGerthel avatar Nov 10 '19 09:11 AdamGerthel

Snack uses the expo client which includes an older version of the native code (where the bug is).

I just checked and the next expo release will include version 0.6.0 which should fix your issue.

janicduplessis avatar Nov 10 '19 15:11 janicduplessis

Oh, I see, I was a little confused since the package.json in your Snack example lists version 0.6.0.

Anyway, I'll just wait for the next Expo release then. Thanks!

AdamGerthel avatar Nov 10 '19 16:11 AdamGerthel

I've upgraded Expo and I'm using 0.6.0 but the issue persists. Your snack has the same issue still.

AdamGerthel avatar Dec 12 '19 11:12 AdamGerthel

@AdamGerthel Is this still an issue?

janicduplessis avatar May 26 '20 18:05 janicduplessis

It's been a while since I work of those parts of the code but... seems like it, yes.

AdamGerthel avatar May 26 '20 19:05 AdamGerthel

Thanks, I just checked and I can confirm it still happens, will look at it again.

janicduplessis avatar May 26 '20 19:05 janicduplessis

Weird, I can still repro in snack but not locally in my example app. This is going to be hard to investigate.

janicduplessis avatar May 26 '20 20:05 janicduplessis

is this perhaps the same issue? #170

tanteemmie avatar Feb 25 '21 15:02 tanteemmie

Any update on this issue? Still having the same problem today, when the StatusBar is hidden on iOS, insets.top is still 20 until I reload the app. Works fine on Android.

devscipline avatar Nov 08 '21 09:11 devscipline

Confirm issue still exist in iOS when controlling hidden props of StatusBar with state

Khuongnb avatar Dec 15 '21 09:12 Khuongnb

React-native by default uses the really old method of controlling the status bar - it uses this check to determine what mode you're using. Note that this is flipped - if this returns YES, the <StatusBar> component won't actually work

Ok - so call this function, and if it returns NO, you need to start listening to these events

When they fire, I think it's enough to just call this function

Happy to provide more pointers if someone wants to take this on

jacobp100 avatar Jan 19 '23 16:01 jacobp100