gpt4 book ai didi

javascript - undefined 不是函数(评估'_reactNavigation.NavigationActions.reset')

转载 作者:可可西里 更新时间:2023-11-01 02:51:31 24 4
gpt4 key购买 nike

我想在一定的超时后将初始屏幕导航到下一个屏幕。启动画面有一个动画,这是在 Airbnb Lottie for React Native 的帮助下完成的。

启动画面代码如下:

import React from "react";
import { Animated, Easing } from "react-native";
import LottieView from "lottie-react-native";
import { NavigationActions } from "react-navigation";

export default class SplashScreen extends React.Component {
static navigationOptions = {
header: null
};

constructor() {
super();
this.state = {
progress: new Animated.Value(0),
}
}

componentDidMount() {
setTimeout(() => {
this.navigateToWalkthrough()
}, 3500);

Animated.timing(this.state.progress, {
toValue: 1,
duration: 3000,
easing: Easing.linear,
}).start();
}

navigateToWalkthrough = () => {
const navigateAction = NavigationActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "Walkthrough" })],
});

this.props.navigation.dispatch(navigateAction);
}

render() {
return(
<LottieView
source={require("../assets/splash/SplashScreenAnimation.json")}
progress={this.state.progress}
/>
);
}
}

运行应用程序后出现以下错误:

undefined is not a function (evaluating'_reactNavigation.NavigationActions.reset')

Main.js 文件如下所示:

import React from "react";
import { View, Text } from "react-native";
import { createStackNavigator } from "react-navigation";

import SplashScreen from "./screens/SplashScreen";
import Walkthrough from "./screens/Walkthrough";

const Routes = createStackNavigator({
Home: {
screen: SplashScreen
},
Walkthrough: {
screen: Walkthrough
}
});

export default class Main extends React.Component {
render() {
return <Routes />;
}
}

任何帮助/反馈?

最佳答案

reset 操作已从 NavigationActions 中删除并且有 StackActions特定于 react-navigation v2 中的 StackNavigator

StackActions is an object containing methods for generating actions specific to stack-based navigators. Its methods expand upon the actions available in NavigationActions.

The following actions are supported:

Reset - Replace current state with a new state

Replace - Replace a route at a given key with another route

Push - Add a route on the top of the stack, and navigate forward to it

Pop - Navigate back to previous routes

PopToTop - Navigate to the top route of the stack, dismissing all other routes

关于javascript - undefined 不是函数(评估'_reactNavigation.NavigationActions.reset'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50443451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com