[英]react-native nativeBase Tabs initialPage change to 3 but still start at tab 0
here is the code: (PAY ATTENTION AT COMMENT IN CODE) 这是代码:(请注意代码中的付款注意)
import React, { Component } from 'react';
import {Container, Tab, Tabs, TabHeading, Icon, Text } from 'native-base';
import style from './../styles/compoCss' ;
import NewDB from './../database/NewDB';
import Category from "../lists/Category";
import HomePage from './../tabs/HomePage'
export default class TabHome extends Component {
render() {
return (
<Container>
<Tabs initialPage={3} > //THIS CODE DOESN'T WORK :(
<Tab heading={
<TabHeading style={style.footerTabHome}>
<Icon name="md-aperture" style={style.iconFooter} />
<Text style={style.textFooter}>New</Text>
</TabHeading>}>
<NewDB/>
</Tab>
<Tab heading={
<TabHeading style={style.footerTabHome}>
<Icon name="md-bookmark" style={style.iconFooter} />
<Text style={style.textFooter}>Bookmark</Text>
</TabHeading>}>
</Tab>
<Tab heading={
<TabHeading style={style.footerTabHome}>
<Icon active name="md-apps" style={style.iconFooter} />
<Text style={style.textFooter}>Catalog</Text>
</TabHeading>}>
<Category/>
</Tab>
<Tab heading={
<TabHeading style={style.footerTabHome}>
<Icon name="md-home" style={style.iconFooter} />
<Text style={style.textFooter}>Home</Text>
</TabHeading>} >
<HomePage/>
</Tab>
</Tabs>
</Container>
);
}
}
and when I build the app or refresh it , default tab is the 3 (Home) and I think it's correct but don't show the Home page contents and when i scroll I find out that it is stack in tab 0 (new)... I search all of the forums and I can't solve my problem. 当我构建应用程序或刷新它时,默认选项卡是3(主页),我认为它是正确的,但是不显示主页内容,当我滚动时,我发现它位于选项卡0(新)中。 ..我搜索了所有论坛,但无法解决我的问题。 please help thanks!
请帮忙谢谢! (this problem is in android device)
(此问题在android设备中)
this problem tricked by this code (but not I want to solve initialPage) 此代码欺骗的问题(但我不想解决initialPage)
...
class TabHome extends Component {
componentDidMount(){
setTimeout(this._tabs.goToPage.bind(this._tabs,1))
}
render(){
return ...
<Tabs ref={component => this._tabs = component}>
...
</Tabs>
....
}
}
if it's because of bugs in native base we must wait for update . 如果是由于本机库中的错误引起的,我们必须等待update。 but except that please help :)
但除了请帮助:)
I am also facing this issue and resolved it by below sample code. 我也面临这个问题,并通过下面的示例代码解决了它。
constructor(props) {
super(props);
this.state = {
initialPage: 1,
activeTab: 0
}; }
componentDidMount() {
setTimeout(() => {
this.setState({ activeTab: 1 });
}, 0);
}
render(){
return ...
<Tabs
locked
initialPage={this.state.initialPage}
page={this.state.activeTab}
>
}
I found a trick: native-base: 2.8.2 In componentDidMount(): 我发现了一个窍门:本机基数:2.8.2在componentDidMount()中:
componentDidMount() {
const { initialPage } = this.props; //or use state
setTimeout(this.tabs.goToPage.bind(this.tabs, initialPage));
}
In render() Tabs : 在render()标签中:
<Tabs
ref={(c) => { this.tabs = c; return; }}
...
source: https://github.com/GeekyAnts/NativeBase/issues/1010#issuecomment-448201520 来源: https : //github.com/GeekyAnts/NativeBase/issues/1010#issuecomment-448201520
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.