मार्गदर्शक · 03

Animated कंपोनंट

गंतव्याकडे हलणारे, हावभावांना प्रतिसाद देणारे आणि डौलाने बाहेर पडणारे साधे एलिमेंट्स रेंडर करा.

Animated.<tag>

Animated.div, Animated.button, Animated.svg आणि इतर प्रत्येक HTML किंवा SVG tag रॅपरशिवाय साधा एलिमेंट रेंडर करतात. त्यांचा style मूल्ये स्वीकारतो, आणि React Native प्रमाणे transform ॲरे असू शकतात.

या एलिमेंट्सवरील मर्यादित transform आणि opacity मोशन — spring सह — ब्राउझर प्लेबॅकसाठी पात्र आहे.

उदाहरण तयार होत आहे…

seed, pose, poses आणि tempo

seed पहिली फ्रेम, pose सध्याचे गंतव्य (ऑब्जेक्ट किंवा poses मधील नोंदीचे नाव), आणि tempo timing किंवा spring. फक्त tempo बदलल्यास न बदललेले गंतव्य पुन्हा चालत नाही.

एलिमेंट पोहोचल्यावर onRest चालते.

Card.jsx
<Animated.article
  seed={{ opacity: 0, transform: [{ translateY: 16 }] }}
  pose={selected ? 'raised' : 'rest'}
  poses={{
    rest: { opacity: 1, transform: [{ translateY: 0 }, { scale: 1 }] },
    raised: { opacity: 1, transform: [{ translateY: -8 }, { scale: 1.04 }] },
  }}
  tempo={{ spring: { stiffness: 300, damping: 26 } }}
  onRest={() => console.log('arrived')}
/>;

हावभावांना प्रतिसाद

respond हावभावांना तात्पुरत्या गंतव्यांशी जोडतो: hover, focus, focusWithin, press, longPress, drag, inView आणि इतर. प्रतिसाद संपल्यावर, एलिमेंट जिथे असेल तिथून आपल्या pose कडे परत येतो.

onResponse प्रत्येक कडा कळवतो, आणि respond={{ press: {} }} दृश्यात काहीही न बदलता हावभाव पाहतो.

उदाहरण तयार होत आहे…

Animated.Scope ने डीफॉल्ट सामायिक करा

Animated.Scope एक pose नाव, tempo आणि ॲनिमेशन डीफॉल्ट त्याच्या आतील Animated एलिमेंट्सना देतो.

Menu.jsx
<Animated.Scope tempo={{ spring: { stiffness: 380, damping: 30 } }}>
  <Animated.li pose={{ opacity: 1 }} />
  <Animated.li pose={{ opacity: 1 }} />
</Animated.Scope>;

तुमचे स्वतःचे कंपोनंट

Animated.wrap(Component) — React Native मध्ये createAnimatedComponent — एकाच DOM एलिमेंटमध्ये रूपांतरित होणाऱ्या ref-फॉरवर्डिंग कंपोनंटला तेच props स्वीकारायला लावते.

Link.jsx
import { forwardRef } from 'react';
import { Animated } from '@kkwaenggwari/animated';

const Link = forwardRef((props, ref) => <a ref={ref} {...props} />);
const AnimatedLink = Animated.wrap(Link);

<AnimatedLink href="/pricing" respond={{ hover: { transform: [{ translateX: 4 }] } }} />;

शोधा

दस्तऐवजांमध्ये शोधण्यासाठी टाइप करा.