@shopify/react-native-skia 0.1.225 → 0.1.228
Sign up to get free protection for your applications and to get access to all the features.
- package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.h +3 -3
- package/cpp/api/JsiSkCanvas.h +2 -1
- package/cpp/api/JsiSkMatrix.h +35 -13
- package/cpp/api/JsiSkPictureRecorder.h +10 -3
- package/cpp/api/JsiSkTypeface.h +1 -0
- package/cpp/rnskia/dom/props/MatrixProp.h +19 -0
- package/cpp/rnskia/dom/props/TransformProp.h +76 -9
- package/lib/commonjs/animation/spring/runSpring.d.ts +3 -0
- package/lib/commonjs/animation/spring/runSpring.js +3 -0
- package/lib/commonjs/animation/spring/runSpring.js.map +1 -1
- package/lib/commonjs/animation/spring/useSpring.d.ts +3 -0
- package/lib/commonjs/animation/spring/useSpring.js +3 -0
- package/lib/commonjs/animation/spring/useSpring.js.map +1 -1
- package/lib/commonjs/animation/timing/runTiming.d.ts +3 -0
- package/lib/commonjs/animation/timing/runTiming.js +3 -0
- package/lib/commonjs/animation/timing/runTiming.js.map +1 -1
- package/lib/commonjs/animation/timing/useLoop.d.ts +3 -0
- package/lib/commonjs/animation/timing/useLoop.js +3 -0
- package/lib/commonjs/animation/timing/useLoop.js.map +1 -1
- package/lib/commonjs/animation/timing/useTiming.d.ts +3 -0
- package/lib/commonjs/animation/timing/useTiming.js +3 -0
- package/lib/commonjs/animation/timing/useTiming.js.map +1 -1
- package/lib/commonjs/dom/nodes/JsiSkDOM.js +2 -0
- package/lib/commonjs/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/commonjs/dom/nodes/datatypes/Fitting.d.ts +5 -5
- package/lib/commonjs/dom/nodes/datatypes/Fitting.js.map +1 -1
- package/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +235 -75
- package/lib/commonjs/dom/nodes/datatypes/Gradient.js.map +1 -1
- package/lib/commonjs/dom/types/Common.d.ts +3 -3
- package/lib/commonjs/dom/types/Common.js.map +1 -1
- package/lib/commonjs/external/reanimated/interpolators.d.ts +1 -0
- package/lib/commonjs/external/reanimated/interpolators.js +24 -5
- package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
- package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +2 -1
- package/lib/commonjs/external/reanimated/moduleWrapper.js +9 -7
- package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +34 -28
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/Drawing.d.ts +5 -0
- package/lib/commonjs/renderer/components/Drawing.js +5 -0
- package/lib/commonjs/renderer/components/Drawing.js.map +1 -1
- package/lib/commonjs/renderer/components/shapes/FitBox.d.ts +5 -5
- package/lib/commonjs/skia/core/Matrix.d.ts +2 -2
- package/lib/commonjs/skia/core/Matrix.js.map +1 -1
- package/lib/commonjs/skia/core/Picture.d.ts +2 -2
- package/lib/commonjs/skia/core/Picture.js +12 -2
- package/lib/commonjs/skia/core/Picture.js.map +1 -1
- package/lib/commonjs/skia/core/Vector.d.ts +0 -5
- package/lib/commonjs/skia/core/Vector.js +1 -17
- package/lib/commonjs/skia/core/Vector.js.map +1 -1
- package/lib/commonjs/skia/types/Canvas.d.ts +1 -1
- package/lib/commonjs/skia/types/Canvas.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix.d.ts +4 -20
- package/lib/commonjs/skia/types/Matrix.js +4 -70
- package/lib/commonjs/skia/types/Matrix.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.d.ts +90 -0
- package/lib/commonjs/skia/types/Matrix4.js +312 -0
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -0
- package/lib/commonjs/skia/types/Path/Path.d.ts +1 -1
- package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
- package/lib/commonjs/skia/types/Picture/PictureRecorder.d.ts +1 -1
- package/lib/commonjs/skia/types/Picture/PictureRecorder.js.map +1 -1
- package/lib/commonjs/skia/types/Rect.d.ts +1 -0
- package/lib/commonjs/skia/types/Rect.js +18 -0
- package/lib/commonjs/skia/types/Rect.js.map +1 -1
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +13 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/Host.d.ts +2 -3
- package/lib/commonjs/skia/web/Host.js +4 -12
- package/lib/commonjs/skia/web/Host.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkCanvas.d.ts +1 -1
- package/lib/commonjs/skia/web/JsiSkCanvas.js +13 -13
- package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkColorFilterFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkColorFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.js +2 -2
- package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImage.js +6 -6
- package/lib/commonjs/skia/web/JsiSkImage.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFactory.js +2 -2
- package/lib/commonjs/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js +3 -3
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMaskFilterFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkMaskFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.d.ts +2 -2
- package/lib/commonjs/skia/web/JsiSkMatrix.js +6 -1
- package/lib/commonjs/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPaint.js +3 -3
- package/lib/commonjs/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPath.js +5 -5
- package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkPathEffectFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPathFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkPathFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPicture.js +1 -1
- package/lib/commonjs/skia/web/JsiSkPicture.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkPictureRecorder.d.ts +1 -1
- package/lib/commonjs/skia/web/JsiSkPictureRecorder.js +1 -1
- package/lib/commonjs/skia/web/JsiSkPictureRecorder.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkShaderFactory.js +5 -5
- package/lib/commonjs/skia/web/JsiSkShaderFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkVerticesFactory.js +3 -3
- package/lib/commonjs/skia/web/JsiSkVerticesFactory.js.map +1 -1
- package/lib/commonjs/values/api.d.ts +23 -2
- package/lib/commonjs/values/api.js +44 -1
- package/lib/commonjs/values/api.js.map +1 -1
- package/lib/commonjs/values/hooks/useClockValue.d.ts +3 -0
- package/lib/commonjs/values/hooks/useClockValue.js +3 -0
- package/lib/commonjs/values/hooks/useClockValue.js.map +1 -1
- package/lib/commonjs/values/hooks/useComputedValue.d.ts +3 -0
- package/lib/commonjs/values/hooks/useComputedValue.js +3 -0
- package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
- package/lib/commonjs/values/hooks/useValue.d.ts +3 -0
- package/lib/commonjs/values/hooks/useValue.js +3 -0
- package/lib/commonjs/values/hooks/useValue.js.map +1 -1
- package/lib/commonjs/values/hooks/useValueEffect.d.ts +3 -0
- package/lib/commonjs/values/hooks/useValueEffect.js +3 -0
- package/lib/commonjs/values/hooks/useValueEffect.js.map +1 -1
- package/lib/commonjs/values/types.d.ts +4 -4
- package/lib/commonjs/values/types.js.map +1 -1
- package/lib/commonjs/views/SkiaView.d.ts +5 -0
- package/lib/commonjs/views/SkiaView.js +9 -0
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/module/animation/spring/runSpring.d.ts +3 -0
- package/lib/module/animation/spring/runSpring.js +3 -0
- package/lib/module/animation/spring/runSpring.js.map +1 -1
- package/lib/module/animation/spring/useSpring.d.ts +3 -0
- package/lib/module/animation/spring/useSpring.js +3 -0
- package/lib/module/animation/spring/useSpring.js.map +1 -1
- package/lib/module/animation/timing/runTiming.d.ts +3 -0
- package/lib/module/animation/timing/runTiming.js +3 -0
- package/lib/module/animation/timing/runTiming.js.map +1 -1
- package/lib/module/animation/timing/useLoop.d.ts +3 -0
- package/lib/module/animation/timing/useLoop.js +3 -0
- package/lib/module/animation/timing/useLoop.js.map +1 -1
- package/lib/module/animation/timing/useTiming.d.ts +3 -0
- package/lib/module/animation/timing/useTiming.js +3 -0
- package/lib/module/animation/timing/useTiming.js.map +1 -1
- package/lib/module/dom/nodes/JsiSkDOM.js +2 -0
- package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Fitting.d.ts +5 -5
- package/lib/module/dom/nodes/datatypes/Fitting.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Gradient.d.ts +235 -75
- package/lib/module/dom/nodes/datatypes/Gradient.js.map +1 -1
- package/lib/module/dom/types/Common.d.ts +3 -3
- package/lib/module/dom/types/Common.js.map +1 -1
- package/lib/module/external/reanimated/interpolators.d.ts +1 -0
- package/lib/module/external/reanimated/interpolators.js +22 -6
- package/lib/module/external/reanimated/interpolators.js.map +1 -1
- package/lib/module/external/reanimated/moduleWrapper.d.ts +2 -1
- package/lib/module/external/reanimated/moduleWrapper.js +7 -6
- package/lib/module/external/reanimated/moduleWrapper.js.map +1 -1
- package/lib/module/renderer/Canvas.js +35 -29
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/Drawing.d.ts +5 -0
- package/lib/module/renderer/components/Drawing.js +6 -0
- package/lib/module/renderer/components/Drawing.js.map +1 -1
- package/lib/module/renderer/components/shapes/FitBox.d.ts +5 -5
- package/lib/module/skia/core/Matrix.d.ts +2 -2
- package/lib/module/skia/core/Matrix.js.map +1 -1
- package/lib/module/skia/core/Picture.d.ts +2 -2
- package/lib/module/skia/core/Picture.js +12 -3
- package/lib/module/skia/core/Picture.js.map +1 -1
- package/lib/module/skia/core/Vector.d.ts +0 -5
- package/lib/module/skia/core/Vector.js +0 -13
- package/lib/module/skia/core/Vector.js.map +1 -1
- package/lib/module/skia/types/Canvas.d.ts +1 -1
- package/lib/module/skia/types/Canvas.js.map +1 -1
- package/lib/module/skia/types/Matrix.d.ts +4 -20
- package/lib/module/skia/types/Matrix.js +3 -71
- package/lib/module/skia/types/Matrix.js.map +1 -1
- package/lib/module/skia/types/Matrix4.d.ts +90 -0
- package/lib/module/skia/types/Matrix4.js +274 -0
- package/lib/module/skia/types/Matrix4.js.map +1 -0
- package/lib/module/skia/types/Path/Path.d.ts +1 -1
- package/lib/module/skia/types/Path/Path.js.map +1 -1
- package/lib/module/skia/types/Picture/PictureRecorder.d.ts +1 -1
- package/lib/module/skia/types/Picture/PictureRecorder.js.map +1 -1
- package/lib/module/skia/types/Rect.d.ts +1 -0
- package/lib/module/skia/types/Rect.js +9 -0
- package/lib/module/skia/types/Rect.js.map +1 -1
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/Host.d.ts +2 -3
- package/lib/module/skia/web/Host.js +2 -7
- package/lib/module/skia/web/Host.js.map +1 -1
- package/lib/module/skia/web/JsiSkCanvas.d.ts +1 -1
- package/lib/module/skia/web/JsiSkCanvas.js +14 -14
- package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
- package/lib/module/skia/web/JsiSkColorFilterFactory.js +2 -2
- package/lib/module/skia/web/JsiSkColorFilterFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkFont.js +3 -3
- package/lib/module/skia/web/JsiSkFont.js.map +1 -1
- package/lib/module/skia/web/JsiSkImage.js +7 -7
- package/lib/module/skia/web/JsiSkImage.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFactory.js +3 -3
- package/lib/module/skia/web/JsiSkImageFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFilterFactory.js +4 -4
- package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkMaskFilterFactory.js +2 -2
- package/lib/module/skia/web/JsiSkMaskFilterFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkMatrix.d.ts +2 -2
- package/lib/module/skia/web/JsiSkMatrix.js +6 -1
- package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
- package/lib/module/skia/web/JsiSkPaint.js +4 -4
- package/lib/module/skia/web/JsiSkPaint.js.map +1 -1
- package/lib/module/skia/web/JsiSkPath.js +6 -6
- package/lib/module/skia/web/JsiSkPath.js.map +1 -1
- package/lib/module/skia/web/JsiSkPathEffectFactory.js +2 -2
- package/lib/module/skia/web/JsiSkPathEffectFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkPathFactory.js +2 -2
- package/lib/module/skia/web/JsiSkPathFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkPicture.js +2 -2
- package/lib/module/skia/web/JsiSkPicture.js.map +1 -1
- package/lib/module/skia/web/JsiSkPictureRecorder.d.ts +1 -1
- package/lib/module/skia/web/JsiSkPictureRecorder.js +1 -1
- package/lib/module/skia/web/JsiSkPictureRecorder.js.map +1 -1
- package/lib/module/skia/web/JsiSkShaderFactory.js +6 -6
- package/lib/module/skia/web/JsiSkShaderFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkVerticesFactory.js +2 -2
- package/lib/module/skia/web/JsiSkVerticesFactory.js.map +1 -1
- package/lib/module/values/api.d.ts +23 -2
- package/lib/module/values/api.js +44 -1
- package/lib/module/values/api.js.map +1 -1
- package/lib/module/values/hooks/useClockValue.d.ts +3 -0
- package/lib/module/values/hooks/useClockValue.js +3 -0
- package/lib/module/values/hooks/useClockValue.js.map +1 -1
- package/lib/module/values/hooks/useComputedValue.d.ts +3 -0
- package/lib/module/values/hooks/useComputedValue.js +3 -0
- package/lib/module/values/hooks/useComputedValue.js.map +1 -1
- package/lib/module/values/hooks/useValue.d.ts +3 -0
- package/lib/module/values/hooks/useValue.js +3 -0
- package/lib/module/values/hooks/useValue.js.map +1 -1
- package/lib/module/values/hooks/useValueEffect.d.ts +3 -0
- package/lib/module/values/hooks/useValueEffect.js +3 -0
- package/lib/module/values/hooks/useValueEffect.js.map +1 -1
- package/lib/module/values/types.d.ts +4 -4
- package/lib/module/values/types.js.map +1 -1
- package/lib/module/views/SkiaView.d.ts +5 -0
- package/lib/module/views/SkiaView.js +10 -0
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/typescript/src/animation/spring/runSpring.d.ts +3 -0
- package/lib/typescript/src/animation/spring/useSpring.d.ts +3 -0
- package/lib/typescript/src/animation/timing/runTiming.d.ts +3 -0
- package/lib/typescript/src/animation/timing/useLoop.d.ts +3 -0
- package/lib/typescript/src/animation/timing/useTiming.d.ts +3 -0
- package/lib/typescript/src/dom/nodes/datatypes/Fitting.d.ts +5 -5
- package/lib/typescript/src/dom/nodes/datatypes/Gradient.d.ts +235 -75
- package/lib/typescript/src/dom/types/Common.d.ts +3 -3
- package/lib/typescript/src/external/reanimated/interpolators.d.ts +1 -0
- package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +2 -1
- package/lib/typescript/src/renderer/components/Drawing.d.ts +5 -0
- package/lib/typescript/src/renderer/components/shapes/FitBox.d.ts +5 -5
- package/lib/typescript/src/skia/core/Matrix.d.ts +2 -2
- package/lib/typescript/src/skia/core/Picture.d.ts +2 -2
- package/lib/typescript/src/skia/core/Vector.d.ts +0 -5
- package/lib/typescript/src/skia/types/Canvas.d.ts +1 -1
- package/lib/typescript/src/skia/types/Matrix.d.ts +4 -20
- package/lib/typescript/src/skia/types/Matrix4.d.ts +90 -0
- package/lib/typescript/src/skia/types/Path/Path.d.ts +1 -1
- package/lib/typescript/src/skia/types/Picture/PictureRecorder.d.ts +1 -1
- package/lib/typescript/src/skia/types/Rect.d.ts +1 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/Host.d.ts +2 -3
- package/lib/typescript/src/skia/web/JsiSkCanvas.d.ts +1 -1
- package/lib/typescript/src/skia/web/JsiSkMatrix.d.ts +2 -2
- package/lib/typescript/src/skia/web/JsiSkPictureRecorder.d.ts +1 -1
- package/lib/typescript/src/values/api.d.ts +23 -2
- package/lib/typescript/src/values/hooks/useClockValue.d.ts +3 -0
- package/lib/typescript/src/values/hooks/useComputedValue.d.ts +3 -0
- package/lib/typescript/src/values/hooks/useValue.d.ts +3 -0
- package/lib/typescript/src/values/hooks/useValueEffect.d.ts +3 -0
- package/lib/typescript/src/values/types.d.ts +4 -4
- package/lib/typescript/src/views/SkiaView.d.ts +5 -0
- package/package.json +2 -1
- package/src/animation/spring/runSpring.ts +3 -0
- package/src/animation/spring/useSpring.ts +3 -0
- package/src/animation/timing/runTiming.ts +3 -0
- package/src/animation/timing/useLoop.ts +3 -0
- package/src/animation/timing/useTiming.ts +3 -0
- package/src/dom/nodes/JsiSkDOM.ts +4 -0
- package/src/dom/nodes/datatypes/Fitting.ts +10 -2
- package/src/dom/nodes/datatypes/Gradient.ts +2 -2
- package/src/dom/types/Common.ts +5 -3
- package/src/external/reanimated/interpolators.ts +30 -7
- package/src/external/reanimated/moduleWrapper.ts +6 -0
- package/src/renderer/Canvas.tsx +41 -30
- package/src/renderer/components/Drawing.tsx +5 -0
- package/src/skia/core/Matrix.ts +2 -2
- package/src/skia/core/Picture.ts +11 -3
- package/src/skia/core/Vector.ts +0 -4
- package/src/skia/types/Canvas.ts +1 -1
- package/src/skia/types/Matrix.ts +7 -85
- package/src/skia/types/Matrix4.ts +344 -0
- package/src/skia/types/Path/Path.ts +1 -1
- package/src/skia/types/Picture/PictureRecorder.ts +1 -1
- package/src/skia/types/Rect.ts +14 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/Host.ts +4 -3
- package/src/skia/web/JsiSkCanvas.ts +24 -17
- package/src/skia/web/JsiSkColorFilterFactory.ts +5 -2
- package/src/skia/web/JsiSkFont.ts +3 -3
- package/src/skia/web/JsiSkImage.ts +14 -11
- package/src/skia/web/JsiSkImageFactory.ts +3 -3
- package/src/skia/web/JsiSkImageFilterFactory.ts +5 -5
- package/src/skia/web/JsiSkMaskFilterFactory.ts +6 -2
- package/src/skia/web/JsiSkMatrix.ts +14 -3
- package/src/skia/web/JsiSkPaint.ts +4 -4
- package/src/skia/web/JsiSkPath.ts +9 -6
- package/src/skia/web/JsiSkPathEffectFactory.ts +2 -2
- package/src/skia/web/JsiSkPathFactory.ts +2 -2
- package/src/skia/web/JsiSkPicture.ts +4 -4
- package/src/skia/web/JsiSkPictureRecorder.ts +6 -2
- package/src/skia/web/JsiSkShaderFactory.ts +6 -6
- package/src/skia/web/JsiSkVerticesFactory.ts +2 -2
- package/src/values/api.ts +55 -2
- package/src/values/hooks/useClockValue.ts +3 -0
- package/src/values/hooks/useComputedValue.ts +3 -0
- package/src/values/hooks/useValue.ts +3 -0
- package/src/values/hooks/useValueEffect.ts +3 -0
- package/src/values/types.ts +6 -6
- package/src/views/SkiaView.tsx +11 -0
package/src/renderer/Canvas.tsx
CHANGED
@@ -4,7 +4,6 @@ import React, {
|
|
4
4
|
useMemo,
|
5
5
|
forwardRef,
|
6
6
|
useRef,
|
7
|
-
useLayoutEffect,
|
8
7
|
} from "react";
|
9
8
|
import type {
|
10
9
|
RefObject,
|
@@ -13,13 +12,13 @@ import type {
|
|
13
12
|
ForwardedRef,
|
14
13
|
FunctionComponent,
|
15
14
|
} from "react";
|
15
|
+
import type { LayoutChangeEvent } from "react-native";
|
16
16
|
|
17
|
-
import { SkiaDomView,
|
17
|
+
import { SkiaDomView, SkiaPictureView } from "../views";
|
18
18
|
import { Skia } from "../skia/Skia";
|
19
19
|
import type { TouchHandler, SkiaBaseViewProps } from "../views";
|
20
20
|
import type { SkiaValue } from "../values/types";
|
21
21
|
import { JsiDrawingContext } from "../dom/types";
|
22
|
-
import { useValue } from "../values";
|
23
22
|
|
24
23
|
import { SkiaRoot } from "./Reconciler";
|
25
24
|
import { NATIVE_DOM } from "./HostComponents";
|
@@ -33,34 +32,42 @@ export interface CanvasProps extends SkiaBaseViewProps {
|
|
33
32
|
onTouch?: TouchHandler;
|
34
33
|
}
|
35
34
|
|
36
|
-
const useOnSizeEvent = (
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
const useOnSizeEvent = (
|
36
|
+
resultValue: SkiaBaseViewProps["onSize"],
|
37
|
+
onLayout?: (event: LayoutChangeEvent) => void
|
38
|
+
) => {
|
39
|
+
return useCallback(
|
40
|
+
(event: LayoutChangeEvent) => {
|
41
|
+
if (onLayout) {
|
42
|
+
onLayout(event);
|
43
|
+
}
|
44
|
+
const { width, height } = event.nativeEvent.layout;
|
41
45
|
|
42
|
-
useLayoutEffect(() => {
|
43
|
-
if (!resultValue) {
|
44
|
-
return;
|
45
|
-
}
|
46
|
-
return onSize.addListener((newValue) => {
|
47
46
|
if (isValue(resultValue)) {
|
48
|
-
resultValue.current =
|
49
|
-
} else {
|
50
|
-
resultValue.value =
|
47
|
+
resultValue.current = { width, height };
|
48
|
+
} else if (resultValue) {
|
49
|
+
resultValue.value = { width, height };
|
51
50
|
}
|
52
|
-
}
|
53
|
-
|
54
|
-
|
55
|
-
return onSize;
|
51
|
+
},
|
52
|
+
[onLayout, resultValue]
|
53
|
+
);
|
56
54
|
};
|
57
55
|
|
58
56
|
export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
59
57
|
(
|
60
|
-
{
|
58
|
+
{
|
59
|
+
children,
|
60
|
+
style,
|
61
|
+
debug,
|
62
|
+
mode,
|
63
|
+
onTouch,
|
64
|
+
onSize: _onSize,
|
65
|
+
onLayout: _onLayout,
|
66
|
+
...props
|
67
|
+
},
|
61
68
|
forwardedRef
|
62
69
|
) => {
|
63
|
-
const
|
70
|
+
const onLayout = useOnSizeEvent(_onSize, _onLayout);
|
64
71
|
const innerRef = useCanvasRef();
|
65
72
|
const ref = useCombinedRefs(forwardedRef, innerRef);
|
66
73
|
const redraw = useCallback(() => {
|
@@ -102,26 +109,30 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
|
102
109
|
style={style}
|
103
110
|
root={root.dom}
|
104
111
|
onTouch={onTouch}
|
105
|
-
|
112
|
+
onLayout={onLayout}
|
106
113
|
mode={mode}
|
107
114
|
debug={debug}
|
108
115
|
{...props}
|
109
116
|
/>
|
110
117
|
);
|
111
118
|
} else {
|
119
|
+
// This is for debugging
|
120
|
+
const recorder = Skia.PictureRecorder();
|
121
|
+
const canvas = recorder.beginRecording(
|
122
|
+
Skia.XYWHRect(0, 0, 2_000_000, 2_000_000)
|
123
|
+
);
|
124
|
+
const ctx = new JsiDrawingContext(Skia, canvas);
|
125
|
+
root.dom.render(ctx);
|
126
|
+
const picture = recorder.finishRecordingAsPicture();
|
112
127
|
return (
|
113
|
-
<
|
128
|
+
<SkiaPictureView
|
114
129
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
115
130
|
ref={ref as any}
|
116
131
|
style={style}
|
117
132
|
mode={mode}
|
118
133
|
debug={debug}
|
119
|
-
|
120
|
-
|
121
|
-
onTouch && onTouch(info.touches);
|
122
|
-
const ctx = new JsiDrawingContext(Skia, canvas);
|
123
|
-
root.dom.render(ctx);
|
124
|
-
}}
|
134
|
+
picture={picture}
|
135
|
+
onLayout={onLayout}
|
125
136
|
{...props}
|
126
137
|
/>
|
127
138
|
);
|
@@ -2,6 +2,11 @@ import React from "react";
|
|
2
2
|
|
3
3
|
import type { CustomDrawingNodeProps } from "../../dom/types";
|
4
4
|
|
5
|
+
/**
|
6
|
+
* @deprecated If you are looking to use the Skia imperative API, you can use:
|
7
|
+
* The picture API: https://shopify.github.io/react-native-skia/docs/shapes/pictures/
|
8
|
+
* The offscreen API: https://shopify.github.io/react-native-skia/docs/animations/textures
|
9
|
+
*/
|
5
10
|
export const Drawing = (props: CustomDrawingNodeProps) => {
|
6
11
|
return <skDrawing {...props} />;
|
7
12
|
};
|
package/src/skia/core/Matrix.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Skia } from "../Skia";
|
2
|
-
import type {
|
2
|
+
import type { Transforms3d } from "../types";
|
3
3
|
import { processTransform } from "../types";
|
4
4
|
|
5
|
-
export const processTransform2d = (transforms:
|
5
|
+
export const processTransform2d = (transforms: Transforms3d) =>
|
6
6
|
processTransform(Skia.Matrix(), transforms);
|
package/src/skia/core/Picture.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { Skia } from "../Skia";
|
2
|
-
import type
|
2
|
+
import { isRect, type SkCanvas, type SkRect, type SkSize } from "../types";
|
3
3
|
|
4
4
|
/**
|
5
5
|
* Memoizes and returns an SkPicture that can be drawn to another canvas.
|
@@ -7,9 +7,17 @@ import type { SkCanvas, SkRect } from "../types";
|
|
7
7
|
* @param cb Callback for drawing to the canvas
|
8
8
|
* @returns SkPicture
|
9
9
|
*/
|
10
|
-
export const createPicture = (
|
10
|
+
export const createPicture = (
|
11
|
+
cb: (canvas: SkCanvas) => void,
|
12
|
+
rect?: SkRect | SkSize
|
13
|
+
) => {
|
14
|
+
"worklet";
|
11
15
|
const recorder = Skia.PictureRecorder();
|
12
|
-
|
16
|
+
let bounds: undefined | SkRect;
|
17
|
+
if (rect) {
|
18
|
+
bounds = isRect(rect) ? rect : Skia.XYWHRect(0, 0, rect.width, rect.height);
|
19
|
+
}
|
20
|
+
const canvas = recorder.beginRecording(bounds);
|
13
21
|
cb(canvas);
|
14
22
|
return recorder.finishRecordingAsPicture();
|
15
23
|
};
|
package/src/skia/core/Vector.ts
CHANGED
package/src/skia/types/Canvas.ts
CHANGED
@@ -485,7 +485,7 @@ export interface SkCanvas {
|
|
485
485
|
* Replaces current matrix with m premultiplied with the existing matrix.
|
486
486
|
* @param m
|
487
487
|
*/
|
488
|
-
concat(m: SkMatrix): void;
|
488
|
+
concat(m: SkMatrix | number[]): void;
|
489
489
|
|
490
490
|
/**
|
491
491
|
* Draws the given picture using the current clip, current matrix, and the provided paint.
|
package/src/skia/types/Matrix.ts
CHANGED
@@ -1,22 +1,13 @@
|
|
1
1
|
import type { SkJSIInstance } from "./JsiInstance";
|
2
2
|
import type { SkCanvas } from "./Canvas";
|
3
|
-
|
4
|
-
|
5
|
-
SkewX = 1,
|
6
|
-
TransX = 2,
|
7
|
-
SkewY = 3,
|
8
|
-
ScaleY = 4,
|
9
|
-
TransY = 5,
|
10
|
-
Persp0 = 6,
|
11
|
-
Persp1 = 7,
|
12
|
-
Persp2 = 8,
|
13
|
-
}
|
3
|
+
import type { Matrix3, Matrix4, Transforms3d } from "./Matrix4";
|
4
|
+
import { processTransform3d } from "./Matrix4";
|
14
5
|
|
15
6
|
export const isMatrix = (obj: unknown): obj is SkMatrix =>
|
16
7
|
obj !== null && (obj as SkJSIInstance<string>).__typename__ === "Matrix";
|
17
8
|
|
18
9
|
export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
19
|
-
concat: (matrix: SkMatrix) => SkMatrix;
|
10
|
+
concat: (matrix: SkMatrix | Matrix4 | Matrix3 | number[]) => SkMatrix;
|
20
11
|
translate: (x: number, y: number) => SkMatrix;
|
21
12
|
scale: (x: number, y?: number) => SkMatrix;
|
22
13
|
skew: (x: number, y: number) => SkMatrix;
|
@@ -29,88 +20,19 @@ export interface SkMatrix extends SkJSIInstance<"Matrix"> {
|
|
29
20
|
get: () => number[];
|
30
21
|
}
|
31
22
|
|
32
|
-
type Transform2dName =
|
33
|
-
| "translateX"
|
34
|
-
| "translateY"
|
35
|
-
| "scale"
|
36
|
-
| "skewX"
|
37
|
-
| "skewY"
|
38
|
-
| "scaleX"
|
39
|
-
| "scaleY"
|
40
|
-
| "rotateZ"
|
41
|
-
| "rotate";
|
42
|
-
|
43
|
-
type Transformations = {
|
44
|
-
readonly [Name in Transform2dName]: number;
|
45
|
-
};
|
46
|
-
|
47
|
-
export type Transforms2d = readonly (
|
48
|
-
| Pick<Transformations, "translateX">
|
49
|
-
| Pick<Transformations, "translateY">
|
50
|
-
| Pick<Transformations, "scale">
|
51
|
-
| Pick<Transformations, "scaleX">
|
52
|
-
| Pick<Transformations, "scaleY">
|
53
|
-
| Pick<Transformations, "skewX">
|
54
|
-
| Pick<Transformations, "skewY">
|
55
|
-
| Pick<Transformations, "rotate">
|
56
|
-
)[];
|
57
|
-
|
58
23
|
export interface TransformProp {
|
59
|
-
transform?:
|
24
|
+
transform?: Transforms3d;
|
60
25
|
}
|
61
26
|
|
62
27
|
export const processTransform = <T extends SkMatrix | SkCanvas>(
|
63
28
|
m: T,
|
64
|
-
transforms:
|
29
|
+
transforms: Transforms3d
|
65
30
|
) => {
|
66
|
-
|
67
|
-
|
68
|
-
const value = (transform as Pick<Transformations, typeof key>)[key];
|
69
|
-
if (key === "translateX") {
|
70
|
-
m.translate(value, 0);
|
71
|
-
continue;
|
72
|
-
}
|
73
|
-
if (key === "translateY") {
|
74
|
-
m.translate(0, value);
|
75
|
-
continue;
|
76
|
-
}
|
77
|
-
if (key === "scale") {
|
78
|
-
m.scale(value, value);
|
79
|
-
continue;
|
80
|
-
}
|
81
|
-
if (key === "scaleX") {
|
82
|
-
m.scale(value, 1);
|
83
|
-
continue;
|
84
|
-
}
|
85
|
-
if (key === "scaleY") {
|
86
|
-
m.scale(1, value);
|
87
|
-
continue;
|
88
|
-
}
|
89
|
-
if (key === "skewX") {
|
90
|
-
m.skew(value, 0);
|
91
|
-
continue;
|
92
|
-
}
|
93
|
-
if (key === "skewY") {
|
94
|
-
m.skew(0, value);
|
95
|
-
continue;
|
96
|
-
}
|
97
|
-
if (key === "rotate" || key === "rotateZ") {
|
98
|
-
if (isMatrix(m)) {
|
99
|
-
m.rotate(value);
|
100
|
-
} else {
|
101
|
-
m.rotate(toDegrees(value), 0, 0);
|
102
|
-
}
|
103
|
-
continue;
|
104
|
-
}
|
105
|
-
exhaustiveCheck(key);
|
106
|
-
}
|
31
|
+
const m3 = processTransform3d(transforms);
|
32
|
+
m.concat(m3);
|
107
33
|
return m;
|
108
34
|
};
|
109
35
|
|
110
|
-
const exhaustiveCheck = (a: never): never => {
|
111
|
-
throw new Error(`Unknown transformation: ${a}`);
|
112
|
-
};
|
113
|
-
|
114
36
|
export const toDegrees = (rad: number) => {
|
115
37
|
return (rad * 180) / Math.PI;
|
116
38
|
};
|
@@ -0,0 +1,344 @@
|
|
1
|
+
type Point = { x: number; y: number };
|
2
|
+
type Vec2 = readonly [number, number];
|
3
|
+
type Vec3 = readonly [number, number, number];
|
4
|
+
type Vec4 = readonly [number, number, number, number];
|
5
|
+
|
6
|
+
export type Matrix3 = readonly [
|
7
|
+
number,
|
8
|
+
number,
|
9
|
+
number,
|
10
|
+
number,
|
11
|
+
number,
|
12
|
+
number,
|
13
|
+
number,
|
14
|
+
number,
|
15
|
+
number
|
16
|
+
];
|
17
|
+
|
18
|
+
export type Matrix4 = readonly [
|
19
|
+
number,
|
20
|
+
number,
|
21
|
+
number,
|
22
|
+
number,
|
23
|
+
number,
|
24
|
+
number,
|
25
|
+
number,
|
26
|
+
number,
|
27
|
+
number,
|
28
|
+
number,
|
29
|
+
number,
|
30
|
+
number,
|
31
|
+
number,
|
32
|
+
number,
|
33
|
+
number,
|
34
|
+
number
|
35
|
+
];
|
36
|
+
|
37
|
+
type Transform3dName =
|
38
|
+
| "translateX"
|
39
|
+
| "translateY"
|
40
|
+
| "translateZ"
|
41
|
+
| "translate"
|
42
|
+
| "scale"
|
43
|
+
| "scaleX"
|
44
|
+
| "scaleY"
|
45
|
+
| "skewX"
|
46
|
+
| "skewY"
|
47
|
+
| "rotateZ"
|
48
|
+
| "rotate"
|
49
|
+
| "perspective"
|
50
|
+
| "rotateX"
|
51
|
+
| "rotateY"
|
52
|
+
| "matrix";
|
53
|
+
|
54
|
+
type Transformations = {
|
55
|
+
[Name in Transform3dName]: Name extends "matrix"
|
56
|
+
? Matrix4
|
57
|
+
: Name extends "translate"
|
58
|
+
? Vec3 | Vec2
|
59
|
+
: number;
|
60
|
+
};
|
61
|
+
|
62
|
+
type Transform3d =
|
63
|
+
| Pick<Transformations, "translateX">
|
64
|
+
| Pick<Transformations, "translateY">
|
65
|
+
| Pick<Transformations, "translateZ">
|
66
|
+
| Pick<Transformations, "translate">
|
67
|
+
| Pick<Transformations, "scale">
|
68
|
+
| Pick<Transformations, "scaleX">
|
69
|
+
| Pick<Transformations, "scaleY">
|
70
|
+
| Pick<Transformations, "skewX">
|
71
|
+
| Pick<Transformations, "skewY">
|
72
|
+
| Pick<Transformations, "perspective">
|
73
|
+
| Pick<Transformations, "rotateX">
|
74
|
+
| Pick<Transformations, "rotateY">
|
75
|
+
| Pick<Transformations, "rotateZ">
|
76
|
+
| Pick<Transformations, "rotate">
|
77
|
+
| Pick<Transformations, "matrix">;
|
78
|
+
|
79
|
+
export type Transforms3d = Transform3d[];
|
80
|
+
|
81
|
+
const exhaustiveCheck = (a: never): never => {
|
82
|
+
"worklet";
|
83
|
+
throw new Error(`Unexhaustive handling for ${a}`);
|
84
|
+
};
|
85
|
+
|
86
|
+
/**
|
87
|
+
* @worklet
|
88
|
+
*/
|
89
|
+
export const Matrix4 = (): Matrix4 => {
|
90
|
+
"worklet";
|
91
|
+
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
92
|
+
};
|
93
|
+
|
94
|
+
/**
|
95
|
+
* @worklet
|
96
|
+
*/
|
97
|
+
export const translate = (x: number, y: number, z: number = 0): Matrix4 => {
|
98
|
+
"worklet";
|
99
|
+
return [1, 0, 0, x, 0, 1, 0, y, 0, 0, 1, z, 0, 0, 0, 1];
|
100
|
+
};
|
101
|
+
|
102
|
+
/**
|
103
|
+
* @worklet
|
104
|
+
*/
|
105
|
+
export const perspective = (p: number): Matrix4 => {
|
106
|
+
"worklet";
|
107
|
+
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, -1 / p, 1];
|
108
|
+
};
|
109
|
+
|
110
|
+
const normalizeVec = (vec: Vec3): Vec3 => {
|
111
|
+
"worklet";
|
112
|
+
const [x, y, z] = vec;
|
113
|
+
const length = Math.sqrt(x * x + y * y + z * z);
|
114
|
+
// Check for zero length to avoid division by zero
|
115
|
+
if (length === 0) {
|
116
|
+
return [0, 0, 0];
|
117
|
+
}
|
118
|
+
return [x / length, y / length, z / length];
|
119
|
+
};
|
120
|
+
|
121
|
+
const rotatedUnitSinCos = (
|
122
|
+
axisVec: Vec3,
|
123
|
+
sinAngle: number,
|
124
|
+
cosAngle: number
|
125
|
+
): Matrix4 => {
|
126
|
+
"worklet";
|
127
|
+
const x = axisVec[0];
|
128
|
+
const y = axisVec[1];
|
129
|
+
const z = axisVec[2];
|
130
|
+
const c = cosAngle;
|
131
|
+
const s = sinAngle;
|
132
|
+
const t = 1 - c;
|
133
|
+
return [
|
134
|
+
t * x * x + c,
|
135
|
+
t * x * y - s * z,
|
136
|
+
t * x * z + s * y,
|
137
|
+
0,
|
138
|
+
t * x * y + s * z,
|
139
|
+
t * y * y + c,
|
140
|
+
t * y * z - s * x,
|
141
|
+
0,
|
142
|
+
t * x * z - s * y,
|
143
|
+
t * y * z + s * x,
|
144
|
+
t * z * z + c,
|
145
|
+
0,
|
146
|
+
0,
|
147
|
+
0,
|
148
|
+
0,
|
149
|
+
1,
|
150
|
+
];
|
151
|
+
};
|
152
|
+
|
153
|
+
const matrixVecMul4 = (m: Matrix4, v: Vec4) => {
|
154
|
+
"worklet";
|
155
|
+
const [vx, vy, vz, vw] = v;
|
156
|
+
return [
|
157
|
+
vx * m[0] + vy * m[4] + vz * m[8] + vw * m[12],
|
158
|
+
vx * m[1] + vy * m[5] + vz * m[9] + vw * m[13],
|
159
|
+
vx * m[2] + vy * m[6] + vz * m[10] + vw * m[14],
|
160
|
+
vx * m[3] + vy * m[7] + vz * m[11] + vw * m[15],
|
161
|
+
];
|
162
|
+
};
|
163
|
+
|
164
|
+
/**
|
165
|
+
* @worklet
|
166
|
+
*/
|
167
|
+
export const mapPoint3d = (m: Matrix4, v: Vec3) => {
|
168
|
+
"worklet";
|
169
|
+
const r = matrixVecMul4(m, [...v, 1]);
|
170
|
+
return [r[0] / r[3], r[1] / r[3], r[2] / r[3]] as const;
|
171
|
+
};
|
172
|
+
|
173
|
+
/**
|
174
|
+
* @worklet
|
175
|
+
*/
|
176
|
+
export const multiply4 = (a: Matrix4, b: Matrix4): Matrix4 => {
|
177
|
+
"worklet";
|
178
|
+
const result = new Array(16).fill(0);
|
179
|
+
for (let i = 0; i < 4; i++) {
|
180
|
+
for (let j = 0; j < 4; j++) {
|
181
|
+
result[i * 4 + j] =
|
182
|
+
a[i * 4] * b[j] +
|
183
|
+
a[i * 4 + 1] * b[j + 4] +
|
184
|
+
a[i * 4 + 2] * b[j + 8] +
|
185
|
+
a[i * 4 + 3] * b[j + 12];
|
186
|
+
}
|
187
|
+
}
|
188
|
+
return result as unknown as Matrix4;
|
189
|
+
};
|
190
|
+
|
191
|
+
const skewY = (angle: number): Matrix4 => {
|
192
|
+
"worklet";
|
193
|
+
return [1, Math.tan(angle), 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
194
|
+
};
|
195
|
+
|
196
|
+
const skewX = (angle: number): Matrix4 => {
|
197
|
+
"worklet";
|
198
|
+
return [1, 0, 0, 0, Math.tan(angle), 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
199
|
+
};
|
200
|
+
|
201
|
+
/**
|
202
|
+
* @worklet
|
203
|
+
*/
|
204
|
+
export const toMatrix3 = (m: Matrix4) => {
|
205
|
+
"worklet";
|
206
|
+
return [m[0], m[1], m[3], m[4], m[5], m[7], m[12], m[13], m[15]];
|
207
|
+
};
|
208
|
+
|
209
|
+
const rotate = (axis: Vec3, value: number) => {
|
210
|
+
"worklet";
|
211
|
+
return rotatedUnitSinCos(
|
212
|
+
normalizeVec(axis),
|
213
|
+
Math.sin(value),
|
214
|
+
Math.cos(value)
|
215
|
+
);
|
216
|
+
};
|
217
|
+
|
218
|
+
/**
|
219
|
+
* @worklet
|
220
|
+
*/
|
221
|
+
export const pivot = (m: Matrix4, p: Point) => {
|
222
|
+
"worklet";
|
223
|
+
return multiply4(translate(p.x, p.y), multiply4(m, translate(-p.x, -p.y)));
|
224
|
+
};
|
225
|
+
|
226
|
+
/**
|
227
|
+
* @worklet
|
228
|
+
*/
|
229
|
+
export const scale = (
|
230
|
+
sx: number,
|
231
|
+
sy: number,
|
232
|
+
sz: number = 1,
|
233
|
+
p?: Point
|
234
|
+
): Matrix4 => {
|
235
|
+
"worklet";
|
236
|
+
const m4: Matrix4 = [sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0, 0, 0, 0, 1];
|
237
|
+
if (p) {
|
238
|
+
return pivot(m4, p);
|
239
|
+
}
|
240
|
+
return m4;
|
241
|
+
};
|
242
|
+
|
243
|
+
const rotateAxis = (axis: Vec3, angle: number, p?: Point) => {
|
244
|
+
"worklet";
|
245
|
+
const result = rotate(axis, angle);
|
246
|
+
if (p) {
|
247
|
+
return pivot(result, p);
|
248
|
+
}
|
249
|
+
return result;
|
250
|
+
};
|
251
|
+
|
252
|
+
/**
|
253
|
+
* @worklet
|
254
|
+
*/
|
255
|
+
export const rotateZ = (value: number, p?: Point) => {
|
256
|
+
"worklet";
|
257
|
+
return rotateAxis([0, 0, 1], value, p);
|
258
|
+
};
|
259
|
+
|
260
|
+
/**
|
261
|
+
* @worklet
|
262
|
+
*/
|
263
|
+
export const rotateX = (value: number, p?: Point) => {
|
264
|
+
"worklet";
|
265
|
+
return rotateAxis([1, 0, 0], value, p);
|
266
|
+
};
|
267
|
+
|
268
|
+
/**
|
269
|
+
* @worklet
|
270
|
+
*/
|
271
|
+
export const rotateY = (value: number, p?: Point) => {
|
272
|
+
"worklet";
|
273
|
+
return rotateAxis([0, 1, 0], value, p);
|
274
|
+
};
|
275
|
+
|
276
|
+
/**
|
277
|
+
* @worklet
|
278
|
+
*/
|
279
|
+
export const processTransform3d = (transforms: Transforms3d) => {
|
280
|
+
"worklet";
|
281
|
+
return toMatrix3(
|
282
|
+
transforms.reduce((acc, val) => {
|
283
|
+
const key = Object.keys(val)[0] as Transform3dName;
|
284
|
+
const transform = val as Pick<Transformations, typeof key>;
|
285
|
+
if (key === "translateX") {
|
286
|
+
const value = transform[key];
|
287
|
+
return multiply4(acc, translate(value, 0, 0));
|
288
|
+
}
|
289
|
+
if (key === "translate") {
|
290
|
+
const [x, y, z = 0] = transform[key];
|
291
|
+
return multiply4(acc, translate(x, y, z));
|
292
|
+
}
|
293
|
+
if (key === "translateY") {
|
294
|
+
const value = transform[key];
|
295
|
+
return multiply4(acc, translate(0, value, 0));
|
296
|
+
}
|
297
|
+
if (key === "translateZ") {
|
298
|
+
const value = transform[key];
|
299
|
+
return multiply4(acc, translate(0, 0, value));
|
300
|
+
}
|
301
|
+
if (key === "scale") {
|
302
|
+
const value = transform[key];
|
303
|
+
return multiply4(acc, scale(value, value, 1));
|
304
|
+
}
|
305
|
+
if (key === "scaleX") {
|
306
|
+
const value = transform[key];
|
307
|
+
return multiply4(acc, scale(value, 1, 1));
|
308
|
+
}
|
309
|
+
if (key === "scaleY") {
|
310
|
+
const value = transform[key];
|
311
|
+
return multiply4(acc, scale(1, value, 1));
|
312
|
+
}
|
313
|
+
if (key === "skewX") {
|
314
|
+
const value = transform[key];
|
315
|
+
return multiply4(acc, skewX(value));
|
316
|
+
}
|
317
|
+
if (key === "skewY") {
|
318
|
+
const value = transform[key];
|
319
|
+
return multiply4(acc, skewY(value));
|
320
|
+
}
|
321
|
+
if (key === "rotateX") {
|
322
|
+
const value = transform[key];
|
323
|
+
return multiply4(acc, rotate([1, 0, 0], value));
|
324
|
+
}
|
325
|
+
if (key === "rotateY") {
|
326
|
+
const value = transform[key];
|
327
|
+
return multiply4(acc, rotate([0, 1, 0], value));
|
328
|
+
}
|
329
|
+
if (key === "perspective") {
|
330
|
+
const value = transform[key];
|
331
|
+
return multiply4(acc, perspective(value));
|
332
|
+
}
|
333
|
+
if (key === "rotate" || key === "rotateZ") {
|
334
|
+
const value = transform[key];
|
335
|
+
return multiply4(acc, rotate([0, 0, 1], value));
|
336
|
+
}
|
337
|
+
if (key === "matrix") {
|
338
|
+
const value = transform[key];
|
339
|
+
return multiply4(acc, value);
|
340
|
+
}
|
341
|
+
return exhaustiveCheck(key);
|
342
|
+
}, Matrix4())
|
343
|
+
);
|
344
|
+
};
|
@@ -540,7 +540,7 @@ export interface SkPath extends SkJSIInstance<"Path"> {
|
|
540
540
|
/**
|
541
541
|
* Transforms the path by the specified matrix.
|
542
542
|
*/
|
543
|
-
transform(m3: SkMatrix): SkPath;
|
543
|
+
transform(m3: SkMatrix | number[]): SkPath;
|
544
544
|
|
545
545
|
/**
|
546
546
|
* Interpolates between Path with point array of equal size.
|
@@ -9,7 +9,7 @@ export interface SkPictureRecorder {
|
|
9
9
|
*
|
10
10
|
* @param bounds - a rect to cull the results.
|
11
11
|
*/
|
12
|
-
beginRecording(bounds
|
12
|
+
beginRecording(bounds?: SkRect): SkCanvas;
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Returns the captured draw commands as a picture and invalidates the canvas returned earlier.
|
package/src/skia/types/Rect.ts
CHANGED
@@ -4,3 +4,17 @@ export interface SkRect {
|
|
4
4
|
readonly width: number;
|
5
5
|
readonly height: number;
|
6
6
|
}
|
7
|
+
|
8
|
+
export const isRect = (def: unknown): def is SkRect => {
|
9
|
+
"worklet";
|
10
|
+
if (typeof def === "object" && def !== null) {
|
11
|
+
const rect = def as SkRect;
|
12
|
+
return (
|
13
|
+
typeof rect.x === "number" &&
|
14
|
+
typeof rect.y === "number" &&
|
15
|
+
typeof rect.width === "number" &&
|
16
|
+
typeof rect.height === "number"
|
17
|
+
);
|
18
|
+
}
|
19
|
+
return false;
|
20
|
+
};
|
package/src/skia/types/index.ts
CHANGED