react-native nativeBase 选项卡 initialPage 更改为 3 但仍从选项卡 0 开始

react-native nativeBase Tabs initialPage change to 3 but still start at tab 0

代码如下:(注意代码中的注释)

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>
    );
  }
}

当我构建应用程序或刷新它时,默认选项卡是 3(主页),我认为它是正确的但不显示主页内容,当我滚动时我发现它在选项卡中堆叠0(新)... 我搜索了所有论坛,但无法解决我的问题。请帮助谢谢! (此问题在 android 设备中)

这个问题被这段代码骗了(但不是我想解决initialPage)

... 
class TabHome extends Component {
  componentDidMount(){
  setTimeout(this._tabs.goToPage.bind(this._tabs,1))
}
render(){
  return ...
   <Tabs ref={component => this._tabs = component}>
     ...
   </Tabs>
   ....
  }
}

如果是因为本机基础中的错误,我们必须等待更新。但除此之外请帮忙:)

我发现了一个窍门: 本机基础:2.8.2 在 componentDidMount():

componentDidMount() {
    const { initialPage } = this.props; //or use state
    setTimeout(this.tabs.goToPage.bind(this.tabs, initialPage));
}

在 render() 选项卡中:

<Tabs
    ref={(c) => { this.tabs = c; return; }}
...

来源:https://github.com/GeekyAnts/NativeBase/issues/1010#issuecomment-448201520

我也遇到了这个问题,通过下面的示例代码解决了。

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}
      >
}