【发布时间】:2019-07-24 08:43:05
【问题描述】:
我正在尝试从屏幕顶部弹出一条消息,停留一段时间然后回到屏幕外。问题是当我尝试添加延迟时,无论我设置什么延迟值,它总是延迟大约 5 秒。这是一个例子:
import React, { Component } from "react";
import { Animated, View, Text, StyleSheet, Dimensions } from "react-native";
export default class PopupModal extends Component {
constructor(props) {
super(props);
this.state = {
message: "Hello!",
yTranslation: new Animated.Value(0.1)
};
}
render() {
return (
<Animated.View style={{ ...styles.container, transform: [{ translateY: this.state.yTranslation }] }}>
<View style={styles.innerContainer}>
<Text>{this.state.message}</Text>
</View>
</Animated.View>
);
}
componentDidMount() {
Animated.sequence([
Animated.timing(this.state.yTranslation, {
toValue: 130,
duration: 500,
useNativeDriver: true
}),
Animated.timing(this.state.yTranslation, {
toValue: 0,
delay: 10, // <-- Here it doesn't matter which value I choose, it always delays for about 5 seconds.
duration: 500,
useNativeDriver: true
})
]).start();
}
}
const win = Dimensions.get("window");
const styles = StyleSheet.create({
container: {
position: "absolute",
bottom: win.height,
left: 60,
right: 60,
alignItems: "center",
justifyContent: "center"
},
innerContainer: {
paddingHorizontal: 10,
paddingVertical: 5,
backgroundColor: "white",
borderColor: "#444",
borderWidth: 5,
borderRadius: 10
}
});
反应版本:16.8.3
React Native 版本:0.59.9
设备:Pixel 2 (API 28) Android 模拟器
【问题讨论】:
标签: javascript react-native animation react-animated