Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove bottom border of header in React Native using useLayoutEffect hook

I want to remove the faint border from the bottom of the header in React Native. I'm using useLayoutEffect() hook to modify the header but unable to remove the border. I've tried using borderBottomWidth: 0 inside headerStyle but it's not working.

    useLayoutEffect(() => {
        navigation.setOptions({
          title: "Signal",
          headerStyle: { backgroundColor: "#fff", borderBottomWidth: 0 },
          headerTitleStyle: { color: "#000" },
          headerTintColor: "#000",
        });
      }, [navigation]);

Emulator screenshot showing the border line to be removed

like image 595
Nishant Narayan Rout Avatar asked Nov 18 '25 15:11

Nishant Narayan Rout


2 Answers

Recently ran across this in React Navigation 6 but found there is another way. Per the docs there is headerShadowVisible

Docs:

Whether to hide the elevation shadow (Android) or the bottom border (iOS) on the header. This is a short-hand for the following styles:

{
  elevation: 0,
  shadowOpacity: 0,
  borderBottomWidth: 0,
}

If the above styles are specified in headerStyle along with headerShadowVisible: false, then headerShadowVisible: false will take precedence.

Example:

<Stack.Screen
  name="Example"
  component={Example}
  options={({ route }) => ({
    title: route.params.title,
    headerTintColor: '#fff',
    headerStyle: {
      backgroundColor: route.params.color,
    },
    headerShadowVisible: false, // applied here
    headerBackTitleVisible: false,
  })}
/>
like image 110
DᴀʀᴛʜVᴀᴅᴇʀ Avatar answered Nov 20 '25 04:11

DᴀʀᴛʜVᴀᴅᴇʀ


If you are using react-navigation you remove the bottom border by specifying the following for the headerStyle in your navigationOptions:

headerStyle: {
  shadowColor: 'transparent', // this covers iOS
  elevation: 0, // this covers Android
},
like image 30
Alistair Nelson Avatar answered Nov 20 '25 04:11

Alistair Nelson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!