@shopify/react-native-skia 0.1.176 → 0.1.180
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +2 -0
- package/cpp/jsi/JsiHostObject.cpp +13 -7
- package/cpp/jsi/JsiHostObject.h +3 -1
- package/cpp/jsi/RuntimeAwareCache.cpp +9 -0
- package/cpp/jsi/RuntimeAwareCache.h +101 -0
- package/cpp/jsi/RuntimeLifecycleMonitor.cpp +57 -0
- package/cpp/jsi/RuntimeLifecycleMonitor.h +32 -0
- package/cpp/rnskia/RNSkManager.cpp +4 -0
- package/cpp/rnskia/RNSkView.h +5 -3
- package/cpp/rnskia/dom/base/JsiDomNode.h +22 -2
- package/cpp/rnskia/dom/nodes/JsiImageFilterNodes.h +10 -9
- package/lib/commonjs/dom/nodes/paint/ImageFilters.js +10 -2
- package/lib/commonjs/dom/nodes/paint/ImageFilters.js.map +1 -1
- package/lib/commonjs/external/reanimated/index.d.ts +1 -0
- package/lib/commonjs/external/reanimated/index.js +13 -0
- package/lib/commonjs/external/reanimated/index.js.map +1 -1
- package/lib/commonjs/external/reanimated/moduleWrapper.d.ts +8 -0
- package/lib/commonjs/external/reanimated/moduleWrapper.js +68 -0
- package/lib/commonjs/external/reanimated/moduleWrapper.js.map +1 -0
- package/lib/commonjs/external/reanimated/renderHelpers.d.ts +5 -0
- package/lib/commonjs/external/reanimated/renderHelpers.js +81 -0
- package/lib/commonjs/external/reanimated/renderHelpers.js.map +1 -0
- package/lib/commonjs/external/reanimated/useSharedValueEffect.d.ts +2 -5
- package/lib/commonjs/external/reanimated/useSharedValueEffect.js +10 -25
- package/lib/commonjs/external/reanimated/useSharedValueEffect.js.map +1 -1
- package/lib/commonjs/headless/index.d.ts +3 -0
- package/lib/commonjs/headless/index.js +57 -0
- package/lib/commonjs/headless/index.js.map +1 -0
- package/lib/commonjs/mock/index.d.ts +1 -2
- package/lib/commonjs/mock/index.js +0 -4
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.js +7 -1
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/Container.d.ts +2 -1
- package/lib/commonjs/renderer/Container.js +2 -0
- package/lib/commonjs/renderer/Container.js.map +1 -1
- package/lib/commonjs/renderer/HostConfig.js +6 -4
- package/lib/commonjs/renderer/HostConfig.js.map +1 -1
- package/lib/commonjs/renderer/Reconciler.d.ts +1 -1
- package/lib/commonjs/renderer/Reconciler.js +2 -1
- package/lib/commonjs/renderer/Reconciler.js.map +1 -1
- package/lib/commonjs/renderer/processors/Animations/Animations.d.ts +4 -1
- package/lib/commonjs/renderer/processors/Animations/Animations.js.map +1 -1
- package/lib/module/dom/nodes/paint/ImageFilters.js +10 -2
- package/lib/module/dom/nodes/paint/ImageFilters.js.map +1 -1
- package/lib/module/external/reanimated/index.d.ts +1 -0
- package/lib/module/external/reanimated/index.js +1 -0
- package/lib/module/external/reanimated/index.js.map +1 -1
- package/lib/module/external/reanimated/moduleWrapper.d.ts +8 -0
- package/lib/module/external/reanimated/moduleWrapper.js +50 -0
- package/lib/module/external/reanimated/moduleWrapper.js.map +1 -0
- package/lib/module/external/reanimated/renderHelpers.d.ts +5 -0
- package/lib/module/external/reanimated/renderHelpers.js +72 -0
- package/lib/module/external/reanimated/renderHelpers.js.map +1 -0
- package/lib/module/external/reanimated/useSharedValueEffect.d.ts +2 -5
- package/lib/module/external/reanimated/useSharedValueEffect.js +7 -22
- package/lib/module/external/reanimated/useSharedValueEffect.js.map +1 -1
- package/lib/module/headless/index.d.ts +3 -0
- package/lib/module/headless/index.js +29 -0
- package/lib/module/headless/index.js.map +1 -0
- package/lib/module/mock/index.d.ts +1 -2
- package/lib/module/mock/index.js +0 -3
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.js +7 -1
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/Container.d.ts +2 -1
- package/lib/module/renderer/Container.js +2 -0
- package/lib/module/renderer/Container.js.map +1 -1
- package/lib/module/renderer/HostConfig.js +5 -4
- package/lib/module/renderer/HostConfig.js.map +1 -1
- package/lib/module/renderer/Reconciler.d.ts +1 -1
- package/lib/module/renderer/Reconciler.js +2 -1
- package/lib/module/renderer/Reconciler.js.map +1 -1
- package/lib/module/renderer/processors/Animations/Animations.d.ts +4 -1
- package/lib/module/renderer/processors/Animations/Animations.js.map +1 -1
- package/lib/typescript/src/external/reanimated/index.d.ts +1 -0
- package/lib/typescript/src/external/reanimated/moduleWrapper.d.ts +8 -0
- package/lib/typescript/src/external/reanimated/renderHelpers.d.ts +5 -0
- package/lib/typescript/src/external/reanimated/useSharedValueEffect.d.ts +2 -5
- package/lib/typescript/src/headless/index.d.ts +3 -0
- package/lib/typescript/src/mock/index.d.ts +1 -2
- package/lib/typescript/src/renderer/Container.d.ts +2 -1
- package/lib/typescript/src/renderer/Reconciler.d.ts +1 -1
- package/lib/typescript/src/renderer/processors/Animations/Animations.d.ts +4 -1
- package/package.json +1 -1
- package/src/dom/nodes/paint/ImageFilters.ts +8 -2
- package/src/external/reanimated/index.ts +1 -0
- package/src/external/reanimated/moduleWrapper.ts +60 -0
- package/src/external/reanimated/renderHelpers.ts +70 -0
- package/src/external/reanimated/useSharedValueEffect.ts +17 -23
- package/src/headless/index.ts +31 -0
- package/src/mock/index.ts +0 -5
- package/src/renderer/Canvas.tsx +6 -2
- package/src/renderer/Container.tsx +2 -1
- package/src/renderer/HostConfig.ts +8 -2
- package/src/renderer/Reconciler.tsx +3 -2
- package/src/renderer/processors/Animations/Animations.ts +9 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["DefaultEventPriority","createNode","isSelector","isValue","mapKeys","shallowEq","DEBUG","debug","console","log","appendNode","parent","child","addChild","removeNode","removeChild","insertBefore","before","insertChildBefore","skHostConfig","now","Date","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","container","root","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","type","pristineProps","props","node","materialize","depMgr","subscribeNode","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","resetAfterCommit","update","redraw","getPublicInstance","prepareUpdate","_instance","oldProps","newProps","rootContainerInstance","propsAreEqual","commitUpdate","instance","updatePayload","prevProps","nextProps","_internalHandle","unsubscribeNode","setProps","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","children","forEach","preparePortalMount","removeChildFromContainer","insertInContainerBefore","getCurrentEventPriority","beforeActiveInstanceBlur","afterActiveInstanceBlur","detachDeletedInstance","result","key","prop","current","selector","value"],"sources":["HostConfig.ts"],"sourcesContent":["/*global NodeJS*/\nimport type { HostConfig } from \"react-reconciler\";\nimport { DefaultEventPriority } from \"react-reconciler/constants\";\n\nimport type { NodeType, Node } from \"../dom/types\";\nimport type { SkiaValue } from \"../values\";\n\nimport type { Container } from \"./Container\";\nimport { createNode } from \"./HostComponents\";\nimport type { AnimatedProps } from \"./processors\";\nimport { isSelector, isValue } from \"./processors\";\nimport { mapKeys, 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\ntype Instance = Node<unknown>;\n\ntype Props = object;\ntype TextInstance = Node<unknown>;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = Container;\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 appendNode = (parent: Node<unknown>, child: Node<unknown>) => {\n parent.addChild(child);\n};\n\nconst removeNode = (parent: Node<unknown>, child: Node<unknown>) => {\n return parent.removeChild(child);\n};\n\nconst insertBefore = (\n parent: Node<unknown>,\n child: Node<unknown>,\n before: Node<unknown>\n) => {\n parent.insertChildBefore(child, before);\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 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.root, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Container) => {\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 pristineProps,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n const props = { ...pristineProps };\n const node = createNode(container, type, materialize(props));\n container.depMgr.subscribeNode(node, props);\n return 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 resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.depMgr.update();\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) {\n return null;\n }\n debug(\"update \", type);\n return rootContainerInstance;\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)) {\n return;\n }\n const props = { ...nextProps };\n updatePayload.depMgr.unsubscribeNode(instance);\n instance.setProps(materialize(props));\n updatePayload.depMgr.subscribeNode(instance, props);\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.root.children().forEach((child) => {\n container.root.removeChild(child);\n });\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (container, child) => {\n removeNode(container.root, child);\n },\n\n insertInContainerBefore: (container, child, before) => {\n insertBefore(container.root, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n // see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n getCurrentEventPriority: () => DefaultEventPriority,\n beforeActiveInstanceBlur: () => {},\n afterActiveInstanceBlur: () => {},\n detachDeletedInstance: () => {},\n};\n\nconst materialize = <P>(props: AnimatedProps<P>) => {\n const result = { ...props } as P;\n mapKeys(props).forEach((key) => {\n const prop = props[key];\n if (isValue(prop)) {\n result[key] = (prop as SkiaValue<P[typeof key]>).current;\n } else if (isSelector(prop)) {\n result[key] = prop.selector(prop.value.current) as P[typeof key];\n }\n });\n\n return result;\n};\n"],"mappings":"AAAA;AAEA,SAASA,oBAAT,QAAqC,4BAArC;AAMA,SAASC,UAAT,QAA2B,kBAA3B;AAEA,SAASC,UAAT,EAAqBC,OAArB,QAAoC,cAApC;AACA,SAASC,OAAT,EAAkBC,SAAlB,QAAmC,aAAnC;AAEA,MAAMC,KAAK,GAAG,KAAd;AACA,OAAO,MAAMC,KAAK,GAAG,YAA6C;EAChE,IAAID,KAAJ,EAAW;IACTE,OAAO,CAACC,GAAR,CAAY,YAAZ;EACD;AACF,CAJM;;AAmCP,MAAMC,UAAU,GAAG,CAACC,MAAD,EAAwBC,KAAxB,KAAiD;EAClED,MAAM,CAACE,QAAP,CAAgBD,KAAhB;AACD,CAFD;;AAIA,MAAME,UAAU,GAAG,CAACH,MAAD,EAAwBC,KAAxB,KAAiD;EAClE,OAAOD,MAAM,CAACI,WAAP,CAAmBH,KAAnB,CAAP;AACD,CAFD;;AAIA,MAAMI,YAAY,GAAG,CACnBL,MADmB,EAEnBC,KAFmB,EAGnBK,MAHmB,KAIhB;EACHN,MAAM,CAACO,iBAAP,CAAyBN,KAAzB,EAAgCK,MAAhC;AACD,CAND;;AAQA,OAAO,MAAME,YAA4B,GAAG;EAC1C;AACF;AACA;EACEC,GAAG,EAAEC,IAAI,CAACD,GAJgC;EAK1CE,gBAAgB,EAAE,IALwB;EAM1CC,iBAAiB,EAAE,KANuB;EAO1CC,mBAAmB,EAAE,KAPqB;EAQ1CC,iBAAiB,EAAE,KARuB;EAS1C;EAEAC,eAAe,EAAEC,UAXyB;EAY1CC,aAAa,EAAEC,YAZ2B;EAa1CC,SAAS,EAAE,CAAC,CAb8B;;EAe1CC,sBAAsB,CAACC,SAAD,EAAYpB,KAAZ,EAAmB;IACvCL,KAAK,CAAC,wBAAD,EAA2ByB,SAA3B,EAAsCpB,KAAtC,CAAL;IACAF,UAAU,CAACsB,SAAS,CAACC,IAAX,EA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AAE,MAAMzF,oBA7KW;EA8K1C0F,wBAAwB,EAAE,MAAM,CAAE,CA9KQ;EA+K1CC,uBAAuB,EAAE,MAAM,CAAE,CA/KS;EAgL1CC,qBAAqB,EAAE,MAAM,CAAE;AAhLW,CAArC;;AAmLP,MAAMxC,WAAW,GAAOF,KAAJ,IAAgC;EAClD,MAAM2C,MAAM,GAAG,EAAE,GAAG3C;EAAL,CAAf;EACA9C,OAAO,CAAC8C,KAAD,CAAP,CAAemC,OAAf,CAAwBS,GAAD,IAAS;IAC9B,MAAMC,IAAI,GAAG7C,KAAK,CAAC4C,GAAD,CAAlB;;IACA,IAAI3F,OAAO,CAAC4F,IAAD,CAAX,EAAmB;MACjBF,MAAM,CAACC,GAAD,CAAN,GAAeC,IAAD,CAAmCC,OAAjD;IACD,CAFD,MAEO,IAAI9F,UAAU,CAAC6F,IAAD,CAAd,EAAsB;MAC3BF,MAAM,CAACC,GAAD,CAAN,GAAcC,IAAI,CAACE,QAAL,CAAcF,IAAI,CAACG,KAAL,CAAWF,OAAzB,CAAd;IACD;EACF,CAPD;EASA,OAAOH,MAAP;AACD,CAZD"}
|
1
|
+
{"version":3,"names":["DefaultEventPriority","bindReanimatedProps","extractReanimatedProps","createNode","isSelector","isValue","mapKeys","shallowEq","DEBUG","debug","console","log","appendNode","parent","child","addChild","removeNode","removeChild","insertBefore","before","insertChildBefore","skHostConfig","now","Date","supportsMutation","isPrimaryRenderer","supportsPersistence","supportsHydration","scheduleTimeout","setTimeout","cancelTimeout","clearTimeout","noTimeout","appendChildToContainer","container","root","appendChild","getRootHostContext","_rootContainerInstance","getChildHostContext","_parentHostContext","_type","shouldSetTextContent","_props","createTextInstance","_text","_hostContext","_internalInstanceHandle","Error","createInstance","type","pristineProps","props","reanimatedProps","node","materialize","depMgr","subscribeNode","appendInitialChild","parentInstance","finalizeInitialChildren","commitMount","prepareForCommit","_containerInfo","resetAfterCommit","update","redraw","getPublicInstance","prepareUpdate","_instance","oldProps","newProps","rootContainerInstance","propsAreEqual","commitUpdate","instance","updatePayload","prevProps","nextProps","_internalHandle","unsubscribeNode","setProps","commitTextUpdate","_textInstance","_oldText","_newText","clearContainer","children","forEach","preparePortalMount","removeChildFromContainer","insertInContainerBefore","getCurrentEventPriority","beforeActiveInstanceBlur","afterActiveInstanceBlur","detachDeletedInstance","result","key","prop","current","selector","value"],"sources":["HostConfig.ts"],"sourcesContent":["/*global NodeJS*/\nimport type { HostConfig } from \"react-reconciler\";\nimport { DefaultEventPriority } from \"react-reconciler/constants\";\n\nimport type { NodeType, Node } from \"../dom/types\";\nimport type { SkiaValue } from \"../values\";\nimport {\n bindReanimatedProps,\n extractReanimatedProps,\n} from \"../external/reanimated\";\n\nimport type { Container } from \"./Container\";\nimport { createNode } from \"./HostComponents\";\nimport type { AnimatedProps } from \"./processors\";\nimport { isSelector, isValue } from \"./processors\";\nimport { mapKeys, 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\ntype Instance = Node<unknown>;\n\ntype Props = object;\ntype TextInstance = Node<unknown>;\ntype SuspenseInstance = Instance;\ntype HydratableInstance = Instance;\ntype PublicInstance = Instance;\ntype HostContext = null;\ntype UpdatePayload = Container;\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 appendNode = (parent: Node<unknown>, child: Node<unknown>) => {\n parent.addChild(child);\n};\n\nconst removeNode = (parent: Node<unknown>, child: Node<unknown>) => {\n return parent.removeChild(child);\n};\n\nconst insertBefore = (\n parent: Node<unknown>,\n child: Node<unknown>,\n before: Node<unknown>\n) => {\n parent.insertChildBefore(child, before);\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 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.root, child);\n },\n\n appendChild(parent, child) {\n debug(\"appendChild\", parent, child);\n appendNode(parent, child);\n },\n\n getRootHostContext: (_rootContainerInstance: Container) => {\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 pristineProps,\n container,\n _hostContext,\n _internalInstanceHandle\n ) {\n debug(\"createInstance\", type);\n const [props, reanimatedProps] = extractReanimatedProps(pristineProps);\n const node = createNode(container, type, materialize(props));\n bindReanimatedProps(container, node, reanimatedProps);\n container.depMgr.subscribeNode(node, props);\n return 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 resetAfterCommit(container) {\n debug(\"resetAfterCommit\");\n container.depMgr.update();\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) {\n return null;\n }\n debug(\"update \", type);\n return rootContainerInstance;\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)) {\n return;\n }\n const [props, reanimatedProps] = extractReanimatedProps(nextProps);\n updatePayload.depMgr.unsubscribeNode(instance);\n instance.setProps(materialize(props));\n bindReanimatedProps(updatePayload, instance, reanimatedProps);\n updatePayload.depMgr.subscribeNode(instance, props);\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.root.children().forEach((child) => {\n container.root.removeChild(child);\n });\n },\n\n preparePortalMount: () => {\n debug(\"preparePortalMount\");\n },\n\n removeChild: (parent, child) => {\n removeNode(parent, child);\n },\n\n removeChildFromContainer: (container, child) => {\n removeNode(container.root, child);\n },\n\n insertInContainerBefore: (container, child, before) => {\n insertBefore(container.root, child, before);\n },\n\n insertBefore: (parent, child, before) => {\n insertBefore(parent, child, before);\n },\n // see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-expect-error\n getCurrentEventPriority: () => DefaultEventPriority,\n beforeActiveInstanceBlur: () => {},\n afterActiveInstanceBlur: () => {},\n detachDeletedInstance: () => {},\n};\n\nconst materialize = <P>(props: AnimatedProps<P>) => {\n const result = { ...props } as P;\n mapKeys(props).forEach((key) => {\n const prop = props[key];\n if (isValue(prop)) {\n result[key] = (prop as SkiaValue<P[typeof key]>).current;\n } else if (isSelector(prop)) {\n result[key] = prop.selector(prop.value.current) as P[typeof key];\n }\n });\n\n return result;\n};\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1CD,YAAY,EAAE,CAACL,MAAD,EAASC,KAAT,EAAgBK,MAAhB,KAA2B;IACvCD,YAAY,CAACL,MAAD,EAASC,KAAT,EAAgBK,MAAhB,CAAZ;EACD,CA3KyC;EA4K1C;EACA;EACA;EACAyE,uBAAuB,EAAE,MAAM5F,oBA/KW;EAgL1C6F,wBAAwB,EAAE,MAAM,CAAE,CAhLQ;EAiL1CC,uBAAuB,EAAE,MAAM,CAAE,CAjLS;EAkL1CC,qBAAqB,EAAE,MAAM,CAAE;AAlLW,CAArC;;AAqLP,MAAMxC,WAAW,GAAOH,KAAJ,IAAgC;EAClD,MAAM4C,MAAM,GAAG,EAAE,GAAG5C;EAAL,CAAf;EACA9C,OAAO,CAAC8C,KAAD,CAAP,CAAeoC,OAAf,CAAwBS,GAAD,IAAS;IAC9B,MAAMC,IAAI,GAAG9C,KAAK,CAAC6C,GAAD,CAAlB;;IACA,IAAI5F,OAAO,CAAC6F,IAAD,CAAX,EAAmB;MACjBF,MAAM,CAACC,GAAD,CAAN,GAAeC,IAAD,CAAmCC,OAAjD;IACD,CAFD,MAEO,IAAI/F,UAAU,CAAC8F,IAAD,CAAd,EAAsB;MAC3BF,MAAM,CAACC,GAAD,CAAN,GAAcC,IAAI,CAACE,QAAL,CAAcF,IAAI,CAACG,KAAL,CAAWF,OAAzB,CAAd;IACD;EACF,CAPD;EASA,OAAOH,MAAP;AACD,CAZD"}
|
@@ -5,7 +5,7 @@ declare type RegisterValues = (values: Array<SkiaValue<unknown>>) => () => void;
|
|
5
5
|
export declare class SkiaRoot {
|
6
6
|
private root;
|
7
7
|
private container;
|
8
|
-
constructor(Skia: Skia, registerValues?: RegisterValues, redraw?: () => void);
|
8
|
+
constructor(Skia: Skia, registerValues?: RegisterValues, redraw?: () => void, getNativeId?: () => number);
|
9
9
|
render(element: ReactNode): void;
|
10
10
|
unmount(): void;
|
11
11
|
get dom(): import("..").RenderNode<import("..").GroupProps>;
|
@@ -17,13 +17,14 @@ export class SkiaRoot {
|
|
17
17
|
constructor(Skia) {
|
18
18
|
let registerValues = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => () => {};
|
19
19
|
let redraw = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : () => {};
|
20
|
+
let getNativeId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : () => 0;
|
20
21
|
|
21
22
|
_defineProperty(this, "root", void 0);
|
22
23
|
|
23
24
|
_defineProperty(this, "container", void 0);
|
24
25
|
|
25
26
|
const depMgr = createDependencyManager(registerValues);
|
26
|
-
this.container = new Container(Skia, depMgr, redraw);
|
27
|
+
this.container = new Container(Skia, depMgr, redraw, getNativeId);
|
27
28
|
this.root = skiaReconciler.createContainer(this.container, 0, null, true, null, "", console.error, null);
|
28
29
|
}
|
29
30
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["ReactReconciler","DependencyManager","skHostConfig","debug","hostDebug","Container","skiaReconciler","createDependencyManager","registerValues","global","SkiaDomApi","injectIntoDevTools","bundleType","version","rendererPackageName","SkiaRoot","constructor","Skia","redraw","depMgr","container","root","createContainer","console","error","render","element","updateContainer","unmount","remove","dom"],"sources":["Reconciler.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport type { Skia } from \"../skia/types\";\nimport type { SkiaValue } from \"../values/types\";\n\nimport { DependencyManager } from \"./DependencyManager\";\nimport { skHostConfig, debug as hostDebug } from \"./HostConfig\";\nimport { Container } from \"./Container\";\n\nconst skiaReconciler = ReactReconciler(skHostConfig);\n\ntype RegisterValues = (values: Array<SkiaValue<unknown>>) => () => void;\n\nconst createDependencyManager = (registerValues: RegisterValues) =>\n global.SkiaDomApi && global.SkiaDomApi.DependencyManager\n ? global.SkiaDomApi.DependencyManager(registerValues)\n : new DependencyManager(registerValues);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nexport class SkiaRoot {\n private root: OpaqueRoot;\n private container: Container;\n\n constructor(\n Skia: Skia,\n registerValues: RegisterValues = () => () => {},\n redraw: () => void = () => {}\n ) {\n const depMgr = createDependencyManager(registerValues);\n this.container = new Container(Skia, depMgr, redraw);\n this.root = skiaReconciler.createContainer(\n this.container,\n 0,\n null,\n true,\n null,\n \"\",\n console.error,\n null\n );\n }\n\n render(element: ReactNode) {\n skiaReconciler.updateContainer(element, this.root, null, () => {\n hostDebug(\"updateContainer\");\n });\n }\n\n unmount() {\n skiaReconciler.updateContainer(null, this.root, null, () => {\n this.container.depMgr.remove();\n });\n }\n\n get dom() {\n return this.container.root;\n }\n}\n"],"mappings":";;AAEA,OAAOA,eAAP,MAA4B,kBAA5B;AAKA,SAASC,iBAAT,QAAkC,qBAAlC;AACA,SAASC,YAAT,EAAuBC,KAAK,IAAIC,SAAhC,QAAiD,cAAjD;AACA,SAASC,SAAT,QAA0B,aAA1B;AAEA,MAAMC,cAAc,GAAGN,eAAe,CAACE,YAAD,CAAtC;;AAIA,MAAMK,uBAAuB,GAAIC,cAAD,IAC9BC,MAAM,CAACC,UAAP,IAAqBD,MAAM,CAACC,UAAP,CAAkBT,iBAAvC,GACIQ,MAAM,CAACC,UAAP,CAAkBT,iBAAlB,CAAoCO,cAApC,CADJ,GAEI,IAAIP,iBAAJ,CAAsBO,cAAtB,CAHN;;AAKAF,cAAc,CAACK,kBAAf,CAAkC;EAChCC,UAAU,EAAE,CADoB;EAEhCC,OAAO,EAAE,OAFuB;EAGhCC,mBAAmB,EAAE;AAHW,CAAlC;AAMA,OAAO,MAAMC,QAAN,CAAe;EAIpBC,WAAW,CACTC,IADS,
|
1
|
+
{"version":3,"names":["ReactReconciler","DependencyManager","skHostConfig","debug","hostDebug","Container","skiaReconciler","createDependencyManager","registerValues","global","SkiaDomApi","injectIntoDevTools","bundleType","version","rendererPackageName","SkiaRoot","constructor","Skia","redraw","getNativeId","depMgr","container","root","createContainer","console","error","render","element","updateContainer","unmount","remove","dom"],"sources":["Reconciler.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { OpaqueRoot } from \"react-reconciler\";\nimport ReactReconciler from \"react-reconciler\";\n\nimport type { Skia } from \"../skia/types\";\nimport type { SkiaValue } from \"../values/types\";\n\nimport { DependencyManager } from \"./DependencyManager\";\nimport { skHostConfig, debug as hostDebug } from \"./HostConfig\";\nimport { Container } from \"./Container\";\n\nconst skiaReconciler = ReactReconciler(skHostConfig);\n\ntype RegisterValues = (values: Array<SkiaValue<unknown>>) => () => void;\n\nconst createDependencyManager = (registerValues: RegisterValues) =>\n global.SkiaDomApi && global.SkiaDomApi.DependencyManager\n ? global.SkiaDomApi.DependencyManager(registerValues)\n : new DependencyManager(registerValues);\n\nskiaReconciler.injectIntoDevTools({\n bundleType: 1,\n version: \"0.0.1\",\n rendererPackageName: \"react-native-skia\",\n});\n\nexport class SkiaRoot {\n private root: OpaqueRoot;\n private container: Container;\n\n constructor(\n Skia: Skia,\n registerValues: RegisterValues = () => () => {},\n redraw: () => void = () => {},\n getNativeId: () => number = () => 0\n ) {\n const depMgr = createDependencyManager(registerValues);\n this.container = new Container(Skia, depMgr, redraw, getNativeId);\n this.root = skiaReconciler.createContainer(\n this.container,\n 0,\n null,\n true,\n null,\n \"\",\n console.error,\n null\n );\n }\n\n render(element: ReactNode) {\n skiaReconciler.updateContainer(element, this.root, null, () => {\n hostDebug(\"updateContainer\");\n });\n }\n\n unmount() {\n skiaReconciler.updateContainer(null, this.root, null, () => {\n this.container.depMgr.remove();\n });\n }\n\n get dom() {\n return this.container.root;\n }\n}\n"],"mappings":";;AAEA,OAAOA,eAAP,MAA4B,kBAA5B;AAKA,SAASC,iBAAT,QAAkC,qBAAlC;AACA,SAASC,YAAT,EAAuBC,KAAK,IAAIC,SAAhC,QAAiD,cAAjD;AACA,SAASC,SAAT,QAA0B,aAA1B;AAEA,MAAMC,cAAc,GAAGN,eAAe,CAACE,YAAD,CAAtC;;AAIA,MAAMK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AHC,GAAG,GAAG;IACR,OAAO,KAAKV,SAAL,CAAeC,IAAtB;EACD;;AAtCmB"}
|
@@ -1,11 +1,14 @@
|
|
1
1
|
import type { SkiaSelector, SkiaValue } from "../../../values";
|
2
|
+
export declare type SharedValueType<T = number> = {
|
3
|
+
value: T;
|
4
|
+
};
|
2
5
|
export declare const isValue: (value: unknown) => value is SkiaValue<unknown>;
|
3
6
|
export declare const isSelector: <T, R>(value: unknown) => value is {
|
4
7
|
selector: (v: T) => R;
|
5
8
|
value: SkiaValue<T>;
|
6
9
|
};
|
7
10
|
export declare const isAnimated: <T>(props: AnimatedProps<T, never>) => boolean;
|
8
|
-
export declare type AnimatedProp<T, P = any> = T | SkiaValue<T> | SkiaSelector<T, P>;
|
11
|
+
export declare type AnimatedProp<T, P = any> = T | SkiaValue<T> | SkiaSelector<T, P> | SharedValueType<T>;
|
9
12
|
export declare type AnimatedProps<T, O extends keyof T | never = never> = {
|
10
13
|
[K in keyof T]: K extends "children" ? T[K] : K extends O ? T[K] : AnimatedProp<T[K]>;
|
11
14
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["isValue","value","undefined","__typename__","isSelector","selector","isAnimated","props","Object","values"],"sources":["Animations.ts"],"sourcesContent":["import type { SkiaSelector, SkiaValue } from \"../../../values\";\n\nexport const isValue = (value: unknown): value is SkiaValue<unknown> => {\n if (value === undefined || value === null) {\n return false;\n }\n try {\n if (\n typeof value === \"object\" &&\n \"__typename__\" in value &&\n (value as unknown as SkiaValue<unknown>).__typename__ === \"RNSkValue\"\n ) {\n return true;\n }\n } catch {}\n return false;\n};\n\nexport const isSelector = <T, R>(\n value: unknown\n): value is {\n selector: (v: T) => R;\n value: SkiaValue<T>;\n} => {\n if (value) {\n return (\n typeof value === \"object\" &&\n \"selector\" in value &&\n \"value\" in value &&\n (value as Record<string, unknown>).selector !== undefined &&\n (value as Record<string, unknown>).value !== undefined\n );\n }\n return false;\n};\n\nexport const isAnimated = <T>(props: AnimatedProps<T>) => {\n for (const value of Object.values(props)) {\n if (isValue(value) || isSelector(value)) {\n return true;\n }\n }\n return false;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnimatedProp<T, P = any>
|
1
|
+
{"version":3,"names":["isValue","value","undefined","__typename__","isSelector","selector","isAnimated","props","Object","values"],"sources":["Animations.ts"],"sourcesContent":["import type { SkiaSelector, SkiaValue } from \"../../../values\";\n\nexport type SharedValueType<T = number> = {\n value: T;\n};\n\nexport const isValue = (value: unknown): value is SkiaValue<unknown> => {\n if (value === undefined || value === null) {\n return false;\n }\n try {\n if (\n typeof value === \"object\" &&\n \"__typename__\" in value &&\n (value as unknown as SkiaValue<unknown>).__typename__ === \"RNSkValue\"\n ) {\n return true;\n }\n } catch {}\n return false;\n};\n\nexport const isSelector = <T, R>(\n value: unknown\n): value is {\n selector: (v: T) => R;\n value: SkiaValue<T>;\n} => {\n if (value) {\n return (\n typeof value === \"object\" &&\n \"selector\" in value &&\n \"value\" in value &&\n (value as Record<string, unknown>).selector !== undefined &&\n (value as Record<string, unknown>).value !== undefined\n );\n }\n return false;\n};\n\nexport const isAnimated = <T>(props: AnimatedProps<T>) => {\n for (const value of Object.values(props)) {\n if (isValue(value) || isSelector(value)) {\n return true;\n }\n }\n return false;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type AnimatedProp<T, P = any> =\n | T\n | SkiaValue<T>\n | SkiaSelector<T, P>\n | SharedValueType<T>;\n\nexport type AnimatedProps<T, O extends keyof T | never = never> = {\n [K in keyof T]: K extends \"children\"\n ? T[K]\n : K extends O\n ? T[K]\n : AnimatedProp<T[K]>;\n};\n\nexport type SkiaProps<\n P = object,\n O extends keyof P | never = never\n> = AnimatedProps<P, O>;\n\ntype WithOptional<T extends object, N extends keyof T> = Omit<T, N> & {\n [K in N]?: T[K];\n};\n\nexport type SkiaDefaultProps<\n T extends object,\n N extends keyof T\n> = WithOptional<SkiaProps<T>, N>;\n"],"mappings":"AAMA,OAAO,MAAMA,OAAO,GAAIC,KAAD,IAAiD;EACtE,IAAIA,KAAK,KAAKC,SAAV,IAAuBD,KAAK,KAAK,IAArC,EAA2C;IACzC,OAAO,KAAP;EACD;;EACD,IAAI;IACF,IACE,OAAOA,KAAP,KAAiB,QAAjB,IACA,kBAAkBA,KADlB,IAECA,KAAD,CAAyCE,YAAzC,KAA0D,WAH5D,EAIE;MACA,OAAO,IAAP;IACD;EACF,CARD,CAQE,MAAM,CAAE;;EACV,OAAO,KAAP;AACD,CAdM;AAgBP,OAAO,MAAMC,UAAU,GACrBH,KADwB,IAKrB;EACH,IAAIA,KAAJ,EAAW;IACT,OACE,OAAOA,KAAP,KAAiB,QAAjB,IACA,cAAcA,KADd,IAEA,WAAWA,KAFX,IAGCA,KAAD,CAAmCI,QAAnC,KAAgDH,SAHhD,IAICD,KAAD,CAAmCA,KAAnC,KAA6CC,SAL/C;EAOD;;EACD,OAAO,KAAP;AACD,CAhBM;AAkBP,OAAO,MAAMI,UAAU,GAAOC,KAAJ,IAAgC;EACxD,KAAK,MAAMN,KAAX,IAAoBO,MAAM,CAACC,MAAP,CAAcF,KAAd,CAApB,EAA0C;IACxC,IAAIP,OAAO,CAACC,KAAD,CAAP,IAAkBG,UAAU,CAACH,KAAD,CAAhC,EAAyC;MACvC,OAAO,IAAP;IACD;EACF;;EACD,OAAO,KAAP;AACD,CAPM,C,CASP"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import type { SharedValueType } from "../../renderer/processors/Animations";
|
2
|
+
export declare const HAS_REANIMATED2: boolean;
|
3
|
+
export declare const HAS_REANIMATED3: boolean;
|
4
|
+
export declare const useSharedValue: any;
|
5
|
+
export declare const startMapper: any;
|
6
|
+
export declare const stopMapper: any;
|
7
|
+
export declare const runOnJS: any;
|
8
|
+
export declare const isSharedValue: <T>(value: unknown) => value is SharedValueType<T>;
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import type { Container } from "../../renderer/Container";
|
2
|
+
import type { AnimatedProps } from "../../renderer/processors";
|
3
|
+
import type { Node } from "../../dom/types";
|
4
|
+
export declare function extractReanimatedProps(props: AnimatedProps<any>): AnimatedProps<any, never>[];
|
5
|
+
export declare function bindReanimatedProps(container: Container, node: Node<any>, reanimatedProps: AnimatedProps<any>): void;
|
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
value: T;
|
3
|
-
};
|
1
|
+
import type { SharedValueType } from "../../renderer/processors/Animations";
|
4
2
|
/**
|
5
3
|
* Connects a shared value from reanimated to a SkiaView or Canvas
|
6
4
|
* so whenever the shared value changes the SkiaView will redraw.
|
7
5
|
* @param cb Callback that will be called whenever the shared value changes.
|
8
6
|
* @param values One or more shared values to listen for.
|
9
7
|
*/
|
10
|
-
export declare const useSharedValueEffect: <T = number>(cb: () => void, value:
|
11
|
-
export {};
|
8
|
+
export declare const useSharedValueEffect: <T = number>(cb: () => void, value: SharedValueType<T>, ...values: SharedValueType<T>[]) => void;
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { Skia as SkiaApi } from "../skia/types";
|
2
2
|
import type * as SkiaExports from "../skia";
|
3
|
-
import type * as ExternalExports from "../external";
|
4
3
|
import type * as ValueExports from "../values";
|
5
4
|
import type * as AnimationExports from "../animation";
|
6
5
|
import { ShaderLib } from "../renderer/components/shaders/ShaderLib";
|
@@ -9,7 +8,7 @@ export declare const vec: (x?: number, y?: number) => {
|
|
9
8
|
x: number;
|
10
9
|
y: number;
|
11
10
|
};
|
12
|
-
export declare const Mock: typeof SkiaExports & typeof
|
11
|
+
export declare const Mock: typeof SkiaExports & typeof ValueExports & typeof AnimationExports & {
|
13
12
|
createDrawing: () => any;
|
14
13
|
createDeclaration: () => any;
|
15
14
|
ShaderLib: typeof ShaderLib;
|
@@ -4,9 +4,10 @@ import type { DependencyManager } from "./DependencyManager";
|
|
4
4
|
export declare class Container {
|
5
5
|
depMgr: DependencyManager;
|
6
6
|
redraw: () => void;
|
7
|
+
getNativeId: () => number;
|
7
8
|
private _root;
|
8
9
|
Sk: SkDOM;
|
9
|
-
constructor(Skia: Skia, depMgr: DependencyManager, redraw?: () => void);
|
10
|
+
constructor(Skia: Skia, depMgr: DependencyManager, redraw?: () => void, getNativeId?: () => number);
|
10
11
|
draw(ctx: DrawingContext): void;
|
11
12
|
get root(): RenderNode<GroupProps>;
|
12
13
|
}
|
@@ -5,7 +5,7 @@ declare type RegisterValues = (values: Array<SkiaValue<unknown>>) => () => void;
|
|
5
5
|
export declare class SkiaRoot {
|
6
6
|
private root;
|
7
7
|
private container;
|
8
|
-
constructor(Skia: Skia, registerValues?: RegisterValues, redraw?: () => void);
|
8
|
+
constructor(Skia: Skia, registerValues?: RegisterValues, redraw?: () => void, getNativeId?: () => number);
|
9
9
|
render(element: ReactNode): void;
|
10
10
|
unmount(): void;
|
11
11
|
get dom(): import("..").RenderNode<import("..").GroupProps>;
|
@@ -1,11 +1,14 @@
|
|
1
1
|
import type { SkiaSelector, SkiaValue } from "../../../values";
|
2
|
+
export declare type SharedValueType<T = number> = {
|
3
|
+
value: T;
|
4
|
+
};
|
2
5
|
export declare const isValue: (value: unknown) => value is SkiaValue<unknown>;
|
3
6
|
export declare const isSelector: <T, R>(value: unknown) => value is {
|
4
7
|
selector: (v: T) => R;
|
5
8
|
value: SkiaValue<T>;
|
6
9
|
};
|
7
10
|
export declare const isAnimated: <T>(props: AnimatedProps<T, never>) => boolean;
|
8
|
-
export declare type AnimatedProp<T, P = any> = T | SkiaValue<T> | SkiaSelector<T, P>;
|
11
|
+
export declare type AnimatedProp<T, P = any> = T | SkiaValue<T> | SkiaSelector<T, P> | SharedValueType<T>;
|
9
12
|
export declare type AnimatedProps<T, O extends keyof T | never = never> = {
|
10
13
|
[K in keyof T]: K extends "children" ? T[K] : K extends O ? T[K] : AnimatedProp<T[K]>;
|
11
14
|
};
|
package/package.json
CHANGED
@@ -103,15 +103,21 @@ export class DisplacementMapImageFilterNode extends ImageFilterDeclaration<Displ
|
|
103
103
|
}
|
104
104
|
|
105
105
|
decorate(ctx: DeclarationContext) {
|
106
|
+
this.decorateChildren(ctx);
|
106
107
|
const { channelX, channelY, scale } = this.props;
|
108
|
+
const shader = ctx.shaders.pop();
|
109
|
+
if (!shader) {
|
110
|
+
throw new Error("DisplacementMap expects a shader as child");
|
111
|
+
}
|
112
|
+
const map = this.Skia.ImageFilter.MakeShader(shader, null);
|
107
113
|
const imgf = this.Skia.ImageFilter.MakeDisplacementMap(
|
108
114
|
ColorChannel[enumKey(channelX)],
|
109
115
|
ColorChannel[enumKey(channelY)],
|
110
116
|
scale,
|
111
|
-
|
117
|
+
map,
|
112
118
|
this.input(ctx)
|
113
119
|
);
|
114
|
-
|
120
|
+
ctx.imageFilters.push(imgf);
|
115
121
|
}
|
116
122
|
}
|
117
123
|
|
@@ -0,0 +1,60 @@
|
|
1
|
+
import { useMemo } from "react";
|
2
|
+
|
3
|
+
import type { SharedValueType } from "../../renderer/processors/Animations";
|
4
|
+
|
5
|
+
// This one is needed for the deprecated useSharedValue function
|
6
|
+
// We can remove it once we remove the deprecation
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
8
|
+
let Reanimated2: any;
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
10
|
+
let Reanimated3: any;
|
11
|
+
let reanimatedVersion: string;
|
12
|
+
|
13
|
+
try {
|
14
|
+
Reanimated2 = require("react-native-reanimated");
|
15
|
+
reanimatedVersion =
|
16
|
+
// eslint-disable-next-line import/extensions
|
17
|
+
require("react-native-reanimated/package.json").version;
|
18
|
+
if (
|
19
|
+
reanimatedVersion &&
|
20
|
+
(reanimatedVersion >= "3.0.0" || reanimatedVersion.includes("3.0.0-"))
|
21
|
+
) {
|
22
|
+
Reanimated3 = Reanimated2;
|
23
|
+
}
|
24
|
+
} catch (e) {}
|
25
|
+
|
26
|
+
export const HAS_REANIMATED2 = !!Reanimated2;
|
27
|
+
export const HAS_REANIMATED3 = !!Reanimated3;
|
28
|
+
|
29
|
+
function throwOnMissingReanimated2() {
|
30
|
+
if (!HAS_REANIMATED2) {
|
31
|
+
throw new Error(
|
32
|
+
"Reanimated was not found, make sure react-native-reanimated package is installed if you want to use \
|
33
|
+
react-naitve-skia's integration layer API."
|
34
|
+
);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
function throwOnMissingReanimated3() {
|
39
|
+
if (!HAS_REANIMATED3) {
|
40
|
+
throw new Error(
|
41
|
+
`Reanimated version ${reanimatedVersion} is not supported, please upgrade to 3.0.0 or newer.`
|
42
|
+
);
|
43
|
+
}
|
44
|
+
throwOnMissingReanimated2();
|
45
|
+
}
|
46
|
+
|
47
|
+
export const useSharedValue =
|
48
|
+
Reanimated2?.useSharedValue ||
|
49
|
+
((value: number) => useMemo(() => ({ value }), [value]));
|
50
|
+
|
51
|
+
export const startMapper =
|
52
|
+
Reanimated2?.startMapper || throwOnMissingReanimated2;
|
53
|
+
export const stopMapper = Reanimated2?.stopMapper || throwOnMissingReanimated2;
|
54
|
+
export const runOnJS = Reanimated2?.runOnJS || throwOnMissingReanimated2;
|
55
|
+
export const isSharedValue = <T>(
|
56
|
+
value: unknown
|
57
|
+
): value is SharedValueType<T> => {
|
58
|
+
throwOnMissingReanimated3();
|
59
|
+
return !!value && Reanimated3.isSharedValue(value);
|
60
|
+
};
|
@@ -0,0 +1,70 @@
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
2
|
+
/* eslint-disable reanimated/js-function-in-worklet */
|
3
|
+
import type { Container } from "../../renderer/Container";
|
4
|
+
import type { AnimatedProps } from "../../renderer/processors";
|
5
|
+
import type { Node } from "../../dom/types";
|
6
|
+
|
7
|
+
import {
|
8
|
+
startMapper,
|
9
|
+
stopMapper,
|
10
|
+
isSharedValue,
|
11
|
+
HAS_REANIMATED3,
|
12
|
+
} from "./moduleWrapper";
|
13
|
+
|
14
|
+
const _bindings = new WeakMap<Node<unknown>, unknown>();
|
15
|
+
|
16
|
+
export function extractReanimatedProps(props: AnimatedProps<any>) {
|
17
|
+
if (!HAS_REANIMATED3) {
|
18
|
+
return [props, {}];
|
19
|
+
}
|
20
|
+
const reanimatedProps = {} as AnimatedProps<any>;
|
21
|
+
const otherProps = {} as AnimatedProps<any>;
|
22
|
+
for (const propName in props) {
|
23
|
+
if (propName === "children") {
|
24
|
+
continue;
|
25
|
+
}
|
26
|
+
const propValue = props[propName];
|
27
|
+
if (isSharedValue(propValue)) {
|
28
|
+
reanimatedProps[propName] = propValue;
|
29
|
+
otherProps[propName] = propValue.value;
|
30
|
+
} else {
|
31
|
+
otherProps[propName] = propValue;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
return [otherProps, reanimatedProps];
|
35
|
+
}
|
36
|
+
|
37
|
+
export function bindReanimatedProps(
|
38
|
+
container: Container,
|
39
|
+
node: Node<any>,
|
40
|
+
reanimatedProps: AnimatedProps<any>
|
41
|
+
) {
|
42
|
+
if (!HAS_REANIMATED3) {
|
43
|
+
return;
|
44
|
+
}
|
45
|
+
const sharedValues = Object.values(reanimatedProps);
|
46
|
+
const previousMapperId = _bindings.get(node);
|
47
|
+
if (previousMapperId !== undefined) {
|
48
|
+
stopMapper(previousMapperId);
|
49
|
+
}
|
50
|
+
if (sharedValues.length > 0) {
|
51
|
+
const viewId = container.getNativeId();
|
52
|
+
const { SkiaViewApi } = global;
|
53
|
+
const mapperId = startMapper(() => {
|
54
|
+
"worklet";
|
55
|
+
for (const propName in reanimatedProps) {
|
56
|
+
node && node.setProp(propName, reanimatedProps[propName].value);
|
57
|
+
}
|
58
|
+
// On React Native we use the SkiaViewApi to redraw because it can
|
59
|
+
// run on the worklet thread (container.redraw can't)
|
60
|
+
// if SkiaViewApi is undefined, we are on web and container.redraw()
|
61
|
+
// can safely be invoked
|
62
|
+
if (SkiaViewApi) {
|
63
|
+
SkiaViewApi.requestRedraw(viewId);
|
64
|
+
} else {
|
65
|
+
container.redraw();
|
66
|
+
}
|
67
|
+
}, sharedValues);
|
68
|
+
_bindings.set(node, mapperId);
|
69
|
+
}
|
70
|
+
}
|
@@ -1,22 +1,14 @@
|
|
1
|
-
import { useEffect
|
1
|
+
import { useEffect } from "react";
|
2
2
|
|
3
|
-
|
4
|
-
let Reanimated: any;
|
3
|
+
import type { SharedValueType } from "../../renderer/processors/Animations";
|
5
4
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
value: T;
|
14
|
-
};
|
15
|
-
|
16
|
-
const useSharedValueWrapper =
|
17
|
-
Reanimated?.useSharedValue === undefined
|
18
|
-
? (value: number) => useMemo(() => ({ value }), [value])
|
19
|
-
: Reanimated.useSharedValue;
|
5
|
+
import {
|
6
|
+
HAS_REANIMATED2,
|
7
|
+
useSharedValue,
|
8
|
+
runOnJS,
|
9
|
+
startMapper,
|
10
|
+
stopMapper,
|
11
|
+
} from "./moduleWrapper";
|
20
12
|
|
21
13
|
/**
|
22
14
|
* Connects a shared value from reanimated to a SkiaView or Canvas
|
@@ -26,19 +18,21 @@ const useSharedValueWrapper =
|
|
26
18
|
*/
|
27
19
|
export const useSharedValueEffect = <T = number>(
|
28
20
|
cb: () => void,
|
29
|
-
value:
|
30
|
-
...values:
|
21
|
+
value: SharedValueType<T>,
|
22
|
+
...values: SharedValueType<T>[]
|
31
23
|
) => {
|
32
|
-
|
24
|
+
console.warn(
|
25
|
+
`useSharedValueEffect() is now deprecated, you can use Reanimated values directly.
|
26
|
+
Learn more at https://shopify.github.io/react-native-skia/.`
|
27
|
+
);
|
28
|
+
const input = useSharedValue(0);
|
33
29
|
|
34
30
|
useEffect(() => {
|
35
|
-
if (!
|
31
|
+
if (!HAS_REANIMATED2) {
|
36
32
|
console.warn(
|
37
33
|
"Reanimated was not found and the useSharedValueEffect hook will have no effect."
|
38
34
|
);
|
39
35
|
} else {
|
40
|
-
const { runOnJS, startMapper, stopMapper } = Reanimated;
|
41
|
-
|
42
36
|
// Start a mapper in Reanimated
|
43
37
|
const mapperId = startMapper(
|
44
38
|
() => {
|
@@ -0,0 +1,31 @@
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
2
|
+
// @ts-ignore
|
3
|
+
import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
|
4
|
+
import type { ReactNode } from "react";
|
5
|
+
|
6
|
+
import { JsiSkApi } from "../skia/web";
|
7
|
+
import { SkiaRoot } from "../renderer/Reconciler";
|
8
|
+
import { JsiDrawingContext } from "../dom/types";
|
9
|
+
|
10
|
+
export * from "../renderer/components";
|
11
|
+
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
13
|
+
let Skia: any;
|
14
|
+
|
15
|
+
export const draw = (element: ReactNode, width: number, height: number) => {
|
16
|
+
if (!Skia) {
|
17
|
+
Skia = JsiSkApi(CanvasKit);
|
18
|
+
}
|
19
|
+
const surface = Skia.Surface.MakeOffscreen(width, height);
|
20
|
+
if (surface === null) {
|
21
|
+
throw new Error("Couldn't create surface!");
|
22
|
+
}
|
23
|
+
const root = new SkiaRoot(Skia);
|
24
|
+
root.render(element);
|
25
|
+
const canvas = surface.getCanvas();
|
26
|
+
const ctx = new JsiDrawingContext(Skia, canvas);
|
27
|
+
root.dom.render(ctx);
|
28
|
+
surface.flush();
|
29
|
+
const image = surface.makeImageSnapshot();
|
30
|
+
return image;
|
31
|
+
};
|
package/src/mock/index.ts
CHANGED
@@ -6,10 +6,8 @@ import * as ValuesHooks from "../values/hooks";
|
|
6
6
|
import { Selector } from "../values/selector";
|
7
7
|
import * as BaseSkia from "../skia/types";
|
8
8
|
import type * as SkiaExports from "../skia";
|
9
|
-
import type * as ExternalExports from "../external";
|
10
9
|
import type * as ValueExports from "../values";
|
11
10
|
import type * as AnimationExports from "../animation";
|
12
|
-
import { useSharedValueEffect } from "../external/reanimated/useSharedValueEffect";
|
13
11
|
import * as timingFunctions from "../animation/timing";
|
14
12
|
import * as springFunctions from "../animation/spring";
|
15
13
|
import * as decayFunctions from "../animation/decay";
|
@@ -35,7 +33,6 @@ export const Skia: SkiaApi = new Stub() as any;
|
|
35
33
|
export const vec = (x?: number, y?: number) => ({ x: x ?? 0, y: y ?? x ?? 0 });
|
36
34
|
|
37
35
|
export const Mock: typeof SkiaExports &
|
38
|
-
typeof ExternalExports &
|
39
36
|
typeof ValueExports &
|
40
37
|
typeof AnimationExports & {
|
41
38
|
createDrawing: () => any;
|
@@ -82,8 +79,6 @@ export const Mock: typeof SkiaExports &
|
|
82
79
|
bottomRight: Noop,
|
83
80
|
center: Noop,
|
84
81
|
processTransform2d: Noop,
|
85
|
-
// ExternalExports
|
86
|
-
useSharedValueEffect,
|
87
82
|
// ValueExports
|
88
83
|
...Values,
|
89
84
|
...ValuesHooks,
|
package/src/renderer/Canvas.tsx
CHANGED
@@ -37,6 +37,10 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
|
37
37
|
const redraw = useCallback(() => {
|
38
38
|
innerRef.current?.redraw();
|
39
39
|
}, [innerRef]);
|
40
|
+
const getNativeId = useCallback(() => {
|
41
|
+
const id = innerRef.current?.nativeId ?? -1;
|
42
|
+
return id;
|
43
|
+
}, [innerRef]);
|
40
44
|
|
41
45
|
const registerValues = useCallback(
|
42
46
|
(values: Array<SkiaValue<unknown>>) => {
|
@@ -48,8 +52,8 @@ export const Canvas = forwardRef<SkiaDomView, CanvasProps>(
|
|
48
52
|
[ref]
|
49
53
|
);
|
50
54
|
const root = useMemo(
|
51
|
-
() => new SkiaRoot(Skia, registerValues, redraw),
|
52
|
-
[redraw, registerValues]
|
55
|
+
() => new SkiaRoot(Skia, registerValues, redraw, getNativeId),
|
56
|
+
[redraw, registerValues, getNativeId]
|
53
57
|
);
|
54
58
|
|
55
59
|
// Render effect
|
@@ -15,7 +15,8 @@ export class Container {
|
|
15
15
|
constructor(
|
16
16
|
Skia: Skia,
|
17
17
|
public depMgr: DependencyManager,
|
18
|
-
public redraw: () => void = () => {}
|
18
|
+
public redraw: () => void = () => {},
|
19
|
+
public getNativeId: () => number = () => 0
|
19
20
|
) {
|
20
21
|
this.Sk = new JsiSkDOM({ Skia, depMgr });
|
21
22
|
this._root = this.Sk.Group();
|
@@ -4,6 +4,10 @@ import { DefaultEventPriority } from "react-reconciler/constants";
|
|
4
4
|
|
5
5
|
import type { NodeType, Node } from "../dom/types";
|
6
6
|
import type { SkiaValue } from "../values";
|
7
|
+
import {
|
8
|
+
bindReanimatedProps,
|
9
|
+
extractReanimatedProps,
|
10
|
+
} from "../external/reanimated";
|
7
11
|
|
8
12
|
import type { Container } from "./Container";
|
9
13
|
import { createNode } from "./HostComponents";
|
@@ -121,8 +125,9 @@ export const skHostConfig: SkiaHostConfig = {
|
|
121
125
|
_internalInstanceHandle
|
122
126
|
) {
|
123
127
|
debug("createInstance", type);
|
124
|
-
const props =
|
128
|
+
const [props, reanimatedProps] = extractReanimatedProps(pristineProps);
|
125
129
|
const node = createNode(container, type, materialize(props));
|
130
|
+
bindReanimatedProps(container, node, reanimatedProps);
|
126
131
|
container.depMgr.subscribeNode(node, props);
|
127
132
|
return node;
|
128
133
|
},
|
@@ -193,9 +198,10 @@ export const skHostConfig: SkiaHostConfig = {
|
|
193
198
|
if (shallowEq(prevProps, nextProps)) {
|
194
199
|
return;
|
195
200
|
}
|
196
|
-
const props =
|
201
|
+
const [props, reanimatedProps] = extractReanimatedProps(nextProps);
|
197
202
|
updatePayload.depMgr.unsubscribeNode(instance);
|
198
203
|
instance.setProps(materialize(props));
|
204
|
+
bindReanimatedProps(updatePayload, instance, reanimatedProps);
|
199
205
|
updatePayload.depMgr.subscribeNode(instance, props);
|
200
206
|
},
|
201
207
|
|
@@ -31,10 +31,11 @@ export class SkiaRoot {
|
|
31
31
|
constructor(
|
32
32
|
Skia: Skia,
|
33
33
|
registerValues: RegisterValues = () => () => {},
|
34
|
-
redraw: () => void = () => {}
|
34
|
+
redraw: () => void = () => {},
|
35
|
+
getNativeId: () => number = () => 0
|
35
36
|
) {
|
36
37
|
const depMgr = createDependencyManager(registerValues);
|
37
|
-
this.container = new Container(Skia, depMgr, redraw);
|
38
|
+
this.container = new Container(Skia, depMgr, redraw, getNativeId);
|
38
39
|
this.root = skiaReconciler.createContainer(
|
39
40
|
this.container,
|
40
41
|
0,
|