我在react-native中的stackNavigator中遇到了一个小问题。
我有两个正在浏览的 View :Skatebay 和 Profile。 当我使用 stackNavigator 时,它会在 Skatebay View 中添加一个顶栏“标题”,我如何删除它,如果不可能,我可以将其样式设置为看起来像我已经创建的标题吗?
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableHighlight,
Image,
ScrollView,
Button,
} from 'react-native';
import { StackNavigator } from 'react-navigation';
import s from './styles/main.js';
class skatebay extends React.Component{
render(){
const { navigate } = this.props.navigation;
return (
<View style={s.container}>
<View style={s.toolbar}>
<TouchableHighlight style={s.toolbarButton} onPress={() => navigate('Profile')}
title="Profile">
<Image style={s.toolIcon} source={require('./gfx/profile.png')}/>
</TouchableHighlight>
<TouchableHighlight style={s.toolbarTitle} onPress={alert}>
<Image style={s.logo} source={require('./gfx/logos.png')}/>
</TouchableHighlight>
<TouchableHighlight style={s.toolbarButton} onPress={alert}>
<Image style={s.toolIcon} source={require('./gfx/settings.png')}/>
</TouchableHighlight>
</View>
</View>
);
}
}
剖面图
class ProfileScreen extends React.Component {
static navigationOptions = {
title: 'Profile',
};
render() {
return (
<View>
<Text>profile</Text>
</View>
);
}
}
const skatebayApp = StackNavigator({
Main: {screen: skatebay},
Profile: {screen: ProfileScreen}
});
AppRegistry.registerComponent('skatebayApp', () => skatebayApp);
我正在谈论我创建的白色标题上方的蓝色/灰色标题。
最佳答案
如果您不想要 StackNavigator 的默认 header ,您可以将 none 传递给 StackNavigatorConfig https://reactnavigation.org/docs/navigators/stack#StackNavigatorConfig
const skatebayApp = StackNavigator({
Main: {screen: skatebay},
Profile: {screen: ProfileScreen}
}, {
headerMode: 'none'
});
关于javascript - react native 堆栈导航 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43759507/