Nic*_*nie 7 javascript reactjs react-native react-navigation
我正在使用 React Native 构建 Android 和 iOS 应用程序。我用来react-navigation在屏幕之间导航。
问题在于 iOS 上的导航与 Android 上的导航不同(下图)。我希望它们都像 Android 上一样,那么如何在 iOS 上隐藏“搜索汽车”呢?
我已将导航选项设置如下:
Screen.navigationOptions = () => {
const title = 'Search location';
return {
headerTitleStyle: {
fontSize: 18,
color: styles.headerTitle.color,
paddingTop: 5,
height: 40
},
headerStyle: {
backgroundColor: '#fdfdfd'
},
title
};
};
Run Code Online (Sandbox Code Playgroud)
Nen*_*dra 10
从版本 5 开始,它是 screenOptions 中的选项 headerBackTitleVisible
使用示例:
1. 在导航器中
<Stack.Navigator
screenOptions={{
headerBackTitleVisible: false
}}
>
<Stack.Screen name="route-name" component={ScreenComponent} />
</Stack.Navigator>
Run Code Online (Sandbox Code Playgroud)
2. 屏幕内
如果您只想隐藏在单个屏幕中,您可以通过设置屏幕组件上的 screenOptions 来完成此操作,请参见下面的示例:
<Stack.Screen options={{headerBackTitleVisible: false}} name="route-name" component={ScreenComponent} />
Run Code Online (Sandbox Code Playgroud)
3. 屏幕导航选项
Screen.navigationOptions = ({ navigation }) => {
headerTitle: 'Title',
headerLeft: () =>
<View>
/* custom View here - back icon/back button text */
</View
}
Run Code Online (Sandbox Code Playgroud)
4. 所有屏幕的导航器通用
import { HeaderBackButton } from '@react-navigation/elements';
<Stack.Navigator
screenOptions={({ navigation }) => ({
headerLeft: () => (
<HeaderBackButton
labelVisible={false}
tintColor={'#FFF'}
onPress={() => navigation.goBack()}
/>
)
})}>
Run Code Online (Sandbox Code Playgroud)
您需要设置headerBackTitleVisible: false隐藏后退按钮标题。它可以位于屏幕上options、导航器上screenOptions,或者像您的情况一样Screen.navigationOptions。
Screen.navigationOptions = () => {
const title = 'Search location';
return {
headerBackTitleVisible: false, // all you needed
headerTitleStyle: {
fontSize: 18,
color: styles.headerTitle.color,
paddingTop: 5,
height: 40
},
headerStyle: {
backgroundColor: '#fdfdfd'
},
title
};
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8608 次 |
| 最近记录: |