我正在尝试在React Native中创建动画,其中角色会做一些俯卧撑。 我想在此时完成上下移动。
所以我将gif动画分成2个gif,没有重复。一个让他上升,另一个让他下降。 这些图像是本地存储的
问题是gif更改时闪烁。
我尝试了react-fast-image,但是gif动画太慢并且gif自动循环播放。 我试图在过渡图像中添加过渡图像,但图像仍然闪烁。 图像onLoadEnd回调似乎在图像最终加载之前还为时过早。
在这里我如何切换图像
if (up.includes(this.props.timer))
this.setState({ currentGif: upGif,cacheImage: downPng })
if (down.includes(this.props.timer))
this.setState({ currentGif: downGif,cacheImage: upPng })
以下是渲染器:
render() {
return (
<View
style={{ position: 'absolute',bottom: 70 }}
>
<Image
source={this.state.cacheImage}
style={{ width: 400,height: 330,position: 'relative',bottom: 70 }}
fadeDuration={0}
/>
<Image
source={this.state.currentGif}
style={{ width: 400,position: 'absolute',bottom: 70 }}
fadeDuration={0}
onLoadEnd={() => {this.setState({cacheImage: null})}} // the Image should be loaded so I can hide the cache Image,but it desapear before the gif is loaded
/>
</View>
)
}