【问题标题】:Automatically move Material tab bar in react native在反应原生中自动移动 Material 标签栏
【发布时间】:2019-12-15 16:29:18
【问题描述】:

我有一个带有 5 个标签的材质顶部标签栏。但是所有 5 个选项卡都无法适应一个屏幕。在下面的屏幕截图中,只有 4 个选项卡可见。 我需要一种行为,当单击第三个选项卡时,选项卡栏会自动向左移动。我搜索了文档找不到类似的东西。

这里是 app.js

class App extends Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        <AppContainer />
      </View>
    );
  }
}
const AppTabNavigator = createMaterialTopTabNavigator(
  {
    Home: {
      screen: HomeScreen,
      navigationOptions: {
        tabBarLabel: 'Home'
      }
    },
    Settings: {
      screen: SettingsScreen,
      navigationOptions: {
        tabBarlabel: 'Settings'
      }
    },
    Orders: {
      screen: OrdersScreen,
      navigationOptions: {
        tabBarlabel: 'Order List'
      }
    },
    Cancelled: {
      screen: CancelledItemsScreen,
      navigationOptions: {
        tabBarlabel: 'Cancelled Items'
      }
    },
    Others: {
      screen: OthersScreen,
      navigationOptions: {
        tabBarlabel: 'Others'
      }
    }
  },
  {
    initialRouteName: 'Home',
    tabBarOptions: {
      tabStyle: {
        width: 100,
        overflow: 'hidden'
      }
    }
  }
);

const AppContainer = createAppContainer(AppTabNavigator);
export default App;

【问题讨论】:

  • 为什么我把两个屏幕放在同一个屏幕上?
  • 屏幕仅用于测试目的。
  • 尝试使用不同的名称设置不同的屏幕。
  • 我还是没搞明白是哪一个重复了。所有 5 个屏幕都是独一无二的
  • 注册我的答案

标签: reactjs react-native tabbar react-native-navigation


【解决方案1】:

你可以试试这个代码。

renderScene = ({ route }) => {
  if (Math.abs(this.state.index - this.state.routes.indexOf(route)) > 5) {
    return <View />;
  }

  return <MySceneComponent route={route} />;
};

【讨论】:

  • 对不起,我没有得到你的代码。你能改变我上面发布的代码吗?
猜你喜欢
  • 1970-01-01
  • 2019-03-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-04
  • 1970-01-01
相关资源
最近更新 更多