【发布时间】:2020-04-29 13:51:58
【问题描述】:
我正在尝试制作一个简单的动画,其中我的图像会淡入。
下面的代码我正在导入{useSpring, animated} from 'react-spring'。
我创建了简单的 useSpring 函数 logoLoadingScreen。然后我在 IMAGE 的样式中添加函数;但是,没有显示动画。
import React from 'react';
import {useSpring, animated} from 'react-spring'
import {View,Text,StyleSheet,Image} from 'react-native';
const logoReParty = () =>{
require('../img/img1.jpg')
}
const logoLoadingScreen = () => {
//react Native ANIMATION from 'react-spring'
const fade = useSpring({
from:{
opacity: 0
},
to: {
opacity: 1
}
});
return <View>
<Image source={require('../img/img1.jpg')}
style={[styles.logoBackground, logoLoadingScreen]}
resizeMode={"contain"}
/>
<Text style={styles.loadingLogo}>Loading Screen</Text>
</View>
};
此外,我在下面尝试了这种方法来利用“动画”库来包装 VIEW 内容。
但是我收到一条错误消息stating 'Invariant Violation: Element type is invalid expected a string or a class/function but got: undefined。
return <animated.View>
<Image source={require('../img/img1.jpg')}
style={[styles.logoBackground, logoLoadingScreen]}
resizeMode={"contain"}
/>
<Text style={styles.loadingLogo}>Loading Screen</Text>
</animated.View>
};
如何使用 react-spring 在图像上显示淡入淡出动画? 另外,如何显示整个屏幕的淡入淡出动画?
谢谢你:)
更新
如下所述,我创建了新的 const AnimatedView = animated(View)。然而,屏幕的不透明度并没有改变,我看不到动画的变化。
const AnimatedView = animated(View);
const logoLoadingScreen = () => {
//react Native ANIMATION from 'react-spring'
const fade = useSpring({
from:{
opacity: 0
},
to: {
opacity: 0.2
}
});
return <AnimatedView style={logoLoadingScreen}>
<Image source={require('../img/img1.jpg')}
style={[styles.logoBackground, logoLoadingScreen]}
resizeMode={"contain"}
/>
<Text style={styles.loadingLogo}>Loading Screen</Text>
</AnimatedView>
};
动画没有出现在屏幕上的可能原因是什么?仅供参考:没有更多的错误,而是屏幕上没有显示动画。 再次感谢您的帮助! ^^
已解决
添加淡入淡出的内部样式解决了我的动画问题。
return <AnimatedView style={logoLoadingScreen,fade}>
感谢那些帮助我的人:)
【问题讨论】:
标签: javascript reactjs react-native animation react-spring