Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/docs/docs/pictures.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const size = 256;
const n = 20;

const paint = Skia.Paint();
const recorder = Skia.PictureRecorder();

export const HelloWorld = () => {
const progress = useSharedValue(0);
Expand All @@ -43,7 +44,6 @@ export const HelloWorld = () => {

const picture = useDerivedValue(() => {
"worklet";
const recorder = Skia.PictureRecorder();
const canvas = recorder.beginRecording(Skia.XYWHRect(0, 0, size, size));
const numberOfCircles = Math.floor(progress.value * n);
for (let i = 0; i < numberOfCircles; i++) {
Expand Down
3 changes: 3 additions & 0 deletions apps/example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
Video,
Chat,
LiquidGlass,
Pictures,
} from "./Examples";
import { CI, Tests } from "./Tests";
import { HomeScreen } from "./Home";
Expand Down Expand Up @@ -71,6 +72,7 @@ const linking: LinkingOptions<StackParamList> = {
SpeedTest: "speedtest",
Video: "video",
Chat: "chat",
Pictures: "pictures",
},
},
prefixes: ["rnskia://"],
Expand Down Expand Up @@ -232,6 +234,7 @@ const App = () => {
name="Performance"
component={PerformanceDrawingTest}
/>
<Stack.Screen name="Pictures" component={Pictures} />
</Stack.Navigator>
</NavigationContainer>
</GestureHandlerRootView>
Expand Down
44 changes: 44 additions & 0 deletions apps/example/src/Examples/Pictures/Pictures.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import React, { useEffect } from "react";
import { Canvas, Picture, Skia } from "@shopify/react-native-skia";
import {
useDerivedValue,
useSharedValue,
withRepeat,
withTiming,
} from "react-native-reanimated";

const size = 256;
const n = 20;

const paint = Skia.Paint();

export const Pictures = () => {
const progress = useSharedValue(0);

useEffect(() => {
progress.value = withRepeat(withTiming(1, { duration: 3000 }), -1, true);
}, [progress]);

const picture = useDerivedValue(() => {
"worklet";
const recorder = Skia.PictureRecorder();
const canvas = recorder.beginRecording(Skia.XYWHRect(0, 0, size, size));
const angle = progress.value * Math.PI * 2;
for (let i = 0; i < n; i++) {
const alpha = Math.pow((i + 1) / n, 5) * 200;
const r = ((i + 1) / n) * (size / 4);
const offset = ((i + 1) / n) * (size / 4);
const cx = size / 2 + Math.cos(angle + (i * Math.PI * 2) / n) * offset;
const cy = size / 2 + Math.sin(angle + (i * Math.PI * 2) / n) * offset;
paint.setColor(Skia.Color(`rgba(0, 122, 255, ${alpha / 255})`));
canvas.drawCircle(cx, cy, r, paint);
}
return recorder.finishRecordingAsPicture();
});

return (
<Canvas style={{ flex: 1 }}>
<Picture picture={picture} />
</Canvas>
);
};
1 change: 1 addition & 0 deletions apps/example/src/Examples/Pictures/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Pictures";
1 change: 1 addition & 0 deletions apps/example/src/Examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ export * from "./FrostedCard";
export * from "./SpeedTest";
export * from "./Video";
export * from "./Chat";
export * from "./Pictures";
5 changes: 5 additions & 0 deletions apps/example/src/Home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ export const HomeScreen = () => {
/>
<HomeScreenButton title="📹 Video" description="Video" route="Video" />
<HomeScreenButton title="💬 Chat" description="Chat" route="Chat" />
<HomeScreenButton
title="🖼 Pictures"
description="Animated circle trail using Pictures"
route="Pictures"
/>
</ScrollView>
);
};
1 change: 1 addition & 0 deletions apps/example/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ export type StackParamList = {
SpeedTest: undefined;
Video: undefined;
Chat: undefined;
Pictures: undefined;
};
Loading