inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

iOS/Android 앱 개발을 위한 실전 React Native - Basic

다른 Animation 효과 생성하기

hooks 방식으로 하는 소스도 올려봅니다.

252

evanjin
0

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;

답변 0