@shopify/react-native-skia 0.1.156 → 0.1.158

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/android/build.gradle +10 -5
  2. package/cpp/api/JsiSkContourMeasure.h +7 -5
  3. package/lib/commonjs/dom/nodes/DrawingNode.js +1 -5
  4. package/lib/commonjs/dom/nodes/DrawingNode.js.map +1 -1
  5. package/lib/commonjs/dom/nodes/RenderNode.js +2 -8
  6. package/lib/commonjs/dom/nodes/RenderNode.js.map +1 -1
  7. package/lib/commonjs/dom/nodes/drawings/Text.js +4 -9
  8. package/lib/commonjs/dom/nodes/drawings/Text.js.map +1 -1
  9. package/lib/commonjs/dom/types/Common.js.map +1 -1
  10. package/lib/commonjs/dom/types/Drawings.js.map +1 -1
  11. package/lib/commonjs/mock/index.js +0 -1
  12. package/lib/commonjs/mock/index.js.map +1 -1
  13. package/lib/commonjs/renderer/Canvas.js +10 -2
  14. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  15. package/lib/commonjs/renderer/HostComponents.js.map +1 -1
  16. package/lib/commonjs/renderer/HostConfig.js +10 -1
  17. package/lib/commonjs/renderer/HostConfig.js.map +1 -1
  18. package/lib/commonjs/renderer/components/Mask.js +1 -3
  19. package/lib/commonjs/renderer/components/Mask.js.map +1 -1
  20. package/lib/commonjs/renderer/components/Paint.js +5 -18
  21. package/lib/commonjs/renderer/components/Paint.js.map +1 -1
  22. package/lib/commonjs/renderer/useCanvas.js +18 -2
  23. package/lib/commonjs/renderer/useCanvas.js.map +1 -1
  24. package/lib/commonjs/skia/core/Picture.js +1 -24
  25. package/lib/commonjs/skia/core/Picture.js.map +1 -1
  26. package/lib/commonjs/skia/core/Rect.js +1 -1
  27. package/lib/commonjs/skia/core/Rect.js.map +1 -1
  28. package/lib/commonjs/skia/types/ContourMeasure.js.map +1 -1
  29. package/lib/commonjs/skia/types/Size.js +2 -0
  30. package/lib/commonjs/skia/types/Size.js.map +1 -0
  31. package/lib/commonjs/skia/types/index.js +13 -0
  32. package/lib/commonjs/skia/types/index.js.map +1 -1
  33. package/lib/commonjs/skia/web/JsiSkColor.js +8 -0
  34. package/lib/commonjs/skia/web/JsiSkColor.js.map +1 -1
  35. package/lib/commonjs/skia/web/JsiSkContourMeasure.js +4 -7
  36. package/lib/commonjs/skia/web/JsiSkContourMeasure.js.map +1 -1
  37. package/lib/commonjs/values/web/RNSkReadonlyValue.js +4 -2
  38. package/lib/commonjs/values/web/RNSkReadonlyValue.js.map +1 -1
  39. package/lib/commonjs/views/SkiaBaseWebView.js +2 -2
  40. package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
  41. package/lib/module/animation/spring/runSpring.js +1 -1
  42. package/lib/module/animation/spring/runSpring.js.map +1 -1
  43. package/lib/module/animation/spring/useSpring.js +1 -1
  44. package/lib/module/animation/spring/useSpring.js.map +1 -1
  45. package/lib/module/animation/timing/createTiming.js +6 -2
  46. package/lib/module/animation/timing/createTiming.js.map +1 -1
  47. package/lib/module/animation/timing/functions/getResolvedParams.js +10 -6
  48. package/lib/module/animation/timing/functions/getResolvedParams.js.map +1 -1
  49. package/lib/module/animation/timing/useTiming.js +3 -1
  50. package/lib/module/animation/timing/useTiming.js.map +1 -1
  51. package/lib/module/dom/nodes/DrawingNode.js +2 -6
  52. package/lib/module/dom/nodes/DrawingNode.js.map +1 -1
  53. package/lib/module/dom/nodes/JsiSkDOM.js +2 -2
  54. package/lib/module/dom/nodes/JsiSkDOM.js.map +1 -1
  55. package/lib/module/dom/nodes/RenderNode.js +1 -4
  56. package/lib/module/dom/nodes/RenderNode.js.map +1 -1
  57. package/lib/module/dom/nodes/datatypes/Gradient.js +2 -2
  58. package/lib/module/dom/nodes/datatypes/Gradient.js.map +1 -1
  59. package/lib/module/dom/nodes/drawings/Text.js +4 -9
  60. package/lib/module/dom/nodes/drawings/Text.js.map +1 -1
  61. package/lib/module/dom/nodes/paint/Shaders.js +4 -2
  62. package/lib/module/dom/nodes/paint/Shaders.js.map +1 -1
  63. package/lib/module/dom/types/Common.js.map +1 -1
  64. package/lib/module/dom/types/Drawings.js.map +1 -1
  65. package/lib/module/mock/index.js +10 -7
  66. package/lib/module/mock/index.js.map +1 -1
  67. package/lib/module/renderer/Canvas.js +10 -2
  68. package/lib/module/renderer/Canvas.js.map +1 -1
  69. package/lib/module/renderer/HostComponents.js.map +1 -1
  70. package/lib/module/renderer/HostConfig.js +9 -1
  71. package/lib/module/renderer/HostConfig.js.map +1 -1
  72. package/lib/module/renderer/components/Mask.js +2 -4
  73. package/lib/module/renderer/components/Mask.js.map +1 -1
  74. package/lib/module/renderer/components/Paint.js +3 -14
  75. package/lib/module/renderer/components/Paint.js.map +1 -1
  76. package/lib/module/renderer/useCanvas.js +13 -0
  77. package/lib/module/renderer/useCanvas.js.map +1 -1
  78. package/lib/module/skia/core/Picture.js +0 -18
  79. package/lib/module/skia/core/Picture.js.map +1 -1
  80. package/lib/module/skia/core/Rect.js +1 -1
  81. package/lib/module/skia/core/Rect.js.map +1 -1
  82. package/lib/module/skia/core/Vector.js +1 -1
  83. package/lib/module/skia/core/Vector.js.map +1 -1
  84. package/lib/module/skia/types/ContourMeasure.js.map +1 -1
  85. package/lib/module/skia/types/Size.js +2 -0
  86. package/lib/module/skia/types/Size.js.map +1 -0
  87. package/lib/module/skia/types/index.js +1 -0
  88. package/lib/module/skia/types/index.js.map +1 -1
  89. package/lib/module/skia/web/Host.js +1 -1
  90. package/lib/module/skia/web/Host.js.map +1 -1
  91. package/lib/module/skia/web/JsiSkColor.js +8 -0
  92. package/lib/module/skia/web/JsiSkColor.js.map +1 -1
  93. package/lib/module/skia/web/JsiSkContourMeasure.js +3 -7
  94. package/lib/module/skia/web/JsiSkContourMeasure.js.map +1 -1
  95. package/lib/module/skia/web/JsiSkMatrix.js +1 -1
  96. package/lib/module/skia/web/JsiSkMatrix.js.map +1 -1
  97. package/lib/module/values/web/RNSkAnimation.js +2 -2
  98. package/lib/module/values/web/RNSkAnimation.js.map +1 -1
  99. package/lib/module/values/web/RNSkReadonlyValue.js +4 -2
  100. package/lib/module/values/web/RNSkReadonlyValue.js.map +1 -1
  101. package/lib/module/views/SkiaBaseWebView.js +5 -3
  102. package/lib/module/views/SkiaBaseWebView.js.map +1 -1
  103. package/lib/module/views/useTouchHandler.js +6 -6
  104. package/lib/module/views/useTouchHandler.js.map +1 -1
  105. package/lib/module/web/WithSkiaWeb.js +1 -1
  106. package/lib/module/web/WithSkiaWeb.js.map +1 -1
  107. package/lib/typescript/src/dom/nodes/RenderNode.d.ts +1 -3
  108. package/lib/typescript/src/dom/types/Common.d.ts +2 -3
  109. package/lib/typescript/src/dom/types/Drawings.d.ts +1 -3
  110. package/lib/typescript/src/renderer/Canvas.d.ts +4 -1
  111. package/lib/typescript/src/renderer/HostComponents.d.ts +1 -5
  112. package/lib/typescript/src/renderer/components/Paint.d.ts +3 -4
  113. package/lib/typescript/src/renderer/useCanvas.d.ts +1 -0
  114. package/lib/typescript/src/skia/core/Picture.d.ts +0 -8
  115. package/lib/typescript/src/skia/types/ContourMeasure.d.ts +3 -2
  116. package/lib/typescript/src/skia/types/Size.d.ts +4 -0
  117. package/lib/typescript/src/skia/types/index.d.ts +1 -0
  118. package/lib/typescript/src/skia/web/JsiSkContourMeasure.d.ts +2 -6
  119. package/package.json +12 -6
  120. package/src/dom/nodes/DrawingNode.ts +2 -4
  121. package/src/dom/nodes/RenderNode.ts +1 -13
  122. package/src/dom/nodes/drawings/Text.ts +4 -4
  123. package/src/dom/types/Common.ts +2 -4
  124. package/src/dom/types/Drawings.ts +1 -4
  125. package/src/mock/index.ts +0 -1
  126. package/src/renderer/Canvas.tsx +18 -3
  127. package/src/renderer/HostComponents.ts +1 -4
  128. package/src/renderer/HostConfig.ts +8 -1
  129. package/src/renderer/components/Mask.tsx +2 -2
  130. package/src/renderer/components/Paint.tsx +3 -14
  131. package/src/renderer/useCanvas.ts +14 -0
  132. package/src/skia/core/Picture.ts +0 -24
  133. package/src/skia/core/Rect.ts +1 -1
  134. package/src/skia/types/ContourMeasure.tsx +3 -2
  135. package/src/skia/types/Size.ts +4 -0
  136. package/src/skia/types/index.ts +1 -0
  137. package/src/skia/web/JsiSkColor.ts +11 -0
  138. package/src/skia/web/JsiSkContourMeasure.ts +7 -3
  139. package/src/values/web/RNSkReadonlyValue.ts +4 -2
  140. package/src/views/SkiaBaseWebView.tsx +2 -2
@@ -12,7 +12,7 @@ const useInternalTouchHandler = function (handlers) {
12
12
  history.forEach(touches => {
13
13
  // Enumerate touches
14
14
  for (let i = 0; i < touches.length; i++) {
15
- var _prevTouchInfoRef$cur, _prevVelocityRef$curr, _prevVelocityRef$curr2;
15
+ var _prevTouchInfoRef$cur, _prevTouchInfoRef$cur2, _prevTouch$x, _prevTouch$y, _prevVelocityRef$curr, _prevVelocityRef$curr2, _prevVelocityRef$curr3, _prevVelocityRef$curr4;
16
16
 
17
17
  if (!multiTouch && i > 0) {
18
18
  break;
@@ -21,9 +21,9 @@ const useInternalTouchHandler = function (handlers) {
21
21
  const touch = touches[i];
22
22
  const prevTouch = prevTouchInfoRef.current[touch.id]; // Calculate the velocity from the previous touch.
23
23
 
24
- const timeDiffseconds = touch.timestamp - (((_prevTouchInfoRef$cur = prevTouchInfoRef.current[touch.id]) === null || _prevTouchInfoRef$cur === void 0 ? void 0 : _prevTouchInfoRef$cur.timestamp) ?? touch.timestamp);
25
- const distX = touch.x - ((prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.x) ?? touch.x);
26
- const distY = touch.y - ((prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.y) ?? touch.y);
24
+ const timeDiffseconds = touch.timestamp - ((_prevTouchInfoRef$cur = (_prevTouchInfoRef$cur2 = prevTouchInfoRef.current[touch.id]) === null || _prevTouchInfoRef$cur2 === void 0 ? void 0 : _prevTouchInfoRef$cur2.timestamp) !== null && _prevTouchInfoRef$cur !== void 0 ? _prevTouchInfoRef$cur : touch.timestamp);
25
+ const distX = touch.x - ((_prevTouch$x = prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.x) !== null && _prevTouch$x !== void 0 ? _prevTouch$x : touch.x);
26
+ const distY = touch.y - ((_prevTouch$y = prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.y) !== null && _prevTouch$y !== void 0 ? _prevTouch$y : touch.y);
27
27
 
28
28
  if (touch.type !== TouchType.Start && touch.type !== TouchType.End && touch.type !== TouchType.Cancelled && timeDiffseconds > 0) {
29
29
  prevVelocityRef.current[touch.id] = {
@@ -33,8 +33,8 @@ const useInternalTouchHandler = function (handlers) {
33
33
  }
34
34
 
35
35
  const extendedTouchInfo = { ...touch,
36
- velocityX: ((_prevVelocityRef$curr = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr === void 0 ? void 0 : _prevVelocityRef$curr.x) ?? 0,
37
- velocityY: ((_prevVelocityRef$curr2 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr2 === void 0 ? void 0 : _prevVelocityRef$curr2.y) ?? 0
36
+ velocityX: (_prevVelocityRef$curr = (_prevVelocityRef$curr2 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr2 === void 0 ? void 0 : _prevVelocityRef$curr2.x) !== null && _prevVelocityRef$curr !== void 0 ? _prevVelocityRef$curr : 0,
37
+ velocityY: (_prevVelocityRef$curr3 = (_prevVelocityRef$curr4 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr4 === void 0 ? void 0 : _prevVelocityRef$curr4.y) !== null && _prevVelocityRef$curr3 !== void 0 ? _prevVelocityRef$curr3 : 0
38
38
  }; // Save previous touch
39
39
 
40
40
  prevTouchInfoRef.current[touch.id] = touch;
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useRef","PixelRatio","TouchType","useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","prevTouch","current","id","timeDiffseconds","timestamp","distX","x","distY","y","type","Start","End","Cancelled","get","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"sources":["useTouchHandler.ts"],"sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback, useRef } from \"react\";\nimport { PixelRatio } from \"react-native\";\n\nimport type { Vector } from \"../skia/types\";\n\nimport type {\n ExtendedTouchInfo,\n TouchHandlers,\n TouchHandler,\n TouchInfo,\n} from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst useInternalTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = [],\n multiTouch = false\n): TouchHandler => {\n const prevTouchInfoRef = useRef<{ [key: number]: TouchInfo | undefined }>({});\n const prevVelocityRef = useRef<{ [key: number]: Vector | undefined }>({});\n\n return useCallback((history: Array<Array<TouchInfo>>) => {\n // Process all items in the current touch history\n history.forEach((touches) => {\n // Enumerate touches\n for (let i = 0; i < touches.length; i++) {\n if (!multiTouch && i > 0) {\n break;\n }\n\n const touch = touches[i];\n const prevTouch = prevTouchInfoRef.current[touch.id];\n // Calculate the velocity from the previous touch.\n const timeDiffseconds =\n touch.timestamp -\n (prevTouchInfoRef.current[touch.id]?.timestamp ?? touch.timestamp);\n\n const distX = touch.x - (prevTouch?.x ?? touch.x);\n const distY = touch.y - (prevTouch?.y ?? touch.y);\n\n if (\n touch.type !== TouchType.Start &&\n touch.type !== TouchType.End &&\n touch.type !== TouchType.Cancelled &&\n timeDiffseconds > 0\n ) {\n prevVelocityRef.current[touch.id] = {\n x: distX / timeDiffseconds / PixelRatio.get(),\n y: distY / timeDiffseconds / PixelRatio.get(),\n };\n }\n\n const extendedTouchInfo: ExtendedTouchInfo = {\n ...touch,\n velocityX: prevVelocityRef.current[touch.id]?.x ?? 0,\n velocityY: prevVelocityRef.current[touch.id]?.y ?? 0,\n };\n\n // Save previous touch\n prevTouchInfoRef.current[touch.id] = touch;\n\n if (touch.type === TouchType.Start) {\n delete prevVelocityRef.current[touch.id];\n handlers.onStart && handlers.onStart(touch);\n } else if (touch.type === TouchType.Active) {\n handlers.onActive && handlers.onActive(extendedTouchInfo);\n } else {\n handlers.onEnd && handlers.onEnd(extendedTouchInfo);\n }\n }\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler only handles single touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, false);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler handles multiple touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useMultiTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, true);\n};\n"],"mappings":"AACA,SAASA,WAAT,EAAsBC,MAAtB,QAAoC,OAApC;AACA,SAASC,UAAT,QAA2B,cAA3B;AAUA,SAASC,SAAT,QAA0B,SAA1B;;AAEA,MAAMC,uBAAuB,GAAG,UAC9BC,QAD8B,EAIb;EAAA,IAFjBC,IAEiB,uEAFM,EAEN;EAAA,IADjBC,UACiB,uEADJ,KACI;EACjB,MAAMC,gBAAgB,GAAGP,MAAM,CAA2C,EAA3C,CAA/B;EACA,MAAMQ,eAAe,GAAGR,MAAM,CAAwC,EAAxC,CAA9B;EAEA,OAAOD,WAAW,CAAEU,OAAD,IAAsC;IACvD;IACAA,OAAO,CAACC,OAAR,CAAiBC,OAAD,IAAa;MAC3B;MACA,KAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,OAAO,CAACE,MAA5B,EAAoCD,CAAC,EAArC,EAAyC;QAAA;;QACvC,IAAI,CAACN,UAAD,IAAeM,CAAC,G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,eAAe,CAACQ,OAAhB,CAAwBF,KAAK,CAACG,EAA9B,mFAAmCM,CAAnC,KAAwC;QAHR,CAA7C,CA3BuC,CAiCvC;;QACAhB,gBAAgB,CAACS,OAAjB,CAAyBF,KAAK,CAACG,EAA/B,IAAqCH,KAArC;;QAEA,IAAIA,KAAK,CAACU,IAAN,KAAetB,SAAS,CAACuB,KAA7B,EAAoC;UAClC,OAAOjB,eAAe,CAACQ,OAAhB,CAAwBF,KAAK,CAACG,EAA9B,CAAP;UACAb,QAAQ,CAAC4B,OAAT,IAAoB5B,QAAQ,CAAC4B,OAAT,CAAiBlB,KAAjB,CAApB;QACD,CAHD,MAGO,IAAIA,KAAK,CAACU,IAAN,KAAetB,SAAS,CAAC+B,MAA7B,EAAqC;UAC1C7B,QAAQ,CAAC8B,QAAT,IAAqB9B,QAAQ,CAAC8B,QAAT,CAAkBL,iBAAlB,CAArB;QACD,CAFM,MAEA;UACLzB,QAAQ,CAAC+B,KAAT,IAAkB/B,QAAQ,CAAC+B,KAAT,CAAeN,iBAAf,CAAlB;QACD;MACF;IACF,CA/CD,EAFuD,CAkDvD;EACD,CAnDiB,EAmDfxB,IAnDe,CAAlB;AAoDD,CA5DD;AA8DA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAM+B,eAAe,GAAG,UAC7BhC,QAD6B,EAGZ;EAAA,IADjBC,IACiB,uEADM,EACN;EACjB,OAAOF,uBAAuB,CAACC,QAAD,EAAWC,IAAX,EAAiB,KAAjB,CAA9B;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMgC,oBAAoB,GAAG,UAClCjC,QADkC,EAGjB;EAAA,IADjBC,IACiB,uEADM,EACN;EACjB,OAAOF,uBAAuB,CAACC,QAAD,EAAWC,IAAX,EAAiB,IAAjB,CAA9B;AACD,CALM"}
1
+ {"version":3,"names":["useCallback","useRef","PixelRatio","TouchType","useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","prevTouch","current","id","timeDiffseconds","timestamp","distX","x","distY","y","type","Start","End","Cancelled","get","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"sources":["useTouchHandler.ts"],"sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback, useRef } from \"react\";\nimport { PixelRatio } from \"react-native\";\n\nimport type { Vector } from \"../skia/types\";\n\nimport type {\n ExtendedTouchInfo,\n TouchHandlers,\n TouchHandler,\n TouchInfo,\n} from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst useInternalTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = [],\n multiTouch = false\n): TouchHandler => {\n const prevTouchInfoRef = useRef<{ [key: number]: TouchInfo | undefined }>({});\n const prevVelocityRef = useRef<{ [key: number]: Vector | undefined }>({});\n\n return useCallback((history: Array<Array<TouchInfo>>) => {\n // Process all items in the current touch history\n history.forEach((touches) => {\n // Enumerate touches\n for (let i = 0; i < touches.length; i++) {\n if (!multiTouch && i > 0) {\n break;\n }\n\n const touch = touches[i];\n const prevTouch = prevTouchInfoRef.current[touch.id];\n // Calculate the velocity from the previous touch.\n const timeDiffseconds =\n touch.timestamp -\n (prevTouchInfoRef.current[touch.id]?.timestamp ?? touch.timestamp);\n\n const distX = touch.x - (prevTouch?.x ?? touch.x);\n const distY = touch.y - (prevTouch?.y ?? touch.y);\n\n if (\n touch.type !== TouchType.Start &&\n touch.type !== TouchType.End &&\n touch.type !== TouchType.Cancelled &&\n timeDiffseconds > 0\n ) {\n prevVelocityRef.current[touch.id] = {\n x: distX / timeDiffseconds / PixelRatio.get(),\n y: distY / timeDiffseconds / PixelRatio.get(),\n };\n }\n\n const extendedTouchInfo: ExtendedTouchInfo = {\n ...touch,\n velocityX: prevVelocityRef.current[touch.id]?.x ?? 0,\n velocityY: prevVelocityRef.current[touch.id]?.y ?? 0,\n };\n\n // Save previous touch\n prevTouchInfoRef.current[touch.id] = touch;\n\n if (touch.type === TouchType.Start) {\n delete prevVelocityRef.current[touch.id];\n handlers.onStart && handlers.onStart(touch);\n } else if (touch.type === TouchType.Active) {\n handlers.onActive && handlers.onActive(extendedTouchInfo);\n } else {\n handlers.onEnd && handlers.onEnd(extendedTouchInfo);\n }\n }\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler only handles single touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, false);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler handles multiple touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useMultiTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, true);\n};\n"],"mappings":"AACA,SAASA,WAAT,EAAsBC,MAAtB,QAAoC,OAApC;AACA,SAASC,UAAT,QAA2B,cAA3B;AAUA,SAASC,SAAT,QAA0B,SAA1B;;AAEA,MAAMC,uBAAuB,GAAG,UAC9BC,QAD8B,EAIb;EAAA,IAFjBC,IAEiB,uEAFM,EAEN;EAAA,IADjBC,UACiB,uEADJ,KACI;EACjB,MAAMC,gBAAgB,GAAGP,MAAM,CAA2C,EAA3C,CAA/B;EACA,MAAMQ,eAAe,GAAGR,MAAM,CAAwC,EAAxC,CAA9B;EAEA,OAAOD,WAAW,CAAEU,OAAD,IAAsC;IACvD;IACAA,OAAO,CAACC,OAAR,CAAiBC,OAAD,IAAa;MAC3B;MACA,KAAK,IAAIC,C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,CAACC,QAAD,EAAWC,IAAX,EAAiB,IAAjB,CAA9B;AACD,CALM"}
@@ -19,7 +19,7 @@ export const WithSkiaWeb = _ref => {
19
19
  return getComponent();
20
20
  }), [getComponent, opts]);
21
21
  return /*#__PURE__*/React.createElement(Suspense, {
22
- fallback: fallback ?? null
22
+ fallback: fallback !== null && fallback !== void 0 ? fallback : null
23
23
  }, /*#__PURE__*/React.createElement(Inner, null));
24
24
  };
25
25
  //# sourceMappingURL=WithSkiaWeb.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["React","useMemo","lazy","Suspense","Platform","LoadSkiaWeb","WithSkiaWeb","getComponent","fallback","opts","Inner","OS","console","warn"],"sources":["WithSkiaWeb.tsx"],"sourcesContent":["import type { ComponentProps, ComponentType } from \"react\";\nimport React, { useMemo, lazy, Suspense } from \"react\";\nimport { Platform } from \"react-native\";\n\nimport { LoadSkiaWeb } from \"./LoadSkiaWeb\";\n\ninterface WithSkiaProps {\n fallback?: ComponentProps<typeof Suspense>[\"fallback\"];\n getComponent: () => Promise<{ default: ComponentType }>;\n opts?: Parameters<typeof LoadSkiaWeb>[0];\n}\n\nexport const WithSkiaWeb = ({\n getComponent,\n fallback,\n opts,\n}: WithSkiaProps) => {\n const Inner = useMemo(\n // TODO: investigate\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (): any =>\n lazy(async () => {\n if (Platform.OS === \"web\") {\n await LoadSkiaWeb(opts);\n } else {\n console.warn(\n \"<WithSkiaWeb /> is only necessary on web. Consider not using on native.\"\n );\n }\n return getComponent();\n }),\n [getComponent, opts]\n );\n return (\n <Suspense fallback={fallback ?? null}>\n <Inner />\n </Suspense>\n );\n};\n"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,OAAhB,EAAyBC,IAAzB,EAA+BC,QAA/B,QAA+C,OAA/C;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA,SAASC,WAAT,QAA4B,eAA5B;AAQA,OAAO,MAAMC,WAAW,GAAG,QAIN;EAAA,IAJO;IAC1BC,YAD0B;IAE1BC,QAF0B;IAG1BC;EAH0B,CAIP;EACnB,MAAMC,KAAK,GAAGT,OAAO,EACnB;EACA;EACA,mBACEC,IAAI,CAAC,YAAY;IACf,IAAIE,QAAQ,CAACO,EAAT,KAAgB,KAApB,EAA2B;MACzB,MAAMN,WAAW,CAACI,IAAD,CAAjB;IACD,CAFD,MAEO;MACLG,OAAO,CAACC,IAAR,CACE,yEADF;IAGD;;IACD,OAAON,YAAY,EAAnB;EACD,CATG,CAJa,EAcnB,CAACA,YAAD,EAAeE,IAAf,CAdmB,CAArB;EAgBA,oBACE,oBAAC,QAAD;IAAU,QAAQ,EAAED,QAAQ,IAAI;EAAhC,gBACE,oBAAC,KAAD,OADF,CADF;AAKD,CA1BM"}
1
+ {"version":3,"names":["React","useMemo","lazy","Suspense","Platform","LoadSkiaWeb","WithSkiaWeb","getComponent","fallback","opts","Inner","OS","console","warn"],"sources":["WithSkiaWeb.tsx"],"sourcesContent":["import type { ComponentProps, ComponentType } from \"react\";\nimport React, { useMemo, lazy, Suspense } from \"react\";\nimport { Platform } from \"react-native\";\n\nimport { LoadSkiaWeb } from \"./LoadSkiaWeb\";\n\ninterface WithSkiaProps {\n fallback?: ComponentProps<typeof Suspense>[\"fallback\"];\n getComponent: () => Promise<{ default: ComponentType }>;\n opts?: Parameters<typeof LoadSkiaWeb>[0];\n}\n\nexport const WithSkiaWeb = ({\n getComponent,\n fallback,\n opts,\n}: WithSkiaProps) => {\n const Inner = useMemo(\n // TODO: investigate\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (): any =>\n lazy(async () => {\n if (Platform.OS === \"web\") {\n await LoadSkiaWeb(opts);\n } else {\n console.warn(\n \"<WithSkiaWeb /> is only necessary on web. Consider not using on native.\"\n );\n }\n return getComponent();\n }),\n [getComponent, opts]\n );\n return (\n <Suspense fallback={fallback ?? null}>\n <Inner />\n </Suspense>\n );\n};\n"],"mappings":"AACA,OAAOA,KAAP,IAAgBC,OAAhB,EAAyBC,IAAzB,EAA+BC,QAA/B,QAA+C,OAA/C;AACA,SAASC,QAAT,QAAyB,cAAzB;AAEA,SAASC,WAAT,QAA4B,eAA5B;AAQA,OAAO,MAAMC,WAAW,GAAG,QAIN;EAAA,IAJO;IAC1BC,YAD0B;IAE1BC,QAF0B;IAG1BC;EAH0B,CAIP;EACnB,MAAMC,KAAK,GAAGT,OAAO,EACnB;EACA;EACA,mBACEC,IAAI,CAAC,YAAY;IACf,IAAIE,QAAQ,CAACO,EAAT,KAAgB,KAApB,EAA2B;MACzB,MAAMN,WAAW,CAACI,IAAD,CAAjB;IACD,CAFD,MAEO;MACLG,OAAO,CAACC,IAAR,CACE,yEADF;IAGD;;IACD,OAAON,YAAY,EAAnB;EACD,CATG,CAJa,EAcnB,CAACA,YAAD,EAAeE,IAAf,CAdmB,CAArB;EAgBA,oBACE,oBAAC,QAAD;IAAU,QAAQ,EAAED,QAAF,aAAEA,QAAF,cAAEA,QAAF,GAAc;EAAhC,gBACE,oBAAC,KAAD,OADF,CADF;AAKD,CA1BM"}
@@ -1,6 +1,5 @@
1
- import type { RefObject } from "react";
2
1
  import type { SkMatrix, SkRect, SkRRect, SkPath, SkPaint } from "../../skia/types";
3
- import type { RenderNode, GroupProps, DrawingContext, NodeType, Node, DeclarationNode } from "../types";
2
+ import type { RenderNode, GroupProps, DrawingContext, NodeType, Node } from "../types";
4
3
  import type { NodeContext } from "./Node";
5
4
  import { JsiNode } from "./Node";
6
5
  interface PaintCache {
@@ -25,5 +24,4 @@ export declare abstract class JsiRenderNode<P extends GroupProps> extends JsiNod
25
24
  render(parentCtx: DrawingContext): void;
26
25
  abstract renderNode(ctx: DrawingContext): void;
27
26
  }
28
- export declare const isSkPaint: (obj: RefObject<DeclarationNode<unknown, SkPaint>> | SkPaint) => obj is SkPaint;
29
27
  export {};
@@ -1,6 +1,5 @@
1
- import type { ReactNode, RefObject } from "react";
1
+ import type { ReactNode } from "react";
2
2
  import type { BlendMode, Color, PaintStyle, SkMatrix, SkPaint, SkPath, SkRect, SkRRect, StrokeCap, StrokeJoin, Transforms2d, Vector } from "../../skia/types";
3
- import type { DeclarationNode } from "./Node";
4
3
  export declare type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;
5
4
  export declare type PathDef = string | SkPath;
6
5
  export declare type ClipDef = SkRRect | SkRect | PathDef;
@@ -53,5 +52,5 @@ export interface PaintProps extends ChildrenProps {
53
52
  export interface GroupProps extends PaintProps, TransformProps {
54
53
  clip?: ClipDef;
55
54
  invertClip?: boolean;
56
- layer?: RefObject<DeclarationNode<unknown, SkPaint>> | SkPaint | boolean;
55
+ layer?: SkPaint | boolean;
57
56
  }
@@ -1,10 +1,8 @@
1
- import type { RefObject } from "react";
2
1
  import type { FillType, SkImage, StrokeOpts, Vector, Color, SkPoint, BlendMode, PointMode, VertexMode, SkFont, SkRRect, SkTextBlob, SkPicture, SkSVG, SkPaint, SkRect } from "../../skia/types";
3
2
  import type { CircleDef, Fit, GroupProps, PathDef, RectDef, RRectDef, SkEnum } from "./Common";
4
3
  import type { DrawingContext } from "./DrawingContext";
5
- import type { DeclarationNode } from "./Node";
6
4
  export interface DrawingNodeProps extends GroupProps {
7
- paint?: SkPaint | RefObject<DeclarationNode<unknown, SkPaint>>;
5
+ paint?: SkPaint;
8
6
  }
9
7
  export declare type ImageProps = DrawingNodeProps & RectDef & {
10
8
  fit: Fit;
@@ -3,6 +3,8 @@ import type { RefObject, ReactNode, ComponentProps } from "react";
3
3
  import ReactReconciler from "react-reconciler";
4
4
  import { SkiaView } from "../views";
5
5
  import type { TouchHandler } from "../views";
6
+ import type { SkiaMutableValue } from "../values";
7
+ import type { SkSize } from "../skia/types";
6
8
  import { Container } from "./Container";
7
9
  export declare const skiaReconciler: ReactReconciler.Reconciler<Container, import("..").Node<unknown>, import("..").Node<unknown>, import("..").Node<unknown>, import("..").Node<unknown>>;
8
10
  export declare const useCanvasRef: () => React.RefObject<SkiaView>;
@@ -10,5 +12,6 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
10
12
  ref?: RefObject<SkiaView>;
11
13
  children: ReactNode;
12
14
  onTouch?: TouchHandler;
15
+ onSize?: SkiaMutableValue<SkSize>;
13
16
  }
14
- export declare const Canvas: React.ForwardRefExoticComponent<Pick<CanvasProps, "children" | "style" | "mode" | "debug" | "onDraw" | "hitSlop" | "onLayout" | "pointerEvents" | "removeClippedSubviews" | "testID" | "nativeID" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "onTouch"> & React.RefAttributes<SkiaView>>;
17
+ export declare const Canvas: React.ForwardRefExoticComponent<Pick<CanvasProps, "children" | "style" | "mode" | "debug" | "onDraw" | "hitSlop" | "onLayout" | "pointerEvents" | "removeClippedSubviews" | "testID" | "nativeID" | "collapsable" | "needsOffscreenAlphaCompositing" | "renderToHardwareTextureAndroid" | "focusable" | "shouldRasterizeIOS" | "isTVSelectable" | "hasTVPreferredFocus" | "tvParallaxProperties" | "tvParallaxShiftDistanceX" | "tvParallaxShiftDistanceY" | "tvParallaxTiltAngle" | "tvParallaxMagnification" | "onStartShouldSetResponder" | "onMoveShouldSetResponder" | "onResponderEnd" | "onResponderGrant" | "onResponderReject" | "onResponderMove" | "onResponderRelease" | "onResponderStart" | "onResponderTerminationRequest" | "onResponderTerminate" | "onStartShouldSetResponderCapture" | "onMoveShouldSetResponderCapture" | "onTouchStart" | "onTouchMove" | "onTouchEnd" | "onTouchCancel" | "onTouchEndCapture" | "accessible" | "accessibilityActions" | "accessibilityLabel" | "accessibilityRole" | "accessibilityState" | "accessibilityHint" | "accessibilityValue" | "onAccessibilityAction" | "accessibilityLiveRegion" | "importantForAccessibility" | "accessibilityElementsHidden" | "accessibilityViewIsModal" | "onAccessibilityEscape" | "onAccessibilityTap" | "onMagicTap" | "accessibilityIgnoresInvertColors" | "onTouch" | "onSize"> & React.RefAttributes<SkiaView>>;
@@ -1,9 +1,7 @@
1
- import type { ForwardedRef } from "react";
2
1
  import { NodeType } from "../dom/types";
3
2
  import type { CircleProps, DrawingNodeProps, ImageProps, PaintProps, PathProps, CustomDrawingNodeProps, LineProps, OvalProps, DiffRectProps, PointsProps, RectProps, RoundedRectProps, TextProps, VerticesProps, BlurMaskFilterProps, BlendImageFilterProps, BlurImageFilterProps, DisplacementMapImageFilterProps, DropShadowImageFilterProps, OffsetImageFilterProps, RuntimeShaderImageFilterProps, MatrixColorFilterProps, ShaderProps, ImageShaderProps, LinearGradientProps, GroupProps, PatchProps, BlendColorFilterProps, DashPathEffectProps, DiscretePathEffectProps, CornerPathEffectProps, Line2DPathEffectProps, Path1DPathEffectProps, Path2DPathEffectProps, TextPathProps, TextBlobProps, GlyphsProps, TwoPointConicalGradientProps, TurbulenceProps, SweepGradientProps, RadialGradientProps, ColorProps, PictureProps, ImageSVGProps, LerpColorFilterProps, BoxProps, BoxShadowProps } from "../dom/types";
4
3
  import type { ChildrenProps } from "../dom/types/Common";
5
4
  import type { BlendProps, MorphologyImageFilterProps } from "../dom/types/ImageFilters";
6
- import type { PaintNode } from "../dom/nodes/PaintNode";
7
5
  import type { Container } from "./Container";
8
6
  import type { SkiaProps } from "./processors";
9
7
  declare global {
@@ -11,9 +9,7 @@ declare global {
11
9
  interface IntrinsicElements {
12
10
  skGroup: SkiaProps<GroupProps>;
13
11
  skLayer: SkiaProps<ChildrenProps>;
14
- skPaint: SkiaProps<PaintProps> & {
15
- ref: ForwardedRef<PaintNode>;
16
- };
12
+ skPaint: SkiaProps<PaintProps>;
17
13
  skFill: SkiaProps<DrawingNodeProps>;
18
14
  skImage: SkiaProps<ImageProps>;
19
15
  skCircle: SkiaProps<CircleProps>;
@@ -1,5 +1,4 @@
1
- import React from "react";
1
+ /// <reference types="react" />
2
+ import type { SkiaProps } from "../processors";
2
3
  import type { DrawingNodeProps } from "../../dom/types";
3
- import type { PaintNode } from "../../dom/nodes/PaintNode";
4
- export declare const usePaintRef: () => React.RefObject<PaintNode>;
5
- export declare const Paint: React.ForwardRefExoticComponent<import("../processors").AnimatedProps<DrawingNodeProps, never> & React.RefAttributes<PaintNode>>;
4
+ export declare const Paint: (props: SkiaProps<DrawingNodeProps>) => JSX.Element;
@@ -11,4 +11,5 @@ interface CanvasContext {
11
11
  declare const CanvasContext: React.Context<CanvasContext | null>;
12
12
  export declare const CanvasProvider: React.Provider<CanvasContext | null>;
13
13
  export declare const useCanvas: () => CanvasContext;
14
+ export declare const useSkiaPrivate: () => Skia;
14
15
  export {};
@@ -1,12 +1,4 @@
1
- import type { DependencyList } from "react";
2
1
  import type { SkCanvas, SkRect } from "../types";
3
- /**
4
- * Memoizes and returns an SkPicture that can be drawn to another canvas.
5
- * @param rect Picture bounds
6
- * @param cb Callback for drawing to the canvas
7
- * @returns SkPicture
8
- */
9
- export declare const usePicture: (rect: SkRect, cb: (canvas: SkCanvas) => void, deps?: DependencyList) => import("../types").SkPicture;
10
2
  /**
11
3
  * Memoizes and returns an SkPicture that can be drawn to another canvas.
12
4
  * @param rect Picture bounds
@@ -1,5 +1,6 @@
1
1
  import type { SkJSIInstance } from "./JsiInstance";
2
2
  import type { SkPath } from "./Path/Path";
3
+ import type { SkPoint } from "./Point";
3
4
  export interface PosTan {
4
5
  px: number;
5
6
  py: number;
@@ -9,10 +10,10 @@ export interface PosTan {
9
10
  export interface SkContourMeasure extends SkJSIInstance<"ContourMeasure"> {
10
11
  /**
11
12
  * Returns the given position and tangent line for the distance on the given contour.
12
- * The return value is 4 floats in this order: posX, posY, vecX, vecY.
13
+ * The return value an array of 2 vectors: [position, tangent]
13
14
  * @param distance - will be pinned between 0 and length().
14
15
  */
15
- getPosTan(distance: number): PosTan;
16
+ getPosTan(distance: number): [position: SkPoint, tangent: SkPoint];
16
17
  /**
17
18
  * Returns an Path representing the segment of this contour.
18
19
  * @param startD - will be pinned between 0 and length()
@@ -0,0 +1,4 @@
1
+ export interface SkSize {
2
+ width: number;
3
+ height: number;
4
+ }
@@ -25,3 +25,4 @@ export * from "./RSXform";
25
25
  export * from "./JsiInstance";
26
26
  export * from "./Skia";
27
27
  export * from "./TextBlob";
28
+ export * from "./Size";
@@ -2,14 +2,10 @@ import type { CanvasKit, ContourMeasure } from "canvaskit-wasm";
2
2
  import type { SkContourMeasure } from "../types";
3
3
  import { HostObject } from "./Host";
4
4
  import { JsiSkPath } from "./JsiSkPath";
5
+ import { JsiSkPoint } from "./JsiSkPoint";
5
6
  export declare class JsiSkContourMeasure extends HostObject<ContourMeasure, "ContourMeasure"> implements SkContourMeasure {
6
7
  constructor(CanvasKit: CanvasKit, ref: ContourMeasure);
7
- getPosTan(distance: number): {
8
- px: number;
9
- py: number;
10
- tx: number;
11
- ty: number;
12
- };
8
+ getPosTan(distance: number): [position: JsiSkPoint, tangent: JsiSkPoint];
13
9
  getSegment(startD: number, stopD: number, startWithMoveTo: boolean): JsiSkPath;
14
10
  isClosed(): boolean;
15
11
  length(): number;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "setup-skia-web": "./scripts/setup-canvaskit.js"
8
8
  },
9
9
  "title": "React Native Skia",
10
- "version": "0.1.156",
10
+ "version": "0.1.158",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -67,8 +67,8 @@
67
67
  "licenseFilename": "LICENSE.md",
68
68
  "readmeFilename": "README.md",
69
69
  "peerDependencies": {
70
- "react": ">=16.8.1",
71
- "react-native": ">=0.63.0-rc.0 <1.0.x",
70
+ "react": ">=18.0",
71
+ "react-native": ">=0.64",
72
72
  "react-native-reanimated": ">=2.0.0"
73
73
  },
74
74
  "peerDependenciesMeta": {
@@ -77,9 +77,10 @@
77
77
  }
78
78
  },
79
79
  "devDependencies": {
80
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
80
81
  "@types/jest": "^28.1.6",
81
82
  "@types/react-native": "0.66.2",
82
- "@types/react-reconciler": "0.26.4",
83
+ "@types/react-reconciler": "^0.26.7",
83
84
  "eslint": "8.21.0",
84
85
  "eslint-config-react-native-wcandillon": "3.9.0",
85
86
  "eslint-plugin-reanimated": "2.0.0",
@@ -92,7 +93,7 @@
92
93
  },
93
94
  "dependencies": {
94
95
  "canvaskit-wasm": "0.36.1",
95
- "react-reconciler": "0.26.2"
96
+ "react-reconciler": "^0.27.0"
96
97
  },
97
98
  "eslintIgnore": [
98
99
  "node_modules/",
@@ -103,7 +104,12 @@
103
104
  "output": "lib",
104
105
  "targets": [
105
106
  "commonjs",
106
- "module",
107
+ [
108
+ "module",
109
+ {
110
+ "configFile": "./.babelrc"
111
+ }
112
+ ],
107
113
  "typescript"
108
114
  ]
109
115
  },
@@ -9,7 +9,7 @@ import type {
9
9
  import type { NodeContext } from "./Node";
10
10
  import { JsiDeclarationNode } from "./Node";
11
11
  import { PaintNode } from "./PaintNode";
12
- import { isSkPaint, JsiRenderNode } from "./RenderNode";
12
+ import { JsiRenderNode } from "./RenderNode";
13
13
 
14
14
  export abstract class JsiDrawingNode<P extends DrawingNodeProps, C>
15
15
  extends JsiRenderNode<P>
@@ -52,10 +52,8 @@ export abstract class JsiDrawingNode<P extends DrawingNodeProps, C>
52
52
  }
53
53
 
54
54
  renderNode(ctx: DrawingContext): void {
55
- if (this.props.paint && isSkPaint(this.props.paint)) {
55
+ if (this.props.paint) {
56
56
  this.draw({ ...ctx, paint: this.props.paint });
57
- } else if (this.props.paint && this.props.paint.current != null) {
58
- this.draw({ ...ctx, paint: this.props.paint.current.materialize() });
59
57
  } else {
60
58
  this.draw(ctx);
61
59
  }
@@ -1,5 +1,3 @@
1
- import type { RefObject } from "react";
2
-
3
1
  import type {
4
2
  SkMatrix,
5
3
  SkRect,
@@ -21,7 +19,6 @@ import type {
21
19
  DrawingContext,
22
20
  NodeType,
23
21
  Node,
24
- DeclarationNode,
25
22
  } from "../types";
26
23
 
27
24
  import { isPathDef, processPath, processTransformProps } from "./datatypes";
@@ -236,17 +233,12 @@ export abstract class JsiRenderNode<P extends GroupProps>
236
233
  this.clipRRect !== undefined;
237
234
  const shouldSave = hasTransform || hasClip || !!layer;
238
235
  const op = invertClip ? ClipOp.Difference : ClipOp.Intersect;
239
-
240
236
  if (shouldSave) {
241
237
  if (layer) {
242
238
  if (typeof layer === "boolean") {
243
239
  canvas.saveLayer();
244
- } else if (isSkPaint(layer)) {
245
- canvas.saveLayer(layer);
246
240
  } else {
247
- canvas.saveLayer(
248
- layer.current ? layer.current.materialize() : undefined
249
- );
241
+ canvas.saveLayer(layer);
250
242
  }
251
243
  } else {
252
244
  canvas.save();
@@ -274,10 +266,6 @@ export abstract class JsiRenderNode<P extends GroupProps>
274
266
  abstract renderNode(ctx: DrawingContext): void;
275
267
  }
276
268
 
277
- export const isSkPaint = (
278
- obj: RefObject<DeclarationNode<unknown, SkPaint>> | SkPaint
279
- ): obj is SkPaint => "__typename__" in obj && obj.__typename__ === "Paint";
280
-
281
269
  const concatPaint = (
282
270
  parent: SkPaint,
283
271
  {
@@ -57,10 +57,10 @@ export class TextPathNode extends JsiDrawingNode<TextPathProps, SkTextBlob> {
57
57
  }
58
58
  // Gives us the (x, y) coordinates as well as the cos/sin of the tangent
59
59
  // line at that position.
60
- const { px, py, tx, ty } = cont.getPosTan(dist);
61
- const adjustedX = px - (width / 2) * tx;
62
- const adjustedY = py - (width / 2) * ty;
63
- rsx.push(this.Skia.RSXform(tx, ty, adjustedX, adjustedY));
60
+ const [p, t] = cont.getPosTan(dist);
61
+ const adjustedX = p.x - (width / 2) * t.x;
62
+ const adjustedY = p.y - (width / 2) * t.y;
63
+ rsx.push(this.Skia.RSXform(t.x, t.y, adjustedX, adjustedY));
64
64
  dist += width / 2;
65
65
  }
66
66
  return this.Skia.TextBlob.MakeFromRSXform(text, rsx, font);
@@ -1,4 +1,4 @@
1
- import type { ReactNode, RefObject } from "react";
1
+ import type { ReactNode } from "react";
2
2
 
3
3
  import type {
4
4
  BlendMode,
@@ -15,8 +15,6 @@ import type {
15
15
  Vector,
16
16
  } from "../../skia/types";
17
17
 
18
- import type { DeclarationNode } from "./Node";
19
-
20
18
  export type SkEnum<T> = Uncapitalize<keyof T extends string ? keyof T : never>;
21
19
 
22
20
  export type PathDef = string | SkPath;
@@ -86,5 +84,5 @@ export interface PaintProps extends ChildrenProps {
86
84
  export interface GroupProps extends PaintProps, TransformProps {
87
85
  clip?: ClipDef;
88
86
  invertClip?: boolean;
89
- layer?: RefObject<DeclarationNode<unknown, SkPaint>> | SkPaint | boolean;
87
+ layer?: SkPaint | boolean;
90
88
  }
@@ -1,5 +1,3 @@
1
- import type { RefObject } from "react";
2
-
3
1
  import type {
4
2
  FillType,
5
3
  SkImage,
@@ -29,10 +27,9 @@ import type {
29
27
  SkEnum,
30
28
  } from "./Common";
31
29
  import type { DrawingContext } from "./DrawingContext";
32
- import type { DeclarationNode } from "./Node";
33
30
 
34
31
  export interface DrawingNodeProps extends GroupProps {
35
- paint?: SkPaint | RefObject<DeclarationNode<unknown, SkPaint>>;
32
+ paint?: SkPaint;
36
33
  }
37
34
 
38
35
  export type ImageProps = DrawingNodeProps &
package/src/mock/index.ts CHANGED
@@ -53,7 +53,6 @@ export const Mock: typeof SkiaExports &
53
53
  useTypeface: Noop,
54
54
  useImage: Noop,
55
55
  useSVG: Noop,
56
- usePicture: Noop,
57
56
  createPicture: Noop,
58
57
  // 3. Point/Rect/Transform utilities
59
58
  vec,
@@ -20,7 +20,8 @@ import { SkiaView, useDrawCallback } from "../views";
20
20
  import type { TouchHandler } from "../views";
21
21
  import { useValue } from "../values/hooks/useValue";
22
22
  import { Skia } from "../skia/Skia";
23
- import type { SkiaValue } from "../values";
23
+ import type { SkiaValue, SkiaMutableValue } from "../values";
24
+ import type { SkSize } from "../skia/types";
24
25
 
25
26
  import { debug as hostDebug, skHostConfig } from "./HostConfig";
26
27
  // import { debugTree } from "./nodes";
@@ -49,10 +50,11 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
49
50
  ref?: RefObject<SkiaView>;
50
51
  children: ReactNode;
51
52
  onTouch?: TouchHandler;
53
+ onSize?: SkiaMutableValue<SkSize>;
52
54
  }
53
55
 
54
56
  export const Canvas = forwardRef<SkiaView, CanvasProps>(
55
- ({ children, style, debug, mode, onTouch }, forwardedRef) => {
57
+ ({ children, style, debug, mode, onTouch, onSize }, forwardedRef) => {
56
58
  const size = useValue({ width: 0, height: 0 });
57
59
  const canvasCtx = useMemo(() => ({ Skia, size }), [size]);
58
60
  const innerRef = useCanvasRef();
@@ -77,7 +79,17 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
77
79
  }, [redraw, registerValues]);
78
80
 
79
81
  const root = useMemo(
80
- () => skiaReconciler.createContainer(container, 0, false, null),
82
+ () =>
83
+ skiaReconciler.createContainer(
84
+ container,
85
+ 0,
86
+ null,
87
+ true,
88
+ null,
89
+ "",
90
+ console.error,
91
+ null
92
+ ),
81
93
  [container]
82
94
  );
83
95
  // Render effect
@@ -104,6 +116,9 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
104
116
  height !== canvasCtx.size.current.height
105
117
  ) {
106
118
  canvasCtx.size.current = { width, height };
119
+ if (onSize) {
120
+ onSize.current = { width, height };
121
+ }
107
122
  }
108
123
  paint.reset();
109
124
  const ctx = {
@@ -1,5 +1,3 @@
1
- import type { ForwardedRef } from "react";
2
-
3
1
  import { NodeType } from "../dom/types";
4
2
  import type {
5
3
  CircleProps,
@@ -55,7 +53,6 @@ import type {
55
53
  BlendProps,
56
54
  MorphologyImageFilterProps,
57
55
  } from "../dom/types/ImageFilters";
58
- import type { PaintNode } from "../dom/nodes/PaintNode";
59
56
 
60
57
  import type { Container } from "./Container";
61
58
  import { exhaustiveCheck } from "./typeddash";
@@ -67,7 +64,7 @@ declare global {
67
64
  interface IntrinsicElements {
68
65
  skGroup: SkiaProps<GroupProps>;
69
66
  skLayer: SkiaProps<ChildrenProps>;
70
- skPaint: SkiaProps<PaintProps> & { ref: ForwardedRef<PaintNode> };
67
+ skPaint: SkiaProps<PaintProps>;
71
68
 
72
69
  // Drawings
73
70
  skFill: SkiaProps<DrawingNodeProps>;
@@ -1,5 +1,6 @@
1
1
  /*global NodeJS*/
2
2
  import type { HostConfig } from "react-reconciler";
3
+ import { DefaultEventPriority } from "react-reconciler/constants";
3
4
 
4
5
  import type { NodeType, Node } from "../dom/types";
5
6
  import type { SkiaValue } from "../values";
@@ -67,7 +68,6 @@ export const skHostConfig: SkiaHostConfig = {
67
68
  * This function is used by the reconciler in order to calculate current time for prioritising work.
68
69
  */
69
70
  now: Date.now,
70
-
71
71
  supportsMutation: true,
72
72
  isPrimaryRenderer: false,
73
73
  supportsPersistence: false,
@@ -232,6 +232,13 @@ export const skHostConfig: SkiaHostConfig = {
232
232
  insertBefore: (parent, child, before) => {
233
233
  insertBefore(parent, child, before);
234
234
  },
235
+ // see https://github.com/pmndrs/react-three-fiber/pull/2360#discussion_r916356874
236
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
237
+ // @ts-expect-error
238
+ getCurrentEventPriority: () => DefaultEventPriority,
239
+ beforeActiveInstanceBlur: () => {},
240
+ afterActiveInstanceBlur: () => {},
241
+ detachDeletedInstance: () => {},
235
242
  };
236
243
 
237
244
  const materialize = <P>(props: AnimatedProps<P>) => {
@@ -2,7 +2,7 @@ import type { ReactNode } from "react";
2
2
  import React, { useMemo } from "react";
3
3
 
4
4
  import { BlendMode } from "../../skia/types";
5
- import { useCanvas } from "../useCanvas";
5
+ import { useSkiaPrivate } from "../useCanvas";
6
6
 
7
7
  import { Group } from "./Group";
8
8
 
@@ -14,7 +14,7 @@ interface MaskProps {
14
14
  }
15
15
 
16
16
  export const Mask = ({ children, mask, mode, clip }: MaskProps) => {
17
- const { Skia } = useCanvas();
17
+ const Skia = useSkiaPrivate();
18
18
  const maskPaint = useMemo(() => {
19
19
  const paint = Skia.Paint();
20
20
  paint.setBlendMode(BlendMode.Src);
@@ -1,19 +1,8 @@
1
- /* eslint-disable max-len */
2
- import React, { useRef, forwardRef } from "react";
1
+ import React from "react";
3
2
 
4
3
  import type { SkiaProps } from "../processors";
5
4
  import type { DrawingNodeProps } from "../../dom/types";
6
- import type { PaintNode } from "../../dom/nodes/PaintNode";
7
5
 
8
- export const usePaintRef = () => {
9
- console.log(`usePaintRef() is now deprecated.
10
- If you are using the layer property, simply pass the component directly: https://shopify.github.io/react-native-skia/docs/group#layer-effects.
11
- If you are using the paint property, please the following paint properties directly: https://shopify.github.io/react-native-skia/docs/paint/overview`);
12
- return useRef<PaintNode>(null);
6
+ export const Paint = (props: SkiaProps<DrawingNodeProps>) => {
7
+ return <skPaint {...props} />;
13
8
  };
14
-
15
- export const Paint = forwardRef<PaintNode, SkiaProps<DrawingNodeProps>>(
16
- (props, ref) => {
17
- return <skPaint ref={ref} {...props} />;
18
- }
19
- );
@@ -14,8 +14,22 @@ export const CanvasProvider = CanvasContext.Provider;
14
14
 
15
15
  export const useCanvas = () => {
16
16
  const ctx = useContext(CanvasContext);
17
+ console.warn(
18
+ // eslint-disable-next-line max-len
19
+ "useCanvas is deprecated. use the onSize property instead: https://shopify.github.io/react-native-skia/docs/canvas/overview"
20
+ );
17
21
  if (!ctx) {
18
22
  throw new Error("Canvas context is not available");
19
23
  }
20
24
  return ctx;
21
25
  };
26
+
27
+ // This private function will be removed once we remove the useCanvas hook and
28
+ // implement the Mask component as a node (will be faster too)
29
+ export const useSkiaPrivate = () => {
30
+ const ctx = useContext(CanvasContext);
31
+ if (!ctx) {
32
+ throw new Error("Canvas context is not available");
33
+ }
34
+ return ctx.Skia;
35
+ };