【问题标题】:react-native nativeBase Tabs initialPage change to 3 but still start at tab 0react-native nativeBase 选项卡的初始页面更改为 3,但仍从选项卡 0 开始
【发布时间】:2018-02-12 09:35:05
【问题描述】:

这是代码:(请注意代码中的注释)

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 react-native tabs default native-base


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

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

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

      如果是因为原生基础的错误,我们必须等待更新。但除了请帮忙:)

      【讨论】:

      • 如果有人找到解决方案,我很感激
      【解决方案3】:

      我发现了一个窍门: 本机基础: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

      【讨论】:

        猜你喜欢
        • 2021-12-30
        • 1970-01-01
        • 2012-08-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多