คู่มือ · 07
มาจาก React Native
อะไรเหมือนเดิม อะไรเปลี่ยน และเว็บเพิ่มอะไร
การเรียกเหมือนเดิม
ตัวควบคุม กราฟ และการตั้งค่าเป็นไปตาม Animated ของ React Native เรนเดอร์โฮสต์ DOM อย่าง Animated.div ในจุดที่ React Native เรนเดอร์ Animated.View useAnimatedValue ใช้ได้เหมือนใน React Native
กำลังเตรียมตัวอย่าง…
ความต่างที่ควรรู้
รายละเอียดเหล่านี้ทำให้โค้ดที่ย้ายมาทำงานแบบเดียวกับบนอุปกรณ์
useNativeDriverและisInteractionยอมรับได้ แต่การเล่นจะถูกเลือกตามผลลัพธ์แต่ละตัวแทน ผลลัพธ์ที่เข้าเงื่อนไขจะเล่นในเบราว์เซอร์ ที่เหลือเล่นใน JavaScriptspringรับstiffness/damping/mass,bounciness/speedหรือtension/frictionและใช้ค่าเริ่มต้นของ React Native หากไม่ระบุinterpolateรองรับeasingและโหมด extrapolation ทั้งสามแบบEasingตรงกับ React Native รวมถึงelasticEasing.expถูกปรับสเกลใหม่ 0.1% ให้เริ่มที่ 0 พอดี จึงใช้การเล่นของเบราว์เซอร์ได้- ความเร็วของ decay เป็นหน่วยต่อมิลลิวินาที และความเร็วของ spring เป็นหน่วยต่อวินาที เหมือนใน React Native
Animated.createAnimatedComponentห่อคอมโพเนนต์ที่ส่งต่อ ref
// 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 จัดการการออกและเลย์เอาต์