inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

XY Animation의 추가 효과 및 Triggering Button 생성

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

239

evanjin
0

import React, {useRef} from 'react';
import {Easing, Animated, StyleSheet, View, Button} from 'react-native';

const AnimOne = () => {
  const mySquare = useRef(new Animated.ValueXY(0, 0)).current;
  const runAnimation = () => {
    Animated.timing(mySquare, {
      toValue: {x: 50, y: 300},
      duration: 2000,
      delay: 1500,
      easing: Easing.elastic(3),
      useNativeDriver: false,
    }).start();
  };
  return (
    <View>
      <Animated.View style={mySquare.getLayout()}>
        <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