가이드 · 02

타이밍, 스프링, 조합

드라이버를 고르고, 여러 개를 조합하고, 하나를 멈추거나 교체할 때 정확히 무슨 일이 일어나는지 압니다.

timing, spring, decay

timing은 정해진 duration 동안 곡선을 따릅니다. spring은 물리를 따르므로 고정된 길이가 없습니다. decay는 속도로 출발해 점점 느려집니다.

같은 드라이버가 숫자, ValueXY, 묶음을 모두 받으므로 { x, y, opacity }를 함께 움직일 수 있습니다.

예제를 준비하는 중…

스프링 매개변수

한 가지 방식만 쓰세요. 아무것도 주지 않으면 React Native 기본 스프링(tension 40, friction 7)입니다. 스프링의 velocity 기본값은 끊긴 궤적의 속도입니다.

springs.js
spring(value, { toValue: 1 }); // React Native default
spring(value, { toValue: 1, stiffness: 260, damping: 20 }); // physical
spring(value, { toValue: 1, bounciness: 8, speed: 12 }); // React Native style
spring(value, { toValue: 1, tension: 40, friction: 7 }); // origami style

조합하기

sequence는 차례로, parallel은 함께, stagger는 간격을 두고 차례로 시작하고, delay는 기다리고, loop는 반복합니다. 결과도 컨트롤러이므로 조합을 중첩할 수 있습니다.

예제를 준비하는 중…

start, stop, reset

모든 컨트롤러에는 start(callback?), stop(), reset()이 있습니다. 콜백은 { finished }를 받으며, 모션이 멈추거나 교체되면 false입니다.

같은 값에서 새 드라이버를 시작하면 실행 중인 드라이버를 지금 위치에서 교체합니다. 어느 끝으로도 튀지 않습니다.

controller.js
const move = timing(value, { toValue: 1, duration: 600 });

move.start(({ finished }) => {
  // finished is false when stopped or replaced by a new animation
});
move.stop(); // keeps the value where it is on screen
move.reset(); // returns to where this animation started

다른 값 추적하기

살아 있는 toValue는 그 값이 바뀔 때마다 드라이버를 다시 시작합니다. React Native의 tracking과 같습니다. follow(target, source)는 같은 스프링 연결을 이름 있는 함수로 쓴 것입니다.

tracking.js
// A live toValue tracks another value, like React Native tracking.
spring(badge, { toValue: pointer, stiffness: 300, damping: 26 }).start();

// follow() is the same connection as a named function.
follow(badge, pointer, { stiffness: 300, damping: 26 });

Easing과 키프레임

Easing은 React Native와 같습니다. linear, quad, cubic, sin, circle, exp, elastic, back, bounce, bezier와 in, out, inOut 도우미가 있습니다. keyframes(value, frames, options)는 선택적인 times, repeat로 값 하나를 여러 숫자에 걸쳐 움직입니다.

검색

입력하면 문서를 검색합니다.