-
-
Save wcandillon/4ade39497f96a4e2745b57b0cb071d8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Canvas, Skia } from "@shopify/react-native-skia"; | |
import React, { useEffect } from "react"; | |
import { Dimensions, View } from "react-native"; | |
import { makeMutable, cancelAnimation } from "react-native-reanimated"; | |
import { HelloSticker, HelloStickerDimensions } from "./HelloSticker"; | |
import { LocationSticker, LocationStickerDimensions } from "./LocationSticker"; | |
import { Picture, PictureDimensions } from "./Picture"; | |
import { GestureHandler } from "./GestureHandler"; | |
const { width, height } = Dimensions.get("window"); | |
const stickers = [ | |
{ | |
Sticker: Picture, | |
dimensions: PictureDimensions, | |
matrix: makeMutable(Skia.Matrix()), | |
}, | |
{ | |
Sticker: HelloSticker, | |
dimensions: HelloStickerDimensions, | |
matrix: makeMutable(Skia.Matrix()), | |
}, | |
{ | |
Sticker: LocationSticker, | |
dimensions: LocationStickerDimensions, | |
matrix: makeMutable(Skia.Matrix()), | |
}, | |
]; | |
export const Stickers = () => { | |
// When unmounting the component we need to cancel animations if any | |
useEffect(() => { | |
return () => { | |
stickers.forEach(({ matrix }) => { | |
cancelAnimation(matrix); | |
}); | |
}; | |
}); | |
return ( | |
<View> | |
<Canvas style={{ width, height }}> | |
{stickers.map(({ Sticker, matrix }, index) => ( | |
<Sticker key={index} matrix={matrix} /> | |
))} | |
</Canvas> | |
{stickers.map(({ dimensions, matrix }, index) => ( | |
<GestureHandler key={index} matrix={matrix} dimensions={dimensions} /> | |
))} | |
</View> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment