react-navigation icon indicating copy to clipboard operation
react-navigation copied to clipboard

navigationBarColor props breaking safeArea / textinput & more

Open pierroo opened this issue 3 years ago • 20 comments

Current behavior

On android, adding navigationBarColor in the screenOptions of a @react-navigation/native-stack will completely mess up the display of the app. TextInput will no longer be pulled up above the keyboard and the view doesn't adjust naturally SafeAreaView turns out messed up and needs to be manually added on some screens, while removed on others and it seems random.

Expected behavior

navigationBarColor should simply allow us to change the navigation bar color without messing everything else. Or does it add some kind of safeArea and extra changes under the hood?

Reproduction

basic code is enough

Platform

  • [X] Android
  • [ ] iOS
  • [ ] Web
  • [ ] Windows
  • [ ] MacOS

Packages

  • [ ] @react-navigation/bottom-tabs
  • [ ] @react-navigation/drawer
  • [ ] @react-navigation/material-bottom-tabs
  • [ ] @react-navigation/material-top-tabs
  • [ ] @react-navigation/stack
  • [X] @react-navigation/native-stack
  • [ ] react-native-tab-view
  • [ ] flipper-plugin-react-navigation

Environment

  • [x] I've removed the packages that I don't use
package version
@react-navigation/native ^6.0.16
@react-navigation/drawer ^6.5.3
@react-navigation/stack ^6.3.7
@react-navigation/native-stack ^6.9.4
react-native-safe-area-context ^3.3.2
react-native-screens ^3.18.2
react-native-gesture-handler 2.8.0
react-native-reanimated ^2.13.0
react-native-tab-view ^3.3.2
react-native-pager-view ^5.4.25
react-native 0.69.7
node
npm or yarn

pierroo avatar Jan 07 '23 11:01 pierroo

Hey! Thanks for opening the issue. The issue doesn't seem to contain a link to a repro (a snack.expo.dev link, a www.typescriptlang.org/play link or link to a GitHub repo under your username).

Can you provide a minimal repro which demonstrates the issue? Please try to keep the repro as small as possible and make sure that we can run it without additional setup.

A repro will help us debug the issue. The issue will be closed automatically after a while if you don't provide a repro.

github-actions[bot] avatar Jan 07 '23 11:01 github-actions[bot]

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 6.0.16, latest: 6.1.1)
  • @react-navigation/drawer (found: 6.5.3, latest: 6.5.6)
  • @react-navigation/stack (found: 6.3.7, latest: 6.3.10)
  • react-native-tab-view (found: 3.3.2, latest: 3.3.4)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

github-actions[bot] avatar Jan 07 '23 11:01 github-actions[bot]

already checked; issue still remains. and that's quite a big one :/

pierroo avatar Jan 18 '23 15:01 pierroo

Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.

github-actions[bot] avatar Feb 18 '23 01:02 github-actions[bot]

Hey! Thanks for opening the issue. Seems that this issue is related to react-native-screens library which is a dependency of React Navigation. Can you also post your issue in this repo so that it's notified to the maintainers of that library? This will help us fix the issue faster since it's upto the maintainers of that library to investigate it.

github-actions[bot] avatar Feb 18 '23 03:02 github-actions[bot]

Hey, I tested this and can't seem to replicate your problem. Can you share code that reproduces the problem? For example, I used native stack and set the navigationBarColor to #ff0000. Inside one of the screens I added the code below, it all seems to be working fine when the keyboard opens up.

<SafeAreaView style={{ flex: 1 }}>
  <KeyboardAvoidingView style={{ flex: 1 }} behavior={Platform.OS === 'ios' ? 'padding' : 'height'}>
    <TouchableWithoutFeedback onPress={Keyboard.dismiss}>
      <View style={{
        padding: 24,
        flex: 1,
        justifyContent: 'space-around'
      }}>
        <Text style={{
          fontSize: 36,
          marginBottom: 48,
        }}>Header</Text>
        <TextInput placeholder="Username" style={{
          height: 40,
          borderColor: '#000000',
          borderBottomWidth: 1,
          marginBottom: 36,
        }} />
        <View style={{
          backgroundColor: 'white',
          marginTop: 12,
        }}>
          <Button title="Submit" onPress={() => null} />
        </View>
      </View>
    </TouchableWithoutFeedback>
  </KeyboardAvoidingView>
</SafeAreaView>

BeeMargarida avatar Feb 21 '23 11:02 BeeMargarida

Im facing the same issue with android. Everything works as expected without defining navigationBarColor, but as soon as I add it safeArea / textinput avoiding stops working. The project uses RN 0.68.1 and latest versions of react-navigation.

crashWunderdog avatar Mar 03 '23 12:03 crashWunderdog

Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.

github-actions[bot] avatar Apr 03 '23 01:04 github-actions[bot]

this still is a (big) issue. Not stale

pierroo avatar Apr 03 '23 08:04 pierroo

Wondering if anyone has a work around or know if this broke in a specific version I can roll back to.

Experiencing exactly this. It's not the end of the world if the app doesn't bleed to the edges with the color I want, but trying to work around this with manual adjustments has a very obvious pitfalls.

Thanks again for all the hardwork everyone, I get what it takes to maintain a package like this.

arthur5005 avatar Apr 22 '23 10:04 arthur5005

Can't provide a repro at the moment, but I wanted to chime in and say I'm also experiencing exactly the same issue.

To work around it, I'm using expo-navigation-bar to tweak styles separately from react-navigation.

wtfabio avatar May 08 '23 01:05 wtfabio

Hello 👋, this issue has been open for more than a month without a repro or any activity. If the issue is still present in the latest version, please provide a repro or leave a comment within 7 days to keep it open, otherwise it will be closed automatically. If you found a solution or workaround for the issue, please comment here for others to find. If this issue is critical for you, please consider sending a pull request to fix it.

github-actions[bot] avatar Jun 07 '23 02:06 github-actions[bot]

not stale unfortunately; still happening and quite an issue

pierroo avatar Jun 15 '23 08:06 pierroo

Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro.

github-actions[bot] avatar Jun 15 '23 08:06 github-actions[bot]

I was able to find a workaround for this issue by switching from the SafeAreaView component to useSafeAreaInsets hook as suggested by the React Navigation docs on Supporting safe areas. The relevant section is copied below:

While React Native exports a SafeAreaView component, this component only supports iOS 10+ with no support for older iOS versions or Android. In addition, it also has some issues, i.e. if a screen containing safe area is animating, it causes jumpy behavior. So we recommend to use the useSafeAreaInsets hook from the react-native-safe-area-context library to handle safe areas in a more reliable way.

My change involved going from something like this:

export default function ScreenBackground({ children }: PropsWithChildren<{}>) {
  return <SafeAreaView>{children}</SafeAreaView>;
}

to something like this:

export default function ScreenBackground({ children }: PropsWithChildren<{}>) {
  const insets = useSafeAreaInsets();
  return (
    <View
      style={{
        // Paddings to handle safe area
        paddingTop: insets.top,
        paddingBottom: insets.bottom,
        paddingLeft: insets.left,
        paddingRight: insets.right,
      }}
    >
      {children}
    </View>
  );
}

High5Apps avatar Oct 16 '23 12:10 High5Apps

Also just wanted to add that I got bit by this from adding screenOptions={{ navigationBarColor: "#FFFFFF" }} to my Stack.Navigator. While the safe area fix above seems to work, this is very problematic for screens that aren't safe area-aware at all, as their content appears behind the Android nav bar. This seems to include LogBox.

CleanShot 2023-11-21 at 18 20 48@2x

wbobeirne avatar Nov 22 '23 00:11 wbobeirne

Looks like this might be downstream in react-native-screens: https://github.com/software-mansion/react-native-screens/issues/1530

wbobeirne avatar Nov 22 '23 00:11 wbobeirne

Can confirm this mr fixes this issue,

https://github.com/software-mansion/react-native-screens/pull/1988/files

so should be fixed when it's released to rn screens

humaidk2 avatar Jan 08 '24 08:01 humaidk2

Can confirm this mr fixes this issue,

https://github.com/software-mansion/react-native-screens/pull/1988/files

so should be fixed when it's released to rn screens

this works fine, Thanks!.

gokul1630 avatar Aug 08 '24 15:08 gokul1630

I am facing a similar issue on react-native-screen 4.4.0, and RN 76. Content is going behind navbar intermittently and shifting the screen behind the statusbar. Was their any intermittent fix that I can try?

sarthak-cars24 avatar May 05 '25 09:05 sarthak-cars24