React native 反应导航头灯不可见
我正在尝试渲染屏幕标题右侧的按钮。但是我没有得到想要的结果。我已向一名官员介绍了情况。这是我的屏幕的最新版本。React native 反应导航头灯不可见,react-native,react-navigation,react-navigation-stack,React Native,React Navigation,React Navigation Stack,我正在尝试渲染屏幕标题右侧的按钮。但是我没有得到想要的结果。我已向一名官员介绍了情况。这是我的屏幕的最新版本。 这是我的导航代码段 <NavigationContainer> <Stack.Navigator screenOptions={{ headerStyle: { backgroundColor: Colors.header.backgroundColor,
这是我的导航代码段
<NavigationContainer>
<Stack.Navigator screenOptions={{
headerStyle: {
backgroundColor: Colors.header.backgroundColor,
},
headerTintColor: Colors.header.fontColor,
headerTitleAlign: 'left',
headerTitleStyle: {
fontSize: Fonts.size.regular
}
}}>
<Stack.Screen name='Home' component={Home} options={{
headerTitle: 'Seguro',
headerRight: () => {
<Button // I want to render this button
onPress={() => console.log('This is a button!')}
title="Info"
color="#fff"
/>
}
}} />
<Stack.Screen name='Login' component={Login} />
</Stack.Navigator>
</NavigationContainer>
{
console.log('这是一个按钮!')}
title=“Info”
color=“#fff”
/>
}
}} />
问题是您没有返回任何内容
选项1:隐式返回..括在括号中表示隐式返回
<Stack.Screen name='Home'
component={Home}
options={{
headerTitle: 'Seguro',
headerRight: () => (
<Button
onPress={() => console.log('This is a button!')}
title="Info"
color="#fff"
/>
)
}} />
<Stack.Screen name='Home'
component={Home}
options={{
headerTitle: 'Seguro',
headerRight: () => {
return (
<Button
onPress={() => console.log('This is a button!')}
title="Info"
color="#fff"
/>
)
}
}} />
(
console.log('这是一个按钮!')}
title=“Info”
color=“#fff”
/>
)
}} />
选项2:显式返回
<Stack.Screen name='Home'
component={Home}
options={{
headerTitle: 'Seguro',
headerRight: () => (
<Button
onPress={() => console.log('This is a button!')}
title="Info"
color="#fff"
/>
)
}} />
<Stack.Screen name='Home'
component={Home}
options={{
headerTitle: 'Seguro',
headerRight: () => {
return (
<Button
onPress={() => console.log('This is a button!')}
title="Info"
color="#fff"
/>
)
}
}} />
{
返回(
console.log('这是一个按钮!')}
title=“Info”
color=“#fff”
/>
)
}
}} />
该死!你救了我一天。我怎么会错过这件事