SteffeyDev / react-native-popover-view

A well-tested, adaptable, lightweight <Popover> component for react-native
MIT License
613 stars 92 forks source link

popvoer displays in an unusual position on certain Android devices #156

Open buynao opened 1 year ago

buynao commented 1 year ago

Describe the bug

This bug only occurs on specific Android Devices, where the popvoer is displayed in an unusual position.

It seems that the statusBar is hidden when the popover is displayed, resulting in the wrong value for verticalOffset.

For the most part, there is no problem with this line of code.

verticalOffset={pures.is.android() ? -StatusBar.currentHeight : 0}

Device/Setup Info:

Screenshots

image

Debug Output

I can't reproduce the problem myself using the emulator, so I don't have any debug-related information to give

Code Config

<Popover
      isVisible={visible }
      onRequestClose={() => {...}}
      onOpenComplete={() => {...}}
      // StatusBar.currentHeight wrong calculation?
      verticalOffset={pures.is.android() ? -StatusBar.currentHeight : 0}
      placement={PopoverPlacement.BOTTOM}
      from={<SomeText/>}
      backgroundStyle={{ opacity: 0 }}
      animationConfig={{ duration: 200 }}
      popoverStyle={styles.popover}
 >...</Popover>
jeffinhk commented 1 year ago

Same issue happening here under following conditions : "react-native": "0.71.8", "react-native-popover-view": "^5.1.7",

Android SDK :
minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33

tabish-kook commented 1 year ago

I am facing the same issue on the following version.

"react-native-popover-view": "^5.1.8", "react-native": "0.72.3",

Android SDK : minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33

mlazari commented 11 months ago

This issue with the popover showing in the wrong position appears when the status bar translucency is different in the popover. There are 2 cases:

  1. The status bar is translucent with the popover closed, but becomes non-translucent when the popover is shown. In this case the popover position is too low. Can be fixed by either setting statusBarTranslucent={true} for the Popover component, or adjusting the vertical offset to account for the status bar height with verticalOffset={-StatusBar.currentHeight}
  2. The status bar is non-translucent with the popover closed, but becomes translucent when the popover is shown. In this case the popover position is too high. Can be fixed by either setting statusBarTranslucent={false} for the Popover component, or adjusting the vertical offset to account for the status bar height with verticalOffset={StatusBar.currentHeight}

This issue as far as I understand happens because the popover position is computed in one coordinate system, but displayed in another one. When the status bar is translucent, the vertical coordinates are relative to the top of the screen, when it is not translucent - they are relative to the bottom of the status bar.

Not sure if there is a way to solve this automatically from the library, since there is no way to get if the status bar is translucent currently or not.

Bulandent commented 10 months ago

This issue with the popover showing in the wrong position appears when the status bar translucency is different in the popover. There are 2 cases:

  1. The status bar is translucent with the popover closed, but becomes non-translucent when the popover is shown. In this case the popover position is too low. Can be fixed by either setting statusBarTranslucent={true} for the Popover component, or adjusting the vertical offset to account for the status bar height with verticalOffset={-StatusBar.currentHeight}
  2. The status bar is non-translucent with the popover closed, but becomes translucent when the popover is shown. In this case the popover position is too high. Can be fixed by either setting statusBarTranslucent={false} for the Popover component, or adjusting the vertical offset to account for the status bar height with verticalOffset={StatusBar.currentHeight}

This issue as far as I understand happens because the popover position is computed in one coordinate system, but displayed in another one. When the status bar is translucent, the vertical coordinates are relative to the top of the screen, when it is not translucent - they are relative to the bottom of the status bar.

Not sure if there is a way to solve this automatically from the library, since there is no way to get if the status bar is translucent currently or not.

statusBarTranslucent={true} can solved my issue. Thanks.