คู่มือ · 07

มาจาก React Native

อะไรเหมือนเดิม อะไรเปลี่ยน และเว็บเพิ่มอะไร

การเรียกเหมือนเดิม

ตัวควบคุม กราฟ และการตั้งค่าเป็นไปตาม Animated ของ React Native เรนเดอร์โฮสต์ DOM อย่าง Animated.div ในจุดที่ React Native เรนเดอร์ Animated.View useAnimatedValue ใช้ได้เหมือนใน React Native

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

ความต่างที่ควรรู้

รายละเอียดเหล่านี้ทำให้โค้ดที่ย้ายมาทำงานแบบเดียวกับบนอุปกรณ์

  • useNativeDriver และ isInteraction ยอมรับได้ แต่การเล่นจะถูกเลือกตามผลลัพธ์แต่ละตัวแทน ผลลัพธ์ที่เข้าเงื่อนไขจะเล่นในเบราว์เซอร์ ที่เหลือเล่นใน JavaScript
  • spring รับ stiffness/damping/mass, bounciness/speed หรือ tension/friction และใช้ค่าเริ่มต้นของ React Native หากไม่ระบุ
  • interpolate รองรับ easing และโหมด extrapolation ทั้งสามแบบ
  • Easing ตรงกับ React Native รวมถึง elastic Easing.exp ถูกปรับสเกลใหม่ 0.1% ให้เริ่มที่ 0 พอดี จึงใช้การเล่นของเบราว์เซอร์ได้
  • ความเร็วของ decay เป็นหน่วยต่อมิลลิวินาที และความเร็วของ spring เป็นหน่วยต่อวินาที เหมือนใน React Native
  • Animated.createAnimatedComponent ห่อคอมโพเนนต์ที่ส่งต่อ ref
Spinner.jsx
// React Native
<Animated.View style={{ transform: [{ rotate }] }} />

// React DOM with @kkwaenggwari/animated — the rest is identical
<Animated.div style={{ transform: [{ rotate }] }} />

const spin = useAnimatedValue(0);
const rotate = spin.interpolate({ inputRange: [0, 1], outputRange: ['0deg', '360deg'] });

Animated.loop(
  Animated.timing(spin, { toValue: 1, duration: 900, easing: Easing.linear, useNativeDriver: true }),
).start();

เว็บเพิ่มอะไร

style ธรรมดาของ React รับค่าจาก hook ได้โดยตรง seed/pose/respond อธิบายปลายทางและท่าทาง และ Animated.Keep กับ Animated.Scene จัดการการออกและเลย์เอาต์

ค้นหา

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