From 6bc050872d67e473da6716b3d99647ab51d09628 Mon Sep 17 00:00:00 2001 From: William Candillon Date: Sun, 12 Jan 2025 08:25:40 +0100 Subject: [PATCH] =?UTF-8?q?feat(=F0=9F=8E=A8):=20Enable=20new=20reconciler?= =?UTF-8?q?=20by=20default=20on=20iOS=20and=20Android=20(#2865)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old reconciler is still available via `CanvasOld` if needed --- apps/paper/package.json | 2 +- .../src/Examples/Breathe/TestReconciller.tsx | 106 ++++++++ packages/skia/src/index.ts | 2 +- packages/skia/src/renderer/Canvas.tsx | 158 +++++------ packages/skia/src/renderer/Canvas2.tsx | 128 --------- packages/skia/src/renderer/Canvas2.web.tsx | 6 - packages/skia/src/renderer/CanvasOld.tsx | 126 +++++++++ packages/skia/src/sksg/Container.ts | 8 +- packages/skia/src/sksg/HostConfig2.ts | 247 ++++++++++++++++++ packages/skia/src/sksg/Recorder/Core.ts | 1 + packages/skia/src/sksg/Recorder/Player.ts | 4 +- packages/skia/src/sksg/Recorder/Recorder.ts | 1 - yarn.lock | 18 +- 13 files changed, 579 insertions(+), 228 deletions(-) create mode 100644 apps/paper/src/Examples/Breathe/TestReconciller.tsx delete mode 100644 packages/skia/src/renderer/Canvas2.tsx delete mode 100644 packages/skia/src/renderer/Canvas2.web.tsx create mode 100644 packages/skia/src/renderer/CanvasOld.tsx create mode 100644 packages/skia/src/sksg/HostConfig2.ts diff --git a/apps/paper/package.json b/apps/paper/package.json index 77226ab3f8..0bf42d9ada 100644 --- a/apps/paper/package.json +++ b/apps/paper/package.json @@ -31,7 +31,7 @@ "react-native-reanimated": "^3.16.5", "react-native-safe-area-context": "^4.10.9", "react-native-screens": "^4.3.0", - "react-native-svg": "^15.9.0", + "react-native-svg": "^15.10.1", "react-native-wgpu": "0.1.19", "typescript": "^5.2.2" }, diff --git a/apps/paper/src/Examples/Breathe/TestReconciller.tsx b/apps/paper/src/Examples/Breathe/TestReconciller.tsx new file mode 100644 index 0000000000..f117bc037b --- /dev/null +++ b/apps/paper/src/Examples/Breathe/TestReconciller.tsx @@ -0,0 +1,106 @@ +import React, { useCallback, useMemo, useState } from "react"; +import { Button, StyleSheet, useWindowDimensions, View } from "react-native"; +import { + BlurMask, + vec, + Canvas, + Circle, + Fill, + Group, + polar2Canvas, + mix, +} from "@shopify/react-native-skia"; +import type { SharedValue } from "react-native-reanimated"; +import { useDerivedValue } from "react-native-reanimated"; + +import { useLoop } from "../../components/Animations"; + +const c1 = "#61bea2"; +const c2 = "#529ca0"; + +interface RingProps { + index: number; + progress: SharedValue; + total: number; +} + +const Ring = ({ index, progress, total }: RingProps) => { + const { width, height } = useWindowDimensions(); + const R = width / 4; + const center = useMemo( + () => vec(width / 2, height / 2 - 64), + [height, width] + ); + + const theta = (index * (2 * Math.PI)) / total; + const transform = useDerivedValue(() => { + const { x, y } = polar2Canvas( + { theta, radius: progress.value * R }, + { x: 0, y: 0 } + ); + const scale = mix(progress.value, 0.3, 1); + return [{ translateX: x }, { translateY: y }, { scale }]; + }); + + return ( + + ); +}; + +export const Breathe = () => { + const [rings, setRings] = useState(12); + const { width, height } = useWindowDimensions(); + const center = useMemo( + () => vec(width / 2, height / 2 - 64), + [height, width] + ); + + const progress = useLoop({ duration: 3000 }); + + const transform = useDerivedValue(() => [ + { rotate: mix(progress.value, -Math.PI, 0) }, + ]); + + const add = useCallback(() => { + setRings((r) => r + 1); + }, []); + const remove = useCallback(() => { + setRings((r) => Math.max(1, r - 1)); + }, []); + return ( + + +