web-ridge / react-native-paper-dates

Smooth and fast cross platform Material Design date and time picker for React Native Paper
https://www.reactnativepaperdates.com
MIT License
637 stars 161 forks source link

Fixing Date Picker Modal Overlapping StatusBar in iOS #352

Closed AnassHmida closed 6 months ago

AnassHmida commented 7 months ago

Hello,

This PR resolves the issue where the content of the date picker modal in iOS is displayed under the StatusBar, preventing users from interacting with the close and save buttons. The problem arose due to the use of an incorrect property for calculating the StatusBar height in the DatePickerModal component for iOS. This fix replaces the incorrect property StatusBar.currentHeight with the appropriate StatusBarManager.HEIGHT for iOS. The changes ensure that the content is properly displayed and the user can interact with the necessary buttons within the date picker modal.

Changes Made:

Fixes: https://github.com/web-ridge/react-native-paper-dates/issues/258#issue-1602789368

Thanks.

joeburghard commented 7 months ago

This approach did not resolve my issue with modal positioning underneath statusbar. I did have a better experience using the getHeight method from nativemodules

  const [iosHeight, setIOSHeight] = React.useState<number>(0)
 NativeModules.StatusBarManager.getHeight(({ height }: { height: number }) => {
    setIOSHeight(height)
  })
<View
                  style={[
                    {
                      height: Platform.select({
                        ios: iosHeight,
                        ...
RichardLindhout commented 7 months ago

I think the best approach is to use react-native-safe-area-context for this (which we already have as a dependency)

joeburghard commented 6 months ago

@AnassHmida Could you refactor your changes to try the solution @RichardLindhout suggested?

RichardLindhout commented 6 months ago

I did a fix myself, can you verify this change @AnassHmida

AnassHmida commented 6 months ago

Hello @joeburghard , the fix you mentioned causes a crash in android , you need to limit it to IOS only :

Platform.OS === "ios" &&  NativeModules.StatusBarManager.getHeight(({ height }: { height: number }) => {
setIOSHeight(height)
})

but other than that , it works great !

AnassHmida commented 6 months ago

Hey @RichardLindhout , one second , i'm verifying this

AnassHmida commented 6 months ago

Hey again @RichardLindhout , it seems that the 'react-native-safe-area-context' doesn't seem to work here , i tried the latest version that you released , but now the problem seems to persist , for IOS IOS and Android Android , i'm going to create a pull request based on @joeburghard 's answer with an android fix.

RichardLindhout commented 6 months ago

No it should work I think you did not use the provider

import { SafeAreaProvider } from 'react-native-safe-area-context';
function App() {
  return <SafeAreaProvider>

...other providers
</SafeAreaProvider>;
}
RichardLindhout commented 6 months ago

react-native-safe-area-context is already a dependency for react-native-paper and this works great! I never saw this problem in my apps so it should be the provider :)

RichardLindhout commented 6 months ago

Hmm looks like its double applied now :)

I think we may need to improve docs on this

Scherm­afbeelding 2023-12-07 om 17 47 37

AnassHmida commented 6 months ago

Hmm looks like its double applied now :)

I think we may need to improve docs on this

Scherm­afbeelding 2023-12-07 om 17 47 37

Humm i don't know , i'm wrapping my views in a SafeAreaProvider tag , but that doesn't seem to fix anything , and i don't think it should be conditioned to be like that in the first place , i made a second PR based on @joeburghard 's answer which should be WAI.

Thanks.

RichardLindhout commented 6 months ago

Please let me know if newest release work for you, on my device it works. We have also support for all the different use cases and the pagesheet presentation style