From d2dae1263ce678b87bc4897b1a4ea62f63dcc3dd Mon Sep 17 00:00:00 2001 From: ankit-tailor Date: Mon, 9 Oct 2023 13:12:12 +0530 Subject: [PATCH] feat: animated svg components in driver --- .../src/index.tsx | 11 +- packages/animation-moti-driver/src/index.tsx | 37 +++++ .../src/AnimatedComponents/index.tsx | 126 +++++++++++++++++- 3 files changed, 172 insertions(+), 2 deletions(-) diff --git a/packages/animation-legend-motion-driver/src/index.tsx b/packages/animation-legend-motion-driver/src/index.tsx index 0a0333cc3..9a5cd0f88 100644 --- a/packages/animation-legend-motion-driver/src/index.tsx +++ b/packages/animation-legend-motion-driver/src/index.tsx @@ -15,6 +15,7 @@ import { AnimatePresence as MotionAnimatePresence, createMotionAnimatedComponent, } from '@legendapp/motion'; +import { MotionSvg } from '@legendapp/motion/svg'; import { propertyTokenMap } from './propertyTokenMap'; import { Pressable } from 'react-native'; @@ -167,9 +168,17 @@ const AnimatePresence = React.forwardRef( const AnimatedPressable = createMotionAnimatedComponent( Pressable ) as React.ComponentType; + +const MotionComponents = { + ...Motion, + ...MotionSvg, + Pressable: AnimatedPressable, + AnimatePresence, +}; + export class MotionAnimationDriver implements IAnimationDriverPlugin { name: 'MotionAnimationDriver'; - engine = { ...Motion, Pressable: AnimatedPressable, AnimatePresence }; + engine = MotionComponents; config = { aliases: { ':animate': 'animate', diff --git a/packages/animation-moti-driver/src/index.tsx b/packages/animation-moti-driver/src/index.tsx index 86df238a5..d6c93dec7 100644 --- a/packages/animation-moti-driver/src/index.tsx +++ b/packages/animation-moti-driver/src/index.tsx @@ -13,6 +13,32 @@ import { MotiProgressBar, AnimatePresence, } from 'moti'; +import { + Svg as RNSvg, + Rect as RNRect, + Circle as RNCircle, + Ellipse as RNEllipse, + Line as RNLine, + Polyline as RNPolyline, + Path as RNPath, + TSpan as RNTSpan, + TextPath as RNTextPath, + G as RNG, + ClipPath as RNClipPath, +} from 'react-native-svg'; +import { motifySvg } from 'moti/svg'; + +const Svg = motifySvg(RNSvg); +const Rect = motifySvg(RNRect); +const Circle = motifySvg(RNCircle); +const Ellipse = motifySvg(RNEllipse); +const Line = motifySvg(RNLine); +const Polyline = motifySvg(RNPolyline); +const Path = motifySvg(RNPath); +const TSpan = motifySvg(RNTSpan); +const TextPath = motifySvg(RNTextPath); +const G = motifySvg(RNG); +const ClipPath = motifySvg(RNClipPath); let Moti = { Image: MotiImage, @@ -21,6 +47,17 @@ let Moti = { ScrollView: MotiScrollView, SafeAreaView: MotiSafeAreaView, ProgressBar: MotiProgressBar, + Svg, + Rect, + Circle, + Ellipse, + Line, + Polyline, + Path, + TSpan, + TextPath, + G, + ClipPath, AnimatePresence, }; export class MotiAnimationDriver implements IAnimationDriverPlugin { diff --git a/packages/animation-resolver/src/AnimatedComponents/index.tsx b/packages/animation-resolver/src/AnimatedComponents/index.tsx index b472f8b45..b494c4d2f 100644 --- a/packages/animation-resolver/src/AnimatedComponents/index.tsx +++ b/packages/animation-resolver/src/AnimatedComponents/index.tsx @@ -9,10 +9,23 @@ import type { FlatListProps, SectionListProps, } from 'react-native'; +import type { + SvgProps, + GProps, + ClipPathProps, + RectProps, + PolylineProps, + CircleProps, + EllipseProps, + LineProps, + PathProps, + TSpanProps, + TextPathProps, +} from 'react-native-svg'; const getAnimationResolverPlugin: any = (plugins: any[]) => { let pluginData; - plugins.forEach((plugin) => { + plugins?.forEach((plugin) => { if (plugin.name === 'AnimationResolver') { pluginData = plugin; } @@ -94,6 +107,95 @@ const AnimatedSectionList = ( const Component = animatedComponent('SectionList', props); return ; }; + +const AnimatedSvg = ( + props: SvgProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('Svg', props); + return ; +}; +const AnimatedRect = ( + props: RectProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('Rect', props); + return ; +}; +const AnimatedCircle = ( + props: CircleProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('Circle', props); + return ; +}; +const AnimatedEllipse = ( + props: EllipseProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('Ellipse', props); + return ; +}; +const AnimatedLine = ( + props: LineProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('Line', props); + return ; +}; +const AnimatedPolyline = ( + props: PolylineProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('Polyline', props); + return ; +}; +const AnimatedPath = ( + props: PathProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('Path', props); + return ; +}; +const AnimatedTSpan = ( + props: TSpanProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('TSpan', props); + return ; +}; +const AnimatedTextPath = ( + props: TextPathProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('TextPath', props); + return ; +}; +const AnimatedG = ( + props: GProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('G', props); + return ; +}; +const AnimatedClipPath = ( + props: ClipPathProps & { + animationComponentGluestack: true; + } +) => { + const Component = animatedComponent('ClipPath', props); + return ; +}; const AnimatePresence = animatedComponent('AnimatePresence', {}); AnimatedText.displayName = 'Gluestack-AnimatedResolver-AnimatedText'; @@ -109,6 +211,17 @@ AnimatedSectionList.displayName = 'Gluestack-AnimatedResolver-AnimatedSectionList'; AnimatePresence.displayName = 'Gluestack-AnimatedResolver-AnimatedAnimatePresence'; +AnimatedSvg.displayName = 'Gluestack-AnimatedResolver-AnimatedSvg'; +AnimatedRect.displayName = 'Gluestack-AnimatedResolver-AnimatedRect'; +AnimatedCircle.displayName = 'Gluestack-AnimatedResolver-AnimatedCircle'; +AnimatedEllipse.displayName = 'Gluestack-AnimatedResolver-AnimatedEllipse'; +AnimatedLine.displayName = 'Gluestack-AnimatedResolver-AnimatedLine'; +AnimatedPolyline.displayName = 'Gluestack-AnimatedResolver-AnimatedPolyline'; +AnimatedPath.displayName = 'Gluestack-AnimatedResolver-AnimatedPath'; +AnimatedTSpan.displayName = 'Gluestack-AnimatedResolver-AnimatedTSpan'; +AnimatedTextPath.displayName = 'Gluestack-AnimatedResolver-AnimatedTextPath'; +AnimatedG.displayName = 'Gluestack-AnimatedResolver-AnimatedG'; +AnimatedClipPath.displayName = 'Gluestack-AnimatedResolver-AnimatedClipPath'; export { AnimatedText, @@ -120,4 +233,15 @@ export { AnimatedFlatList, AnimatedSectionList, AnimatePresence, + AnimatedSvg, + AnimatedRect, + AnimatedCircle, + AnimatedEllipse, + AnimatedLine, + AnimatedPolyline, + AnimatedPath, + AnimatedTSpan, + AnimatedTextPath, + AnimatedG, + AnimatedClipPath, };