th3rdwave / react-native-safe-area-context

A flexible way to handle safe area insets in JS. Also works on Android and Web!
MIT License
2.08k stars 191 forks source link

When UIDocumentPickerViewController is displayed and hidden, useSafeAreaFrame returns an incorrect result #506

Open suiyunpiaoliu opened 2 weeks ago

suiyunpiaoliu commented 2 weeks ago

In iOS systems, when UIDocumentPickerViewController is displayed, useSafeAreaFrame returns the correct result, but when UIDocumentPickerViewController is hidden, the result returned by useSafeAreaFrame is not restored

jacobp100 commented 2 weeks ago

What does the frame change to when it’s presented?

suiyunpiaoliu commented 2 weeks ago

On iPhone 15 Pro, before displaying UIDocumentPickerViewController, useSafeAreaFrame returns {width: 375, height: 812, x: 0, y: 0}, and when UIDocumentPickerViewController is displayed, it returns {y: 44, width: 343, height: 742.7093333333333, x: 16}, But when UIDocumentPickerViewController is hidden, the result is not restored

jacobp100 commented 2 weeks ago

Gotta be honest I’m not sure why the frame changes 😅 are the insets correct?

suiyunpiaoliu commented 2 weeks ago

insets didn't change when the UIDocumentPickerViewController trigger

jacobp100 commented 2 weeks ago

This is sort of what I'd expect. Trying to get the frame in real time is quite difficult since iOS doesn't give you a way to do this. I don't particularly like the useSafeAreaFrame API because we can't handle every single case. What are you trying to achieve here? I might be able to give you some alternatives

suiyunpiaoliu commented 2 weeks ago

Thanks, i modified the code of react-native-safe-area-context locally. Add the following code to the init of RNCSafeAreaProvider. m [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(invalidateSafeAreaInsets) name:@"UIWindowFrameDidChange" object:nil];

And sent this notification when UIDocumentPickerViewController is hidden

jacobp100 commented 2 weeks ago

We already check for a few of these cases - like keyboards. If you want to submit a PR, I'm pretty sure we'd be able to merge it