import React, {useRef} from 'react';
import {Animated, StyleSheet, View, Button} from 'react-native';
const AnimOne = () => {
const mySquare = useRef(new Animated.Value(1)).current;
const runAnimation = () => {
Animated.timing(mySquare, {
toValue: 0,
duration: 2000,
delay: 1500,
useNativeDriver: false,
}).start();
};
return (
<View>
<Animated.View style={{opacity: mySquare}}>
<View style={styles.square} />
</Animated.View>
<Button title="Animation Start" onPress={runAnimation} />
</View>
);
};
const styles = StyleSheet.create({
square: {
width: 100,
height: 100,
backgroundColor: 'skyblue',
},
});
export default AnimOne;
hooks 방식으로 하는 소스도 올려봅니다.
evanjin
작성일
21.03.30 11:32
조회수
122
댓글 0