标签: react-navigation

如何在常量中使用反应导航?

我使用 const 来显示组件。现在,当我对 const 中的按钮使用反应导航时,我看到了这个错误:未定义不是一个对象(评估 '_this.props.navigation.navigate')

我尝试将 navigation={this.props.navigation} 添加到按钮以允许导航,但没有奏效。

const WomenTab = () => (
    <View>
      <Button onPress={() => {
                        this.props.navigation.dispatch(StackActions.reset({
                          index: 0,
                          actions: [
                            NavigationActions.navigate({ routeName: 'Wallet' })
                          ],
                        }))
                      }}>
          <Text>Click</Text>
      </Button>
    <View>
);
Run Code Online (Sandbox Code Playgroud)

库链接:http : //github.com/react-native-community/react-native-tab-view

reactjs react-native react-native-navigation react-navigation

2
推荐指数
1
解决办法
755
查看次数

动画来回旋转徽标单击与本机反应

我正在尝试为菜单徽标设置动画以在单击时旋转。当它向上旋转时,我成功地获得了旋转,但它在向下旋转时直接变为 0,而不是通过旋转动画。

这是我的组件:

import React from 'react';
import { TouchableOpacity, Animated } from 'react-native';
import PropTypes from 'prop-types';

import styles from './styles';

const TabIcon = ({
  route,
  renderIcon,
  onPress,
  focused,
  menuToggled,
  activeTintColor,
  inactiveTintColor,
}) => {
  const isMenuLogo = route.params && route.params.navigationDisabled;
  const animation = new Animated.Value(0);

  Animated.timing(animation, {
    toValue: menuToggled ? 1 : 0,
    duration: 200,
    useNativeDriver: true,
  }).start();

  const rotateInterpolate = animation.interpolate({
    inputRange: [0, 1],
    outputRange: ['0deg', '180deg'],
  });
  const animatedStyles = { transform: [{ rotate: rotateInterpolate }] …
Run Code Online (Sandbox Code Playgroud)

animation reactjs react-native react-navigation

2
推荐指数
1
解决办法
5401
查看次数

导航到登录屏幕后重置堆栈

我正在制作一个 react-native 移动应用程序,我有一个导航抽屉,上面有一个注销按钮。我知道如何从那里导航到登录屏幕,使用props.navigation.navigate('Login'),但问题是如果用户这样做,他们仍然可以从登录屏幕打开抽屉并导航回其他屏幕之一,或者按后退按钮在安卓上。

如果用户来自另一个页面,我想我可以在登录屏幕上进行检查,然后禁用打开抽屉按钮,但这似乎有点麻烦。我想知道是否有正确的方法可以做到这一点,也许是在登录时重置堆栈,我不确定。

react-native react-native-android react-navigation

2
推荐指数
1
解决办法
8292
查看次数

使用 React Navigation 多次堆叠同一屏幕

我有3个屏幕上StackNavigatorMainSearchMonsterPageItemPage。我想堆叠MonsterPageItemPage多次(从MonsterPage你可以去,ItemPage反之亦然)

可以实例化屏幕吗?

const AppNavigator = createStackNavigator(
    {
        Home: MainSearch,
        MonsterPage: MonsterPage,
        ItemPage: ItemPage
    },
    {
        initialRouteName: "Home"
    }
);

export default createAppContainer(AppNavigator);
Run Code Online (Sandbox Code Playgroud)

我想要的是:

MainSearch -> ItemPage(1) -> MonsterPage(1) -> ItemPage(2) -> 等等...

或者

MainSearch -> MonsterPage(1) -> ItemPage(1) -> MonsterPage(2) -> 等等...

我得到的:

MainSearch -> MonsterPage(1) -> ItemPage(1) ->(返回) MonsterPage(1)

Gif 显示会发生什么

主搜索

onPress={() => { this.props.navigation.navigate(`${r._source.super_cat === 'monster' ? 'MonsterPage' : 'ItemPage'}`, …
Run Code Online (Sandbox Code Playgroud)

javascript react-native react-navigation react-navigation-stack

2
推荐指数
1
解决办法
1951
查看次数

React Native 使用不同的 props 导航到同一页面

我正在开发一个使用侧抽屉的 RN 应用程序。(RN 版本:0.59.8)

const DrawerNavigator = createDrawerNavigator(
    {
        Home: {
            screen: HomeScreen
        },
        Poems: {
            screen: PoemsScreen
        },
        Contest: {
            screen: ContestScreen
        },
        AboutMe: {
            screen: AboutMeScreen
        }
    },
    DrawerConfig
);

export default createAppContainer(DrawerNavigator);
Run Code Online (Sandbox Code Playgroud)

使用的 react-navigation 版本是 3.11.0。在菜单中,多个子项指向同一个页面,即 ViewPager,但具有不同的参数(页面索引)。问题是以下方法都不起作用:

  1. 尝试使用推送而不是导航(返回_this2.props.navigation.push is not a function
  2. 试图重置相应的堆栈。
const resetAction = StackActions.reset({
   index: 0,
   key: 'Poems',
   actions: [NavigationActions.navigate({ routeName: 'Poems' })]
})
this.props.navigation.dispatch(resetAction)
Run Code Online (Sandbox Code Playgroud)

(也试过key: null

任何帮助深表感谢!

react-native react-native-android react-navigation react-navigation-drawer

2
推荐指数
1
解决办法
4837
查看次数

React Native 和 React Navigation — 如何让屏幕标题显示在标题和底部选项卡导航器中也显示

我正在自学 React Native 并构建一个相当简单的应用程序,irMobile.

我已经设置了每个屏幕(以关于屏幕为例)

static navigationOptions = () => ({
  title: 'About'
})
Run Code Online (Sandbox Code Playgroud)

在我的应用程序的主要组件中

const MainNavigator = createBottomTabNavigator({ About })
const StackNavigator = createStackNavigator({ MainNavigator })
const AppContainer = createAppContainer(StackNavigator)
Run Code Online (Sandbox Code Playgroud)

然后在组件本身

  render() {
    return (
      <View style={styles.container}>
        <AppContainer />
      </View>
    )
  }
Run Code Online (Sandbox Code Playgroud)

我的屏幕在底部呈现一个漂亮的导航栏,但标题中没有任何标题,只有一个空白区域。

我已经多次浏览文档,想看看我错过了什么,但我很难过。

如果我使用的检查中的iOS模拟器我可以选择的标题,它表明这是一个Viewx: 0, y: 44width: 375height: 43.7,这样的东西是存在的我就是不能看到它。

我试过设置 aheaderStyle{ backgroundColor: 'red' }查看我是否至少可以看到它,但没有。

iPhone 模拟器的屏幕快照显示标题

但是,如果我更改StackNavigatorAbout屏幕放在那里MainNavigator,如下所示:

const …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

2
推荐指数
1
解决办法
3836
查看次数

在函数组件中反应导航 getParams

问题总结

我在 React Navigation 中使用功能组件,并且正在使用我根据他们的文档创建的 NavigationService 组件中的 NavigationService.navigate 。我需要将参数传递给目标,我可以这样做,但我不知道如何在目标屏幕中检索参数。

我想我只需要在我的 NavigationService.js 文件中添加一些东西,但我不确定它应该是什么,而且我在他们的文档中找不到它。

代码

启动画面中的代码

import NavigationService from "~/app/services/NavigationService";
onPress={() => NavigationService.navigate("CompScreen", { comp })}
Run Code Online (Sandbox Code Playgroud)

导航服务.js

import {
  NavigationActions,
  DrawerActions,
  StackActions
} from "react-navigation";

let navigator;

/**
 * @function setTopLevelNavigator
 * @param  {ref} navigatorRef
 */
function setTopLevelNavigator(navigatorRef) {
  navigator = navigatorRef;
}

/**
 * @function navigate
 * @param  {string} routeName
 * @param  {any} params
 */
function navigate(routeName, params) {
  navigator.dispatch(
    NavigationActions.navigate({
      routeName,
      params
    })
  );
}

/**
 * @function …
Run Code Online (Sandbox Code Playgroud)

javascript node.js reactjs react-native react-navigation

2
推荐指数
1
解决办法
7509
查看次数

Haste 模块映射中不存在模块 `react-navigation-tabs`

我尝试在 React Native 中创建标签导航。但是当我想导入import { createBottomTabNavigator } from 'react-navigation-tabs';. 我有以下错误:bundling failed: Error: Unable to resolve module `react-navigation-tabs` from `/Users/nicolasthibault/Desktop/RunApplication/Runenger/Views/NavigationReact.js`: Module `react-navigation-tabs` does not exist in the Haste module map

我尝试了许多我发现的类似主题的命令,但它们中的任何一个都适用于我的情况。例如,我尝试了这些,但它不能解决我的问题。

1. Clear watchman watches: `watchman watch-del-all`. 2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`. 3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`. 4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.

谢谢你的帮助。

react-native react-navigation

2
推荐指数
1
解决办法
4780
查看次数

如何将静态导航选项与功能组件一起使用?

我如何使用这样的东西:

    /* Imports */
    import React from 'react';
    import { TouchableOpacity, StatusBar, View, Text, Linking } from 'react-native';
    import { Container, Header, Left, Body, Title, Button, List, ListItem, Content } from 'native-base';
    import { AntDesign, MaterialCommunityIcons, Entypo, MaterialIcons, FontAwesome } from '@app/utils/Icons';
    import { custom, responsive } from '@app/styles/config';
    import { withTheme} from '../../theme/themeProvider';
    import { styles } from '../../theme/theme';
    /* /Imports/ */

    class SettingsView extends React.Component {
      /* Navigation Options Like (Header, Title, Menu, Icon, Style) */
      static navigationOptions …
Run Code Online (Sandbox Code Playgroud)

themes react-native react-navigation

2
推荐指数
1
解决办法
5773
查看次数

无法从 React Native 的 Material Top Bar Navigator 中删除 boxShadow

我正在使用 React Native 导航包中的顶部选项卡导航,该导航包是通过该createMaterialTopTabNavigator()函数创建的。默认情况下,标签栏上有一个框阴影,我想禁用它。这是我的标签屏幕配置代码:

const TabScreen = createMaterialTopTabNavigator(
  {
    "Test one": { screen: TestScreen1 },
    "Test two": { screen: TestScreen2 },
    "Test three": { screen: TestScreen3 },
  },
  {
    tabBarPosition: 'top',
    swipeEnabled: true,
    animationEnabled: true,
    tabBarOptions: {
      upperCaseLabel: false,
      scrollEnabled: true,
      activeTintColor: '#000',
      inactiveTintColor: 'rgb(180, 180, 180)',
      pressColor: 'orange',
      style: {
        boxShadow: 'none',
        backgroundColor: '#fff',
        numberOfLines: 1,
      },
      tabStyle: {
        //
      },
      labelStyle: {
        fontSize: 16,
        textAlign: 'center',
      },
      indicatorStyle: {
        borderBottomColor: 'orange',
        borderBottomWidth: 4,
      },
    },
  } …
Run Code Online (Sandbox Code Playgroud)

react-native react-navigation

2
推荐指数
2
解决办法
1390
查看次数