Files
react-native-svg/apps/common/example/examples/Reanimated.tsx
Jakub Grzywacz b3b175a7fb feat: move examples to ./apps (#2507)
# Summary

Due to the large number of example apps in the repository, I decided to
change the structure and move all applications into an "apps" folder to
maintain a clear structure.
2024-10-25 16:12:23 +02:00

47 lines
1.2 KiB
TypeScript

import React, {useEffect} from 'react';
import {StyleSheet, Text} from 'react-native';
import Reanimated, {
useAnimatedProps,
useSharedValue,
withClamp,
withRepeat,
withSpring,
withTiming,
} from 'react-native-reanimated';
import {Rect, Svg} from 'react-native-svg';
// @ts-ignore broken reanimated types
const ReanimatedRect = Reanimated.createAnimatedComponent(Rect);
function ReanimatedRectExample() {
const height = useSharedValue(10);
const position = useSharedValue(0);
useEffect(() => {
height.value = withClamp({min: 0}, withRepeat(withSpring(100), -1, true));
position.value = withRepeat(withTiming(300, {duration: 5000}), -1);
});
const animatedProps = useAnimatedProps(() => ({
width: 30,
height: height.value,
x: position.value,
y: 20,
}));
return (
<Svg height="150" width="300">
{/* @ts-ignore broken reanimated types */}
<ReanimatedRect animatedProps={animatedProps} fill="red" />
</Svg>
);
}
ReanimatedRectExample.title = 'reanimated rectangle';
const title = 'Reanimated';
const samples = [ReanimatedRectExample];
const style = StyleSheet.create({text: {width: 30, height: 30}});
const icon = <Text style={style.text}>R</Text>;
export {icon, samples};