@shopify/react-native-skia 1.9.1 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +1 -0
- package/lib/commonjs/dom/nodes/datatypes/Gradient.js +14 -2
- package/lib/commonjs/dom/nodes/datatypes/Gradient.js.map +1 -1
- package/lib/commonjs/index.d.ts +1 -1
- package/lib/commonjs/index.js +8 -8
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +9 -10
- package/lib/commonjs/renderer/Canvas.js +67 -59
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/CanvasOld.d.ts +11 -0
- package/lib/commonjs/renderer/CanvasOld.js +96 -0
- package/lib/commonjs/renderer/CanvasOld.js.map +1 -0
- package/lib/commonjs/sksg/Container.js +11 -6
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/HostConfig2.d.ts +19 -0
- package/lib/commonjs/sksg/HostConfig2.js +159 -0
- package/lib/commonjs/sksg/HostConfig2.js.map +1 -0
- package/lib/commonjs/sksg/Recorder/Core.js +1 -0
- package/lib/commonjs/sksg/Recorder/Core.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +2 -2
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js +0 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Box.js +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Box.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ColorFilters.js +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ColorFilters.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +4 -4
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Paint.d.ts +0 -1
- package/lib/commonjs/sksg/Recorder/commands/Paint.js +2 -14
- package/lib/commonjs/sksg/Recorder/commands/Paint.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Gradient.d.ts +1 -0
- package/lib/module/dom/nodes/datatypes/Gradient.js +12 -1
- package/lib/module/dom/nodes/datatypes/Gradient.js.map +1 -1
- package/lib/module/index.d.ts +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +9 -10
- package/lib/module/renderer/Canvas.js +65 -55
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/CanvasOld.d.ts +11 -0
- package/lib/module/renderer/CanvasOld.js +87 -0
- package/lib/module/renderer/CanvasOld.js.map +1 -0
- package/lib/module/sksg/Container.js +11 -6
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/HostConfig2.d.ts +19 -0
- package/lib/module/sksg/HostConfig2.js +152 -0
- package/lib/module/sksg/HostConfig2.js.map +1 -0
- package/lib/module/sksg/Recorder/Core.js +1 -0
- package/lib/module/sksg/Recorder/Core.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +2 -2
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/Recorder.js +0 -1
- package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Box.js +2 -2
- package/lib/module/sksg/Recorder/commands/Box.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ColorFilters.js +2 -2
- package/lib/module/sksg/Recorder/commands/ColorFilters.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.js +5 -5
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js +2 -2
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Paint.d.ts +0 -1
- package/lib/module/sksg/Recorder/commands/Paint.js +1 -12
- package/lib/module/sksg/Recorder/commands/Paint.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Shaders.js +2 -2
- package/lib/module/sksg/Recorder/commands/Shaders.js.map +1 -1
- package/lib/typescript/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +1 -0
- package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +2 -2
- package/lib/typescript/lib/commonjs/renderer/CanvasOld.d.ts +3 -0
- package/lib/typescript/lib/commonjs/sksg/HostConfig2.d.ts +44 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/commands/Paint.d.ts +0 -1
- package/lib/typescript/lib/module/dom/nodes/datatypes/Gradient.d.ts +1 -0
- package/lib/typescript/lib/module/index.d.ts +1 -1
- package/lib/typescript/lib/module/mock/index.d.ts +1 -0
- package/lib/typescript/lib/module/renderer/Canvas.d.ts +1 -3
- package/lib/typescript/lib/module/renderer/CanvasOld.d.ts +3 -0
- package/lib/typescript/lib/module/sksg/HostConfig2.d.ts +43 -0
- package/lib/typescript/lib/module/sksg/Recorder/commands/Paint.d.ts +0 -1
- package/lib/typescript/src/dom/nodes/datatypes/Gradient.d.ts +1 -0
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +9 -10
- package/lib/typescript/src/renderer/CanvasOld.d.ts +11 -0
- package/lib/typescript/src/sksg/HostConfig2.d.ts +19 -0
- package/lib/typescript/src/sksg/Recorder/commands/Paint.d.ts +0 -1
- package/package.json +1 -1
- package/src/dom/nodes/datatypes/Gradient.ts +17 -1
- package/src/index.ts +1 -1
- package/src/renderer/Canvas.tsx +80 -78
- package/src/renderer/CanvasOld.tsx +126 -0
- package/src/sksg/Container.ts +6 -2
- package/src/sksg/HostConfig2.ts +247 -0
- package/src/sksg/Recorder/Core.ts +1 -0
- package/src/sksg/Recorder/Player.ts +2 -2
- package/src/sksg/Recorder/Recorder.ts +0 -1
- package/src/sksg/Recorder/commands/Box.ts +2 -2
- package/src/sksg/Recorder/commands/ColorFilters.ts +2 -2
- package/src/sksg/Recorder/commands/Drawing.ts +5 -4
- package/src/sksg/Recorder/commands/ImageFilters.ts +2 -2
- package/src/sksg/Recorder/commands/Paint.ts +1 -17
- package/src/sksg/Recorder/commands/Shaders.ts +2 -1
- package/lib/commonjs/renderer/Canvas2.d.ts +0 -10
- package/lib/commonjs/renderer/Canvas2.js +0 -104
- package/lib/commonjs/renderer/Canvas2.js.map +0 -1
- package/lib/commonjs/renderer/Canvas2.web.d.ts +0 -3
- package/lib/commonjs/renderer/Canvas2.web.js +0 -9
- package/lib/commonjs/renderer/Canvas2.web.js.map +0 -1
- package/lib/module/renderer/Canvas2.d.ts +0 -10
- package/lib/module/renderer/Canvas2.js +0 -97
- package/lib/module/renderer/Canvas2.js.map +0 -1
- package/lib/module/renderer/Canvas2.web.d.ts +0 -3
- package/lib/module/renderer/Canvas2.web.js +0 -3
- package/lib/module/renderer/Canvas2.web.js.map +0 -1
- package/lib/typescript/lib/commonjs/renderer/Canvas2.d.ts +0 -3
- package/lib/typescript/lib/commonjs/renderer/Canvas2.web.d.ts +0 -2
- package/lib/typescript/lib/module/renderer/Canvas2.d.ts +0 -1
- package/lib/typescript/lib/module/renderer/Canvas2.web.d.ts +0 -1
- package/lib/typescript/src/renderer/Canvas2.d.ts +0 -10
- package/lib/typescript/src/renderer/Canvas2.web.d.ts +0 -3
- package/src/renderer/Canvas2.tsx +0 -128
- package/src/renderer/Canvas2.web.tsx +0 -6
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useEffect,
|
|
3
|
+
useCallback,
|
|
4
|
+
useMemo,
|
|
5
|
+
forwardRef,
|
|
6
|
+
useRef,
|
|
7
|
+
} from "react";
|
|
8
|
+
import type {
|
|
9
|
+
RefObject,
|
|
10
|
+
ReactNode,
|
|
11
|
+
MutableRefObject,
|
|
12
|
+
ForwardedRef,
|
|
13
|
+
FunctionComponent,
|
|
14
|
+
} from "react";
|
|
15
|
+
import type { LayoutChangeEvent } from "react-native";
|
|
16
|
+
|
|
17
|
+
import { SkiaDomView } from "../views";
|
|
18
|
+
import type { SkiaBaseViewProps } from "../views";
|
|
19
|
+
|
|
20
|
+
import { SkiaRoot } from "./Reconciler";
|
|
21
|
+
|
|
22
|
+
export const useCanvasRef = () => useRef<SkiaDomView>(null);
|
|
23
|
+
|
|
24
|
+
export interface CanvasOldProps extends SkiaBaseViewProps {
|
|
25
|
+
ref?: RefObject<SkiaDomView>;
|
|
26
|
+
children: ReactNode;
|
|
27
|
+
mode?: "default" | "continuous";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const useOnSizeEvent = (
|
|
31
|
+
resultValue: SkiaBaseViewProps["onSize"],
|
|
32
|
+
onLayout?: (event: LayoutChangeEvent) => void
|
|
33
|
+
) => {
|
|
34
|
+
return useCallback(
|
|
35
|
+
(event: LayoutChangeEvent) => {
|
|
36
|
+
if (onLayout) {
|
|
37
|
+
onLayout(event);
|
|
38
|
+
}
|
|
39
|
+
const { width, height } = event.nativeEvent.layout;
|
|
40
|
+
|
|
41
|
+
if (resultValue) {
|
|
42
|
+
resultValue.value = { width, height };
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
[onLayout, resultValue]
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export const CanvasOld = forwardRef<SkiaDomView, CanvasOldProps>(
|
|
50
|
+
(
|
|
51
|
+
{
|
|
52
|
+
children,
|
|
53
|
+
style,
|
|
54
|
+
debug,
|
|
55
|
+
mode = "default",
|
|
56
|
+
onSize: _onSize,
|
|
57
|
+
onLayout: _onLayout,
|
|
58
|
+
...props
|
|
59
|
+
},
|
|
60
|
+
forwardedRef
|
|
61
|
+
) => {
|
|
62
|
+
const onLayout = useOnSizeEvent(_onSize, _onLayout);
|
|
63
|
+
const innerRef = useCanvasRef();
|
|
64
|
+
const ref = useCombinedRefs(forwardedRef, innerRef);
|
|
65
|
+
const redraw = useCallback(() => {
|
|
66
|
+
innerRef.current?.redraw();
|
|
67
|
+
}, [innerRef]);
|
|
68
|
+
const getNativeId = useCallback(() => {
|
|
69
|
+
const id = innerRef.current?.nativeId ?? -1;
|
|
70
|
+
return id;
|
|
71
|
+
}, [innerRef]);
|
|
72
|
+
|
|
73
|
+
const root = useMemo(
|
|
74
|
+
() => new SkiaRoot(redraw, getNativeId),
|
|
75
|
+
[redraw, getNativeId]
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// Render effect
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
root.render(children);
|
|
81
|
+
}, [children, root, redraw]);
|
|
82
|
+
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
return () => {
|
|
85
|
+
root.unmount();
|
|
86
|
+
};
|
|
87
|
+
}, [root]);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<SkiaDomView
|
|
91
|
+
ref={ref}
|
|
92
|
+
style={style}
|
|
93
|
+
root={root.dom}
|
|
94
|
+
onLayout={onLayout}
|
|
95
|
+
debug={debug}
|
|
96
|
+
mode={mode}
|
|
97
|
+
{...props}
|
|
98
|
+
/>
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
) as FunctionComponent<CanvasOldProps & React.RefAttributes<SkiaDomView>>;
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Combines a list of refs into a single ref. This can be used to provide
|
|
105
|
+
* both a forwarded ref and an internal ref keeping the same functionality
|
|
106
|
+
* on both of the refs.
|
|
107
|
+
* @param refs Array of refs to combine
|
|
108
|
+
* @returns A single ref that can be used in a ref prop.
|
|
109
|
+
*/
|
|
110
|
+
const useCombinedRefs = <T,>(
|
|
111
|
+
...refs: Array<MutableRefObject<T> | ForwardedRef<T>>
|
|
112
|
+
) => {
|
|
113
|
+
const targetRef = React.useRef<T>(null);
|
|
114
|
+
React.useEffect(() => {
|
|
115
|
+
refs.forEach((ref) => {
|
|
116
|
+
if (ref) {
|
|
117
|
+
if (typeof ref === "function") {
|
|
118
|
+
ref(targetRef.current);
|
|
119
|
+
} else {
|
|
120
|
+
ref.current = targetRef.current;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}, [refs]);
|
|
125
|
+
return targetRef;
|
|
126
|
+
};
|
package/src/sksg/Container.ts
CHANGED
|
@@ -14,7 +14,7 @@ const drawOnscreen = (Skia: Skia, nativeId: number, recording: Recording) => {
|
|
|
14
14
|
|
|
15
15
|
const rec = Skia.PictureRecorder();
|
|
16
16
|
const canvas = rec.beginRecording();
|
|
17
|
-
//
|
|
17
|
+
//const start = performance.now();
|
|
18
18
|
|
|
19
19
|
const ctx = createDrawingContext(Skia, recording.paintPool, canvas);
|
|
20
20
|
replay(ctx, recording.commands);
|
|
@@ -87,13 +87,17 @@ class ReanimatedContainer extends Container {
|
|
|
87
87
|
commands: record.commands,
|
|
88
88
|
paintPool: record.paintPool,
|
|
89
89
|
};
|
|
90
|
+
const { nativeId, Skia, recording } = this;
|
|
90
91
|
if (animationValues.size > 0) {
|
|
91
|
-
const { nativeId, Skia, recording } = this;
|
|
92
92
|
this.mapperId = Rea.startMapper(() => {
|
|
93
93
|
"worklet";
|
|
94
94
|
drawOnscreen(Skia, nativeId, recording!);
|
|
95
95
|
}, Array.from(animationValues));
|
|
96
96
|
}
|
|
97
|
+
Rea.runOnUI(() => {
|
|
98
|
+
"worklet";
|
|
99
|
+
drawOnscreen(Skia, nativeId, recording!);
|
|
100
|
+
})();
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
103
|
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/*global NodeJS*/
|
|
2
|
+
import type { Fiber, HostConfig } from "react-reconciler";
|
|
3
|
+
import { DefaultEventPriority } from "react-reconciler/constants";
|
|
4
|
+
|
|
5
|
+
import type { NodeType } from "../dom/types";
|
|
6
|
+
import { shallowEq } from "../renderer/typeddash";
|
|
7
|
+
|
|
8
|
+
import type { Container } from "./Container";
|
|
9
|
+
import type { Node } from "./Node";
|
|
10
|
+
|
|
11
|
+
const DEBUG = false;
|
|
12
|
+
export const debug = (...args: Parameters<typeof console.log>) => {
|
|
13
|
+
if (DEBUG) {
|
|
14
|
+
console.log(...args);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type Instance = Node<unknown>;
|
|
19
|
+
|
|
20
|
+
type Props = object;
|
|
21
|
+
type TextInstance = Node<unknown>;
|
|
22
|
+
type SuspenseInstance = Instance;
|
|
23
|
+
type HydratableInstance = Instance;
|
|
24
|
+
type PublicInstance = Instance;
|
|
25
|
+
type HostContext = null;
|
|
26
|
+
type UpdatePayload = Container;
|
|
27
|
+
type ChildSet = unknown;
|
|
28
|
+
type TimeoutHandle = NodeJS.Timeout;
|
|
29
|
+
type NoTimeout = -1;
|
|
30
|
+
|
|
31
|
+
type SkiaHostConfig = HostConfig<
|
|
32
|
+
NodeType,
|
|
33
|
+
Props,
|
|
34
|
+
Container,
|
|
35
|
+
Instance,
|
|
36
|
+
TextInstance,
|
|
37
|
+
SuspenseInstance,
|
|
38
|
+
HydratableInstance,
|
|
39
|
+
PublicInstance,
|
|
40
|
+
HostContext,
|
|
41
|
+
UpdatePayload,
|
|
42
|
+
ChildSet,
|
|
43
|
+
TimeoutHandle,
|
|
44
|
+
NoTimeout
|
|
45
|
+
>;
|
|
46
|
+
|
|
47
|
+
const appendNode = (parent: Node<unknown>, child: Node<unknown>) => {
|
|
48
|
+
parent.children.push(child);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const removeNode = (parent: Node<unknown>, child: Node<unknown>) => {
|
|
52
|
+
parent.children.splice(parent.children.indexOf(child), 1);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const insertBefore = (
|
|
56
|
+
parent: Node<unknown>,
|
|
57
|
+
child: Node<unknown>,
|
|
58
|
+
before: Node<unknown>
|
|
59
|
+
) => {
|
|
60
|
+
parent.children.splice(parent.children.indexOf(before), 0, child);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const sksgHostConfig: SkiaHostConfig = {
|
|
64
|
+
/**
|
|
65
|
+
* This function is used by the reconciler in order to calculate current time for prioritising work.
|
|
66
|
+
*/
|
|
67
|
+
supportsMutation: true,
|
|
68
|
+
isPrimaryRenderer: false,
|
|
69
|
+
supportsPersistence: false,
|
|
70
|
+
supportsHydration: false,
|
|
71
|
+
//supportsMicrotask: true,
|
|
72
|
+
|
|
73
|
+
scheduleTimeout: setTimeout,
|
|
74
|
+
cancelTimeout: clearTimeout,
|
|
75
|
+
noTimeout: -1,
|
|
76
|
+
|
|
77
|
+
appendChildToContainer(container, child) {
|
|
78
|
+
debug("appendChildToContainer");
|
|
79
|
+
container.root.push(child);
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
appendChild(parent, child) {
|
|
83
|
+
debug("appendChild", parent, child);
|
|
84
|
+
appendNode(parent, child);
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
getRootHostContext: (_rootContainerInstance: Container) => {
|
|
88
|
+
debug("getRootHostContext");
|
|
89
|
+
return null;
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {
|
|
93
|
+
debug("getChildHostContext");
|
|
94
|
+
return null;
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
shouldSetTextContent(_type, _props) {
|
|
98
|
+
return false;
|
|
99
|
+
},
|
|
100
|
+
|
|
101
|
+
createTextInstance(
|
|
102
|
+
_text,
|
|
103
|
+
_rootContainerInstance,
|
|
104
|
+
_hostContext,
|
|
105
|
+
_internalInstanceHandle
|
|
106
|
+
) {
|
|
107
|
+
debug("createTextInstance");
|
|
108
|
+
// return SpanNode({}, text) as SkNode;
|
|
109
|
+
throw new Error("Text nodes are not supported yet");
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
createInstance(
|
|
113
|
+
type,
|
|
114
|
+
propsWithChildren,
|
|
115
|
+
_container,
|
|
116
|
+
_hostContext,
|
|
117
|
+
_internalInstanceHandle
|
|
118
|
+
) {
|
|
119
|
+
debug("createInstance", type);
|
|
120
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
121
|
+
const { children, ...props } = propsWithChildren as any;
|
|
122
|
+
debug("createInstance", type);
|
|
123
|
+
const instance = {
|
|
124
|
+
type,
|
|
125
|
+
props,
|
|
126
|
+
children: [],
|
|
127
|
+
};
|
|
128
|
+
return instance;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
appendInitialChild(parentInstance, child) {
|
|
132
|
+
debug("appendInitialChild");
|
|
133
|
+
appendNode(parentInstance, child);
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
finalizeInitialChildren(
|
|
137
|
+
parentInstance,
|
|
138
|
+
_type,
|
|
139
|
+
_props,
|
|
140
|
+
_rootContainerInstance,
|
|
141
|
+
_hostContext
|
|
142
|
+
) {
|
|
143
|
+
debug("finalizeInitialChildren", parentInstance);
|
|
144
|
+
return false;
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
commitMount() {
|
|
148
|
+
// if finalizeInitialChildren = true
|
|
149
|
+
debug("commitMount");
|
|
150
|
+
},
|
|
151
|
+
|
|
152
|
+
prepareForCommit(_containerInfo) {
|
|
153
|
+
debug("prepareForCommit");
|
|
154
|
+
return null;
|
|
155
|
+
},
|
|
156
|
+
|
|
157
|
+
resetAfterCommit(container) {
|
|
158
|
+
debug("resetAfterCommit");
|
|
159
|
+
container.redraw();
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
getPublicInstance(node: Instance) {
|
|
163
|
+
debug("getPublicInstance");
|
|
164
|
+
return node;
|
|
165
|
+
},
|
|
166
|
+
|
|
167
|
+
prepareUpdate: (
|
|
168
|
+
_instance,
|
|
169
|
+
type,
|
|
170
|
+
oldProps,
|
|
171
|
+
newProps,
|
|
172
|
+
rootContainerInstance,
|
|
173
|
+
_hostContext
|
|
174
|
+
) => {
|
|
175
|
+
debug("prepareUpdate");
|
|
176
|
+
const propsAreEqual = shallowEq(oldProps, newProps);
|
|
177
|
+
if (propsAreEqual) {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
debug("update ", type);
|
|
181
|
+
return rootContainerInstance;
|
|
182
|
+
},
|
|
183
|
+
|
|
184
|
+
commitUpdate(
|
|
185
|
+
instance,
|
|
186
|
+
_updatePayload,
|
|
187
|
+
type,
|
|
188
|
+
prevProps,
|
|
189
|
+
nextProps,
|
|
190
|
+
_internalHandle
|
|
191
|
+
) {
|
|
192
|
+
debug("commitUpdate: ", type);
|
|
193
|
+
if (shallowEq(prevProps, nextProps)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
197
|
+
const { children, ...props } = nextProps as any;
|
|
198
|
+
instance.props = props;
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
commitTextUpdate: (
|
|
202
|
+
_textInstance: TextInstance,
|
|
203
|
+
_oldText: string,
|
|
204
|
+
_newText: string
|
|
205
|
+
) => {
|
|
206
|
+
// textInstance.instance = newText;
|
|
207
|
+
},
|
|
208
|
+
|
|
209
|
+
clearContainer: (container) => {
|
|
210
|
+
debug("clearContainer");
|
|
211
|
+
container.root = [];
|
|
212
|
+
},
|
|
213
|
+
|
|
214
|
+
preparePortalMount: () => {
|
|
215
|
+
debug("preparePortalMount");
|
|
216
|
+
},
|
|
217
|
+
|
|
218
|
+
removeChild: (parent, child) => {
|
|
219
|
+
removeNode(parent, child);
|
|
220
|
+
},
|
|
221
|
+
|
|
222
|
+
removeChildFromContainer: (container, child) => {
|
|
223
|
+
container.root.splice(container.root.indexOf(child), 1);
|
|
224
|
+
},
|
|
225
|
+
|
|
226
|
+
insertInContainerBefore: (container, child, before) => {
|
|
227
|
+
container.root.splice(container.root.indexOf(before), 0, child);
|
|
228
|
+
},
|
|
229
|
+
|
|
230
|
+
insertBefore: (parent, child, before) => {
|
|
231
|
+
insertBefore(parent, child, before);
|
|
232
|
+
},
|
|
233
|
+
|
|
234
|
+
// see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
|
|
235
|
+
getCurrentEventPriority: () => DefaultEventPriority,
|
|
236
|
+
beforeActiveInstanceBlur: () => {},
|
|
237
|
+
afterActiveInstanceBlur: () => {},
|
|
238
|
+
detachDeletedInstance: () => {},
|
|
239
|
+
|
|
240
|
+
getInstanceFromNode: function (_node): Fiber | null | undefined {
|
|
241
|
+
return null;
|
|
242
|
+
},
|
|
243
|
+
prepareScopeUpdate: function (_scopeInstance, _instance): void {},
|
|
244
|
+
getInstanceFromScope: function (_scopeInstance): Instance | null {
|
|
245
|
+
return null;
|
|
246
|
+
},
|
|
247
|
+
};
|
|
@@ -49,7 +49,7 @@ import {
|
|
|
49
49
|
} from "./Core";
|
|
50
50
|
import type { DrawingContext } from "./DrawingContext";
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
function play(ctx: DrawingContext, command: Command) {
|
|
53
53
|
"worklet";
|
|
54
54
|
if (isGroup(command)) {
|
|
55
55
|
command.children.forEach((child) => play(ctx, child));
|
|
@@ -154,7 +154,7 @@ const play = (ctx: DrawingContext, command: Command) => {
|
|
|
154
154
|
ctx.paints.pop();
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
|
-
}
|
|
157
|
+
}
|
|
158
158
|
|
|
159
159
|
export const replay = (ctx: DrawingContext, commands: Command[]) => {
|
|
160
160
|
"worklet";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { deflate, inflate } from "../../../dom/nodes";
|
|
1
|
+
import { deflate, inflate, processColor } from "../../../dom/nodes";
|
|
2
2
|
import type { BoxProps, BoxShadowProps } from "../../../dom/types";
|
|
3
3
|
import { BlurStyle, ClipOp, isRRect } from "../../../skia/types";
|
|
4
4
|
import type { Command } from "../Core";
|
|
@@ -31,7 +31,7 @@ export const drawBox = (ctx: DrawingContext, command: BoxCommand) => {
|
|
|
31
31
|
.map((shadow) => {
|
|
32
32
|
const { color = "black", blur, spread = 0, dx = 0, dy = 0 } = shadow;
|
|
33
33
|
const lPaint = Skia.Paint();
|
|
34
|
-
lPaint.setColor(Skia
|
|
34
|
+
lPaint.setColor(processColor(Skia, color));
|
|
35
35
|
lPaint.setAlphaf(paint.getAlphaf() * opacity);
|
|
36
36
|
lPaint.setMaskFilter(
|
|
37
37
|
Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { enumKey } from "../../../dom/nodes";
|
|
1
|
+
import { enumKey, processColor } from "../../../dom/nodes";
|
|
2
2
|
import type {
|
|
3
3
|
BlendColorFilterProps,
|
|
4
4
|
LerpColorFilterProps,
|
|
@@ -59,7 +59,7 @@ export const pushColorFilter = (
|
|
|
59
59
|
if (isColorFilter(command, NodeType.BlendColorFilter)) {
|
|
60
60
|
const { props } = command;
|
|
61
61
|
const { mode } = props;
|
|
62
|
-
const color = ctx.Skia
|
|
62
|
+
const color = processColor(ctx.Skia, props.color);
|
|
63
63
|
cf = ctx.Skia.ColorFilter.MakeBlend(color, BlendMode[enumKey(mode)]);
|
|
64
64
|
} else if (isColorFilter(command, NodeType.MatrixColorFilter)) {
|
|
65
65
|
const { matrix } = command.props;
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
inflate,
|
|
6
6
|
NodeType,
|
|
7
7
|
processCircle,
|
|
8
|
+
processColor,
|
|
8
9
|
processPath,
|
|
9
10
|
processRect,
|
|
10
11
|
processRRect,
|
|
@@ -87,7 +88,7 @@ export const drawBox = (
|
|
|
87
88
|
.map((shadow) => {
|
|
88
89
|
const { color = "black", blur, spread = 0, dx = 0, dy = 0 } = shadow;
|
|
89
90
|
const lPaint = Skia.Paint();
|
|
90
|
-
lPaint.setColor(Skia
|
|
91
|
+
lPaint.setColor(processColor(Skia, color));
|
|
91
92
|
lPaint.setAlphaf(paint.getAlphaf() * opacity);
|
|
92
93
|
lPaint.setMaskFilter(
|
|
93
94
|
Skia.MaskFilter.MakeBlur(BlurStyle.Normal, blur, true)
|
|
@@ -105,7 +106,7 @@ export const drawBox = (
|
|
|
105
106
|
canvas.save();
|
|
106
107
|
canvas.clipRRect(box, ClipOp.Intersect, false);
|
|
107
108
|
const lPaint = Skia.Paint();
|
|
108
|
-
lPaint.setColor(Skia
|
|
109
|
+
lPaint.setColor(processColor(Skia, color));
|
|
109
110
|
lPaint.setAlphaf(paint.getAlphaf() * opacity);
|
|
110
111
|
|
|
111
112
|
lPaint.setMaskFilter(
|
|
@@ -170,7 +171,7 @@ export const drawVertices = (ctx: DrawingContext, props: VerticesProps) => {
|
|
|
170
171
|
vertexMode,
|
|
171
172
|
props.vertices,
|
|
172
173
|
textures,
|
|
173
|
-
colors ? colors.map((c) => ctx.Skia
|
|
174
|
+
colors ? colors.map((c) => processColor(ctx.Skia, c)) : undefined,
|
|
174
175
|
indices
|
|
175
176
|
);
|
|
176
177
|
const defaultBlendMode = colors ? BlendMode.DstOver : BlendMode.SrcOver;
|
|
@@ -258,7 +259,7 @@ export const drawPatch = (ctx: DrawingContext, props: PatchProps) => {
|
|
|
258
259
|
patch[0].c1,
|
|
259
260
|
];
|
|
260
261
|
const colors = props.colors
|
|
261
|
-
? props.colors.map((c) => ctx.Skia
|
|
262
|
+
? props.colors.map((c) => processColor(ctx.Skia, c))
|
|
262
263
|
: undefined;
|
|
263
264
|
ctx.canvas.drawPatch(points, colors, texture, mode, ctx.paint);
|
|
264
265
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { enumKey, processRadius } from "../../../dom/nodes";
|
|
1
|
+
import { enumKey, processColor, processRadius } from "../../../dom/nodes";
|
|
2
2
|
import type {
|
|
3
3
|
BlendImageFilterProps,
|
|
4
4
|
BlurImageFilterProps,
|
|
@@ -113,7 +113,7 @@ const declareDropShadowImageFilter = (
|
|
|
113
113
|
) => {
|
|
114
114
|
"worklet";
|
|
115
115
|
const { dx, dy, blur, shadowOnly, color: cl, inner } = props;
|
|
116
|
-
const color = ctx.Skia
|
|
116
|
+
const color = processColor(ctx.Skia, cl);
|
|
117
117
|
let factory;
|
|
118
118
|
if (inner) {
|
|
119
119
|
factory = MakeInnerShadow.bind(null, ctx.Skia, shadowOnly);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { enumKey } from "../../../dom/nodes";
|
|
1
|
+
import { enumKey, processColor } from "../../../dom/nodes";
|
|
2
2
|
import type { PaintProps } from "../../../dom/types";
|
|
3
3
|
import {
|
|
4
4
|
BlendMode,
|
|
@@ -8,22 +8,6 @@ import {
|
|
|
8
8
|
} from "../../../skia/types";
|
|
9
9
|
import type { SkPaint, Skia } from "../../../skia/types";
|
|
10
10
|
|
|
11
|
-
export const processColor = (
|
|
12
|
-
Skia: Skia,
|
|
13
|
-
color: number | string | Float32Array | number[]
|
|
14
|
-
) => {
|
|
15
|
-
"worklet";
|
|
16
|
-
if (typeof color === "string" || typeof color === "number") {
|
|
17
|
-
return Skia.Color(color);
|
|
18
|
-
} else if (Array.isArray(color) || color instanceof Float32Array) {
|
|
19
|
-
return color instanceof Float32Array ? color : new Float32Array(color);
|
|
20
|
-
} else {
|
|
21
|
-
throw new Error(
|
|
22
|
-
`Invalid color type: ${typeof color}. Expected number, string, or array.`
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
11
|
export const setPaintProperties = (
|
|
28
12
|
Skia: Skia,
|
|
29
13
|
paint: SkPaint,
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
enumKey,
|
|
3
3
|
fitRects,
|
|
4
4
|
getRect,
|
|
5
|
+
processColor,
|
|
5
6
|
processGradientProps,
|
|
6
7
|
processTransformProps,
|
|
7
8
|
rect2rect,
|
|
@@ -49,7 +50,7 @@ const declareShader = (ctx: DrawingContext, props: ShaderProps) => {
|
|
|
49
50
|
const declareColorShader = (ctx: DrawingContext, props: ColorProps) => {
|
|
50
51
|
"worklet";
|
|
51
52
|
const { color } = props;
|
|
52
|
-
const shader = ctx.Skia.Shader.MakeColor(ctx.Skia
|
|
53
|
+
const shader = ctx.Skia.Shader.MakeColor(processColor(ctx.Skia, color));
|
|
53
54
|
ctx.shaders.push(shader);
|
|
54
55
|
};
|
|
55
56
|
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { ViewProps } from "react-native";
|
|
2
|
-
import type { SharedValue } from "react-native-reanimated";
|
|
3
|
-
import type { SkSize } from "../skia/types";
|
|
4
|
-
export interface Canvas2Props extends ViewProps {
|
|
5
|
-
debug?: boolean;
|
|
6
|
-
opaque?: boolean;
|
|
7
|
-
onSize?: SharedValue<SkSize>;
|
|
8
|
-
mode?: "continuous" | "default";
|
|
9
|
-
}
|
|
10
|
-
export declare const Canvas2: import("react").ForwardRefExoticComponent<Canvas2Props & import("react").RefAttributes<unknown>>;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Canvas2 = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _SkiaViewNativeId = require("../views/SkiaViewNativeId");
|
|
9
|
-
var _SkiaPictureViewNativeComponent = _interopRequireDefault(require("../specs/SkiaPictureViewNativeComponent"));
|
|
10
|
-
var _Reconciler = require("../sksg/Reconciler");
|
|
11
|
-
var _skia = require("../skia");
|
|
12
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
14
|
-
const NativeSkiaPictureView = _SkiaPictureViewNativeComponent.default;
|
|
15
|
-
|
|
16
|
-
// TODO: no need to go through the JS thread for this
|
|
17
|
-
const useOnSizeEvent = (resultValue, onLayout) => {
|
|
18
|
-
return (0, _react.useCallback)(event => {
|
|
19
|
-
if (onLayout) {
|
|
20
|
-
onLayout(event);
|
|
21
|
-
}
|
|
22
|
-
const {
|
|
23
|
-
width,
|
|
24
|
-
height
|
|
25
|
-
} = event.nativeEvent.layout;
|
|
26
|
-
if (resultValue) {
|
|
27
|
-
resultValue.value = {
|
|
28
|
-
width,
|
|
29
|
-
height
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
}, [onLayout, resultValue]);
|
|
33
|
-
};
|
|
34
|
-
const Canvas2 = exports.Canvas2 = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
35
|
-
mode,
|
|
36
|
-
debug,
|
|
37
|
-
opaque,
|
|
38
|
-
children,
|
|
39
|
-
onSize,
|
|
40
|
-
onLayout: _onLayout,
|
|
41
|
-
...viewProps
|
|
42
|
-
}, ref) => {
|
|
43
|
-
const rafId = (0, _react.useRef)(null);
|
|
44
|
-
const onLayout = useOnSizeEvent(onSize, _onLayout);
|
|
45
|
-
// Native ID
|
|
46
|
-
const nativeId = (0, _react.useMemo)(() => {
|
|
47
|
-
return _SkiaViewNativeId.SkiaViewNativeId.current++;
|
|
48
|
-
}, []);
|
|
49
|
-
|
|
50
|
-
// Root
|
|
51
|
-
const root = (0, _react.useMemo)(() => new _Reconciler.SkiaSGRoot(_skia.Skia, nativeId), [nativeId]);
|
|
52
|
-
|
|
53
|
-
// Render effects
|
|
54
|
-
(0, _react.useEffect)(() => {
|
|
55
|
-
root.render(children);
|
|
56
|
-
}, [children, root]);
|
|
57
|
-
(0, _react.useEffect)(() => {
|
|
58
|
-
return () => {
|
|
59
|
-
root.unmount();
|
|
60
|
-
};
|
|
61
|
-
}, [root]);
|
|
62
|
-
const requestRedraw = (0, _react.useCallback)(() => {
|
|
63
|
-
rafId.current = requestAnimationFrame(() => {
|
|
64
|
-
root.render(children);
|
|
65
|
-
if (mode === "continuous") {
|
|
66
|
-
requestRedraw();
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}, [children, mode, root]);
|
|
70
|
-
(0, _react.useEffect)(() => {
|
|
71
|
-
if (mode === "continuous") {
|
|
72
|
-
requestRedraw();
|
|
73
|
-
}
|
|
74
|
-
return () => {
|
|
75
|
-
if (rafId.current !== null) {
|
|
76
|
-
cancelAnimationFrame(rafId.current);
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}, [mode, requestRedraw]);
|
|
80
|
-
|
|
81
|
-
// Component methods
|
|
82
|
-
(0, _react.useImperativeHandle)(ref, () => ({
|
|
83
|
-
makeImageSnapshot: rect => {
|
|
84
|
-
return SkiaViewApi.makeImageSnapshot(nativeId, rect);
|
|
85
|
-
},
|
|
86
|
-
makeImageSnapshotAsync: rect => {
|
|
87
|
-
return SkiaViewApi.makeImageSnapshotAsync(nativeId, rect);
|
|
88
|
-
},
|
|
89
|
-
redraw: () => {
|
|
90
|
-
SkiaViewApi.requestRedraw(nativeId);
|
|
91
|
-
},
|
|
92
|
-
getNativeId: () => {
|
|
93
|
-
return nativeId;
|
|
94
|
-
}
|
|
95
|
-
}));
|
|
96
|
-
return /*#__PURE__*/React.createElement(NativeSkiaPictureView, _extends({
|
|
97
|
-
collapsable: false,
|
|
98
|
-
nativeID: `${nativeId}`,
|
|
99
|
-
debug: debug,
|
|
100
|
-
opaque: opaque,
|
|
101
|
-
onLayout: onLayout
|
|
102
|
-
}, viewProps));
|
|
103
|
-
});
|
|
104
|
-
//# sourceMappingURL=Canvas2.js.map
|