我正在使用UI的本机基础(http://nativebase.io/docs/v2.0.0/components#footerTab)创建一个本机react应用程序。我使用的是footerTabs组件,代码如下
render() {
return (
<Container>
<Header backgroundColor="#ECEFF1">
<Button transparent>
<Icon name='ios-menu' style={{color: 'black'}}/>
</Button>
<Title style={{color:'black'}}>Header</Title>
</Header>
<Content>
<Profile/>
</Content>
<Footer backgroundColor="#212121">
<FooterTab>
<Button backgroundColor="#000" >
<Icon name="ios-person" size={30} color="#900"/>
<Text>Profile</Text>
</Button>
<Button>
<Icon name="ios-search"/>
<Text>Search</Text>
</Button>
<Button>
<Icon name="ios-camera"/>
<Text>Camera</Text>
</Button>
<Button>
<Icon name="ios-apps"/>
<Text>Apps</Text>
</Button>
<Button>
<Icon active name="ios-navigate"/>
<Text>Navigate</Text>
</Button>
</FooterTab>
</Footer>
</Container>
);
}我已经为不同的功能创建了不同的JS文件,如配置文件、搜索、应用程序等。并按如下方式导入它们。
import Profile from './Profile';如何在页脚的按钮上实现onPress功能,以根据所选内容更改内容标记中的组件?
<Content>
<Profile/>
</Content>例如:如果我按下搜索按钮,我希望配置文件标签被替换为,类似地,其他按钮也是如此。
发布于 2017-02-08 02:05:47
在这里,来自原生基础FooterTab并不像iOS中的UITabBar那样持久化实际的选项卡功能,它只是为了设计而持久化。您需要做的是,使用所有四个按钮在所有组件中保留脚注标签,并相应地保持活动状态。要通过选择任何按钮来更改视图,您需要使用导航器将当前视图替换为选定视图,如下所示:
<Button onPress={()=> { this.props.navigator.replace({id:'component name'}) }}>在您的导航器组件中,您应该根据路由有效负载中的id值在renderScene方法中定义所有必需的组件。如果您想要实际的功能作为TabBar工作,那么您可以使用这个第三方模块react-native-tab-navigator。谢谢!
发布于 2017-02-08 03:47:01
与其替换内容,为什么不让每个Button导航到一个新页面呢?
假设您在Profile选项卡上。你可以这样做:
import FooterWrapper from './FooterWrapper'
<Footer>
<FooterWrapper tab='profile' navigator={this.props.navigator} />
</Footer>然后在您的FooterWrapper中(我刚刚处理了一个包含两个选项卡的例子):
constructor(props) {
super(props)
this.state = {
profileTab: this.props.tab === 'profile',
searchTab: this.props.tab === 'search',
}
}
navToProfilePage() {
this.props.navigator.push({
id: 'profile',
tab: 'profile',
})
}
navToSearchPage() {
this.props.navigator.push({
id: 'search',
tab: 'search',
})
}
render() {
return (
<FooterTab>
<Button active={this.state.profileTab} onPress={() => this.navToProfilePage()}>
Profile
<Icon name='ios-person' size={30} color='#900' />
</Button>
<Button active={this.state.searchTab} onPress={() => this.navToSearchPage()}>
Search
<Icon name='ios-search' />
</Button>
</FooterTab>
)
}发布于 2017-02-08 16:56:48
好的,这就是我是如何获得它的,我在内容标记中使用了renderContent方法来根据按钮被单击时的状态变化来生成视图。
<Content>
{this._renderContent(this.state.selectedTab)}
</Content>selectedTab是一个状态变量,其状态是在onPress方法中使用this.setState设置的。renderContent有一个if函数,用于检查选定的选项卡并返回适当的视图。我也尝试了导航方法,但这似乎更清晰。
_renderContent = (Tab: string,) => {
if(this.state.selectedTab==="Profile"){
return (
<Profile/>
);
}
else if(this.state.selectedTab==="Search"){
}
}https://stackoverflow.com/questions/42095875
复制相似问题