I'm trying to have a popup message coming down from the top of the screen, stays for some time and then goes back up out of screen. The problem is when I try to add a delay, no matter what I set the value of the delay it always delays for about 5 seconds. Here's an example:
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
}
});
React version: 16.8.3
React Native version: 0.59.9
Device: Pixel 2 (API 28) Android emulator