mirror of
https://github.com/zoriya/react-native-svg.git
synced 2025-12-05 22:56:11 +00:00
# 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.
47 lines
1.2 KiB
TypeScript
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};
|