Skip to content

Instantly share code, notes, and snippets.

@gwendall
Last active July 28, 2023 17:26
Show Gist options
  • Save gwendall/219728ae019cc10a03b3a408363d955c to your computer and use it in GitHub Desktop.
Save gwendall/219728ae019cc10a03b3a408363d955c to your computer and use it in GitHub Desktop.
export default function Stickers({ stickers = [] }: { stickers: Sticker[] }) {
const [matrixes, setMatrixes] = React.useState<SharedValue<SkMatrix>[]>([]);
React.useEffect(() => {
setMatrixes(stickers.map(() => makeMutable(Skia.Matrix())));
}, [stickers]);
return (
<>
<Canvas>
{stickers.map((sticker, index) => (
<Group key={sticker.id} matrix={matrixes[index]}>
<Image
image={image}
/>
</Group>
))}
</Canvas>
{stickers.map((sticker, index) => {
const dimensions = rect(
sticker.x,
sticker.y,
sticker.width,
sticker.width,
);
if (matrixes[index]) {
return (
<GestureHandler
key={`gesture-handler-${sticker.id}`}
matrix={matrixes[index]}
dimensions={dimensions}
/>
);
}
return null;
})}
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment