గైడ్‌లు · 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 }] } }} />;

వెతకండి

డాక్యుమెంటేషన్‌లో వెతకడానికి టైప్ చేయండి.