javascript - 如何在 react 导航中使标题居中而不受到 headerLeft 的影响?

标签 javascript reactjs react-native react-redux react-navigation

我使用 react 导航,并将标题置于栏中居中,但它受到 headerLeft 的影响, 当我关闭它们时,它就可以工作并将标题准确地居中, 如何使用另一个左右按钮\图标来做到这一点而不影响标题

is not centering

centering when delete the logout button

代码:

const RootNavigator = createStackNavigator({
  Home: {
   screen: Home,
   navigationOptions: {
     title: "Home",
    //headerLeft: null, // here the issue
     headerStyle: {
        backgroundColor: 'rgb(42,55,68)',
     },
      headerTitleStyle: {
         flex: 1,
         textAlign: 'center',
         color: "#fff",
       }
    }
  }
 });

最佳答案

您的 headerTitleStyle Prop 没有问题,只需确保 headerLeft 和 headerRight 都有一个 View 即可。

示例:

 headerLeft : (<View><Entypo name='menu' size={28} color='white' onPress={() => navigation.openDrawer()} /></View>),
 headerRight:(<View></View>)

关于javascript - 如何在 react 导航中使标题居中而不受到 headerLeft 的影响?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53025699/

相关文章:

javascript - 如何在 div 滚动到 View 中时自动重复高度和宽度变化?

ios - 在 React Native 中导航 iOS

javascript - 为什么组件在 this.setState() 完成状态设置之前渲染?

Javascript 在 inappbrowser 与 Chrome 中的行为不同 - 未定义的全局变量

javascript - 使用javascript中的下一个和上一个按钮在部分页面之间移动

javascript - 如何调试随机无响应的react.js网页?

reactjs - 在 Webpack 中使用带有 CSS 模块的语义 UI

android - 使用后退按钮作为 react native android 应用程序的背景

javascript - JS中每个单词首字母大写

javascript - 如何使用 React 从 ReqRes API 渲染用户列表