javascript - 使用 useLayoutEffect 钩子(Hook)删除 React Native 中标题的底部边框

标签 javascript react-native react-hooks border

我想从 React Native 的标题底部删除模糊的边框。我正在使用 useLayoutEffect()钩子(Hook)修改标题但无法删除边框。我试过使用 borderBottomWidth: 0里面 headerStyle但它不起作用。

    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

最佳答案

最近在 React Navigation 6 中遇到了这个问题,但发现还有另一种方法。根据文档有 headerShadowVisible
文档:
是否隐藏 header 上的高程阴影 (Android) 或底部边框 (iOS)。这是以下样式的简写:

{
  elevation: 0,
  shadowOpacity: 0,
  borderBottomWidth: 0,
}
如果headerStyle中指定了以上样式连同 headerShadowVisible: false ,然后 headerShadowVisible: false将优先。
示例:
<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,
  })}
/>

关于javascript - 使用 useLayoutEffect 钩子(Hook)删除 React Native 中标题的底部边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66372004/

相关文章:

javascript - 未解析的函数或方法 JavaScript yii2

javascript - Jquery 使用自定义验证规则验证任意 HTML 元素

javascript - 对话框未关闭 native react

reactjs - 仅当元素位于视口(viewport)上时才调用 UseFrame

javascript - 如何使用 Node/Express 显示特定错误的自定义 html 页面?

javascript - jquery ui 组合框下拉菜单置于最前面

react-native - 多行时 react native TextInput自动增长

javascript - react-native 获取 api 数组

react-native - Catch block 没有捕捉到我的自定义 react 钩子(Hook)中抛出的错误