@shopify/react-native-skia 0.1.138 → 0.1.141
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +5 -1
- package/android/build.gradle +3 -1
- package/cpp/api/JsiSkApi.h +0 -4
- package/cpp/api/JsiSkFont.h +0 -19
- package/lib/commonjs/mock/index.js +0 -4
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +5 -8
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/text/Glyphs.js +4 -6
- package/lib/commonjs/renderer/components/text/Glyphs.js.map +1 -1
- package/lib/commonjs/renderer/components/text/Text.js +4 -6
- package/lib/commonjs/renderer/components/text/Text.js.map +1 -1
- package/lib/commonjs/renderer/components/text/TextPath.js +3 -4
- package/lib/commonjs/renderer/components/text/TextPath.js.map +1 -1
- package/lib/commonjs/renderer/processors/Font.js +1 -27
- package/lib/commonjs/renderer/processors/Font.js.map +1 -1
- package/lib/commonjs/skia/core/Data.js +4 -5
- package/lib/commonjs/skia/core/Data.js.map +1 -1
- package/lib/commonjs/skia/core/Image.js +4 -1
- package/lib/commonjs/skia/core/Image.js.map +1 -1
- package/lib/commonjs/skia/core/SVG.js +3 -1
- package/lib/commonjs/skia/core/SVG.js.map +1 -1
- package/lib/commonjs/skia/core/Typeface.js +4 -1
- package/lib/commonjs/skia/core/Typeface.js.map +1 -1
- package/lib/commonjs/skia/core/index.js +0 -26
- package/lib/commonjs/skia/core/index.js.map +1 -1
- package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.js +0 -2
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
- package/lib/commonjs/skia/types/index.js +0 -13
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkFont.js +0 -6
- package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js +1 -1
- package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +0 -3
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/values/hooks/useComputedValue.js +1 -8
- package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.js +53 -33
- package/lib/commonjs/views/SkiaView.web.js.map +1 -1
- package/lib/commonjs/views/useTouchHandler.js +13 -15
- package/lib/commonjs/views/useTouchHandler.js.map +1 -1
- package/lib/module/mock/index.js +0 -4
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.js +5 -6
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/text/Glyphs.js +4 -5
- package/lib/module/renderer/components/text/Glyphs.js.map +1 -1
- package/lib/module/renderer/components/text/Text.js +4 -5
- package/lib/module/renderer/components/text/Text.js.map +1 -1
- package/lib/module/renderer/components/text/TextPath.js +3 -3
- package/lib/module/renderer/components/text/TextPath.js.map +1 -1
- package/lib/module/renderer/processors/Font.js +0 -23
- package/lib/module/renderer/processors/Font.js.map +1 -1
- package/lib/module/skia/core/Data.js +4 -5
- package/lib/module/skia/core/Data.js.map +1 -1
- package/lib/module/skia/core/Image.js +2 -1
- package/lib/module/skia/core/Image.js.map +1 -1
- package/lib/module/skia/core/SVG.js +2 -1
- package/lib/module/skia/core/SVG.js.map +1 -1
- package/lib/module/skia/core/Typeface.js +2 -1
- package/lib/module/skia/core/Typeface.js.map +1 -1
- package/lib/module/skia/core/index.js +0 -2
- package/lib/module/skia/core/index.js.map +1 -1
- package/lib/module/skia/types/Font/Font.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.js +0 -1
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Path/Path.js.map +1 -1
- package/lib/module/skia/types/index.js +0 -1
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkFont.js +0 -6
- package/lib/module/skia/web/JsiSkFont.js.map +1 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js +1 -1
- package/lib/module/skia/web/JsiSkTextBlobFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +0 -2
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/values/hooks/useComputedValue.js +0 -4
- package/lib/module/values/hooks/useComputedValue.js.map +1 -1
- package/lib/module/views/SkiaView.web.js +53 -34
- package/lib/module/views/SkiaView.web.js.map +1 -1
- package/lib/module/views/useTouchHandler.js +12 -14
- package/lib/module/views/useTouchHandler.js.map +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -3
- package/lib/typescript/src/renderer/DrawingContext.d.ts +1 -2
- package/lib/typescript/src/renderer/processors/Font.d.ts +1 -5
- package/lib/typescript/src/skia/core/index.d.ts +0 -2
- package/lib/typescript/src/skia/types/Font/Font.d.ts +0 -12
- package/lib/typescript/src/skia/types/Skia.d.ts +0 -2
- package/lib/typescript/src/skia/types/index.d.ts +0 -1
- package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -2
- package/lib/typescript/src/values/hooks/useComputedValue.d.ts +0 -1
- package/lib/typescript/src/views/SkiaView.web.d.ts +5 -5
- package/package.json +12 -7
- package/src/mock/index.ts +0 -4
- package/src/renderer/Canvas.tsx +5 -8
- package/src/renderer/DrawingContext.ts +1 -2
- package/src/renderer/components/text/Glyphs.tsx +2 -6
- package/src/renderer/components/text/Text.tsx +2 -3
- package/src/renderer/components/text/TextPath.tsx +2 -3
- package/src/renderer/processors/Font.ts +2 -25
- package/src/skia/core/Data.ts +8 -5
- package/src/skia/core/Image.ts +3 -1
- package/src/skia/core/SVG.ts +3 -1
- package/src/skia/core/Typeface.ts +4 -6
- package/src/skia/core/index.ts +0 -2
- package/src/skia/types/Font/Font.ts +0 -13
- package/src/skia/types/Image/ImageFactory.ts +0 -1
- package/src/skia/types/Path/Path.ts +0 -1
- package/src/skia/types/Skia.ts +0 -2
- package/src/skia/types/index.ts +0 -1
- package/src/skia/web/JsiSkFont.ts +0 -9
- package/src/skia/web/JsiSkTextBlobFactory.ts +1 -1
- package/src/skia/web/JsiSkia.ts +0 -2
- package/src/values/hooks/useComputedValue.ts +0 -5
- package/src/views/SkiaView.web.tsx +41 -46
- package/src/views/useTouchHandler.ts +15 -19
- package/android/README.md +0 -14
- package/cpp/api/JsiSkFontMgr.h +0 -84
- package/cpp/api/JsiSkFontMgrFactory.h +0 -48
- package/cpp/skia/include/third_party/skcms/LICENSE +0 -29
- package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
- package/cpp/skia/readme.txt +0 -1
- package/lib/commonjs/skia/core/Paint.js +0 -28
- package/lib/commonjs/skia/core/Paint.js.map +0 -1
- package/lib/commonjs/skia/core/Path.js +0 -72
- package/lib/commonjs/skia/core/Path.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/FontMgr.js +0 -6
- package/lib/commonjs/skia/types/FontMgr/FontMgr.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js +0 -6
- package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
- package/lib/commonjs/skia/types/FontMgr/index.js +0 -32
- package/lib/commonjs/skia/types/FontMgr/index.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -33
- package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +0 -1
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +0 -25
- package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +0 -1
- package/lib/module/skia/core/Paint.js +0 -17
- package/lib/module/skia/core/Paint.js.map +0 -1
- package/lib/module/skia/core/Path.js +0 -53
- package/lib/module/skia/core/Path.js.map +0 -1
- package/lib/module/skia/types/FontMgr/FontMgr.js +0 -2
- package/lib/module/skia/types/FontMgr/FontMgr.js.map +0 -1
- package/lib/module/skia/types/FontMgr/FontMgrFactory.js +0 -2
- package/lib/module/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
- package/lib/module/skia/types/FontMgr/index.js +0 -3
- package/lib/module/skia/types/FontMgr/index.js.map +0 -1
- package/lib/module/skia/web/JsiSkFontMgr.js +0 -23
- package/lib/module/skia/web/JsiSkFontMgr.js.map +0 -1
- package/lib/module/skia/web/JsiSkFontMgrFactory.js +0 -14
- package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +0 -1
- package/lib/typescript/src/skia/core/Paint.d.ts +0 -6
- package/lib/typescript/src/skia/core/Path.d.ts +0 -21
- package/lib/typescript/src/skia/types/FontMgr/FontMgr.d.ts +0 -18
- package/lib/typescript/src/skia/types/FontMgr/FontMgrFactory.d.ts +0 -4
- package/lib/typescript/src/skia/types/FontMgr/index.d.ts +0 -2
- package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +0 -9
- package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +0 -8
- package/src/skia/core/Paint.ts +0 -22
- package/src/skia/core/Path.ts +0 -60
- package/src/skia/types/FontMgr/FontMgr.ts +0 -24
- package/src/skia/types/FontMgr/FontMgrFactory.ts +0 -12
- package/src/skia/types/FontMgr/index.ts +0 -2
- package/src/skia/web/JsiSkFontMgr.ts +0 -38
- package/src/skia/web/JsiSkFontMgrFactory.ts +0 -18
@@ -12,30 +12,29 @@ const useInternalTouchHandler = function (handlers) {
|
|
12
12
|
history.forEach(touches => {
|
13
13
|
// Enumerate touches
|
14
14
|
for (let i = 0; i < touches.length; i++) {
|
15
|
-
var _prevTouchInfoRef$cur, _prevTouchInfoRef$cur2,
|
15
|
+
var _prevTouchInfoRef$cur, _prevTouchInfoRef$cur2, _prevTouch$x, _prevTouch$y, _prevVelocityRef$curr, _prevVelocityRef$curr2, _prevVelocityRef$curr3, _prevVelocityRef$curr4;
|
16
16
|
|
17
17
|
if (!multiTouch && i > 0) {
|
18
18
|
break;
|
19
19
|
}
|
20
20
|
|
21
|
-
const touch = touches[i];
|
21
|
+
const touch = touches[i];
|
22
|
+
const prevTouch = prevTouchInfoRef.current[touch.id]; // Calculate the velocity from the previous touch.
|
22
23
|
|
23
24
|
const timeDiffseconds = touch.timestamp - ((_prevTouchInfoRef$cur = (_prevTouchInfoRef$cur2 = prevTouchInfoRef.current[touch.id]) === null || _prevTouchInfoRef$cur2 === void 0 ? void 0 : _prevTouchInfoRef$cur2.timestamp) !== null && _prevTouchInfoRef$cur !== void 0 ? _prevTouchInfoRef$cur : touch.timestamp);
|
24
|
-
const distX = touch.x - ((
|
25
|
-
const distY = touch.y - ((
|
25
|
+
const distX = touch.x - ((_prevTouch$x = prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.x) !== null && _prevTouch$x !== void 0 ? _prevTouch$x : touch.x);
|
26
|
+
const distY = touch.y - ((_prevTouch$y = prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.y) !== null && _prevTouch$y !== void 0 ? _prevTouch$y : touch.y);
|
26
27
|
|
27
|
-
if (touch.type !== TouchType.Start && touch.type !== TouchType.End && touch.type !== TouchType.Cancelled) {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
};
|
33
|
-
}
|
28
|
+
if (touch.type !== TouchType.Start && touch.type !== TouchType.End && touch.type !== TouchType.Cancelled && timeDiffseconds > 0) {
|
29
|
+
prevVelocityRef.current[touch.id] = {
|
30
|
+
x: distX / timeDiffseconds / PixelRatio.get(),
|
31
|
+
y: distY / timeDiffseconds / PixelRatio.get()
|
32
|
+
};
|
34
33
|
}
|
35
34
|
|
36
35
|
const extendedTouchInfo = { ...touch,
|
37
|
-
velocityX: (_prevVelocityRef$curr = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$
|
38
|
-
velocityY: (_prevVelocityRef$
|
36
|
+
velocityX: (_prevVelocityRef$curr = (_prevVelocityRef$curr2 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr2 === void 0 ? void 0 : _prevVelocityRef$curr2.x) !== null && _prevVelocityRef$curr !== void 0 ? _prevVelocityRef$curr : 0,
|
37
|
+
velocityY: (_prevVelocityRef$curr3 = (_prevVelocityRef$curr4 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr4 === void 0 ? void 0 : _prevVelocityRef$curr4.y) !== null && _prevVelocityRef$curr3 !== void 0 ? _prevVelocityRef$curr3 : 0
|
39
38
|
}; // Save previous touch
|
40
39
|
|
41
40
|
prevTouchInfoRef.current[touch.id] = touch;
|
@@ -46,7 +45,6 @@ const useInternalTouchHandler = function (handlers) {
|
|
46
45
|
} else if (touch.type === TouchType.Active) {
|
47
46
|
handlers.onActive && handlers.onActive(extendedTouchInfo);
|
48
47
|
} else {
|
49
|
-
handlers.onActive && handlers.onActive(extendedTouchInfo);
|
50
48
|
handlers.onEnd && handlers.onEnd(extendedTouchInfo);
|
51
49
|
}
|
52
50
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["useTouchHandler.ts"],"names":["useCallback","useRef","PixelRatio","TouchType","useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","
|
1
|
+
{"version":3,"sources":["useTouchHandler.ts"],"names":["useCallback","useRef","PixelRatio","TouchType","useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","prevTouch","current","id","timeDiffseconds","timestamp","distX","x","distY","y","type","Start","End","Cancelled","get","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"mappings":"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","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback, useRef } from \"react\";\nimport { PixelRatio } from \"react-native\";\n\nimport type { Vector } from \"../skia/types\";\n\nimport type {\n ExtendedTouchInfo,\n TouchHandlers,\n TouchHandler,\n TouchInfo,\n} from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst useInternalTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = [],\n multiTouch = false\n): TouchHandler => {\n const prevTouchInfoRef = useRef<{ [key: number]: TouchInfo | undefined }>({});\n const prevVelocityRef = useRef<{ [key: number]: Vector | undefined }>({});\n\n return useCallback((history: Array<Array<TouchInfo>>) => {\n // Process all items in the current touch history\n history.forEach((touches) => {\n // Enumerate touches\n for (let i = 0; i < touches.length; i++) {\n if (!multiTouch && i > 0) {\n break;\n }\n\n const touch = touches[i];\n const prevTouch = prevTouchInfoRef.current[touch.id];\n // Calculate the velocity from the previous touch.\n const timeDiffseconds =\n touch.timestamp -\n (prevTouchInfoRef.current[touch.id]?.timestamp ?? touch.timestamp);\n\n const distX = touch.x - (prevTouch?.x ?? touch.x);\n const distY = touch.y - (prevTouch?.y ?? touch.y);\n\n if (\n touch.type !== TouchType.Start &&\n touch.type !== TouchType.End &&\n touch.type !== TouchType.Cancelled &&\n timeDiffseconds > 0\n ) {\n prevVelocityRef.current[touch.id] = {\n x: distX / timeDiffseconds / PixelRatio.get(),\n y: distY / timeDiffseconds / PixelRatio.get(),\n };\n }\n\n const extendedTouchInfo: ExtendedTouchInfo = {\n ...touch,\n velocityX: prevVelocityRef.current[touch.id]?.x ?? 0,\n velocityY: prevVelocityRef.current[touch.id]?.y ?? 0,\n };\n\n // Save previous touch\n prevTouchInfoRef.current[touch.id] = touch;\n\n if (touch.type === TouchType.Start) {\n delete prevVelocityRef.current[touch.id];\n handlers.onStart && handlers.onStart(touch);\n } else if (touch.type === TouchType.Active) {\n handlers.onActive && handlers.onActive(extendedTouchInfo);\n } else {\n handlers.onEnd && handlers.onEnd(extendedTouchInfo);\n }\n }\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler only handles single touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, false);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler handles multiple touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useMultiTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, true);\n};\n"]}
|
@@ -3,7 +3,6 @@ import type { RefObject, ReactNode, ComponentProps } from "react";
|
|
3
3
|
import ReactReconciler from "react-reconciler";
|
4
4
|
import { SkiaView } from "../views";
|
5
5
|
import type { TouchHandler } from "../views";
|
6
|
-
import type { SkFontMgr } from "../skia/types";
|
7
6
|
import { Container } from "./nodes";
|
8
7
|
export declare const skiaReconciler: ReactReconciler.Reconciler<Container, import("./nodes").Node<unknown>, import("./nodes").Node<unknown>, import("./nodes").Node<unknown>, import("./nodes").Node<unknown>>;
|
9
8
|
export declare const useCanvasRef: () => React.RefObject<SkiaView>;
|
@@ -11,6 +10,5 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
|
|
11
10
|
ref?: RefObject<SkiaView>;
|
12
11
|
children: ReactNode;
|
13
12
|
onTouch?: TouchHandler;
|
14
|
-
fontMgr?: SkFontMgr;
|
15
13
|
}
|
16
|
-
export declare const Canvas: React.ForwardRefExoticComponent<Pick<CanvasProps, "children" | "mode" | "debug" | "onDraw" | "hitSlop" | "onLayout" | "pointerEvents" | "removeClippedSubviews" | "style" | "testID" | "nativeID" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "
|
14
|
+
export declare const Canvas: React.ForwardRefExoticComponent<Pick<CanvasProps, "children" | "mode" | "debug" | "onDraw" | "hitSlop" | "onLayout" | "pointerEvents" | "removeClippedSubviews" | "style" | "testID" | "nativeID" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "onTouch"> & React.RefAttributes<SkiaView>>;
|
@@ -1,12 +1,11 @@
|
|
1
1
|
import type { RefObject } from "react";
|
2
2
|
import type { DrawingInfo, SkiaView } from "../views";
|
3
|
-
import type {
|
3
|
+
import type { SkCanvas, SkPaint, Skia, Vector } from "../skia/types";
|
4
4
|
export interface DrawingContext extends Omit<DrawingInfo, "touches"> {
|
5
5
|
canvas: SkCanvas;
|
6
6
|
paint: SkPaint;
|
7
7
|
opacity: number;
|
8
8
|
center: Vector;
|
9
9
|
ref: RefObject<SkiaView>;
|
10
|
-
fontMgr: SkFontMgr;
|
11
10
|
Skia: Skia;
|
12
11
|
}
|
@@ -1,11 +1,7 @@
|
|
1
|
-
import type {
|
1
|
+
import type { SkFont } from "../../skia/types";
|
2
2
|
export declare type FontDef = {
|
3
3
|
font: SkFont;
|
4
|
-
} | {
|
5
|
-
familyName: string;
|
6
|
-
size: number;
|
7
4
|
};
|
8
5
|
export declare const isFont: (fontDef: FontDef) => fontDef is {
|
9
6
|
font: SkFont;
|
10
7
|
};
|
11
|
-
export declare const processFont: (Skia: Skia, fontMgr: SkFontMgr, fontDef: FontDef) => SkFont;
|
@@ -4,9 +4,7 @@ export * from "./Typeface";
|
|
4
4
|
export * from "./Image";
|
5
5
|
export * from "./Picture";
|
6
6
|
export * from "./SVG";
|
7
|
-
export * from "./Path";
|
8
7
|
export * from "./Vector";
|
9
8
|
export * from "./Rect";
|
10
9
|
export * from "./RRect";
|
11
10
|
export * from "./Matrix";
|
12
|
-
export * from "./Paint";
|
@@ -24,18 +24,6 @@ export interface SkFont extends SkJSIInstance<"Font"> {
|
|
24
24
|
* @param paint
|
25
25
|
*/
|
26
26
|
getGlyphWidths(glyphs: number[], paint?: SkPaint): number[];
|
27
|
-
/** Returns the advance width of text.
|
28
|
-
The advance is the normal distance to move before drawing additional text.
|
29
|
-
Returns the bounding box of text if bounds is not nullptr. The paint
|
30
|
-
stroke settings, mask filter, or path effect may modify the bounds.
|
31
|
-
|
32
|
-
@param text character storage encoded with SkTextEncoding
|
33
|
-
@param byteLength length of character storage in bytes
|
34
|
-
@param bounds returns bounding box relative to (0, 0) if not nullptr
|
35
|
-
@param paint optional; may be nullptr
|
36
|
-
@return number of glyphs represented by text of length byteLength
|
37
|
-
*/
|
38
|
-
measureText: (text: string, paint?: SkPaint) => SkRect;
|
39
27
|
/**
|
40
28
|
* Returns the FontMetrics for this font.
|
41
29
|
*/
|
@@ -17,7 +17,6 @@ import type { SkVertices, VertexMode } from "./Vertices/Vertices";
|
|
17
17
|
import type { DataFactory } from "./Data";
|
18
18
|
import type { SVGFactory } from "./SVG";
|
19
19
|
import type { TextBlobFactory } from "./TextBlob";
|
20
|
-
import type { FontMgrFactory } from "./FontMgr/FontMgrFactory";
|
21
20
|
import type { SurfaceFactory } from "./Surface";
|
22
21
|
import type { SkRSXform } from "./RSXform";
|
23
22
|
import type { SkPath } from "./Path/Path";
|
@@ -62,7 +61,6 @@ export interface Skia {
|
|
62
61
|
Data: DataFactory;
|
63
62
|
Image: ImageFactory;
|
64
63
|
SVG: SVGFactory;
|
65
|
-
FontMgr: FontMgrFactory;
|
66
64
|
TextBlob: TextBlobFactory;
|
67
65
|
Surface: SurfaceFactory;
|
68
66
|
}
|
@@ -1,11 +1,10 @@
|
|
1
1
|
import type { CanvasKit, Font } from "canvaskit-wasm";
|
2
|
-
import type { FontEdging, FontHinting, SkFont, SkPaint, SkPoint,
|
2
|
+
import type { FontEdging, FontHinting, SkFont, SkPaint, SkPoint, SkTypeface } from "../types";
|
3
3
|
import { HostObject } from "./Host";
|
4
4
|
import { JsiSkRect } from "./JsiSkRect";
|
5
5
|
import { JsiSkTypeface } from "./JsiSkTypeface";
|
6
6
|
export declare class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
|
7
7
|
constructor(CanvasKit: CanvasKit, ref: Font);
|
8
|
-
measureText(_text: string, _paint?: SkPaint): SkRect;
|
9
8
|
getTextWidth(text: string, paint?: SkPaint | undefined): number;
|
10
9
|
getMetrics(): {
|
11
10
|
ascent: number;
|
@@ -4,10 +4,7 @@ import type { SkRect } from "../skia/types";
|
|
4
4
|
import type { SkiaValue } from "../values";
|
5
5
|
import type { DrawMode, SkiaViewProps } from "./types";
|
6
6
|
import { TouchType } from "./types";
|
7
|
-
export declare class SkiaView extends React.Component<SkiaViewProps
|
8
|
-
width: number;
|
9
|
-
height: number;
|
10
|
-
}> {
|
7
|
+
export declare class SkiaView extends React.Component<SkiaViewProps> {
|
11
8
|
constructor(props: SkiaViewProps);
|
12
9
|
private _surface;
|
13
10
|
private _unsubscriptions;
|
@@ -16,10 +13,13 @@ export declare class SkiaView extends React.Component<SkiaViewProps, {
|
|
16
13
|
private _canvasRef;
|
17
14
|
private _mode;
|
18
15
|
private _redrawRequests;
|
19
|
-
private
|
16
|
+
private width;
|
17
|
+
private height;
|
18
|
+
private requestId;
|
20
19
|
private unsubscribeAll;
|
21
20
|
private onLayout;
|
22
21
|
componentDidMount(): void;
|
22
|
+
componentDidUpdate(): void;
|
23
23
|
componentWillUnmount(): void;
|
24
24
|
/**
|
25
25
|
* Creates a snapshot from the canvas in the surface
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"setup-skia-web": "./scripts/setup-canvaskit.js"
|
8
8
|
},
|
9
9
|
"title": "React Native Skia",
|
10
|
-
"version": "0.1.
|
10
|
+
"version": "0.1.141",
|
11
11
|
"description": "High-performance React Native Graphics using Skia",
|
12
12
|
"main": "lib/module/index.js",
|
13
13
|
"files": [
|
@@ -69,18 +69,23 @@
|
|
69
69
|
"react-native": ">=0.63.0-rc.0 <1.0.x",
|
70
70
|
"react-native-reanimated": ">=2.0.0"
|
71
71
|
},
|
72
|
+
"peerDependenciesMeta": {
|
73
|
+
"react-native-reanimated": {
|
74
|
+
"optional": true
|
75
|
+
}
|
76
|
+
},
|
72
77
|
"devDependencies": {
|
73
|
-
"@types/jest": "^
|
78
|
+
"@types/jest": "^28.1.6",
|
74
79
|
"@types/react-native": "^0.65.0",
|
75
80
|
"@types/react-reconciler": "^0.26.4",
|
76
|
-
"eslint": "
|
77
|
-
"eslint-config-react-native-wcandillon": "
|
78
|
-
"eslint-plugin-reanimated": "
|
79
|
-
"jest": "
|
81
|
+
"eslint": "8.21.0",
|
82
|
+
"eslint-config-react-native-wcandillon": "3.9.0",
|
83
|
+
"eslint-plugin-reanimated": "2.0.0",
|
84
|
+
"jest": "28.1.3",
|
80
85
|
"react": "17.0.2",
|
81
86
|
"react-native": "0.66.2",
|
82
87
|
"react-native-builder-bob": "^0.18.2",
|
83
|
-
"ts-jest": "^
|
88
|
+
"ts-jest": "^28.0.7",
|
84
89
|
"typescript": "^4.6.4"
|
85
90
|
},
|
86
91
|
"dependencies": {
|
package/src/mock/index.ts
CHANGED
@@ -52,12 +52,8 @@ export const Mock: typeof SkiaExports &
|
|
52
52
|
useFont: Noop,
|
53
53
|
useTypeface: Noop,
|
54
54
|
useImage: Noop,
|
55
|
-
usePath: Noop,
|
56
55
|
useSVG: Noop,
|
57
|
-
useTextPath: Noop,
|
58
|
-
usePaint: Noop,
|
59
56
|
usePicture: Noop,
|
60
|
-
useSvgPath: Noop,
|
61
57
|
// 3. Point/Rect/Transform utilities
|
62
58
|
vec,
|
63
59
|
rect: (x: number, y: number, width: number, height: number) => ({
|
package/src/renderer/Canvas.tsx
CHANGED
@@ -18,7 +18,6 @@ import ReactReconciler from "react-reconciler";
|
|
18
18
|
|
19
19
|
import { SkiaView, useDrawCallback } from "../views";
|
20
20
|
import type { TouchHandler } from "../views";
|
21
|
-
import type { SkFontMgr } from "../skia/types";
|
22
21
|
import { useValue } from "../values/hooks/useValue";
|
23
22
|
import { Skia } from "../skia/Skia";
|
24
23
|
|
@@ -50,13 +49,10 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
|
|
50
49
|
ref?: RefObject<SkiaView>;
|
51
50
|
children: ReactNode;
|
52
51
|
onTouch?: TouchHandler;
|
53
|
-
fontMgr?: SkFontMgr;
|
54
52
|
}
|
55
53
|
|
56
|
-
const defaultFontMgr = Skia.FontMgr.RefDefault();
|
57
|
-
|
58
54
|
export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
59
|
-
({ children, style, debug, mode, onTouch
|
55
|
+
({ children, style, debug, mode, onTouch }, forwardedRef) => {
|
60
56
|
const size = useValue({ width: 0, height: 0 });
|
61
57
|
const canvasCtx = useMemo(() => ({ Skia, size }), [size]);
|
62
58
|
const innerRef = useCanvasRef();
|
@@ -106,7 +102,6 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
106
102
|
opacity: 1,
|
107
103
|
ref,
|
108
104
|
center: Skia.Point(width / 2, height / 2),
|
109
|
-
fontMgr: fontMgr ?? defaultFontMgr,
|
110
105
|
Skia,
|
111
106
|
};
|
112
107
|
container.draw(ctx);
|
@@ -116,9 +111,11 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
|
|
116
111
|
|
117
112
|
useEffect(() => {
|
118
113
|
return () => {
|
119
|
-
|
114
|
+
skiaReconciler.updateContainer(null, root, null, () => {
|
115
|
+
container.depMgr.unsubscribe();
|
116
|
+
});
|
120
117
|
};
|
121
|
-
}, [container]);
|
118
|
+
}, [container, root]);
|
122
119
|
|
123
120
|
return (
|
124
121
|
<SkiaView
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { RefObject } from "react";
|
2
2
|
|
3
3
|
import type { DrawingInfo, SkiaView } from "../views";
|
4
|
-
import type {
|
4
|
+
import type { SkCanvas, SkPaint, Skia, Vector } from "../skia/types";
|
5
5
|
|
6
6
|
export interface DrawingContext extends Omit<DrawingInfo, "touches"> {
|
7
7
|
canvas: SkCanvas;
|
@@ -9,6 +9,5 @@ export interface DrawingContext extends Omit<DrawingInfo, "touches"> {
|
|
9
9
|
opacity: number;
|
10
10
|
center: Vector;
|
11
11
|
ref: RefObject<SkiaView>;
|
12
|
-
fontMgr: SkFontMgr;
|
13
12
|
Skia: Skia;
|
14
13
|
}
|
@@ -4,7 +4,6 @@ import type { CustomPaintProps, AnimatedProps } from "../../processors";
|
|
4
4
|
import { createDrawing } from "../../nodes/Drawing";
|
5
5
|
import type { SkPoint } from "../../../skia/types";
|
6
6
|
import type { FontDef } from "../../processors/Font";
|
7
|
-
import { processFont } from "../../processors/Font";
|
8
7
|
|
9
8
|
export interface Glyph {
|
10
9
|
id: number;
|
@@ -24,11 +23,8 @@ interface ProcessedGlyphs {
|
|
24
23
|
}
|
25
24
|
|
26
25
|
const onDraw = createDrawing<GlyphsProps>(
|
27
|
-
(
|
28
|
-
{
|
29
|
-
{ glyphs: rawGlyphs, x, y, ...fontDef }
|
30
|
-
) => {
|
31
|
-
const font = processFont(Skia, fontMgr, fontDef);
|
26
|
+
({ canvas, paint }, { glyphs: rawGlyphs, x, y, ...fontDef }) => {
|
27
|
+
const { font } = fontDef;
|
32
28
|
const { glyphs, positions } = rawGlyphs.reduce<ProcessedGlyphs>(
|
33
29
|
(acc, glyph) => {
|
34
30
|
const { id, pos } = glyph;
|
@@ -6,7 +6,6 @@ import type {
|
|
6
6
|
FontDef,
|
7
7
|
} from "../../processors";
|
8
8
|
import { createDrawing } from "../../nodes/Drawing";
|
9
|
-
import { processFont } from "../../processors";
|
10
9
|
|
11
10
|
type TextProps = CustomPaintProps &
|
12
11
|
FontDef & {
|
@@ -16,8 +15,8 @@ type TextProps = CustomPaintProps &
|
|
16
15
|
};
|
17
16
|
|
18
17
|
const onDraw = createDrawing<TextProps>(
|
19
|
-
({ canvas, paint
|
20
|
-
const font =
|
18
|
+
({ canvas, paint }, { text, x, y, ...fontDef }) => {
|
19
|
+
const { font } = fontDef;
|
21
20
|
canvas.drawText(text, x, y, paint, font);
|
22
21
|
}
|
23
22
|
);
|
@@ -4,7 +4,6 @@ import type { CustomPaintProps, AnimatedProps } from "../../processors";
|
|
4
4
|
import { createDrawing } from "../../nodes";
|
5
5
|
import type { SkPath, SkRSXform } from "../../../skia/types";
|
6
6
|
import type { FontDef } from "../../processors/Font";
|
7
|
-
import { processFont } from "../../processors/Font";
|
8
7
|
|
9
8
|
export type TextPathProps = CustomPaintProps &
|
10
9
|
FontDef & {
|
@@ -15,7 +14,7 @@ export type TextPathProps = CustomPaintProps &
|
|
15
14
|
|
16
15
|
const onDraw = createDrawing<TextPathProps>(
|
17
16
|
(
|
18
|
-
{ canvas, paint,
|
17
|
+
{ canvas, paint, Skia },
|
19
18
|
{ text, initialOffset, path: pathDef, ...fontDef }
|
20
19
|
) => {
|
21
20
|
const path =
|
@@ -25,7 +24,7 @@ const onDraw = createDrawing<TextPathProps>(
|
|
25
24
|
if (path === null) {
|
26
25
|
throw new Error("Invalid path: " + pathDef);
|
27
26
|
}
|
28
|
-
const font =
|
27
|
+
const { font } = fontDef;
|
29
28
|
const ids = font.getGlyphIDs(text);
|
30
29
|
const widths = font.getGlyphWidths(ids, paint);
|
31
30
|
const rsx: SkRSXform[] = [];
|
@@ -1,31 +1,8 @@
|
|
1
|
-
import type {
|
1
|
+
import type { SkFont } from "../../skia/types";
|
2
2
|
|
3
|
-
export type FontDef = { font: SkFont }
|
3
|
+
export type FontDef = { font: SkFont };
|
4
4
|
|
5
5
|
export const isFont = (fontDef: FontDef): fontDef is { font: SkFont } =>
|
6
6
|
// We have an issue to check property existence on JSI backed instances
|
7
7
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8
8
|
(fontDef as any).font !== undefined;
|
9
|
-
|
10
|
-
export const processFont = (
|
11
|
-
Skia: Skia,
|
12
|
-
fontMgr: SkFontMgr,
|
13
|
-
fontDef: FontDef
|
14
|
-
) => {
|
15
|
-
let selectedFont: SkFont;
|
16
|
-
if (isFont(fontDef)) {
|
17
|
-
selectedFont = fontDef.font;
|
18
|
-
} else {
|
19
|
-
console.warn(
|
20
|
-
// eslint-disable-next-line max-len
|
21
|
-
"Using system fonts is deprecated. Please use the font property instead: https://shopify.github.io/react-native-skia/docs/text/fonts"
|
22
|
-
);
|
23
|
-
const { familyName, size } = fontDef;
|
24
|
-
const typeface = fontMgr.matchFamilyStyle(familyName);
|
25
|
-
if (typeface === null) {
|
26
|
-
throw new Error(`No typeface found for ${familyName}`);
|
27
|
-
}
|
28
|
-
selectedFont = Skia.Font(typeface, size);
|
29
|
-
}
|
30
|
-
return selectedFont;
|
31
|
-
};
|
package/src/skia/core/Data.ts
CHANGED
@@ -32,19 +32,22 @@ const loadDataCollection = <T>(
|
|
32
32
|
): Promise<(T | null)[]> =>
|
33
33
|
Promise.all(sources.map((source) => loadData(source, factory, onError)));
|
34
34
|
|
35
|
-
const loadData =
|
35
|
+
const loadData = <T>(
|
36
36
|
source: DataSource,
|
37
37
|
factory: (data: SkData) => T,
|
38
38
|
onError?: (err: Error) => void
|
39
39
|
): Promise<T | null> => {
|
40
40
|
if (source === null) {
|
41
|
-
return null;
|
41
|
+
return new Promise((resolve) => resolve(null));
|
42
42
|
} else if (source instanceof Uint8Array) {
|
43
|
-
return
|
43
|
+
return new Promise((resolve) =>
|
44
|
+
resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))
|
45
|
+
);
|
44
46
|
} else {
|
45
47
|
const uri = typeof source === "string" ? source : resolveAsset(source);
|
46
|
-
|
47
|
-
|
48
|
+
return Skia.Data.fromURI(uri).then((d) =>
|
49
|
+
factoryWrapper(d, factory, onError)
|
50
|
+
);
|
48
51
|
}
|
49
52
|
};
|
50
53
|
|
package/src/skia/core/Image.ts
CHANGED
@@ -3,10 +3,12 @@ import type { DataSource } from "../types";
|
|
3
3
|
|
4
4
|
import { useRawData } from "./Data";
|
5
5
|
|
6
|
+
const imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);
|
7
|
+
|
6
8
|
/**
|
7
9
|
* Returns a Skia Image object
|
8
10
|
* */
|
9
11
|
export const useImage = (
|
10
12
|
source: DataSource | null | undefined,
|
11
13
|
onError?: (err: Error) => void
|
12
|
-
) => useRawData(source,
|
14
|
+
) => useRawData(source, imgFactory, onError);
|
package/src/skia/core/SVG.ts
CHANGED
@@ -3,7 +3,9 @@ import type { DataSource } from "../types";
|
|
3
3
|
|
4
4
|
import { useRawData } from "./Data";
|
5
5
|
|
6
|
+
const svgFactory = Skia.SVG.MakeFromData.bind(Skia.SVG);
|
7
|
+
|
6
8
|
export const useSVG = (
|
7
9
|
source: DataSource | null | undefined,
|
8
10
|
onError?: (err: Error) => void
|
9
|
-
) => useRawData(source,
|
11
|
+
) => useRawData(source, svgFactory, onError);
|
@@ -2,15 +2,13 @@ import { Skia } from "../Skia";
|
|
2
2
|
import type { DataSource } from "../types";
|
3
3
|
|
4
4
|
import { useRawData } from "./Data";
|
5
|
+
|
6
|
+
const tfFactory = Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface);
|
7
|
+
|
5
8
|
/**
|
6
9
|
* Returns a Skia Typeface object
|
7
10
|
* */
|
8
11
|
export const useTypeface = (
|
9
12
|
source: DataSource | null | undefined,
|
10
13
|
onError?: (err: Error) => void
|
11
|
-
) =>
|
12
|
-
useRawData(
|
13
|
-
source,
|
14
|
-
Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface),
|
15
|
-
onError
|
16
|
-
);
|
14
|
+
) => useRawData(source, tfFactory, onError);
|
package/src/skia/core/index.ts
CHANGED
@@ -4,9 +4,7 @@ export * from "./Typeface";
|
|
4
4
|
export * from "./Image";
|
5
5
|
export * from "./Picture";
|
6
6
|
export * from "./SVG";
|
7
|
-
export * from "./Path";
|
8
7
|
export * from "./Vector";
|
9
8
|
export * from "./Rect";
|
10
9
|
export * from "./RRect";
|
11
10
|
export * from "./Matrix";
|
12
|
-
export * from "./Paint";
|
@@ -28,19 +28,6 @@ export interface SkFont extends SkJSIInstance<"Font"> {
|
|
28
28
|
*/
|
29
29
|
getGlyphWidths(glyphs: number[], paint?: SkPaint): number[];
|
30
30
|
|
31
|
-
/** Returns the advance width of text.
|
32
|
-
The advance is the normal distance to move before drawing additional text.
|
33
|
-
Returns the bounding box of text if bounds is not nullptr. The paint
|
34
|
-
stroke settings, mask filter, or path effect may modify the bounds.
|
35
|
-
|
36
|
-
@param text character storage encoded with SkTextEncoding
|
37
|
-
@param byteLength length of character storage in bytes
|
38
|
-
@param bounds returns bounding box relative to (0, 0) if not nullptr
|
39
|
-
@param paint optional; may be nullptr
|
40
|
-
@return number of glyphs represented by text of length byteLength
|
41
|
-
*/
|
42
|
-
measureText: (text: string, paint?: SkPaint) => SkRect;
|
43
|
-
|
44
31
|
/**
|
45
32
|
* Returns the FontMetrics for this font.
|
46
33
|
*/
|
@@ -11,7 +11,6 @@ import type { SkJSIInstance } from "../JsiInstance";
|
|
11
11
|
export interface StrokeOpts {
|
12
12
|
/** The width of the stroked lines. */
|
13
13
|
width?: number;
|
14
|
-
// eslint-disable-next-line camelcase
|
15
14
|
miter_limit?: number;
|
16
15
|
/**
|
17
16
|
* if > 1, increase precision, else if (0 < resScale < 1) reduce precision to
|
package/src/skia/types/Skia.ts
CHANGED
@@ -21,7 +21,6 @@ import type { SkVertices, VertexMode } from "./Vertices/Vertices";
|
|
21
21
|
import type { DataFactory } from "./Data";
|
22
22
|
import type { SVGFactory } from "./SVG";
|
23
23
|
import type { TextBlobFactory } from "./TextBlob";
|
24
|
-
import type { FontMgrFactory } from "./FontMgr/FontMgrFactory";
|
25
24
|
import type { SurfaceFactory } from "./Surface";
|
26
25
|
import type { SkRSXform } from "./RSXform";
|
27
26
|
import type { SkPath } from "./Path/Path";
|
@@ -78,7 +77,6 @@ export interface Skia {
|
|
78
77
|
Data: DataFactory;
|
79
78
|
Image: ImageFactory;
|
80
79
|
SVG: SVGFactory;
|
81
|
-
FontMgr: FontMgrFactory;
|
82
80
|
TextBlob: TextBlobFactory;
|
83
81
|
Surface: SurfaceFactory;
|
84
82
|
}
|