|
| 1 | +import Animated, { |
| 2 | + FadeIn as FadeInBuilder, |
| 3 | + FadeInDown as FadeInDownBuilder, |
| 4 | + FadeInLeft as FadeInLeftBuilder, |
| 5 | + FadeInRight as FadeInRightBuilder, |
| 6 | + FadeInUp as FadeInUpBuilder, |
| 7 | + FadeOut as FadeOutBuilder, |
| 8 | + FadeOutDown as FadeOutDownBuilder, |
| 9 | + FadeOutLeft as FadeOutLeftBuilder, |
| 10 | + FadeOutRight as FadeOutRightBuilder, |
| 11 | + FadeOutUp as FadeOutUpBuilder, |
| 12 | + type ReanimatedAnimation, |
| 13 | + SlideInDown as SlideInDownBuilder, |
| 14 | + SlideInLeft as SlideInLeftBuilder, |
| 15 | + SlideInRight as SlideInRightBuilder, |
| 16 | + SlideInUp as SlideInUpBuilder, |
| 17 | + SlideOutDown as SlideOutDownBuilder, |
| 18 | + SlideOutLeft as SlideOutLeftBuilder, |
| 19 | + SlideOutRight as SlideOutRightBuilder, |
| 20 | + SlideOutUp as SlideOutUpBuilder, |
| 21 | +} from '@plextv/react-lightning-plugin-reanimated'; |
| 22 | +import { Button } from '@plextv/react-native-lightning'; |
| 23 | +import { Column, Row } from '@plextv/react-native-lightning-components'; |
| 24 | +import { type FC, useMemo, useState } from 'react'; |
| 25 | + |
| 26 | +type AnimatedProps = { |
| 27 | + visible: boolean; |
| 28 | + entering?: ReanimatedAnimation; |
| 29 | + exiting?: ReanimatedAnimation; |
| 30 | +}; |
| 31 | + |
| 32 | +function randomColor() { |
| 33 | + return `rgba(${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, ${Math.floor(Math.random() * 255)}, 1)`; |
| 34 | +} |
| 35 | + |
| 36 | +const AnimatedBox: FC<AnimatedProps> = ({ visible, ...props }) => { |
| 37 | + const color = useMemo(() => randomColor(), []); |
| 38 | + |
| 39 | + return visible ? ( |
| 40 | + <Animated.View |
| 41 | + {...props} |
| 42 | + style={{ |
| 43 | + width: 75, |
| 44 | + height: 75, |
| 45 | + backgroundColor: color, |
| 46 | + borderRadius: 16, |
| 47 | + }} |
| 48 | + /> |
| 49 | + ) : null; |
| 50 | +}; |
| 51 | + |
| 52 | +const AnimationExample: FC<{ |
| 53 | + buttonPrefix: string; |
| 54 | + buttonSuffix?: string; |
| 55 | + entering?: ReanimatedAnimation; |
| 56 | + exiting?: ReanimatedAnimation; |
| 57 | +}> = ({ buttonPrefix, buttonSuffix = '', entering, exiting }) => { |
| 58 | + const [visible, setVisible] = useState(true); |
| 59 | + |
| 60 | + return ( |
| 61 | + <Row style={{ gap: 25 }}> |
| 62 | + <Button |
| 63 | + title={`${buttonPrefix} ${visible ? 'Out' : 'In'} ${buttonSuffix}`} |
| 64 | + color="rgba(46, 43, 0, 1)" |
| 65 | + onPress={() => setVisible(!visible)} |
| 66 | + style={{ |
| 67 | + width: 150, |
| 68 | + height: 75, |
| 69 | + borderRadius: 16, |
| 70 | + }} |
| 71 | + ></Button> |
| 72 | + <AnimatedBox visible={visible} entering={entering} exiting={exiting} /> |
| 73 | + </Row> |
| 74 | + ); |
| 75 | +}; |
| 76 | + |
| 77 | +const AnimationBuilderTest = () => { |
| 78 | + return ( |
| 79 | + <Row style={{ gap: 25 }}> |
| 80 | + <Column style={{ gap: 15 }}> |
| 81 | + <AnimationExample |
| 82 | + buttonPrefix="Fade" |
| 83 | + entering={FadeInBuilder.duration(1000)} |
| 84 | + exiting={FadeOutBuilder.duration(1000)} |
| 85 | + /> |
| 86 | + |
| 87 | + <AnimationExample |
| 88 | + buttonPrefix="Fade" |
| 89 | + buttonSuffix="Up" |
| 90 | + entering={FadeInUpBuilder.duration(1000)} |
| 91 | + exiting={FadeOutUpBuilder.duration(1000)} |
| 92 | + /> |
| 93 | + |
| 94 | + <AnimationExample |
| 95 | + buttonPrefix="Fade" |
| 96 | + buttonSuffix="Right" |
| 97 | + entering={FadeInRightBuilder.duration(1000)} |
| 98 | + exiting={FadeOutRightBuilder.duration(1000)} |
| 99 | + /> |
| 100 | + |
| 101 | + <AnimationExample |
| 102 | + buttonPrefix="Fade" |
| 103 | + buttonSuffix="Down" |
| 104 | + entering={FadeInDownBuilder.duration(1000)} |
| 105 | + exiting={FadeOutDownBuilder.duration(1000)} |
| 106 | + /> |
| 107 | + |
| 108 | + <AnimationExample |
| 109 | + buttonPrefix="Fade" |
| 110 | + buttonSuffix="Left" |
| 111 | + entering={FadeInLeftBuilder.duration(1000)} |
| 112 | + exiting={FadeOutLeftBuilder.duration(1000)} |
| 113 | + /> |
| 114 | + </Column> |
| 115 | + |
| 116 | + <Column style={{ gap: 15 }}> |
| 117 | + <AnimationExample |
| 118 | + buttonPrefix="Slide" |
| 119 | + buttonSuffix="Up" |
| 120 | + entering={SlideInUpBuilder.duration(1000)} |
| 121 | + exiting={SlideOutUpBuilder.duration(1000)} |
| 122 | + /> |
| 123 | + |
| 124 | + <AnimationExample |
| 125 | + buttonPrefix="Slide" |
| 126 | + buttonSuffix="Right" |
| 127 | + entering={SlideInRightBuilder.duration(1000)} |
| 128 | + exiting={SlideOutRightBuilder.duration(1000)} |
| 129 | + /> |
| 130 | + |
| 131 | + <AnimationExample |
| 132 | + buttonPrefix="Slide" |
| 133 | + buttonSuffix="Down" |
| 134 | + entering={SlideInDownBuilder.duration(1000)} |
| 135 | + exiting={SlideOutDownBuilder.duration(1000)} |
| 136 | + /> |
| 137 | + |
| 138 | + <AnimationExample |
| 139 | + buttonPrefix="Slide" |
| 140 | + buttonSuffix="Left" |
| 141 | + entering={SlideInLeftBuilder.duration(1000)} |
| 142 | + exiting={SlideOutLeftBuilder.duration(1000)} |
| 143 | + /> |
| 144 | + </Column> |
| 145 | + </Row> |
| 146 | + ); |
| 147 | +}; |
| 148 | + |
| 149 | +export { AnimationBuilderTest }; |
0 commit comments