Pa-*_*won 9 javascript react-native lottie
我想在特定超时后将启动画面导航到下一个屏幕.启动画面有一个动画,在Airbnb Lottie的帮助下为React Native完成.
splashscreen代码如下:
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}
/>
);
}
}Run Code Online (Sandbox Code Playgroud)
我运行应用程序后出现错误:
undefined is not a function (evaluating'_reactNavigation.NavigationActions.reset')
Run Code Online (Sandbox Code Playgroud)
该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 />;
}
}Run Code Online (Sandbox Code Playgroud)
任何帮助/反馈?
ben*_*nel 18
reset动作被移除,NavigationActions并且在反应导航的v2中有StackActions特定的StackNavigator.
StackActions是一个对象,包含用于生成特定于基于堆栈的导航器的操作的方法.其方法扩展了NavigationActions中可用的操作.支持以下操作:
重置 - 用新状态替换当前状态
替换 - 用另一条路线替换给定键的路线
推送 - 在堆栈顶部添加路由,然后向前导航到该路径
Pop - 导航回以前的路线
PopToTop - 导航到堆栈的顶部路径,解除所有其他路径
import { StackActions, NavigationActions } from 'react-navigation';
navigateToWalkthrough = () => {
const navigateAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "Walkthrough" })],
});
this.props.navigation.dispatch(navigateAction);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8336 次 |
| 最近记录: |