How to dynamically create movable Images #1615
-
GoalI want to press add button, that will add a selected Problem
Codeimport { Canvas, rect, Skia } from '@shopify/react-native-skia';
import { StyleSheet, View } from 'react-native';
import { useSharedValue } from 'react-native-reanimated';
import { HeartSticker } from '@assets/stickers';
import { GestureHandler } from './GestureHandler';
import { Image } from './Image';
const WIDTH = 300;
export const dimensions = rect(0, 0, WIDTH, WIDTH);
export const MovableElement = () => {
const matrix = useSharedValue(Skia.Matrix());
return (
<View style={styles.container}>
<Canvas style={styles.container} accessibilityIgnoresInvertColors>
<Image height={370} image={HeartSticker} matrix={matrix} width={400} />
</Canvas>
<GestureHandler matrix={matrix} dimensions={dimensions} debug />
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
}); |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 25 replies
-
It's possible to utilize multiple instances of MovableElement within a single canvas, as illustrated by @wcandillon in this example: link. Alternatively, you can accomplish a similar effect using only one |
Beta Was this translation helpful? Give feedback.
-
try this
I've made two changes
|
Beta Was this translation helpful? Give feedback.
-
@alarm109 @wcandillon @tylerrrkd I have solved this issue you can add unlimited images dynamically I faced this problem earlier and opened a discussion but now I found a solution and it's working fine for me as I have a similar case where I have to add dynamic text on an image on button press Find the code snippets here |
Beta Was this translation helpful? Give feedback.
-
How to do this with Gesture.Simultaneous? |
Beta Was this translation helpful? Give feedback.
this is how I updated the demo to run with dynamic images: https://gist.github.com/wcandillon/4ade39497f96a4e2745b57b0cb071d8c
useSharedValue is just makeMutable + memoization + clean up (cc @dmg46664).