javascript - React Native 中动画完成时触发函数?

标签 javascript android ios animation react-native

我正在使用 React Native 实现启动屏幕,并且我只是使用 StackNavigator路线更改为 启动画面中的动画完成时的>主要 Activity 。为此,我试图找到一种触发 this.props.navigation.navigate('Main') 函数的方法。

The question is that how i can implement the onComplete function in my animation class?

这是我的动画代码:

import React from 'react';
import { Animated, Text, View } from 'react-native';

class FadeInView extends React.Component {
state = {
    fadeAnim: new Animated.Value(0),  // Initial value for opacity: 0
}

componentDidMount() {
    Animated.timing(                  // Animate over time
    this.state.fadeAnim,            // The animated value to drive
    {
        toValue: 1,                   // Animate to opacity: 1 (opaque)
        duration: 1000,              // Make it take a while
    }
    ).start();                        // Starts the animation
}

render() {
    let { fadeAnim } = this.state;

    return (
    <Animated.View                 // Special animatable View
        style={{
        ...this.props.style,
        opacity: fadeAnim,         // Bind opacity to animated value
        }}
    >
        {this.props.children}
    </Animated.View>
    );
}
}

export default FadeInView

和我的SplashScreen:

import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
Image
} from 'react-native';
import FadeInView from '../Animations/FadeInAnimation';
import { StackNavigator } from 'react-navigation';
import RanjoorMain from './RanjoorMain';

class SplashScreen extends Component {
render() {
    return (
    <View style={styles.container}>
        <View style={{flex:1}}></View>
        <FadeInView style={{width: 230, height: 230, backgroundColor: 'transparent'}}>
            <Image style={styles.introLogo}
            source={require('../Images/Logo/Ranjoor.png')}
            />
        </FadeInView>
        <View style={{flex:1}}></View>
    </View>
    );
}
}

const styles = StyleSheet.create({
container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#3863cc',
},
welcome: {
    fontSize: 45,
    textAlign: 'center',
    margin: 10,
},
instructions: {
    textAlign: 'center',
    color: '#242329',
    marginBottom: 5,
},
introLogo: {
    width: 230,
    height: 230
}
});

/* This StackNavigator will change the route to the RanjoorMain.js after a couple of ms */
const GoToRanjoorMain = StackNavigator({
    Splash: { screen: Splas },
    Main: { screen: RanjoorMain }
})

GoToRanjoorMain.navigationOptions = {
title: 'Ranjoor', 
};

export default SplashScreen

最佳答案

您可以为动画的 start 方法提供一个完成处理程序。

Animated.timing(              
    this.state.fadeAnim,          
    {
        toValue: 1,        
        duration: 1000,            
    }
).start(() => nav.goToSomeScreen()); 

关于javascript - React Native 中动画完成时触发函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45006733/

相关文章:

javascript - promise 的网络 worker 的速度

javascript - 正则表达式匹配所有被一个或多个字母或数字包围的单下划线

javascript - 为什么 JavaScript 缺少导入子文件的命令?

android - onTouch() 未调用父布局

android - 在 Eclipse 中更改 Android LogCat 字体

javascript - 检查上一页 URL 是否包含字符串,然后将类添加到当前页面上的元素

java - 如何理解和实现 Twitter API 制作 Android Twitter 客户端

ios - 为其轮廓创建 Box 后 UITextView 的大小和位置错误

ios - 如何远程运行 xcode 机器人

ios - 创建 session UUID Swift