คู่มือ · 05

การเข้า การออก และเลย์เอาต์

เก็บ children ที่กำลังออกไว้จนการเคลื่อนไหวจบ และทำให้การเปลี่ยนตำแหน่งและขนาดเคลื่อนไหว รวมถึงข้ามคอมโพเนนต์

Animated.Keep

Animated.Keep เก็บ children โดยตรงที่มี key ไว้จนผ่าน pose depart seed={false} ทำให้ children ที่อยู่ตั้งแต่การเรนเดอร์แรกเริ่มที่ pose ของตัวเอง wait เลื่อน children ที่จะเข้าไว้จนการออกเสร็จ และ onDeparted ทำงานหลังตัวสุดท้าย

กำลังเตรียมตัวอย่าง…

Animated.Scene และ move

Animated.Scene วัดเลย์เอาต์ที่ commit แล้ว องค์ประกอบที่มี move จะเคลื่อนไหวเมื่อตำแหน่งและขนาดเปลี่ยน สตริงอย่าง move="pill" เชื่อมองค์ประกอบที่มีตัวตนเดียวกันภายใน Scene แม้ตัวหนึ่ง unmount และอีกตัว mount

Scene ถือครอง translate และ scale ของเลย์เอาต์องค์ประกอบเหล่านั้น จึงควรใส่ transform ของคุณไว้ที่องค์ประกอบที่ซ้อนอยู่ข้างใน

กำลังเตรียมตัวอย่าง…

การปรากฏด้วย hook

useAnimatedPresence(visible, { enter, exit }) คืน { mounted, animatedValue } เมื่อคุณอยากควบคุมการ mount เอง

Toast.jsx
const { mounted, animatedValue } = useAnimatedPresence(open, {
  enter: (value) => spring(value, { toValue: 1 }),
  exit: (value) => timing(value, { toValue: 0, duration: 180 }),
});

return mounted ? <div style={{ opacity: animatedValue }}>Saved</div> : null;

นอก React

createLayoutScene ให้การประสาน capture/commit แบบเดียวกันกับ renderer ใดก็ได้ หรือกับการแก้ DOM ด้วยมือ

outside-react.js
const scene = createLayoutScene({ tempo: { spring: { stiffness: 320, damping: 30 } } });
const card = scene.attach(element, { key: 'card' });

scene.capture(); // before the DOM changes
list.prepend(element); // any renderer or manual DOM work
scene.commit(); // animates from the captured rectangles

ค้นหา

พิมพ์เพื่อค้นหาเอกสาร