@shopify/react-native-skia 0.1.145 → 0.1.146
Sign up to get free protection for your applications and to get access to all the features.
- package/cpp/api/JsiSkContourMeasure.h +4 -4
- package/cpp/api/JsiSkDataFactory.h +3 -3
- package/cpp/api/JsiSkFont.h +1 -1
- package/cpp/api/JsiSkPathFactory.h +1 -1
- package/cpp/api/JsiSkPictureFactory.h +1 -1
- package/cpp/api/JsiSkRuntimeEffect.h +6 -6
- package/cpp/api/JsiSkRuntimeEffectFactory.h +1 -1
- package/cpp/jsi/JsiSimpleValueWrapper.h +27 -27
- package/cpp/jsi/JsiValueWrapper.h +127 -0
- package/cpp/rnskia/RNSkDrawView.cpp +41 -17
- package/cpp/rnskia/RNSkDrawView.h +17 -19
- package/cpp/rnskia/RNSkJsiViewApi.h +180 -166
- package/cpp/rnskia/values/RNSkComputedValue.h +11 -11
- package/cpp/rnskia/values/RNSkReadonlyValue.h +19 -19
- package/cpp/rnskia/values/RNSkValue.h +13 -13
- package/cpp/utils/RNSkLog.h +4 -4
- package/lib/commonjs/renderer/HostConfig.js +17 -1
- package/lib/commonjs/renderer/HostConfig.js.map +1 -1
- package/lib/commonjs/views/SkiaView.js +11 -27
- package/lib/commonjs/views/SkiaView.js.map +1 -1
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/HostConfig.js +17 -1
- package/lib/module/renderer/HostConfig.js.map +1 -1
- package/lib/module/views/SkiaView.js +11 -26
- package/lib/module/views/SkiaView.js.map +1 -1
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/views/SkiaView.d.ts +1 -11
- package/lib/typescript/src/views/types.d.ts +5 -5
- package/package.json +1 -1
- package/src/renderer/HostConfig.ts +11 -1
- package/src/views/SkiaView.tsx +17 -28
- package/src/views/types.ts +7 -6
@@ -26,22 +26,22 @@ public:
|
|
26
26
|
update(runtime, arguments[0]);
|
27
27
|
}
|
28
28
|
}
|
29
|
-
|
29
|
+
|
30
30
|
~RNSkValue() {
|
31
31
|
unsubscribe();
|
32
32
|
}
|
33
|
-
|
33
|
+
|
34
34
|
JSI_PROPERTY_SET(current) {
|
35
35
|
// When someone else is setting the value we need to stop any ongoing
|
36
36
|
// animations
|
37
37
|
unsubscribe();
|
38
38
|
update(runtime, value);
|
39
39
|
}
|
40
|
-
|
40
|
+
|
41
41
|
JSI_PROPERTY_SET(animation) {
|
42
42
|
// Cancel existing animation
|
43
43
|
unsubscribe();
|
44
|
-
|
44
|
+
|
45
45
|
// Verify input
|
46
46
|
if(value.isObject() && value.asObject(runtime).isHostObject<RNSkAnimation>(runtime)) {
|
47
47
|
auto animation = value.asObject(runtime).getHostObject<RNSkAnimation>(runtime);
|
@@ -52,24 +52,24 @@ public:
|
|
52
52
|
} else if(value.isUndefined() || value.isNull()) {
|
53
53
|
// Do nothing - we've already unsubscribed
|
54
54
|
} else {
|
55
|
-
jsi::
|
55
|
+
throw jsi::JSError(runtime, "Animation expected.");
|
56
56
|
}
|
57
57
|
}
|
58
|
-
|
58
|
+
|
59
59
|
JSI_PROPERTY_GET(animation) {
|
60
60
|
if(_animation != nullptr) {
|
61
61
|
return jsi::Object::createFromHostObject(runtime, _animation);
|
62
62
|
}
|
63
63
|
return jsi::Value::undefined();
|
64
64
|
}
|
65
|
-
|
65
|
+
|
66
66
|
JSI_EXPORT_PROPERTY_SETTERS(JSI_EXPORT_PROP_SET(RNSkValue, current),
|
67
67
|
JSI_EXPORT_PROP_SET(RNSkValue, animation))
|
68
|
-
|
68
|
+
|
69
69
|
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(RNSkReadonlyValue, __typename__),
|
70
70
|
JSI_EXPORT_PROP_GET(RNSkValue, current),
|
71
71
|
JSI_EXPORT_PROP_GET(RNSkValue, animation))
|
72
|
-
|
72
|
+
|
73
73
|
JSI_EXPORT_FUNCTIONS(
|
74
74
|
JSI_EXPORT_FUNC(RNSkValue, addListener),
|
75
75
|
JSI_EXPORT_FUNC(RNSkReadonlyValue, __invalidate)
|
@@ -91,26 +91,26 @@ private:
|
|
91
91
|
_animation->startClock();
|
92
92
|
}
|
93
93
|
}
|
94
|
-
|
94
|
+
|
95
95
|
void animationDidUpdate(jsi::Runtime& runtime) {
|
96
96
|
if(_animation != nullptr) {
|
97
97
|
// Update ourselves from the current animation value
|
98
98
|
update(runtime, _animation->get_current(runtime));
|
99
99
|
}
|
100
100
|
}
|
101
|
-
|
101
|
+
|
102
102
|
void unsubscribe() {
|
103
103
|
if(_unsubscribe != nullptr) {
|
104
104
|
(*_unsubscribe)();
|
105
105
|
_unsubscribe = nullptr;
|
106
106
|
}
|
107
|
-
|
107
|
+
|
108
108
|
if(_animation != nullptr) {
|
109
109
|
_animation->stopClock();
|
110
110
|
_animation = nullptr;
|
111
111
|
}
|
112
112
|
}
|
113
|
-
|
113
|
+
|
114
114
|
std::shared_ptr<RNSkAnimation> _animation;
|
115
115
|
std::shared_ptr<std::function<void()>> _unsubscribe;
|
116
116
|
};
|
package/cpp/utils/RNSkLog.h
CHANGED
@@ -54,24 +54,24 @@ public:
|
|
54
54
|
#endif
|
55
55
|
va_end(args);
|
56
56
|
}
|
57
|
-
|
57
|
+
|
58
58
|
static void logToJavascriptConsole(jsi::Runtime& runtime, const std::string& message) {
|
59
59
|
auto console = RNSkLogger::getJavascriptConsole(runtime).asObject(runtime);
|
60
60
|
auto log = console.getPropertyAsFunction(runtime, "log");
|
61
61
|
log.call(runtime, jsi::String::createFromUtf8(runtime, message));
|
62
62
|
}
|
63
|
-
|
63
|
+
|
64
64
|
static void warnToJavascriptConsole(jsi::Runtime& runtime, const std::string& message) {
|
65
65
|
auto console = RNSkLogger::getJavascriptConsole(runtime).asObject(runtime);
|
66
66
|
auto warn = console.getPropertyAsFunction(runtime, "warn");
|
67
67
|
warn.call(runtime, jsi::String::createFromUtf8(runtime, message));
|
68
68
|
}
|
69
|
-
|
69
|
+
|
70
70
|
private:
|
71
71
|
static jsi::Value getJavascriptConsole(jsi::Runtime& runtime) {
|
72
72
|
auto console = runtime.global().getProperty(runtime, "console");
|
73
73
|
if(console.isUndefined() || console.isNull()) {
|
74
|
-
jsi::
|
74
|
+
throw jsi::JSError(runtime, "Could not find console object.");
|
75
75
|
return jsi::Value::undefined();
|
76
76
|
}
|
77
77
|
return console;
|
@@ -221,7 +221,23 @@ const skHostConfig = {
|
|
221
221
|
}
|
222
222
|
|
223
223
|
bustBranchMemoization(instance);
|
224
|
-
|
224
|
+
|
225
|
+
if (instance instanceof _nodes.DrawingNode) {
|
226
|
+
const {
|
227
|
+
onDraw,
|
228
|
+
skipProcessing,
|
229
|
+
...props
|
230
|
+
} = nextProps;
|
231
|
+
instance.props = props;
|
232
|
+
} else if (instance instanceof _nodes.DeclarationNode) {
|
233
|
+
const {
|
234
|
+
onDeclare,
|
235
|
+
...props
|
236
|
+
} = nextProps;
|
237
|
+
instance.props = props;
|
238
|
+
} else {
|
239
|
+
throw new Error("Unsupported instance commitUpdate " + instance.constructor.name);
|
240
|
+
}
|
225
241
|
},
|
226
242
|
|
227
243
|
commitTextUpdate: (_textInstance, _oldText, _newText) => {// textInstance.instance = newText;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["HostConfig.ts"],"names":["DEBUG","debug","console","log","allChildrenAreMemoized","node","memoizable","child","children","memoized","bustBranchMemoization","parent","ancestor","bustBranchMemoizable","appendNode","push","removeNode","index","indexOf","splice","depMgr","unsubscribeNode","c","insertBefore","before","beforeIndex","createNode","container","type","props","NodeType","Drawing","onDraw","skipProcessing","p1","DrawingNode","Declaration","onDeclare","p2","DeclarationNode","skHostConfig","now","Date","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","finalizeContainerChildren","resetAfterCommit","redraw","getPublicInstance","prepareUpdate","instance","oldProps","newProps","propsAreEqual","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore"],"mappings":";;;;;;;AAIA;;AACA;;AALA;AAOA,MAAMA,KAAK,GAAG,KAAd;;AACO,MAAMC,KAAK,GAAG,YAA6C;AAChE,MAAID,KAAJ,EAAW;AACTE,IAAAA,OAAO,CAACC,GAAR,CAAY,YAAZ;AACD;AACF,CAJM;;;;AA+CP,MAAMC,sBAAsB,GAAIC,IAAD,IAAoB;AACjD,MAAI,CAACA,IAAI,CAACC,UAAV,EAAsB;AACpB,WAAO,KAAP;AACD;;AACD,OAAK,MAAMC,KAAX,IAAoBF,IAAI,CAACG,QAAzB,EAAmC;AACjC,QAAI,CAACD,KAAK,CAACE,QAAX,EAAqB;AACnB,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAAP;AACD,CAVD;;AAYA,MAAMC,qBAAqB,GAAIC,MAAD,IAAkB;AAC9C,MAAIA,MAAM,CAACL,UAAX,EAAuB;AACrB,QAAIM,QAA0B,GAAGD,MAAjC;;AACA,WAAOC,QAAP,EAAiB;AACfA,MAAAA,QAAQ,CAACH,QAAT,GAAoB,IAApB;AACAG,MAAAA,QAAQ,GAAGA,QAAQ,CAACD,MAApB;AACD;AACF;AACF,CARD;;AAUA,MAAME,oBAAoB,GAAIF,MAAD,IAAkB;AAC7C,MAAIA,MAAM,CAACL,UAAX,EAAuB;AACrB,QAAIM,QAA0B,GAAGD,MAAjC;;AACA,WAAOC,QAAP,EAAiB;AACfA,MAAAA,QAAQ,CAACN,UAAT,GAAsB,KAAtB;AACAM,MAAAA,QAAQ,GAAGA,QAAQ,CAACD,MAApB;AACD;AACF;AACF,CARD;;AAUA,MAAMG,UAAU,GAAG,CAACH,MAAD,EAAeJ,KAAf,KAA+B;AAChDA,EAAAA,KAAK,CAACI,MAAN,GAAeA,MAAf;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F,sBAAsB,CAAC0E,QAAD,CAA7D,EAAyE;AACvE;AACD;;AACDpE,IAAAA,qBAAqB,CAACoE,QAAD,CAArB;AACAA,IAAAA,QAAQ,CAACjD,KAAT,GAAiBwD,SAAjB;AACD,GArIyC;;AAuI1CE,EAAAA,gBAAgB,EAAE,CAChBC,aADgB,EAEhBC,QAFgB,EAGhBC,QAHgB,KAIb,CACH;AACD,GA7IyC;AA+I1CC,EAAAA,cAAc,EAAGhE,SAAD,IAAe;AAC7B1B,IAAAA,KAAK,CAAC,gBAAD,CAAL;AACA0B,IAAAA,SAAS,CAACnB,QAAV,CAAmBW,MAAnB,CAA0B,CAA1B;AACD,GAlJyC;AAoJ1CyE,EAAAA,kBAAkB,EAAE,MAAM;AACxB3F,IAAAA,KAAK,CAAC,oBAAD,CAAL;AACD,GAtJyC;AAwJ1C4F,EAAAA,WAAW,EAAE,CAAClF,MAAD,EAASJ,KAAT,KAAmB;AAC9BS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GA1JyC;AA4J1CuF,EAAAA,wBAAwB,EAAE,CAACnF,MAAD,EAASJ,KAAT,KAAmB;AAC3CS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GA9JyC;AAgK1CwF,EAAAA,uBAAuB,EAAE,CAACpF,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AAClDD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD,GAlKyC;AAoK1CD,EAAAA,YAAY,EAAE,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AACvCD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD;AAtKyC,CAArC","sourcesContent":["/*global NodeJS*/\nimport type { HostConfig } from \"react-reconciler\";\n\nimport type { Node, Container, DeclarationProps, DrawingProps } from \"./nodes\";\nimport { DeclarationNode, DrawingNode, NodeType } from \"./nodes\";\nimport { exhaustiveCheck, shallowEq } from \"./typeddash\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDeclaration: DeclarationProps<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDrawing: DrawingProps<any>;\n }\n }\n}\n\ntype Instance = Node;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Props = any;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = true;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\nconst allChildrenAreMemoized = (node: Instance) => {\n if (!node.memoizable) {\n return false;\n }\n for (const child of node.children) {\n if (!child.memoized) {\n return false;\n }\n }\n return true;\n};\n\nconst bustBranchMemoization = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoized = null;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst bustBranchMemoizable = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoizable = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst appendNode = (parent: Node, child: Node) => {\n child.parent = parent;\n bustBranchMemoization(parent);\n if (!child.memoizable) {\n bustBranchMemoizable(parent);\n }\n if (!parent.memoizable) {\n child.memoizable = false;\n }\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node, child: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n parent.children.splice(index, 1);\n child.depMgr.unsubscribeNode(child);\n // unsubscribe to all children as well\n for (const c of child.children) {\n removeNode(child, c);\n }\n};\n\nconst insertBefore = (parent: Node, child: Node, before: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n if (index !== -1) {\n parent.children.splice(index, 1);\n }\n const beforeIndex = parent.children.indexOf(before);\n parent.children.splice(beforeIndex, 0, child);\n};\n\nconst createNode = (container: Container, type: NodeType, props: Props) => {\n switch (type) {\n case NodeType.Drawing:\n const { onDraw, skipProcessing, ...p1 } = props;\n return new DrawingNode(container.depMgr, onDraw, skipProcessing, p1);\n case NodeType.Declaration:\n const { onDeclare, ...p2 } = props;\n return new DeclarationNode(container.depMgr, onDeclare, p2);\n default:\n // TODO: here we need to throw a nice error message\n // This is the error that will show up when the user uses nodes not supported by Skia (View, Audio, etc)\n return exhaustiveCheck(type);\n }\n};\n\nexport const skHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n now: Date.now,\n\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\", container, child);\n appendNode(container, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Node) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n props,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n return createNode(container, type, props) as Node;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n finalizeContainerChildren: () => {\n debug(\"finalizeContainerChildren\");\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n instance,\n type,\n oldProps,\n newProps,\n _rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual && !instance.memoizable) {\n return null;\n }\n debug(\"update \", type);\n return true;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps) && allChildrenAreMemoized(instance)) {\n return;\n }\n bustBranchMemoization(instance);\n instance.props = nextProps;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.children.splice(0);\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (parent, child) => {\n removeNode(parent, child);\n },\n\n insertInContainerBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n};\n"]}
|
1
|
+
{"version":3,"sources":["HostConfig.ts"],"names":["DEBUG","debug","console","log","allChildrenAreMemoized","node","memoizable","child","children","memoized","bustBranchMemoization","parent","ancestor","bustBranchMemoizable","appendNode","push","removeNode","index","indexOf","splice","depMgr","unsubscribeNode","c","insertBefore","before","beforeIndex","createNode","container","type","props","NodeType","Drawing","onDraw","skipProcessing","p1","DrawingNode","Declaration","onDeclare","p2","DeclarationNode","skHostConfig","now","Date","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","finalizeContainerChildren","resetAfterCommit","redraw","getPublicInstance","prepareUpdate","instance","oldProps","newProps","propsAreEqual","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","constructor","name","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore"],"mappings":";;;;;;;AAIA;;AACA;;AALA;AAOA,MAAMA,KAAK,GAAG,KAAd;;AACO,MAAMC,KAAK,GAAG,YAA6C;AAChE,MAAID,KAAJ,EAAW;AACTE,IAAAA,OAAO,CAACC,GAAR,CAAY,YAAZ;AACD;AACF,CAJM;;;;AA+CP,MAAMC,sBAAsB,GAAIC,IAAD,IAAoB;AACjD,MAAI,CAACA,IAAI,CAACC,UAAV,EAAsB;AACpB,WAAO,KAAP;AACD;;AACD,OAAK,MAAMC,KAAX,IAAoBF,IAAI,CAACG,QAAzB,EAAmC;AACjC,QAAI,CAACD,KAAK,CAACE,QAAX,EAAqB;AACnB,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAAP;AACD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E,CAChBC,aADgB,EAEhBC,QAFgB,EAGhBC,QAHgB,KAIb,CACH;AACD,GAvJyC;AAyJ1CC,EAAAA,cAAc,EAAGlE,SAAD,IAAe;AAC7B1B,IAAAA,KAAK,CAAC,gBAAD,CAAL;AACA0B,IAAAA,SAAS,CAACnB,QAAV,CAAmBW,MAAnB,CAA0B,CAA1B;AACD,GA5JyC;AA8J1C2E,EAAAA,kBAAkB,EAAE,MAAM;AACxB7F,IAAAA,KAAK,CAAC,oBAAD,CAAL;AACD,GAhKyC;AAkK1C8F,EAAAA,WAAW,EAAE,CAACpF,MAAD,EAASJ,KAAT,KAAmB;AAC9BS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GApKyC;AAsK1CyF,EAAAA,wBAAwB,EAAE,CAACrF,MAAD,EAASJ,KAAT,KAAmB;AAC3CS,IAAAA,UAAU,CAACL,MAAD,EAASJ,KAAT,CAAV;AACD,GAxKyC;AA0K1C0F,EAAAA,uBAAuB,EAAE,CAACtF,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AAClDD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD,GA5KyC;AA8K1CD,EAAAA,YAAY,EAAE,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,KAA2B;AACvCD,IAAAA,YAAY,CAACZ,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD;AAhLyC,CAArC","sourcesContent":["/*global NodeJS*/\nimport type { HostConfig } from \"react-reconciler\";\n\nimport type { Node, Container, DeclarationProps, DrawingProps } from \"./nodes\";\nimport { DeclarationNode, DrawingNode, NodeType } from \"./nodes\";\nimport { exhaustiveCheck, shallowEq } from \"./typeddash\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDeclaration: DeclarationProps<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDrawing: DrawingProps<any>;\n }\n }\n}\n\ntype Instance = Node;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Props = any;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = true;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\nconst allChildrenAreMemoized = (node: Instance) => {\n if (!node.memoizable) {\n return false;\n }\n for (const child of node.children) {\n if (!child.memoized) {\n return false;\n }\n }\n return true;\n};\n\nconst bustBranchMemoization = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoized = null;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst bustBranchMemoizable = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoizable = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst appendNode = (parent: Node, child: Node) => {\n child.parent = parent;\n bustBranchMemoization(parent);\n if (!child.memoizable) {\n bustBranchMemoizable(parent);\n }\n if (!parent.memoizable) {\n child.memoizable = false;\n }\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node, child: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n parent.children.splice(index, 1);\n child.depMgr.unsubscribeNode(child);\n // unsubscribe to all children as well\n for (const c of child.children) {\n removeNode(child, c);\n }\n};\n\nconst insertBefore = (parent: Node, child: Node, before: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n if (index !== -1) {\n parent.children.splice(index, 1);\n }\n const beforeIndex = parent.children.indexOf(before);\n parent.children.splice(beforeIndex, 0, child);\n};\n\nconst createNode = (container: Container, type: NodeType, props: Props) => {\n switch (type) {\n case NodeType.Drawing:\n const { onDraw, skipProcessing, ...p1 } = props;\n return new DrawingNode(container.depMgr, onDraw, skipProcessing, p1);\n case NodeType.Declaration:\n const { onDeclare, ...p2 } = props;\n return new DeclarationNode(container.depMgr, onDeclare, p2);\n default:\n // TODO: here we need to throw a nice error message\n // This is the error that will show up when the user uses nodes not supported by Skia (View, Audio, etc)\n return exhaustiveCheck(type);\n }\n};\n\nexport const skHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n now: Date.now,\n\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\", container, child);\n appendNode(container, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Node) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n props,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n return createNode(container, type, props) as Node;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n finalizeContainerChildren: () => {\n debug(\"finalizeContainerChildren\");\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n instance,\n type,\n oldProps,\n newProps,\n _rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual && !instance.memoizable) {\n return null;\n }\n debug(\"update \", type);\n return true;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps) && allChildrenAreMemoized(instance)) {\n return;\n }\n bustBranchMemoization(instance);\n if (instance instanceof DrawingNode) {\n const { onDraw, skipProcessing, ...props } = nextProps;\n instance.props = props;\n } else if (instance instanceof DeclarationNode) {\n const { onDeclare, ...props } = nextProps;\n instance.props = props;\n } else {\n throw new Error(\n \"Unsupported instance commitUpdate \" + instance.constructor.name\n );\n }\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.children.splice(0);\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (parent, child) => {\n removeNode(parent, child);\n },\n\n insertInContainerBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n};\n"]}
|
@@ -32,9 +32,9 @@ class SkiaView extends _react.default.Component {
|
|
32
32
|
} = props;
|
33
33
|
|
34
34
|
if (onDraw) {
|
35
|
-
|
35
|
+
assertSkiaViewApi();
|
36
36
|
|
37
|
-
_api.SkiaViewApi.
|
37
|
+
_api.SkiaViewApi.setJsiProperty(this._nativeId, "drawCallback", onDraw);
|
38
38
|
}
|
39
39
|
}
|
40
40
|
|
@@ -48,9 +48,9 @@ class SkiaView extends _react.default.Component {
|
|
48
48
|
} = this.props;
|
49
49
|
|
50
50
|
if (onDraw !== prevProps.onDraw) {
|
51
|
-
|
51
|
+
assertSkiaViewApi();
|
52
52
|
|
53
|
-
_api.SkiaViewApi.
|
53
|
+
_api.SkiaViewApi.setJsiProperty(this._nativeId, "drawCallback", onDraw);
|
54
54
|
}
|
55
55
|
}
|
56
56
|
/**
|
@@ -61,7 +61,7 @@ class SkiaView extends _react.default.Component {
|
|
61
61
|
|
62
62
|
|
63
63
|
makeImageSnapshot(rect) {
|
64
|
-
|
64
|
+
assertSkiaViewApi();
|
65
65
|
return _api.SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
|
66
66
|
}
|
67
67
|
/**
|
@@ -70,25 +70,9 @@ class SkiaView extends _react.default.Component {
|
|
70
70
|
|
71
71
|
|
72
72
|
redraw() {
|
73
|
-
|
73
|
+
assertSkiaViewApi();
|
74
74
|
|
75
|
-
_api.SkiaViewApi.
|
76
|
-
}
|
77
|
-
/**
|
78
|
-
* Updates the drawing mode for the skia view. This is the same
|
79
|
-
* as declaratively setting the mode property on the SkiaView.
|
80
|
-
* There are two drawing modes, "continuous" and "default",
|
81
|
-
* where the continuous mode will continuously redraw the view and
|
82
|
-
* the default mode will only redraw when any of the regular react
|
83
|
-
* properties are changed like size and margins.
|
84
|
-
* @param mode Drawing mode to use.
|
85
|
-
*/
|
86
|
-
|
87
|
-
|
88
|
-
setDrawMode(mode) {
|
89
|
-
assertDrawCallbacksEnabled();
|
90
|
-
|
91
|
-
_api.SkiaViewApi.setDrawMode(this._nativeId, mode);
|
75
|
+
_api.SkiaViewApi.requestRedraw(this._nativeId);
|
92
76
|
}
|
93
77
|
/**
|
94
78
|
* Registers one or move values as a dependant value of the Skia View. The view will
|
@@ -98,7 +82,7 @@ class SkiaView extends _react.default.Component {
|
|
98
82
|
|
99
83
|
|
100
84
|
registerValues(values) {
|
101
|
-
|
85
|
+
assertSkiaViewApi();
|
102
86
|
return _api.SkiaViewApi.registerValuesInView(this._nativeId, values);
|
103
87
|
}
|
104
88
|
|
@@ -120,9 +104,9 @@ class SkiaView extends _react.default.Component {
|
|
120
104
|
|
121
105
|
exports.SkiaView = SkiaView;
|
122
106
|
|
123
|
-
const
|
124
|
-
if (_api.SkiaViewApi === null || _api.SkiaViewApi.
|
125
|
-
throw Error("Skia Api
|
107
|
+
const assertSkiaViewApi = () => {
|
108
|
+
if (_api.SkiaViewApi === null || _api.SkiaViewApi.setJsiProperty === null || _api.SkiaViewApi.callJsiMethod === null || _api.SkiaViewApi.registerValuesInView === null || _api.SkiaViewApi.requestRedraw === null || _api.SkiaViewApi.makeImageSnapshot === null) {
|
109
|
+
throw Error("Skia View Api was not found.");
|
126
110
|
}
|
127
111
|
};
|
128
112
|
//# sourceMappingURL=SkiaView.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["SkiaView.tsx"],"names":["SkiaViewNativeId","NativeSkiaView","SkiaView","React","Component","constructor","props","_nativeId","onDraw","
|
1
|
+
{"version":3,"sources":["SkiaView.tsx"],"names":["SkiaViewNativeId","NativeSkiaView","SkiaView","React","Component","constructor","props","_nativeId","onDraw","assertSkiaViewApi","SkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","requestRedraw","registerValues","values","registerValuesInView","render","mode","debug","viewProps","callJsiMethod","Error"],"mappings":";;;;;;;AAAA;;AACA;;AAKA;;;;;;;;AAGA,IAAIA,gBAAgB,GAAG,IAAv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MAAAA,KAAK,GAAG,KAAhB;AAAuB,SAAGC;AAA1B,QAAwC,KAAKnB,KAAnD;AACA,wBACE,6BAAC,cAAD;AACE,MAAA,WAAW,EAAE,KADf;AAEE,MAAA,QAAQ,EAAG,GAAE,KAAKC,SAAU,EAF9B;AAGE,MAAA,IAAI,EAAEgB,IAHR;AAIE,MAAA,KAAK,EAAEC;AAJT,OAKMC,SALN,EADF;AASD;;AAhE0D;;;;AAmE7D,MAAMhB,iBAAiB,GAAG,MAAM;AAC9B,MACEC,qBAAgB,IAAhB,IACAA,iBAAYC,cAAZ,KAA+B,IAD/B,IAEAD,iBAAYgB,aAAZ,KAA8B,IAF9B,IAGAhB,iBAAYW,oBAAZ,KAAqC,IAHrC,IAIAX,iBAAYQ,aAAZ,KAA8B,IAJ9B,IAKAR,iBAAYK,iBAAZ,KAAkC,IANpC,EAOE;AACA,UAAMY,KAAK,CAAC,8BAAD,CAAX;AACD;AACF,CAXD","sourcesContent":["import React from \"react\";\nimport { requireNativeComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { NativeSkiaViewProps, SkiaViewProps } from \"./types\";\n\nlet SkiaViewNativeId = 1000;\n\nconst NativeSkiaView = requireNativeComponent<NativeSkiaViewProps>(\n \"ReactNativeSkiaView\"\n);\n\nexport class SkiaView extends React.Component<SkiaViewProps> {\n constructor(props: SkiaViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId++;\n const { onDraw } = props;\n if (onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaViewProps) {\n const { onDraw } = this.props;\n if (onDraw !== prevProps.onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(values: SkiaValue<unknown>[]): () => void {\n assertSkiaViewApi();\n return SkiaViewApi.registerValuesInView(this._nativeId, values);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.callJsiMethod === null ||\n SkiaViewApi.registerValuesInView === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["types.ts"],"names":["TouchType"],"mappings":";;;;;;IAYYA,S;;;WAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;GAAAA,S,yBAAAA,S","sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { SkImage, SkRect
|
1
|
+
{"version":3,"sources":["types.ts"],"names":["TouchType"],"mappings":";;;;;;IAYYA,S;;;WAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;GAAAA,S,yBAAAA,S","sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { SkCanvas, SkImage, SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nexport type DrawMode = \"continuous\" | \"default\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n mode?: DrawMode;\n debug?: boolean;\n};\n\nexport enum TouchType {\n Start,\n Active,\n End,\n Cancelled,\n}\n\nexport interface TouchInfo {\n x: number;\n y: number;\n force: number;\n type: TouchType;\n id: number;\n timestamp: number;\n}\n\nexport interface DrawingInfo {\n width: number;\n height: number;\n timestamp: number;\n touches: Array<Array<TouchInfo>>;\n}\n\nexport type ExtendedTouchInfo = TouchInfo & {\n // points per second\n velocityX: number;\n velocityY: number;\n};\n\nexport type TouchHandlers = {\n onStart?: (touchInfo: TouchInfo) => void;\n onActive?: (touchInfo: ExtendedTouchInfo) => void;\n onEnd?: (touchInfo: ExtendedTouchInfo) => void;\n};\n\nexport type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;\n\nexport type RNSkiaDrawCallback = (canvas: SkCanvas, info: DrawingInfo) => void;\n\n/**\n * Listener interface for value changes\n */\nexport interface ValueListener {\n addListener: (callback: () => void) => number;\n removeListener: (id: number) => void;\n}\n\nexport interface ISkiaViewApi {\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n callJsiMethod: <T extends Array<unknown>>(\n nativeId: number,\n name: string,\n ...args: T\n ) => void;\n registerValuesInView: (\n nativeId: number,\n values: SkiaValue<unknown>[]\n ) => () => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n}\n\nexport interface SkiaViewProps extends ViewProps {\n /**\n * Sets the drawing mode for the skia view. There are two drawing\n * modes, \"continuous\" and \"default\", where the continuous mode will\n * continuously redraw the view, and the default mode will only\n * redraw when any of the regular react properties are changed like\n * sizes and margins.\n */\n mode?: DrawMode;\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Draw callback. Will be called whenever the view is invalidated and\n * needs to redraw. This is either caused by a change in a react\n * property, a touch event, or a call to redraw. If the view is in\n * continuous mode the callback will be called 60 frames per second\n * by the native view.\n */\n onDraw?: RNSkiaDrawCallback;\n}\n"]}
|
@@ -209,7 +209,23 @@ export const skHostConfig = {
|
|
209
209
|
}
|
210
210
|
|
211
211
|
bustBranchMemoization(instance);
|
212
|
-
|
212
|
+
|
213
|
+
if (instance instanceof DrawingNode) {
|
214
|
+
const {
|
215
|
+
onDraw,
|
216
|
+
skipProcessing,
|
217
|
+
...props
|
218
|
+
} = nextProps;
|
219
|
+
instance.props = props;
|
220
|
+
} else if (instance instanceof DeclarationNode) {
|
221
|
+
const {
|
222
|
+
onDeclare,
|
223
|
+
...props
|
224
|
+
} = nextProps;
|
225
|
+
instance.props = props;
|
226
|
+
} else {
|
227
|
+
throw new Error("Unsupported instance commitUpdate " + instance.constructor.name);
|
228
|
+
}
|
213
229
|
},
|
214
230
|
|
215
231
|
commitTextUpdate: (_textInstance, _oldText, _newText) => {// textInstance.instance = newText;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["HostConfig.ts"],"names":["DeclarationNode","DrawingNode","NodeType","exhaustiveCheck","shallowEq","DEBUG","debug","console","log","allChildrenAreMemoized","node","memoizable","child","children","memoized","bustBranchMemoization","parent","ancestor","bustBranchMemoizable","appendNode","push","removeNode","index","indexOf","splice","depMgr","unsubscribeNode","c","insertBefore","before","beforeIndex","createNode","container","type","props","Drawing","onDraw","skipProcessing","p1","Declaration","onDeclare","p2","skHostConfig","now","Date","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","finalizeContainerChildren","resetAfterCommit","redraw","getPublicInstance","prepareUpdate","instance","oldProps","newProps","propsAreEqual","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore"],"mappings":"AAAA;AAIA,SAASA,eAAT,EAA0BC,WAA1B,EAAuCC,QAAvC,QAAuD,SAAvD;AACA,SAASC,eAAT,EAA0BC,SAA1B,QAA2C,aAA3C;AAEA,MAAMC,KAAK,GAAG,KAAd;AACA,OAAO,MAAMC,KAAK,GAAG,YAA6C;AAChE,MAAID,KAAJ,EAAW;AACTE,IAAAA,OAAO,CAACC,GAAR,CAAY,YAAZ;AACD;AACF,CAJM;;AA+CP,MAAMC,sBAAsB,GAAIC,IAAD,IAAoB;AACjD,MAAI,CAACA,IAAI,CAACC,UAAV,EAAsB;AACpB,WAAO,KAAP;AACD;;AACD,OAAK,MAAMC,KAAX,IAAoBF,IAAI,CAACG,QAAzB,EAAmC;AACjC,QAAI,CAACD,KAAK,CAACE,QAAX,EAAqB;AACnB,aAAO,KAAP;AACD;AACF;;AACD,SAAO,IAAP;AACD,CAVD;;AAYA,MAAMC,qBAAqB,GAAIC,MAAD,IAAkB;AAC9C,MAAIA,MAAM,CAACL,UAAX,EAAuB;AACrB,QAAIM,QAA0B,GAAGD,MAAjC;;AACA,WAAOC,QAAP,EAAiB;AACfA,MAAAA,QAAQ,CAACH,QAAT,GAAoB,IAApB;AACAG,MAAAA,QAAQ,GAAGA,QAAQ,CAACD,MAApB;AACD;AACF;AACF,CARD;;AAUA,MAAME,oBAAoB,GAAIF,MAAD,IAAkB;AAC7C,MAAIA,MAAM,CAACL,UAAX,EAAuB;AACrB,QAAIM,QAA0B,GAAGD,MAAjC;;AACA,WAAOC,QAAP,EAAiB;AACfA,MAAAA,QAAQ,CAACN,UAAT,GAAsB,KAAtB;AACAM,MAAAA,QAAQ,GAAGA,QAAQ,CAACD,MA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,MAAD,EAASJ,KAAT,EAAgBiB,MAAhB,CAAZ;AACD;AAtKyC,CAArC","sourcesContent":["/*global NodeJS*/\nimport type { HostConfig } from \"react-reconciler\";\n\nimport type { Node, Container, DeclarationProps, DrawingProps } from \"./nodes\";\nimport { DeclarationNode, DrawingNode, NodeType } from \"./nodes\";\nimport { exhaustiveCheck, shallowEq } from \"./typeddash\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDeclaration: DeclarationProps<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDrawing: DrawingProps<any>;\n }\n }\n}\n\ntype Instance = Node;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Props = any;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = true;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\nconst allChildrenAreMemoized = (node: Instance) => {\n if (!node.memoizable) {\n return false;\n }\n for (const child of node.children) {\n if (!child.memoized) {\n return false;\n }\n }\n return true;\n};\n\nconst bustBranchMemoization = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoized = null;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst bustBranchMemoizable = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoizable = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst appendNode = (parent: Node, child: Node) => {\n child.parent = parent;\n bustBranchMemoization(parent);\n if (!child.memoizable) {\n bustBranchMemoizable(parent);\n }\n if (!parent.memoizable) {\n child.memoizable = false;\n }\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node, child: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n parent.children.splice(index, 1);\n child.depMgr.unsubscribeNode(child);\n // unsubscribe to all children as well\n for (const c of child.children) {\n removeNode(child, c);\n }\n};\n\nconst insertBefore = (parent: Node, child: Node, before: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n if (index !== -1) {\n parent.children.splice(index, 1);\n }\n const beforeIndex = parent.children.indexOf(before);\n parent.children.splice(beforeIndex, 0, child);\n};\n\nconst createNode = (container: Container, type: NodeType, props: Props) => {\n switch (type) {\n case NodeType.Drawing:\n const { onDraw, skipProcessing, ...p1 } = props;\n return new DrawingNode(container.depMgr, onDraw, skipProcessing, p1);\n case NodeType.Declaration:\n const { onDeclare, ...p2 } = props;\n return new DeclarationNode(container.depMgr, onDeclare, p2);\n default:\n // TODO: here we need to throw a nice error message\n // This is the error that will show up when the user uses nodes not supported by Skia (View, Audio, etc)\n return exhaustiveCheck(type);\n }\n};\n\nexport const skHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n now: Date.now,\n\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\", container, child);\n appendNode(container, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Node) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n props,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n return createNode(container, type, props) as Node;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n finalizeContainerChildren: () => {\n debug(\"finalizeContainerChildren\");\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n instance,\n type,\n oldProps,\n newProps,\n _rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual && !instance.memoizable) {\n return null;\n }\n debug(\"update \", type);\n return true;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps) && allChildrenAreMemoized(instance)) {\n return;\n }\n bustBranchMemoization(instance);\n instance.props = nextProps;\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.children.splice(0);\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (parent, child) => {\n removeNode(parent, child);\n },\n\n insertInContainerBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n};\n"]}
|
1
|
+
{"version":3,"sources":["HostConfig.ts"],"names":["DeclarationNode","DrawingNode","NodeType","exhaustiveCheck","shallowEq","DEBUG","debug","console","log","allChildrenAreMemoized","node","memoizable","child","children","memoized","bustBranchMemoization","parent","ancestor","bustBranchMemoizable","appendNode","push","removeNode","index","indexOf","splice","depMgr","unsubscribeNode","c","insertBefore","before","beforeIndex","createNode","container","type","props","Drawing","onDraw","skipProcessing","p1","Declaration","onDeclare","p2","skHostConfig","now","Date","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","finalizeContainerChildren","resetAfterCommit","redraw","getPublicInstance","prepareUpdate","instance","oldProps","newProps","propsAreEqual","commitUpdate","_updatePayload","prevProps","nextProps","_internalHandle","constructor","name","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","preparePortalMount","removeChild","removeChildFromContainer","insertInContainerBefore"],"mappings":"AAAA;AAIA,SAASA,eAAT,EAA0BC,WAA1B,EAAuCC,QAAvC,QAAuD,SAAvD;AACA,SAASC,eAAT,EAA0BC,SAA1B,QAA2C,aAA3C;AAEA,MAAMC,KAAK,GAAG,KAAd;AACA,OAAO,MAAMC,KAAK,GAAG,YAA6C;AAChE,MAAID,KAAJ,EAAW;AACTE,IAAAA,OAAO,CAACC,GA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AAgBiB,MAAhB,CAAZ;AACD;AAhLyC,CAArC","sourcesContent":["/*global NodeJS*/\nimport type { HostConfig } from \"react-reconciler\";\n\nimport type { Node, Container, DeclarationProps, DrawingProps } from \"./nodes\";\nimport { DeclarationNode, DrawingNode, NodeType } from \"./nodes\";\nimport { exhaustiveCheck, shallowEq } from \"./typeddash\";\n\nconst DEBUG = false;\nexport const debug = (...args: Parameters<typeof console.log>) => {\n if (DEBUG) {\n console.log(...args);\n }\n};\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-namespace\n namespace JSX {\n interface IntrinsicElements {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDeclaration: DeclarationProps<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n skDrawing: DrawingProps<any>;\n }\n }\n}\n\ntype Instance = Node;\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Props = any;\ntype TextInstance = Node;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = true;\ntype ChildSet = unknown;\ntype TimeoutHandle = NodeJS.Timeout;\ntype NoTimeout = -1;\n\ntype SkiaHostConfig = HostConfig<\n NodeType,\n Props,\n Container,\n Instance,\n TextInstance,\n SuspenseInstance,\n HydratableInstance,\n PublicInstance,\n HostContext,\n UpdatePayload,\n ChildSet,\n TimeoutHandle,\n NoTimeout\n>;\n\nconst allChildrenAreMemoized = (node: Instance) => {\n if (!node.memoizable) {\n return false;\n }\n for (const child of node.children) {\n if (!child.memoized) {\n return false;\n }\n }\n return true;\n};\n\nconst bustBranchMemoization = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoized = null;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst bustBranchMemoizable = (parent: Node) => {\n if (parent.memoizable) {\n let ancestor: Node | undefined = parent;\n while (ancestor) {\n ancestor.memoizable = false;\n ancestor = ancestor.parent;\n }\n }\n};\n\nconst appendNode = (parent: Node, child: Node) => {\n child.parent = parent;\n bustBranchMemoization(parent);\n if (!child.memoizable) {\n bustBranchMemoizable(parent);\n }\n if (!parent.memoizable) {\n child.memoizable = false;\n }\n parent.children.push(child);\n};\n\nconst removeNode = (parent: Node, child: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n parent.children.splice(index, 1);\n child.depMgr.unsubscribeNode(child);\n // unsubscribe to all children as well\n for (const c of child.children) {\n removeNode(child, c);\n }\n};\n\nconst insertBefore = (parent: Node, child: Node, before: Node) => {\n bustBranchMemoization(parent);\n const index = parent.children.indexOf(child);\n if (index !== -1) {\n parent.children.splice(index, 1);\n }\n const beforeIndex = parent.children.indexOf(before);\n parent.children.splice(beforeIndex, 0, child);\n};\n\nconst createNode = (container: Container, type: NodeType, props: Props) => {\n switch (type) {\n case NodeType.Drawing:\n const { onDraw, skipProcessing, ...p1 } = props;\n return new DrawingNode(container.depMgr, onDraw, skipProcessing, p1);\n case NodeType.Declaration:\n const { onDeclare, ...p2 } = props;\n return new DeclarationNode(container.depMgr, onDeclare, p2);\n default:\n // TODO: here we need to throw a nice error message\n // This is the error that will show up when the user uses nodes not supported by Skia (View, Audio, etc)\n return exhaustiveCheck(type);\n }\n};\n\nexport const skHostConfig: SkiaHostConfig = {\n /**\n * This function is used by the reconciler in order to calculate current time for prioritising work.\n */\n now: Date.now,\n\n supportsMutation: true,\n isPrimaryRenderer: false,\n supportsPersistence: false,\n supportsHydration: false,\n //supportsMicrotask: true,\n\n scheduleTimeout: setTimeout,\n cancelTimeout: clearTimeout,\n noTimeout: -1,\n\n appendChildToContainer(container, child) {\n debug(\"appendChildToContainer\", container, child);\n appendNode(container, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Node) => {\n debug(\"getRootHostContext\");\n return null;\n },\n\n getChildHostContext(_parentHostContext, _type, _rootContainerInstance) {\n debug(\"getChildHostContext\");\n return null;\n },\n\n shouldSetTextContent(_type, _props) {\n return false;\n },\n\n createTextInstance(\n _text,\n _rootContainerInstance,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createTextInstance\");\n // return SpanNode({}, text) as SkNode;\n throw new Error(\"Text nodes are not supported yet\");\n },\n\n createInstance(\n type,\n props,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n return createNode(container, type, props) as Node;\n },\n\n appendInitialChild(parentInstance, child) {\n debug(\"appendInitialChild\");\n appendNode(parentInstance, child);\n },\n\n finalizeInitialChildren(\n parentInstance,\n _type,\n _props,\n _rootContainerInstance,\n _hostContext\n ) {\n debug(\"finalizeInitialChildren\", parentInstance);\n return false;\n },\n\n commitMount() {\n // if finalizeInitialChildren = true\n debug(\"commitMount\");\n },\n\n prepareForCommit(_containerInfo) {\n debug(\"prepareForCommit\");\n return null;\n },\n\n finalizeContainerChildren: () => {\n debug(\"finalizeContainerChildren\");\n },\n\n resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.redraw();\n },\n\n getPublicInstance(node: Instance) {\n debug(\"getPublicInstance\");\n return node;\n },\n\n prepareUpdate: (\n instance,\n type,\n oldProps,\n newProps,\n _rootContainerInstance,\n _hostContext\n ) => {\n debug(\"prepareUpdate\");\n const propsAreEqual = shallowEq(oldProps, newProps);\n if (propsAreEqual && !instance.memoizable) {\n return null;\n }\n debug(\"update \", type);\n return true;\n },\n\n commitUpdate(\n instance,\n _updatePayload,\n type,\n prevProps,\n nextProps,\n _internalHandle\n ) {\n debug(\"commitUpdate: \", type);\n if (shallowEq(prevProps, nextProps) && allChildrenAreMemoized(instance)) {\n return;\n }\n bustBranchMemoization(instance);\n if (instance instanceof DrawingNode) {\n const { onDraw, skipProcessing, ...props } = nextProps;\n instance.props = props;\n } else if (instance instanceof DeclarationNode) {\n const { onDeclare, ...props } = nextProps;\n instance.props = props;\n } else {\n throw new Error(\n \"Unsupported instance commitUpdate \" + instance.constructor.name\n );\n }\n },\n\n commitTextUpdate: (\n _textInstance: TextInstance,\n _oldText: string,\n _newText: string\n ) => {\n // textInstance.instance = newText;\n },\n\n clearContainer: (container) => {\n debug(\"clearContainer\");\n container.children.splice(0);\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (parent, child) => {\n removeNode(parent, child);\n },\n\n insertInContainerBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n};\n"]}
|
@@ -19,8 +19,8 @@ export class SkiaView extends React.Component {
|
|
19
19
|
} = props;
|
20
20
|
|
21
21
|
if (onDraw) {
|
22
|
-
|
23
|
-
SkiaViewApi.
|
22
|
+
assertSkiaViewApi();
|
23
|
+
SkiaViewApi.setJsiProperty(this._nativeId, "drawCallback", onDraw);
|
24
24
|
}
|
25
25
|
}
|
26
26
|
|
@@ -34,8 +34,8 @@ export class SkiaView extends React.Component {
|
|
34
34
|
} = this.props;
|
35
35
|
|
36
36
|
if (onDraw !== prevProps.onDraw) {
|
37
|
-
|
38
|
-
SkiaViewApi.
|
37
|
+
assertSkiaViewApi();
|
38
|
+
SkiaViewApi.setJsiProperty(this._nativeId, "drawCallback", onDraw);
|
39
39
|
}
|
40
40
|
}
|
41
41
|
/**
|
@@ -46,7 +46,7 @@ export class SkiaView extends React.Component {
|
|
46
46
|
|
47
47
|
|
48
48
|
makeImageSnapshot(rect) {
|
49
|
-
|
49
|
+
assertSkiaViewApi();
|
50
50
|
return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);
|
51
51
|
}
|
52
52
|
/**
|
@@ -55,23 +55,8 @@ export class SkiaView extends React.Component {
|
|
55
55
|
|
56
56
|
|
57
57
|
redraw() {
|
58
|
-
|
59
|
-
SkiaViewApi.
|
60
|
-
}
|
61
|
-
/**
|
62
|
-
* Updates the drawing mode for the skia view. This is the same
|
63
|
-
* as declaratively setting the mode property on the SkiaView.
|
64
|
-
* There are two drawing modes, "continuous" and "default",
|
65
|
-
* where the continuous mode will continuously redraw the view and
|
66
|
-
* the default mode will only redraw when any of the regular react
|
67
|
-
* properties are changed like size and margins.
|
68
|
-
* @param mode Drawing mode to use.
|
69
|
-
*/
|
70
|
-
|
71
|
-
|
72
|
-
setDrawMode(mode) {
|
73
|
-
assertDrawCallbacksEnabled();
|
74
|
-
SkiaViewApi.setDrawMode(this._nativeId, mode);
|
58
|
+
assertSkiaViewApi();
|
59
|
+
SkiaViewApi.requestRedraw(this._nativeId);
|
75
60
|
}
|
76
61
|
/**
|
77
62
|
* Registers one or move values as a dependant value of the Skia View. The view will
|
@@ -81,7 +66,7 @@ export class SkiaView extends React.Component {
|
|
81
66
|
|
82
67
|
|
83
68
|
registerValues(values) {
|
84
|
-
|
69
|
+
assertSkiaViewApi();
|
85
70
|
return SkiaViewApi.registerValuesInView(this._nativeId, values);
|
86
71
|
}
|
87
72
|
|
@@ -101,9 +86,9 @@ export class SkiaView extends React.Component {
|
|
101
86
|
|
102
87
|
}
|
103
88
|
|
104
|
-
const
|
105
|
-
if (SkiaViewApi === null || SkiaViewApi.
|
106
|
-
throw Error("Skia Api
|
89
|
+
const assertSkiaViewApi = () => {
|
90
|
+
if (SkiaViewApi === null || SkiaViewApi.setJsiProperty === null || SkiaViewApi.callJsiMethod === null || SkiaViewApi.registerValuesInView === null || SkiaViewApi.requestRedraw === null || SkiaViewApi.makeImageSnapshot === null) {
|
91
|
+
throw Error("Skia View Api was not found.");
|
107
92
|
}
|
108
93
|
};
|
109
94
|
//# sourceMappingURL=SkiaView.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["SkiaView.tsx"],"names":["React","requireNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaView","SkiaView","Component","constructor","props","_nativeId","onDraw","
|
1
|
+
{"version":3,"sources":["SkiaView.tsx"],"names":["React","requireNativeComponent","SkiaViewApi","SkiaViewNativeId","NativeSkiaView","SkiaView","Component","constructor","props","_nativeId","onDraw","assertSkiaViewApi","setJsiProperty","nativeId","componentDidUpdate","prevProps","makeImageSnapshot","rect","redraw","requestRedraw","registerValues","values","registerValuesInView","render","mode","debug","viewProps","callJsiMethod","Error"],"mappings":";;;;AAAA,OAAOA,KAAP,MAAkB,OAAlB;AACA,SAASC,sBAAT,QAAuC,cAAvC;AAKA,SAASC,WAAT,QAA4B,OAA5B;AAGA,IAAIC,gBAAgB,GAAG,IAAvB;AAEA,MAAMC,cAAc,GAAGH,sBAAsB,CAC3C,qBAD2C,CAA7C;AAIA,OAAO,MAAMI,QAAN,SAAuBL,KAAK,CAACM,SAA7B,CAAsD;AAC3DC,EAAAA,WAAW,CAACC,KAAD,EAAuB;AAChC,UAAMA,KAAN;;AADgC;;AAEhC,SAAKC,SAAL,GAAiBN,gBAAgB,EAAjC;AACA,UAAM;AAAEO,MAAAA;AAAF,QAAaF,KAAnB;;AACA,QAAIE,MAAJ,EAAY;AACVC,MAAAA,iBAAiB;AACjBT,MAAAA,WAAW,CAACU,cAAZ,CAA2B,KAAKH,SAAhC,EAA2C,cAA3C,EAA2DC,MAA3D;AACD;AACF;;AAIkB,MAARG,QAAQ,GAAG;AACpB,WAAO,KAAKJ,SAAZ;AACD;;AAEDK,EAAAA,kBAAkB,CAACC,SAAD,EAA2B;AAC3C,UAAM;AAAEL,MAAAA;AAAF,QAAa,KAAKF,KAAxB;;AACA,QAAIE,MAAM,KAAKK,SAAS,CAACL,MAAzB,EAAiC;AAC/BC,MAAAA,iBAAiB;AACjBT,MAAAA,WAAW,CAACU,cAAZ,CAA2B,KAAKH,SAAhC,EAA2C,cAA3C,EAA2DC,MAA3D;AACD;AACF;AAED;AACF;AACA;AACA;AACA;;;AACSM,EAAAA,iBAAiB,CAACC,IAAD,EAAgB;AACtCN,IAAAA,iBAAiB;AACjB,WAAOT,WAAW,CAACc,iBAAZ,CAA8B,KAAKP,SAAnC,EAA8CQ,IAA9C,CAAP;AACD;AAED;AACF;AACA;;;AACSC,EAAAA,MAAM,GAAG;AACdP,IAAAA,iBAAiB;AACjBT,IAAAA,WAAW,CAACiB,aAAZ,CAA0B,KAAKV,SAA/B;AACD;AAED;AACF;AACA;AACA;AACA;;;AACSW,EAAAA,cAAc,CAACC,MAAD,EAA2C;AAC9DV,IAAAA,iBAAiB;AACjB,WAAOT,WAAW,CAACoB,oBAAZ,CAAiC,KAAKb,SAAtC,EAAiDY,MAAjD,CAAP;AACD;;AAEDE,EAAAA,MAAM,GAAG;AACP,UAAM;AAAEC,MAAAA,IAAF;AAAQC,MAAAA,KAAK,GAAG,KAAhB;AAAuB,SAAGC;AAA1B,QAAwC,KAAKlB,KAAnD;AACA,wBACE,oBAAC,cAAD;AACE,MAAA,WAAW,EAAE,KADf;AAEE,MAAA,QAAQ,EAAG,GAAE,KAAKC,SAAU,EAF9B;AAGE,MAAA,IAAI,EAAEe,IAHR;AAIE,MAAA,KAAK,EAAEC;AAJT,OAKMC,SALN,EADF;AASD;;AAhE0D;;AAmE7D,MAAMf,iBAAiB,GAAG,MAAM;AAC9B,MACET,WAAW,KAAK,IAAhB,IACAA,WAAW,CAACU,cAAZ,KAA+B,IAD/B,IAEAV,WAAW,CAACyB,aAAZ,KAA8B,IAF9B,IAGAzB,WAAW,CAACoB,oBAAZ,KAAqC,IAHrC,IAIApB,WAAW,CAACiB,aAAZ,KAA8B,IAJ9B,IAKAjB,WAAW,CAACc,iBAAZ,KAAkC,IANpC,EAOE;AACA,UAAMY,KAAK,CAAC,8BAAD,CAAX;AACD;AACF,CAXD","sourcesContent":["import React from \"react\";\nimport { requireNativeComponent } from \"react-native\";\n\nimport type { SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nimport { SkiaViewApi } from \"./api\";\nimport type { NativeSkiaViewProps, SkiaViewProps } from \"./types\";\n\nlet SkiaViewNativeId = 1000;\n\nconst NativeSkiaView = requireNativeComponent<NativeSkiaViewProps>(\n \"ReactNativeSkiaView\"\n);\n\nexport class SkiaView extends React.Component<SkiaViewProps> {\n constructor(props: SkiaViewProps) {\n super(props);\n this._nativeId = SkiaViewNativeId++;\n const { onDraw } = props;\n if (onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\n }\n }\n\n private _nativeId: number;\n\n public get nativeId() {\n return this._nativeId;\n }\n\n componentDidUpdate(prevProps: SkiaViewProps) {\n const { onDraw } = this.props;\n if (onDraw !== prevProps.onDraw) {\n assertSkiaViewApi();\n SkiaViewApi.setJsiProperty(this._nativeId, \"drawCallback\", onDraw);\n }\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n assertSkiaViewApi();\n return SkiaViewApi.makeImageSnapshot(this._nativeId, rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n public redraw() {\n assertSkiaViewApi();\n SkiaViewApi.requestRedraw(this._nativeId);\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(values: SkiaValue<unknown>[]): () => void {\n assertSkiaViewApi();\n return SkiaViewApi.registerValuesInView(this._nativeId, values);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <NativeSkiaView\n collapsable={false}\n nativeID={`${this._nativeId}`}\n mode={mode}\n debug={debug}\n {...viewProps}\n />\n );\n }\n}\n\nconst assertSkiaViewApi = () => {\n if (\n SkiaViewApi === null ||\n SkiaViewApi.setJsiProperty === null ||\n SkiaViewApi.callJsiMethod === null ||\n SkiaViewApi.registerValuesInView === null ||\n SkiaViewApi.requestRedraw === null ||\n SkiaViewApi.makeImageSnapshot === null\n ) {\n throw Error(\"Skia View Api was not found.\");\n }\n};\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["types.ts"],"names":["TouchType"],"mappings":"AAYA,WAAYA,SAAZ;;WAAYA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;GAAAA,S,KAAAA,S","sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { SkImage, SkRect
|
1
|
+
{"version":3,"sources":["types.ts"],"names":["TouchType"],"mappings":"AAYA,WAAYA,SAAZ;;WAAYA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;AAAAA,EAAAA,S,CAAAA,S;GAAAA,S,KAAAA,S","sourcesContent":["import type { ViewProps } from \"react-native\";\n\nimport type { SkCanvas, SkImage, SkRect } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\n\nexport type DrawMode = \"continuous\" | \"default\";\n\nexport type NativeSkiaViewProps = ViewProps & {\n mode?: DrawMode;\n debug?: boolean;\n};\n\nexport enum TouchType {\n Start,\n Active,\n End,\n Cancelled,\n}\n\nexport interface TouchInfo {\n x: number;\n y: number;\n force: number;\n type: TouchType;\n id: number;\n timestamp: number;\n}\n\nexport interface DrawingInfo {\n width: number;\n height: number;\n timestamp: number;\n touches: Array<Array<TouchInfo>>;\n}\n\nexport type ExtendedTouchInfo = TouchInfo & {\n // points per second\n velocityX: number;\n velocityY: number;\n};\n\nexport type TouchHandlers = {\n onStart?: (touchInfo: TouchInfo) => void;\n onActive?: (touchInfo: ExtendedTouchInfo) => void;\n onEnd?: (touchInfo: ExtendedTouchInfo) => void;\n};\n\nexport type TouchHandler = (touchInfo: Array<Array<TouchInfo>>) => void;\n\nexport type RNSkiaDrawCallback = (canvas: SkCanvas, info: DrawingInfo) => void;\n\n/**\n * Listener interface for value changes\n */\nexport interface ValueListener {\n addListener: (callback: () => void) => number;\n removeListener: (id: number) => void;\n}\n\nexport interface ISkiaViewApi {\n setJsiProperty: <T>(nativeId: number, name: string, value: T) => void;\n callJsiMethod: <T extends Array<unknown>>(\n nativeId: number,\n name: string,\n ...args: T\n ) => void;\n registerValuesInView: (\n nativeId: number,\n values: SkiaValue<unknown>[]\n ) => () => void;\n requestRedraw: (nativeId: number) => void;\n makeImageSnapshot: (nativeId: number, rect?: SkRect) => SkImage;\n}\n\nexport interface SkiaViewProps extends ViewProps {\n /**\n * Sets the drawing mode for the skia view. There are two drawing\n * modes, \"continuous\" and \"default\", where the continuous mode will\n * continuously redraw the view, and the default mode will only\n * redraw when any of the regular react properties are changed like\n * sizes and margins.\n */\n mode?: DrawMode;\n /**\n * When set to true the view will display information about the\n * average time it takes to render.\n */\n debug?: boolean;\n /**\n * Draw callback. Will be called whenever the view is invalidated and\n * needs to redraw. This is either caused by a change in a react\n * property, a touch event, or a call to redraw. If the view is in\n * continuous mode the callback will be called 60 frames per second\n * by the native view.\n */\n onDraw?: RNSkiaDrawCallback;\n}\n"]}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from "react";
|
2
2
|
import type { SkRect } from "../skia/types";
|
3
3
|
import type { SkiaValue } from "../values";
|
4
|
-
import type {
|
4
|
+
import type { SkiaViewProps } from "./types";
|
5
5
|
export declare class SkiaView extends React.Component<SkiaViewProps> {
|
6
6
|
constructor(props: SkiaViewProps);
|
7
7
|
private _nativeId;
|
@@ -17,16 +17,6 @@ export declare class SkiaView extends React.Component<SkiaViewProps> {
|
|
17
17
|
* Sends a redraw request to the native SkiaView.
|
18
18
|
*/
|
19
19
|
redraw(): void;
|
20
|
-
/**
|
21
|
-
* Updates the drawing mode for the skia view. This is the same
|
22
|
-
* as declaratively setting the mode property on the SkiaView.
|
23
|
-
* There are two drawing modes, "continuous" and "default",
|
24
|
-
* where the continuous mode will continuously redraw the view and
|
25
|
-
* the default mode will only redraw when any of the regular react
|
26
|
-
* properties are changed like size and margins.
|
27
|
-
* @param mode Drawing mode to use.
|
28
|
-
*/
|
29
|
-
setDrawMode(mode: DrawMode): void;
|
30
20
|
/**
|
31
21
|
* Registers one or move values as a dependant value of the Skia View. The view will
|
32
22
|
* The view will redraw itself when any of the values change.
|