【发布时间】:2019-01-30 17:09:59
【问题描述】:
所以我正在使用React Navigation 3.0 和 React Native。使用标题时,标题标题在 iOS 上默认居中,但在 Android 上左对齐。我使用了一个修复来将 Android 的标题标题居中,这很好。当显示返回按钮时,标题标题会稍微向右推。无论哪种方式,我都希望标题保持居中。
所以我尝试给 HeaderLeftContainerStyle 一个绝对样式,这样它就不会影响标题的位置,但它没有按预期工作。
有什么建议吗?
下面是一些代码的样子:
const MainCommsStack = createStackNavigator(
{
ShowMessages: {
screen: connect(
mapStateToProps,
mapDispatchToProps,
)(MessageScreen),
},
ChatWindow: DetailStack,
},
{
defaultNavigationOptions: {
headerTitle: 'COMMS',
headerTitleStyle: [
baseStyles.whiteHeaderText,
{
alignSelf: 'center',
textAlign: 'center',
justifyContent: 'center',
flex: 1,
textAlignVertical: 'center',
},
],
headerStyle: {
backgroundColor: colors.vGreen,
},
headerBackImage: <BackButton />,
headerBackTitle: null,
headerLeftContainerStyle: {
position: 'absolute',
left: 10,
},
headerLayoutPreset: 'center',
},
},
);
const CommsStack = createAppContainer(MainCommsStack);
【问题讨论】:
-
您是否尝试过将按钮位置设为绝对位置?
-
不,但我尝试了不同的解决方案并修复了它。查看我的回答并感谢您的回复:D
标签: android react-native react-navigation