React Native 固定页脚与 React Navigation

穆罕默德 Kh75

我正在使用"react-navigation": "^2.11.2"并且有TabNavigator()3 个标签:A、B 和 C。

所以我使用:

...
_Profile: {
  screen: TabNavigator(
    {
      First: A,
      Second: B,
      Third: C
    },
    {
      tabBarPosition: "top",
      swipeEnabled: true,
      lazy: false
    }
  ),
  navigationOptions: ({ navigation }) => ({
    header: <ProfileHeader navigation={navigation} />
  })
},
...

我想在页面 A 和 B 中有一个固定的页脚,但不在 C 中。

首先,我尝试在每个 A 和 B 中创建一个页脚,但结果与我想要的有所不同,请参见下图:

屏幕 A

但是当我尝试滑动到选项卡 B 时,您可以看到页脚未固定:

当我从选项卡 A 滑动到 B 时

对此有什么想法吗?

提前致谢!

穆罕默德 Kh75

我问了贡献者,从现在开始我们有一个完整的例子:

带页脚的自定义标签:

Github 示例


更新

我想链接已损坏,所以我将代码粘贴到此处:

import React from "react";
import {
  LayoutAnimation,
  View,
  StyleSheet,
  StatusBar,
  Text
} from "react-native";
import { SafeAreaView, createMaterialTopTabNavigator } from "react-navigation";
import Ionicons from "react-native-vector-icons/Ionicons";
import { Button } from "./commonComponents/ButtonWithMargin";

class MyHomeScreen extends React.Component {
  static navigationOptions = {
    tabBarLabel: "Home",
    tabBarIcon: ({ tintColor, focused, horizontal }) => (
      <Ionicons
        name={focused ? "ios-home" : "ios-home"}
        size={horizontal ? 20 : 26}
        style={{ color: tintColor }}
      />
    )
  };
  render() {
    const { navigation } = this.props;
    return (
      <SafeAreaView forceInset={{ horizontal: "always", top: "always" }}>
        <Text>Home Screen</Text>
        <Button
          onPress={() => navigation.navigate("Home")}
          title="Go to home tab"
        />
        <Button onPress={() => navigation.goBack(null)} title="Go back" />
      </SafeAreaView>
    );
  }
}

class RecommendedScreen extends React.Component {
  static navigationOptions = {
    tabBarLabel: "Recommended",
    tabBarIcon: ({ tintColor, focused, horizontal }) => (
      <Ionicons
        name={focused ? "ios-people" : "ios-people"}
        size={horizontal ? 20 : 26}
        style={{ color: tintColor }}
      />
    )
  };
  render() {
    const { navigation } = this.props;
    return (
      <SafeAreaView forceInset={{ horizontal: "always", top: "always" }}>
        <Text>Recommended Screen</Text>
        <Button
          onPress={() => navigation.navigate("Home")}
          title="Go to home tab"
        />
        <Button onPress={() => navigation.goBack(null)} title="Go back" />
      </SafeAreaView>
    );
  }
}

class FeaturedScreen extends React.Component {
  static navigationOptions = ({ navigation }) => ({
    tabBarLabel: "Featured",
    tabBarIcon: ({ tintColor, focused, horizontal }) => (
      <Ionicons
        name={focused ? "ios-star" : "ios-star"}
        size={horizontal ? 20 : 26}
        style={{ color: tintColor }}
      />
    )
  });
  render() {
    const { navigation } = this.props;
    return (
      <SafeAreaView forceInset={{ horizontal: "always", top: "always" }}>
        <Text>Featured Screen</Text>
        <Button
          onPress={() => navigation.navigate("Home")}
          title="Go to home tab"
        />
        <Button onPress={() => navigation.goBack(null)} title="Go back" />
      </SafeAreaView>
    );
  }
}

const SimpleTabs = createMaterialTopTabNavigator({
  Home: MyHomeScreen,
  Recommended: RecommendedScreen,
  Featured: FeaturedScreen
});

class TabNavigator extends React.Component {
  static router = SimpleTabs.router;
  componentWillUpdate() {
    LayoutAnimation.easeInEaseOut();
  }
  render() {
    const { navigation } = this.props;
    const { routes, index } = navigation.state;
    const activeRoute = routes[index];
    let bottom = null;
    if (activeRoute.routeName !== "Home") {
      bottom = (
        <View style={{ height: 50, borderTopWidth: StyleSheet.hairlineWidth }}>
          <Button title="Check out" onPress={() => {}} />
        </View>
      );
    }
    return (
      <View style={{ flex: 1 }}>
        <StatusBar barStyle="default" />
        <SafeAreaView
          style={{ flex: 1 }}
          forceInset={{ horizontal: "always", top: "always" }}
        >
          <SimpleTabs navigation={navigation} />
        </SafeAreaView>
        {bottom}
      </View>
    );
  }
}

export default TabNavigator;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

React Native固定页眉/页脚iPhone X

React Native,React-Navigation

React Native:设置 React Navigation 的屏幕标题

React Native Context API react-navigation

React Native Navigation TopBar 图标未显示

等价于React Native Navigation的动态查询参数?

React Native Navigation:在屏幕之间传递数据

React Native Navigation:检查抽屉是否打开

React Native Navigation 不会显示初始组件

Navigation between 2 screens in react native in navigationOptions

TypeError : Object (...) is not a function react native stack navigation

重置主屏幕的导航堆栈(React Navigation和React Native)

在React Native项目中安装react-navigation后警告

React Native,更改React Navigation标头样式

在 react-native 0.59.10 中使用 react-navigation

暗模式不起作用React Navigation React Native

禁止使用react-navigation返回react-native

React Native的React-Navigation:在TabNavigator的Tab中添加徽章

react native:使用 headerRight 导航时,react-navigation 崩溃

React Native-使用React Navigation动态创建导航器

react-native:react-navigation抽屉标签

React Native Firebase启动器和React Navigation

react-native React-Navigation头按钮testID

与expo react native的嵌套react-navigation深度链接

React-native 启动画面和 react-navigation

使用嵌套的 react-navigation 来 React Native HOC

安装React Navigation后无法构建或安装React Native应用

React Native Navigation Error:路线的组件必须是React组件

在React Navigation上更新react-native-maps