@shopify/react-native-skia 0.1.139 → 0.1.142

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. package/android/CMakeLists.txt +5 -1
  2. package/android/build.gradle +3 -1
  3. package/android/cpp/rnskia-android/RNSkDrawViewImpl.cpp +2 -2
  4. package/android/cpp/rnskia-android/RNSkDrawViewImpl.h +1 -1
  5. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.cpp +15 -16
  6. package/android/cpp/rnskia-android/SkiaOpenGLRenderer.h +2 -2
  7. package/android/src/main/java/com/shopify/reactnative/skia/SkiaDrawView.java +69 -27
  8. package/cpp/rnskia/RNSkDrawView.cpp +66 -66
  9. package/cpp/rnskia/RNSkDrawView.h +22 -6
  10. package/cpp/rnskia/RNSkJsiViewApi.h +2 -2
  11. package/cpp/rnskia/values/RNSkComputedValue.h +10 -7
  12. package/cpp/rnskia/values/RNSkReadonlyValue.h +21 -2
  13. package/cpp/rnskia/values/RNSkValue.h +1 -0
  14. package/ios/RNSkia-iOS/RNSkDrawViewImpl.h +1 -1
  15. package/ios/RNSkia-iOS/RNSkDrawViewImpl.mm +2 -2
  16. package/ios/RNSkia-iOS/SkiaDrawView.mm +4 -0
  17. package/lib/commonjs/mock/index.js +3 -1
  18. package/lib/commonjs/mock/index.js.map +1 -1
  19. package/lib/commonjs/renderer/DependencyManager.js +1 -1
  20. package/lib/commonjs/renderer/DependencyManager.js.map +1 -1
  21. package/lib/commonjs/renderer/processors/Animations/Animations.js +18 -5
  22. package/lib/commonjs/renderer/processors/Animations/Animations.js.map +1 -1
  23. package/lib/commonjs/skia/core/Data.js +10 -22
  24. package/lib/commonjs/skia/core/Data.js.map +1 -1
  25. package/lib/commonjs/skia/core/Font.js +2 -3
  26. package/lib/commonjs/skia/core/Font.js.map +1 -1
  27. package/lib/commonjs/skia/core/Image.js.map +1 -1
  28. package/lib/commonjs/skia/core/SVG.js.map +1 -1
  29. package/lib/commonjs/skia/core/Typeface.js.map +1 -1
  30. package/lib/commonjs/skia/types/Data/Data.js +5 -0
  31. package/lib/commonjs/skia/types/Data/Data.js.map +1 -1
  32. package/lib/commonjs/skia/types/Image/ImageFactory.js +0 -2
  33. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  34. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  35. package/lib/commonjs/skia/web/JsiSkCanvas.js +9 -7
  36. package/lib/commonjs/skia/web/JsiSkCanvas.js.map +1 -1
  37. package/lib/commonjs/skia/web/JsiSkPath.js +7 -5
  38. package/lib/commonjs/skia/web/JsiSkPath.js.map +1 -1
  39. package/lib/commonjs/skia/web/JsiSkRRect.js +8 -0
  40. package/lib/commonjs/skia/web/JsiSkRRect.js.map +1 -1
  41. package/lib/commonjs/skia/web/JsiSkRect.js +2 -2
  42. package/lib/commonjs/skia/web/JsiSkRect.js.map +1 -1
  43. package/lib/commonjs/values/hooks/useComputedValue.js +6 -2
  44. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
  45. package/lib/commonjs/values/index.js +13 -0
  46. package/lib/commonjs/values/index.js.map +1 -1
  47. package/lib/commonjs/values/selector.js +24 -0
  48. package/lib/commonjs/values/selector.js.map +1 -0
  49. package/lib/commonjs/values/web/RNSkComputedValue.js +8 -0
  50. package/lib/commonjs/values/web/RNSkComputedValue.js.map +1 -1
  51. package/lib/commonjs/values/web/RNSkReadonlyValue.js +4 -0
  52. package/lib/commonjs/values/web/RNSkReadonlyValue.js.map +1 -1
  53. package/lib/commonjs/views/useTouchHandler.js +13 -15
  54. package/lib/commonjs/views/useTouchHandler.js.map +1 -1
  55. package/lib/module/mock/index.js +2 -1
  56. package/lib/module/mock/index.js.map +1 -1
  57. package/lib/module/renderer/DependencyManager.js +2 -2
  58. package/lib/module/renderer/DependencyManager.js.map +1 -1
  59. package/lib/module/renderer/processors/Animations/Animations.js +13 -4
  60. package/lib/module/renderer/processors/Animations/Animations.js.map +1 -1
  61. package/lib/module/skia/core/Data.js +10 -20
  62. package/lib/module/skia/core/Data.js.map +1 -1
  63. package/lib/module/skia/core/Font.js +2 -3
  64. package/lib/module/skia/core/Font.js.map +1 -1
  65. package/lib/module/skia/core/Image.js.map +1 -1
  66. package/lib/module/skia/core/SVG.js.map +1 -1
  67. package/lib/module/skia/core/Typeface.js.map +1 -1
  68. package/lib/module/skia/types/Data/Data.js +1 -1
  69. package/lib/module/skia/types/Data/Data.js.map +1 -1
  70. package/lib/module/skia/types/Image/ImageFactory.js +0 -1
  71. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  72. package/lib/module/skia/types/Path/Path.js.map +1 -1
  73. package/lib/module/skia/web/JsiSkCanvas.js +8 -7
  74. package/lib/module/skia/web/JsiSkCanvas.js.map +1 -1
  75. package/lib/module/skia/web/JsiSkPath.js +6 -5
  76. package/lib/module/skia/web/JsiSkPath.js.map +1 -1
  77. package/lib/module/skia/web/JsiSkRRect.js +8 -0
  78. package/lib/module/skia/web/JsiSkRRect.js.map +1 -1
  79. package/lib/module/skia/web/JsiSkRect.js +2 -2
  80. package/lib/module/skia/web/JsiSkRect.js.map +1 -1
  81. package/lib/module/values/hooks/useComputedValue.js +7 -3
  82. package/lib/module/values/hooks/useComputedValue.js.map +1 -1
  83. package/lib/module/values/index.js +1 -0
  84. package/lib/module/values/index.js.map +1 -1
  85. package/lib/module/values/selector.js +15 -0
  86. package/lib/module/values/selector.js.map +1 -0
  87. package/lib/module/values/web/RNSkComputedValue.js +8 -0
  88. package/lib/module/values/web/RNSkComputedValue.js.map +1 -1
  89. package/lib/module/values/web/RNSkReadonlyValue.js +4 -0
  90. package/lib/module/values/web/RNSkReadonlyValue.js.map +1 -1
  91. package/lib/module/views/useTouchHandler.js +12 -14
  92. package/lib/module/views/useTouchHandler.js.map +1 -1
  93. package/lib/typescript/src/renderer/processors/Animations/Animations.d.ts +7 -2
  94. package/lib/typescript/src/skia/core/Data.d.ts +3 -5
  95. package/lib/typescript/src/skia/core/Font.d.ts +2 -2
  96. package/lib/typescript/src/skia/core/Image.d.ts +2 -2
  97. package/lib/typescript/src/skia/core/SVG.d.ts +2 -2
  98. package/lib/typescript/src/skia/core/Typeface.d.ts +2 -2
  99. package/lib/typescript/src/skia/types/Data/Data.d.ts +10 -3
  100. package/lib/typescript/src/skia/web/JsiSkRRect.d.ts +1 -0
  101. package/lib/typescript/src/skia/web/JsiSkRect.d.ts +1 -1
  102. package/lib/typescript/src/values/index.d.ts +1 -0
  103. package/lib/typescript/src/values/selector.d.ts +14 -0
  104. package/lib/typescript/src/values/types.d.ts +4 -0
  105. package/lib/typescript/src/values/web/RNSkComputedValue.d.ts +1 -0
  106. package/lib/typescript/src/values/web/RNSkReadonlyValue.d.ts +1 -0
  107. package/package.json +13 -8
  108. package/src/mock/index.ts +2 -1
  109. package/src/renderer/DependencyManager.tsx +5 -2
  110. package/src/renderer/processors/Animations/Animations.ts +27 -5
  111. package/src/skia/core/Data.ts +20 -51
  112. package/src/skia/core/Font.ts +4 -5
  113. package/src/skia/core/Image.ts +2 -2
  114. package/src/skia/core/SVG.ts +2 -2
  115. package/src/skia/core/Typeface.ts +2 -2
  116. package/src/skia/types/Data/Data.ts +11 -1
  117. package/src/skia/types/Image/ImageFactory.ts +0 -1
  118. package/src/skia/types/Path/Path.ts +0 -1
  119. package/src/skia/web/JsiSkCanvas.ts +22 -10
  120. package/src/skia/web/JsiSkPath.ts +14 -5
  121. package/src/skia/web/JsiSkRRect.ts +11 -0
  122. package/src/skia/web/JsiSkRect.ts +2 -5
  123. package/src/values/hooks/useComputedValue.ts +6 -3
  124. package/src/values/index.ts +1 -0
  125. package/src/values/selector.ts +24 -0
  126. package/src/values/types.ts +4 -0
  127. package/src/values/web/RNSkComputedValue.ts +6 -0
  128. package/src/values/web/RNSkReadonlyValue.ts +4 -0
  129. package/src/views/useTouchHandler.ts +15 -19
  130. package/android/README.md +0 -14
  131. package/cpp/skia/include/third_party/skcms/LICENSE +0 -29
  132. package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
  133. package/cpp/skia/readme.txt +0 -1
@@ -2,10 +2,10 @@ import { HostObject } from "./Host";
2
2
  export class JsiSkRect extends HostObject {
3
3
  static fromValue(CanvasKit, rect) {
4
4
  if (rect instanceof JsiSkRect) {
5
- return rect;
5
+ return rect.ref;
6
6
  }
7
7
 
8
- return new JsiSkRect(CanvasKit, CanvasKit.XYWHRect(rect.x, rect.y, rect.width, rect.height));
8
+ return CanvasKit.XYWHRect(rect.x, rect.y, rect.width, rect.height);
9
9
  }
10
10
 
11
11
  constructor(CanvasKit, ref) {
@@ -1 +1 @@
1
- {"version":3,"sources":["JsiSkRect.ts"],"names":["HostObject","JsiSkRect","fromValue","CanvasKit","rect","XYWHRect","x","y","width","height","constructor","ref"],"mappings":"AAIA,SAASA,UAAT,QAA2B,QAA3B;AAEA,OAAO,MAAMC,SAAN,SAAwBD,UAAxB,CAAmE;AACxD,SAATE,SAAS,CAACC,SAAD,EAAuBC,IAAvB,EAAqC;AACnD,QAAIA,IAAI,YAAYH,SAApB,EAA+B;AAC7B,aAAOG,IAAP;AACD;;AACD,WAAO,IAAIH,SAAJ,CACLE,SADK,EAELA,SAAS,CAACE,QAAV,CAAmBD,IAAI,CAACE,CAAxB,EAA2BF,IAAI,CAACG,CAAhC,EAAmCH,IAAI,CAACI,KAAxC,EAA+CJ,IAAI,CAACK,MAApD,CAFK,CAAP;AAID;;AAEDC,EAAAA,WAAW,CAACP,SAAD,EAAuBQ,GAAvB,EAAkC;AAC3C,UAAMR,SAAN,EAAiBQ,GAAjB,EAAsB,MAAtB;AACD;;AAEI,MAADL,CAAC,GAAG;AACN,WAAO,KAAKK,GAAL,CAAS,CAAT,CAAP;AACD;;AAEI,MAADJ,CAAC,GAAG;AACN,WAAO,KAAKI,GAAL,CAAS,CAAT,CAAP;AACD;;AAEQ,MAALH,KAAK,GAAG;AACV,WAAO,KAAKG,GAAL,CAAS,CAAT,IAAc,KAAKA,GAAL,CAAS,CAAT,CAArB;AACD;;AAES,MAANF,MAAM,GAAG;AACX,WAAO,KAAKE,GAAL,CAAS,CAAT,IAAc,KAAKA,GAAL,CAAS,CAAT,CAArB;AACD;;AA7BuE","sourcesContent":["import type { CanvasKit, Rect } from \"canvaskit-wasm\";\n\nimport type { SkRect } from \"../types\";\n\nimport { HostObject } from \"./Host\";\n\nexport class JsiSkRect extends HostObject<Rect, \"Rect\"> implements SkRect {\n static fromValue(CanvasKit: CanvasKit, rect: SkRect) {\n if (rect instanceof JsiSkRect) {\n return rect;\n }\n return new JsiSkRect(\n CanvasKit,\n CanvasKit.XYWHRect(rect.x, rect.y, rect.width, rect.height)\n );\n }\n\n constructor(CanvasKit: CanvasKit, ref: Rect) {\n super(CanvasKit, ref, \"Rect\");\n }\n\n get x() {\n return this.ref[0];\n }\n\n get y() {\n return this.ref[1];\n }\n\n get width() {\n return this.ref[2] - this.ref[0];\n }\n\n get height() {\n return this.ref[3] - this.ref[1];\n }\n}\n"]}
1
+ {"version":3,"sources":["JsiSkRect.ts"],"names":["HostObject","JsiSkRect","fromValue","CanvasKit","rect","ref","XYWHRect","x","y","width","height","constructor"],"mappings":"AAIA,SAASA,UAAT,QAA2B,QAA3B;AAEA,OAAO,MAAMC,SAAN,SAAwBD,UAAxB,CAAmE;AACxD,SAATE,SAAS,CAACC,SAAD,EAAuBC,IAAvB,EAAqC;AACnD,QAAIA,IAAI,YAAYH,SAApB,EAA+B;AAC7B,aAAOG,IAAI,CAACC,GAAZ;AACD;;AACD,WAAOF,SAAS,CAACG,QAAV,CAAmBF,IAAI,CAACG,CAAxB,EAA2BH,IAAI,CAACI,CAAhC,EAAmCJ,IAAI,CAACK,KAAxC,EAA+CL,IAAI,CAACM,MAApD,CAAP;AACD;;AAEDC,EAAAA,WAAW,CAACR,SAAD,EAAuBE,GAAvB,EAAkC;AAC3C,UAAMF,SAAN,EAAiBE,GAAjB,EAAsB,MAAtB;AACD;;AAEI,MAADE,CAAC,GAAG;AACN,WAAO,KAAKF,GAAL,CAAS,CAAT,CAAP;AACD;;AAEI,MAADG,CAAC,GAAG;AACN,WAAO,KAAKH,GAAL,CAAS,CAAT,CAAP;AACD;;AAEQ,MAALI,KAAK,GAAG;AACV,WAAO,KAAKJ,GAAL,CAAS,CAAT,IAAc,KAAKA,GAAL,CAAS,CAAT,CAArB;AACD;;AAES,MAANK,MAAM,GAAG;AACX,WAAO,KAAKL,GAAL,CAAS,CAAT,IAAc,KAAKA,GAAL,CAAS,CAAT,CAArB;AACD;;AA1BuE","sourcesContent":["import type { CanvasKit, Rect } from \"canvaskit-wasm\";\n\nimport type { SkRect } from \"../types\";\n\nimport { HostObject } from \"./Host\";\n\nexport class JsiSkRect extends HostObject<Rect, \"Rect\"> implements SkRect {\n static fromValue(CanvasKit: CanvasKit, rect: SkRect) {\n if (rect instanceof JsiSkRect) {\n return rect.ref;\n }\n return CanvasKit.XYWHRect(rect.x, rect.y, rect.width, rect.height);\n }\n\n constructor(CanvasKit: CanvasKit, ref: Rect) {\n super(CanvasKit, ref, \"Rect\");\n }\n\n get x() {\n return this.ref[0];\n }\n\n get y() {\n return this.ref[1];\n }\n\n get width() {\n return this.ref[2] - this.ref[0];\n }\n\n get height() {\n return this.ref[3] - this.ref[1];\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { useMemo } from "react";
1
+ import { useEffect, useMemo } from "react";
2
2
  import { ValueApi } from "../api";
3
3
  import { isValue } from "../../renderer/processors/Animations";
4
4
  /**
@@ -9,6 +9,10 @@ import { isValue } from "../../renderer/processors/Animations";
9
9
  * @returns A readonly value
10
10
  */
11
11
 
12
- export const useComputedValue = (cb, values) => useMemo(() => ValueApi.createComputedValue(cb, values.filter(isValue)), // eslint-disable-next-line react-hooks/exhaustive-deps
13
- values);
12
+ export const useComputedValue = (cb, values) => {
13
+ const value = useMemo(() => ValueApi.createComputedValue(cb, values.filter(isValue)), // eslint-disable-next-line react-hooks/exhaustive-deps
14
+ values);
15
+ useEffect(() => () => value.__invalidate(), [value]);
16
+ return value;
17
+ };
14
18
  //# sourceMappingURL=useComputedValue.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useComputedValue.ts"],"names":["useMemo","ValueApi","isValue","useComputedValue","cb","values","createComputedValue","filter"],"mappings":"AAAA,SAASA,OAAT,QAAwB,OAAxB;AAEA,SAASC,QAAT,QAAyB,QAAzB;AACA,SAASC,OAAT,QAAwB,sCAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,gBAAgB,GAAG,CAAIC,EAAJ,EAAiBC,MAAjB,KAC9BL,OAAO,CACL,MAAMC,QAAQ,CAACK,mBAAT,CAAgCF,EAAhC,EAAoCC,MAAM,CAACE,MAAP,CAAcL,OAAd,CAApC,CADD,EAEL;AACAG,MAHK,CADF","sourcesContent":["import { useMemo } from \"react\";\n\nimport { ValueApi } from \"../api\";\nimport { isValue } from \"../../renderer/processors/Animations\";\n\n/**\n * Creates a new computed value - a value that will calculate its value depending\n * on other values.\n * @param cb Callback to calculate new value\n * @param values Dependant values\n * @returns A readonly value\n */\nexport const useComputedValue = <R>(cb: () => R, values: unknown[]) =>\n useMemo(\n () => ValueApi.createComputedValue<R>(cb, values.filter(isValue)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n values\n );\n"]}
1
+ {"version":3,"sources":["useComputedValue.ts"],"names":["useEffect","useMemo","ValueApi","isValue","useComputedValue","cb","values","value","createComputedValue","filter","__invalidate"],"mappings":"AAAA,SAASA,SAAT,EAAoBC,OAApB,QAAmC,OAAnC;AAEA,SAASC,QAAT,QAAyB,QAAzB;AACA,SAASC,OAAT,QAAwB,sCAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,gBAAgB,GAAG,CAAIC,EAAJ,EAAiBC,MAAjB,KAAuC;AACrE,QAAMC,KAAK,GAAGN,OAAO,CACnB,MAAMC,QAAQ,CAACM,mBAAT,CAAgCH,EAAhC,EAAoCC,MAAM,CAACG,MAAP,CAAcN,OAAd,CAApC,CADa,EAEnB;AACAG,EAAAA,MAHmB,CAArB;AAKAN,EAAAA,SAAS,CAAC,MAAM,MAAMO,KAAK,CAACG,YAAN,EAAb,EAAmC,CAACH,KAAD,CAAnC,CAAT;AACA,SAAOA,KAAP;AACD,CARM","sourcesContent":["import { useEffect, useMemo } from \"react\";\n\nimport { ValueApi } from \"../api\";\nimport { isValue } from \"../../renderer/processors/Animations\";\n\n/**\n * Creates a new computed value - a value that will calculate its value depending\n * on other values.\n * @param cb Callback to calculate new value\n * @param values Dependant values\n * @returns A readonly value\n */\nexport const useComputedValue = <R>(cb: () => R, values: unknown[]) => {\n const value = useMemo(\n () => ValueApi.createComputedValue<R>(cb, values.filter(isValue)),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n values\n );\n useEffect(() => () => value.__invalidate(), [value]);\n return value;\n};\n"]}
@@ -1,4 +1,5 @@
1
1
  export * from "./types";
2
2
  export * from "./hooks";
3
3
  export * from "./api";
4
+ export * from "./selector";
4
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAd;AACA,cAAc,SAAd;AACA,cAAc,OAAd","sourcesContent":["export * from \"./types\";\nexport * from \"./hooks\";\nexport * from \"./api\";\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAd;AACA,cAAc,SAAd;AACA,cAAc,OAAd;AACA,cAAc,YAAd","sourcesContent":["export * from \"./types\";\nexport * from \"./hooks\";\nexport * from \"./api\";\nexport * from \"./selector\";\n"]}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Wraps a Skia Value with a selector function. The selector function can access the
3
+ * inner values of the Skia Value so that we can dynamically ready array values and
4
+ * object values when doing animations in Skia.
5
+ * @param value Dependant value
6
+ * @param selector Selector function to calculate new value from the Skia Value's value
7
+ * @returns A descriptor that will be used by the reconciler to calculate the value
8
+ */
9
+ export const Selector = (value, selector) => {
10
+ return {
11
+ selector,
12
+ value
13
+ };
14
+ };
15
+ //# sourceMappingURL=selector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["selector.ts"],"names":["Selector","value","selector"],"mappings":"AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,QAAQ,GAAG,CACtBC,KADsB,EAEtBC,QAFsB,KAGY;AAClC,SAAO;AACLA,IAAAA,QADK;AAELD,IAAAA;AAFK,GAAP;AAID,CARM","sourcesContent":["import type { SkiaValue } from \"./types\";\n\nexport type SkiaSelector<TReturn, TInput = unknown> = {\n value: SkiaValue<TInput>;\n selector: (v: TInput) => TReturn;\n};\n\n/**\n * Wraps a Skia Value with a selector function. The selector function can access the\n * inner values of the Skia Value so that we can dynamically ready array values and\n * object values when doing animations in Skia.\n * @param value Dependant value\n * @param selector Selector function to calculate new value from the Skia Value's value\n * @returns A descriptor that will be used by the reconciler to calculate the value\n */\nexport const Selector = <TInput, TReturn>(\n value: SkiaValue<TInput>,\n selector: (v: TInput) => TReturn\n): SkiaSelector<TReturn, TInput> => {\n return {\n selector,\n value,\n };\n};\n"]}
@@ -35,6 +35,14 @@ export class RNSkComputedValue extends RNSkReadonlyValue {
35
35
 
36
36
  unsubscribe() {
37
37
  this._unsubscribers.forEach(unsubscribe => unsubscribe());
38
+
39
+ this._unsubscribers = [];
40
+ }
41
+
42
+ __invalidate() {
43
+ this._unsubscribers.forEach(unsubscribe => unsubscribe());
44
+
45
+ this._unsubscribers = [];
38
46
  }
39
47
 
40
48
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["RNSkComputedValue.ts"],"names":["RNSkReadonlyValue","RNSkComputedValue","constructor","callback","dependencies","unsubscribers","notifyUpdateRef","current","undefined","forEach","dep","push","addListener","_unsubscribers","dependecyUpdated","bind","_callback","update","unsubscribe"],"mappings":";;AAEA,SAASA,iBAAT,QAAkC,qBAAlC;AAEA,OAAO,MAAMC,iBAAN,SAAmCD,iBAAnC,CAAwD;AAC7DE,EAAAA,WAAW,CAACC,QAAD,EAAoBC,YAApB,EAAkD;AAC3D;AACA;AACA,UAAMC,aAAgC,GAAG,EAAzC;AACA,UAAMC,eAAsD,GAAG;AAC7DC,MAAAA,OAAO,EAAEC;AADoD,KAA/D;AAGAJ,IAAAA,YAAY,CAACK,OAAb,CAAsBC,GAAD,IAAS;AAC5B,UAAI,kBAAkBA,GAAlB,IAAyB,iBAAiBA,GAA9C,EAAmD;AACjDL,QAAAA,aAAa,CAACM,IAAd,CACGD,GAAD,CAAoCE,WAApC,CAAgD;AAAA;;AAAA,0CAC9CN,eAAe,CAACC,OAD8B,0DAC9C,2BAAAD,eAAe,CAD+B;AAAA,SAAhD,CADF;AAKD;AACF,KARD;AASA,UAAMH,QAAQ,EAAd;;AAhB2D;;AAAA;;AAiB3D,SAAKU,cAAL,GAAsBR,aAAtB;AACAC,IAAAA,eAAe,CAACC,OAAhB,GAA0B,KAAKO,gBAAL,CAAsBC,IAAtB,CAA2B,IAA3B,CAA1B;AACA,SAAKC,SAAL,GAAiBb,QAAjB;AACD;;AAEOW,EAAAA,gBAAgB,GAAG;AACzB,SAAKG,MAAL,CAAY,KAAKD,SAAL,EAAZ;AACD;;AAKME,EAAAA,WAAW,GAAG;AACnB,SAAKL,cAAL,CAAoBJ,OAApB,CAA6BS,WAAD,IAAiBA,WAAW,EAAxD;AACD;;AAhC4D","sourcesContent":["import type { DependencyList } from \"react\";\n\nimport { RNSkReadonlyValue } from \"./RNSkReadonlyValue\";\n\nexport class RNSkComputedValue<T> extends RNSkReadonlyValue<T> {\n constructor(callback: () => T, dependencies: DependencyList) {\n // Initialize dependencies - we can't call this yet, since\n // super if not called and it requires a start value to be set.\n const unsubscribers: Array<() => void> = [];\n const notifyUpdateRef: { current: (() => void) | undefined } = {\n current: undefined,\n };\n dependencies.forEach((dep) => {\n if (\"__typename__\" in dep && \"addListener\" in dep) {\n unsubscribers.push(\n (dep as RNSkReadonlyValue<unknown>).addListener(() =>\n notifyUpdateRef.current?.()\n )\n );\n }\n });\n super(callback());\n this._unsubscribers = unsubscribers;\n notifyUpdateRef.current = this.dependecyUpdated.bind(this);\n this._callback = callback;\n }\n\n private dependecyUpdated() {\n this.update(this._callback());\n }\n\n private _callback: () => T;\n private _unsubscribers: Array<() => void>;\n\n public unsubscribe() {\n this._unsubscribers.forEach((unsubscribe) => unsubscribe());\n }\n}\n"]}
1
+ {"version":3,"sources":["RNSkComputedValue.ts"],"names":["RNSkReadonlyValue","RNSkComputedValue","constructor","callback","dependencies","unsubscribers","notifyUpdateRef","current","undefined","forEach","dep","push","addListener","_unsubscribers","dependecyUpdated","bind","_callback","update","unsubscribe","__invalidate"],"mappings":";;AAEA,SAASA,iBAAT,QAAkC,qBAAlC;AAEA,OAAO,MAAMC,iBAAN,SAAmCD,iBAAnC,CAAwD;AAC7DE,EAAAA,WAAW,CAACC,QAAD,EAAoBC,YAApB,EAAkD;AAC3D;AACA;AACA,UAAMC,aAAgC,GAAG,EAAzC;AACA,UAAMC,eAAsD,GAAG;AAC7DC,MAAAA,OAAO,EAAEC;AADoD,KAA/D;AAGAJ,IAAAA,YAAY,CAACK,OAAb,CAAsBC,GAAD,IAAS;AAC5B,UAAI,kBAAkBA,GAAlB,IAAyB,iBAAiBA,GAA9C,EAAmD;AACjDL,QAAAA,aAAa,CAACM,IAAd,CACGD,GAAD,CAAoCE,WAApC,CAAgD;AAAA;;AAAA,0CAC9CN,eAAe,CAACC,OAD8B,0DAC9C,2BAAAD,eAAe,CAD+B;AAAA,SAAhD,CADF;AAKD;AACF,KARD;AASA,UAAMH,QAAQ,EAAd;;AAhB2D;;AAAA;;AAiB3D,SAAKU,cAAL,GAAsBR,aAAtB;AACAC,IAAAA,eAAe,CAACC,OAAhB,GAA0B,KAAKO,gBAAL,CAAsBC,IAAtB,CAA2B,IAA3B,CAA1B;AACA,SAAKC,SAAL,GAAiBb,QAAjB;AACD;;AAEOW,EAAAA,gBAAgB,GAAG;AACzB,SAAKG,MAAL,CAAY,KAAKD,SAAL,EAAZ;AACD;;AAKME,EAAAA,WAAW,GAAG;AACnB,SAAKL,cAAL,CAAoBJ,OAApB,CAA6BS,WAAD,IAAiBA,WAAW,EAAxD;;AACA,SAAKL,cAAL,GAAsB,EAAtB;AACD;;AAEMM,EAAAA,YAAY,GAAS;AAC1B,SAAKN,cAAL,CAAoBJ,OAApB,CAA6BS,WAAD,IAAiBA,WAAW,EAAxD;;AACA,SAAKL,cAAL,GAAsB,EAAtB;AACD;;AAtC4D","sourcesContent":["import type { DependencyList } from \"react\";\n\nimport { RNSkReadonlyValue } from \"./RNSkReadonlyValue\";\n\nexport class RNSkComputedValue<T> extends RNSkReadonlyValue<T> {\n constructor(callback: () => T, dependencies: DependencyList) {\n // Initialize dependencies - we can't call this yet, since\n // super if not called and it requires a start value to be set.\n const unsubscribers: Array<() => void> = [];\n const notifyUpdateRef: { current: (() => void) | undefined } = {\n current: undefined,\n };\n dependencies.forEach((dep) => {\n if (\"__typename__\" in dep && \"addListener\" in dep) {\n unsubscribers.push(\n (dep as RNSkReadonlyValue<unknown>).addListener(() =>\n notifyUpdateRef.current?.()\n )\n );\n }\n });\n super(callback());\n this._unsubscribers = unsubscribers;\n notifyUpdateRef.current = this.dependecyUpdated.bind(this);\n this._callback = callback;\n }\n\n private dependecyUpdated() {\n this.update(this._callback());\n }\n\n private _callback: () => T;\n private _unsubscribers: Array<() => void>;\n\n public unsubscribe() {\n this._unsubscribers.forEach((unsubscribe) => unsubscribe());\n this._unsubscribers = [];\n }\n\n public __invalidate(): void {\n this._unsubscribers.forEach((unsubscribe) => unsubscribe());\n this._unsubscribers = [];\n }\n}\n"]}
@@ -32,5 +32,9 @@ export class RNSkReadonlyValue {
32
32
  };
33
33
  }
34
34
 
35
+ __invalidate() {
36
+ this._listeners = [];
37
+ }
38
+
35
39
  }
36
40
  //# sourceMappingURL=RNSkReadonlyValue.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["RNSkReadonlyValue.ts"],"names":["RNSkReadonlyValue","constructor","value","_current","notifyListeners","_listeners","forEach","cb","update","nextValue","current","addListener","push","splice","indexOf"],"mappings":";;AAEA,OAAO,MAAMA,iBAAN,CAAmD;AACxDC,EAAAA,WAAW,CAACC,KAAD,EAAW;AAAA;;AAAA,wCAK0B,EAL1B;;AAAA,0CAgBS,WAhBT;;AACpB,SAAKC,QAAL,GAAgBD,KAAhB;AACD;;AAKOE,EAAAA,eAAe,GAAS;AAC9B,SAAKC,UAAL,CAAgBC,OAAhB,CAAyBC,EAAD,IAAQA,EAAE,CAAC,KAAKJ,QAAN,CAAlC;AACD;;AAESK,EAAAA,MAAM,CAACC,SAAD,EAAqB;AACnC,SAAKN,QAAL,GAAgBM,SAAhB;AACA,SAAKL,eAAL;AACD;;AAIiB,MAAPM,OAAO,GAAM;AACtB,WAAO,KAAKP,QAAZ;AACD;;AAEMQ,EAAAA,WAAW,CAACJ,EAAD,EAAyB;AACzC,SAAKF,UAAL,CAAgBO,IAAhB,CAAqBL,EAArB;;AACA,WAAO,MAAM;AACX,WAAKF,UAAL,CAAgBQ,MAAhB,CAAuB,KAAKR,UAAL,CAAgBS,OAAhB,CAAwBP,EAAxB,CAAvB,EAAoD,CAApD;AACD,KAFD;AAGD;;AA5BuD","sourcesContent":["import type { SkiaValue } from \"../types\";\n\nexport class RNSkReadonlyValue<T> implements SkiaValue<T> {\n constructor(value: T) {\n this._current = value;\n }\n\n private _current: T;\n private _listeners: Array<(value: T) => void> = [];\n\n private notifyListeners(): void {\n this._listeners.forEach((cb) => cb(this._current));\n }\n\n protected update(nextValue: T): void {\n this._current = nextValue;\n this.notifyListeners();\n }\n\n public readonly __typename__ = \"RNSkValue\";\n\n public get current(): T {\n return this._current;\n }\n\n public addListener(cb: (value: T) => void) {\n this._listeners.push(cb);\n return () => {\n this._listeners.splice(this._listeners.indexOf(cb), 1);\n };\n }\n}\n"]}
1
+ {"version":3,"sources":["RNSkReadonlyValue.ts"],"names":["RNSkReadonlyValue","constructor","value","_current","notifyListeners","_listeners","forEach","cb","update","nextValue","current","addListener","push","splice","indexOf","__invalidate"],"mappings":";;AAEA,OAAO,MAAMA,iBAAN,CAAmD;AACxDC,EAAAA,WAAW,CAACC,KAAD,EAAW;AAAA;;AAAA,wCAK0B,EAL1B;;AAAA,0CAgBS,WAhBT;;AACpB,SAAKC,QAAL,GAAgBD,KAAhB;AACD;;AAKOE,EAAAA,eAAe,GAAS;AAC9B,SAAKC,UAAL,CAAgBC,OAAhB,CAAyBC,EAAD,IAAQA,EAAE,CAAC,KAAKJ,QAAN,CAAlC;AACD;;AAESK,EAAAA,MAAM,CAACC,SAAD,EAAqB;AACnC,SAAKN,QAAL,GAAgBM,SAAhB;AACA,SAAKL,eAAL;AACD;;AAIiB,MAAPM,OAAO,GAAM;AACtB,WAAO,KAAKP,QAAZ;AACD;;AAEMQ,EAAAA,WAAW,CAACJ,EAAD,EAAyB;AACzC,SAAKF,UAAL,CAAgBO,IAAhB,CAAqBL,EAArB;;AACA,WAAO,MAAM;AACX,WAAKF,UAAL,CAAgBQ,MAAhB,CAAuB,KAAKR,UAAL,CAAgBS,OAAhB,CAAwBP,EAAxB,CAAvB,EAAoD,CAApD;AACD,KAFD;AAGD;;AAEMQ,EAAAA,YAAY,GAAS;AAC1B,SAAKV,UAAL,GAAkB,EAAlB;AACD;;AAhCuD","sourcesContent":["import type { SkiaValue } from \"../types\";\n\nexport class RNSkReadonlyValue<T> implements SkiaValue<T> {\n constructor(value: T) {\n this._current = value;\n }\n\n private _current: T;\n private _listeners: Array<(value: T) => void> = [];\n\n private notifyListeners(): void {\n this._listeners.forEach((cb) => cb(this._current));\n }\n\n protected update(nextValue: T): void {\n this._current = nextValue;\n this.notifyListeners();\n }\n\n public readonly __typename__ = \"RNSkValue\";\n\n public get current(): T {\n return this._current;\n }\n\n public addListener(cb: (value: T) => void) {\n this._listeners.push(cb);\n return () => {\n this._listeners.splice(this._listeners.indexOf(cb), 1);\n };\n }\n\n public __invalidate(): void {\n this._listeners = [];\n }\n}\n"]}
@@ -12,30 +12,29 @@ const useInternalTouchHandler = function (handlers) {
12
12
  history.forEach(touches => {
13
13
  // Enumerate touches
14
14
  for (let i = 0; i < touches.length; i++) {
15
- var _prevTouchInfoRef$cur, _prevTouchInfoRef$cur2, _prevTouchInfoRef$cur3, _prevTouchInfoRef$cur4, _prevTouchInfoRef$cur5, _prevTouchInfoRef$cur6, _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;
19
19
  }
20
20
 
21
- const touch = touches[i]; // Calculate the velocity from the previous touch.
21
+ const touch = touches[i];
22
+ const prevTouch = prevTouchInfoRef.current[touch.id]; // Calculate the velocity from the previous touch.
22
23
 
23
24
  const timeDiffseconds = touch.timestamp - ((_prevTouchInfoRef$cur = (_prevTouchInfoRef$cur2 = prevTouchInfoRef.current[touch.id]) === null || _prevTouchInfoRef$cur2 === void 0 ? void 0 : _prevTouchInfoRef$cur2.timestamp) !== null && _prevTouchInfoRef$cur !== void 0 ? _prevTouchInfoRef$cur : touch.timestamp);
24
- const distX = touch.x - ((_prevTouchInfoRef$cur3 = (_prevTouchInfoRef$cur4 = prevTouchInfoRef.current[touch.id]) === null || _prevTouchInfoRef$cur4 === void 0 ? void 0 : _prevTouchInfoRef$cur4.x) !== null && _prevTouchInfoRef$cur3 !== void 0 ? _prevTouchInfoRef$cur3 : touch.x);
25
- const distY = touch.y - ((_prevTouchInfoRef$cur5 = (_prevTouchInfoRef$cur6 = prevTouchInfoRef.current[touch.id]) === null || _prevTouchInfoRef$cur6 === void 0 ? void 0 : _prevTouchInfoRef$cur6.y) !== null && _prevTouchInfoRef$cur5 !== void 0 ? _prevTouchInfoRef$cur5 : touch.y);
25
+ const distX = touch.x - ((_prevTouch$x = prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.x) !== null && _prevTouch$x !== void 0 ? _prevTouch$x : touch.x);
26
+ const distY = touch.y - ((_prevTouch$y = prevTouch === null || prevTouch === void 0 ? void 0 : prevTouch.y) !== null && _prevTouch$y !== void 0 ? _prevTouch$y : touch.y);
26
27
 
27
- if (touch.type !== TouchType.Start && touch.type !== TouchType.End && touch.type !== TouchType.Cancelled) {
28
- if (timeDiffseconds > 0) {
29
- prevVelocityRef.current[touch.id] = {
30
- x: distX / timeDiffseconds / PixelRatio.get(),
31
- y: distY / timeDiffseconds / PixelRatio.get()
32
- };
33
- }
28
+ if (touch.type !== TouchType.Start && touch.type !== TouchType.End && touch.type !== TouchType.Cancelled && timeDiffseconds > 0) {
29
+ prevVelocityRef.current[touch.id] = {
30
+ x: distX / timeDiffseconds / PixelRatio.get(),
31
+ y: distY / timeDiffseconds / PixelRatio.get()
32
+ };
34
33
  }
35
34
 
36
35
  const extendedTouchInfo = { ...touch,
37
- velocityX: (_prevVelocityRef$curr = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr === void 0 ? void 0 : _prevVelocityRef$curr.x,
38
- velocityY: (_prevVelocityRef$curr2 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr2 === void 0 ? void 0 : _prevVelocityRef$curr2.y
36
+ velocityX: (_prevVelocityRef$curr = (_prevVelocityRef$curr2 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr2 === void 0 ? void 0 : _prevVelocityRef$curr2.x) !== null && _prevVelocityRef$curr !== void 0 ? _prevVelocityRef$curr : 0,
37
+ velocityY: (_prevVelocityRef$curr3 = (_prevVelocityRef$curr4 = prevVelocityRef.current[touch.id]) === null || _prevVelocityRef$curr4 === void 0 ? void 0 : _prevVelocityRef$curr4.y) !== null && _prevVelocityRef$curr3 !== void 0 ? _prevVelocityRef$curr3 : 0
39
38
  }; // Save previous touch
40
39
 
41
40
  prevTouchInfoRef.current[touch.id] = touch;
@@ -46,7 +45,6 @@ const useInternalTouchHandler = function (handlers) {
46
45
  } else if (touch.type === TouchType.Active) {
47
46
  handlers.onActive && handlers.onActive(extendedTouchInfo);
48
47
  } else {
49
- handlers.onActive && handlers.onActive(extendedTouchInfo);
50
48
  handlers.onEnd && handlers.onEnd(extendedTouchInfo);
51
49
  }
52
50
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["useTouchHandler.ts"],"names":["useCallback","useRef","PixelRatio","TouchType","useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","timeDiffseconds","timestamp","current","id","distX","x","distY","y","type","Start","End","Cancelled","get","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"mappings":"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","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback, useRef } from \"react\";\nimport { PixelRatio } from \"react-native\";\n\nimport type {\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 }>({});\n const prevVelocityRef = useRef<{ [key: number]: { x: number; y: number } }>(\n {}\n );\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\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 =\n touch.x - (prevTouchInfoRef.current[touch.id]?.x ?? touch.x);\n const distY =\n touch.y - (prevTouchInfoRef.current[touch.id]?.y ?? touch.y);\n\n if (\n touch.type !== TouchType.Start &&\n touch.type !== TouchType.End &&\n touch.type !== TouchType.Cancelled\n ) {\n if (timeDiffseconds > 0) {\n prevVelocityRef.current[touch.id] = {\n x: distX / timeDiffseconds / PixelRatio.get(),\n y: distY / timeDiffseconds / PixelRatio.get(),\n };\n }\n }\n\n const extendedTouchInfo: ExtendedTouchInfo = {\n ...touch,\n velocityX: prevVelocityRef.current[touch.id]?.x,\n velocityY: prevVelocityRef.current[touch.id]?.y,\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.onActive && handlers.onActive(extendedTouchInfo);\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"]}
1
+ {"version":3,"sources":["useTouchHandler.ts"],"names":["useCallback","useRef","PixelRatio","TouchType","useInternalTouchHandler","handlers","deps","multiTouch","prevTouchInfoRef","prevVelocityRef","history","forEach","touches","i","length","touch","prevTouch","current","id","timeDiffseconds","timestamp","distX","x","distY","y","type","Start","End","Cancelled","get","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"mappings":"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","sourcesContent":["import type { DependencyList } from \"react\";\nimport { useCallback, useRef } from \"react\";\nimport { PixelRatio } from \"react-native\";\n\nimport type { Vector } from \"../skia/types\";\n\nimport type {\n ExtendedTouchInfo,\n TouchHandlers,\n TouchHandler,\n TouchInfo,\n} from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst useInternalTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = [],\n multiTouch = false\n): TouchHandler => {\n const prevTouchInfoRef = useRef<{ [key: number]: TouchInfo | undefined }>({});\n const prevVelocityRef = useRef<{ [key: number]: Vector | undefined }>({});\n\n return useCallback((history: Array<Array<TouchInfo>>) => {\n // Process all items in the current touch history\n history.forEach((touches) => {\n // Enumerate touches\n for (let i = 0; i < touches.length; i++) {\n if (!multiTouch && i > 0) {\n break;\n }\n\n const touch = touches[i];\n const prevTouch = prevTouchInfoRef.current[touch.id];\n // Calculate the velocity from the previous touch.\n const timeDiffseconds =\n touch.timestamp -\n (prevTouchInfoRef.current[touch.id]?.timestamp ?? touch.timestamp);\n\n const distX = touch.x - (prevTouch?.x ?? touch.x);\n const distY = touch.y - (prevTouch?.y ?? touch.y);\n\n if (\n touch.type !== TouchType.Start &&\n touch.type !== TouchType.End &&\n touch.type !== TouchType.Cancelled &&\n timeDiffseconds > 0\n ) {\n prevVelocityRef.current[touch.id] = {\n x: distX / timeDiffseconds / PixelRatio.get(),\n y: distY / timeDiffseconds / PixelRatio.get(),\n };\n }\n\n const extendedTouchInfo: ExtendedTouchInfo = {\n ...touch,\n velocityX: prevVelocityRef.current[touch.id]?.x ?? 0,\n velocityY: prevVelocityRef.current[touch.id]?.y ?? 0,\n };\n\n // Save previous touch\n prevTouchInfoRef.current[touch.id] = touch;\n\n if (touch.type === TouchType.Start) {\n delete prevVelocityRef.current[touch.id];\n handlers.onStart && handlers.onStart(touch);\n } else if (touch.type === TouchType.Active) {\n handlers.onActive && handlers.onActive(extendedTouchInfo);\n } else {\n handlers.onEnd && handlers.onEnd(extendedTouchInfo);\n }\n }\n });\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler only handles single touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, false);\n};\n\n/**\n * Provides a callback for handling touch events in the Skia View.\n * This touch handler handles multiple touches.\n * @param handlers Callbacks for the different touch states\n * @param deps optional Dependency array to update the handlers\n * @returns A function that can be used from within the onDraw callback to\n * update and handle touch events. Call it with the touches property from\n * the info object.\n */\nexport const useMultiTouchHandler = (\n handlers: TouchHandlers,\n deps: DependencyList = []\n): TouchHandler => {\n return useInternalTouchHandler(handlers, deps, true);\n};\n"]}
@@ -1,7 +1,12 @@
1
- import type { SkiaValue } from "../../../values";
1
+ import type { SkiaSelector, SkiaValue } from "../../../values";
2
2
  export declare const isValue: (value: unknown) => value is SkiaValue<unknown>;
3
+ export declare const isSelector: <T, R>(value: unknown) => value is {
4
+ selector: (v: T) => R;
5
+ value: SkiaValue<T>;
6
+ };
3
7
  export declare const isAnimated: <T>(props: AnimatedProps<T>) => boolean;
4
8
  export declare const materialize: <T>(props: AnimatedProps<T>) => T;
9
+ export declare type AnimatedProp<T, P = any> = T | SkiaValue<T> | SkiaSelector<T, P>;
5
10
  export declare type AnimatedProps<T> = {
6
- [K in keyof T]: T[K] | SkiaValue<T[K]>;
11
+ [K in keyof T]: AnimatedProp<T[K]>;
7
12
  };
@@ -1,5 +1,3 @@
1
- import type { DependencyList } from "react";
2
- import type { SkData, DataSource } from "../types";
3
- export declare const useDataCollection: <T>(sources: DataSource[], factory: (data: SkData) => T, onError?: ((err: Error) => void) | undefined, deps?: DependencyList | undefined) => (T | null)[] | null;
4
- export declare const useRawData: <T>(source: DataSource | null | undefined, factory: (data: SkData) => T, onError?: ((err: Error) => void) | undefined, deps?: DependencyList | undefined) => T | null;
5
- export declare const useData: (source: DataSource | null | undefined, onError?: ((err: Error) => void) | undefined, deps?: DependencyList | undefined) => SkData | null;
1
+ import type { SkData, DataSourceParam } from "../types";
2
+ export declare const useRawData: <T>(source: DataSourceParam, factory: (data: SkData) => T, onError?: ((err: Error) => void) | undefined) => T | null;
3
+ export declare const useData: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => SkData | null;
@@ -1,5 +1,5 @@
1
- import type { DataSource, SkFont } from "../types";
1
+ import type { DataSourceParam } from "../types";
2
2
  /**
3
3
  * Returns a Skia Font object
4
4
  * */
5
- export declare const useFont: (font: DataSource | null | undefined, size?: number | undefined, onError?: ((err: Error) => void) | undefined) => SkFont | null;
5
+ export declare const useFont: (font: DataSourceParam, size?: number | undefined, onError?: ((err: Error) => void) | undefined) => import("../types").SkFont | null;
@@ -1,5 +1,5 @@
1
- import type { DataSource } from "../types";
1
+ import type { DataSourceParam } from "../types";
2
2
  /**
3
3
  * Returns a Skia Image object
4
4
  * */
5
- export declare const useImage: (source: DataSource | null | undefined, onError?: ((err: Error) => void) | undefined) => import("../types").SkImage | null;
5
+ export declare const useImage: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => import("../types").SkImage | null;
@@ -1,2 +1,2 @@
1
- import type { DataSource } from "../types";
2
- export declare const useSVG: (source: DataSource | null | undefined, onError?: ((err: Error) => void) | undefined) => import("../types").SkSVG | null;
1
+ import type { DataSourceParam } from "../types";
2
+ export declare const useSVG: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => import("../types").SkSVG | null;
@@ -1,5 +1,5 @@
1
- import type { DataSource } from "../types";
1
+ import type { DataSourceParam } from "../types";
2
2
  /**
3
3
  * Returns a Skia Typeface object
4
4
  * */
5
- export declare const useTypeface: (source: DataSource | null | undefined, onError?: ((err: Error) => void) | undefined) => import("../types").SkTypeface | null;
5
+ export declare const useTypeface: (source: DataSourceParam, onError?: ((err: Error) => void) | undefined) => import("../types").SkTypeface | null;
@@ -1,5 +1,12 @@
1
- /// <reference types="node" />
2
- /// <reference types="react-native" />
3
1
  import type { SkJSIInstance } from "../JsiInstance";
4
2
  export declare type SkData = SkJSIInstance<"Data">;
5
- export declare type DataSource = ReturnType<typeof require> | string | Uint8Array;
3
+ declare type RNModule = number;
4
+ declare type ESModule = {
5
+ __esModule: true;
6
+ default: string;
7
+ };
8
+ export declare type DataModule = RNModule | ESModule;
9
+ export declare type DataSource = DataModule | string | Uint8Array;
10
+ export declare type DataSourceParam = DataSource | null | undefined;
11
+ export declare const isRNModule: (mod: DataModule) => mod is number;
12
+ export {};
@@ -3,6 +3,7 @@ import type { SkRRect } from "../types";
3
3
  import { HostObject } from "./Host";
4
4
  import { JsiSkRect } from "./JsiSkRect";
5
5
  export declare class JsiSkRRect extends HostObject<RRect, "RRect"> implements SkRRect {
6
+ static fromValue(CanvasKit: CanvasKit, rect: SkRRect): Float32Array;
6
7
  constructor(CanvasKit: CanvasKit, ref: RRect);
7
8
  get rx(): number;
8
9
  get ry(): number;
@@ -2,7 +2,7 @@ import type { CanvasKit, Rect } from "canvaskit-wasm";
2
2
  import type { SkRect } from "../types";
3
3
  import { HostObject } from "./Host";
4
4
  export declare class JsiSkRect extends HostObject<Rect, "Rect"> implements SkRect {
5
- static fromValue(CanvasKit: CanvasKit, rect: SkRect): JsiSkRect;
5
+ static fromValue(CanvasKit: CanvasKit, rect: SkRect): Float32Array;
6
6
  constructor(CanvasKit: CanvasKit, ref: Rect);
7
7
  get x(): number;
8
8
  get y(): number;
@@ -1,3 +1,4 @@
1
1
  export * from "./types";
2
2
  export * from "./hooks";
3
3
  export * from "./api";
4
+ export * from "./selector";
@@ -0,0 +1,14 @@
1
+ import type { SkiaValue } from "./types";
2
+ export declare type SkiaSelector<TReturn, TInput = unknown> = {
3
+ value: SkiaValue<TInput>;
4
+ selector: (v: TInput) => TReturn;
5
+ };
6
+ /**
7
+ * Wraps a Skia Value with a selector function. The selector function can access the
8
+ * inner values of the Skia Value so that we can dynamically ready array values and
9
+ * object values when doing animations in Skia.
10
+ * @param value Dependant value
11
+ * @param selector Selector function to calculate new value from the Skia Value's value
12
+ * @returns A descriptor that will be used by the reconciler to calculate the value
13
+ */
14
+ export declare const Selector: <TInput, TReturn>(value: SkiaValue<TInput>, selector: (v: TInput) => TReturn) => SkiaSelector<TReturn, TInput>;
@@ -8,6 +8,10 @@ export interface SkiaValue<T = number> {
8
8
  * Returns unsubscribe method.
9
9
  */
10
10
  addListener: (cb: (value: T) => void) => () => void;
11
+ /**
12
+ * Invalidates the value. Has different meaning depending on the type of the value.
13
+ */
14
+ __invalidate: () => void;
11
15
  /**
12
16
  * Field to make typechecking easier
13
17
  */
@@ -6,4 +6,5 @@ export declare class RNSkComputedValue<T> extends RNSkReadonlyValue<T> {
6
6
  private _callback;
7
7
  private _unsubscribers;
8
8
  unsubscribe(): void;
9
+ __invalidate(): void;
9
10
  }
@@ -8,4 +8,5 @@ export declare class RNSkReadonlyValue<T> implements SkiaValue<T> {
8
8
  readonly __typename__ = "RNSkValue";
9
9
  get current(): T;
10
10
  addListener(cb: (value: T) => void): () => void;
11
+ __invalidate(): void;
11
12
  }
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.139",
10
+ "version": "0.1.142",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -37,7 +37,7 @@
37
37
  ],
38
38
  "scripts": {
39
39
  "tsc": "tsc --noEmit",
40
- "lint": "eslint . --ext .ts,.tsx --max-warnings 0",
40
+ "lint": "eslint . --ext .ts,.tsx --max-warnings 0 --cache",
41
41
  "test": "jest",
42
42
  "postinstall": "node scripts/install-npm.js",
43
43
  "build": "bob build"
@@ -69,18 +69,23 @@
69
69
  "react-native": ">=0.63.0-rc.0 <1.0.x",
70
70
  "react-native-reanimated": ">=2.0.0"
71
71
  },
72
+ "peerDependenciesMeta": {
73
+ "react-native-reanimated": {
74
+ "optional": true
75
+ }
76
+ },
72
77
  "devDependencies": {
73
- "@types/jest": "^27.0.3",
78
+ "@types/jest": "^28.1.6",
74
79
  "@types/react-native": "^0.65.0",
75
80
  "@types/react-reconciler": "^0.26.4",
76
- "eslint": "7.32.0",
77
- "eslint-config-react-native-wcandillon": "^3.7.2",
78
- "eslint-plugin-reanimated": "^1.2.6",
79
- "jest": "^27.4.3",
81
+ "eslint": "8.21.0",
82
+ "eslint-config-react-native-wcandillon": "3.9.0",
83
+ "eslint-plugin-reanimated": "2.0.0",
84
+ "jest": "28.1.3",
80
85
  "react": "17.0.2",
81
86
  "react-native": "0.66.2",
82
87
  "react-native-builder-bob": "^0.18.2",
83
- "ts-jest": "^27.0.7",
88
+ "ts-jest": "^28.0.7",
84
89
  "typescript": "^4.6.4"
85
90
  },
86
91
  "dependencies": {
package/src/mock/index.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  import type { Color, Skia as SkiaApi, SkRect, Vector } from "../skia/types";
4
4
  import * as Values from "../values/web";
5
5
  import * as ValuesHooks from "../values/hooks";
6
+ import { Selector } from "../values/selector";
6
7
  import * as BaseSkia from "../skia/types";
7
8
  import type * as SkiaExports from "../skia";
8
9
  import type * as ExternalExports from "../external";
@@ -46,7 +47,6 @@ export const Mock: typeof SkiaExports &
46
47
  Skia,
47
48
  ...BaseSkia,
48
49
  // 2. Hooks
49
- useDataCollection: Noop,
50
50
  useRawData: Noop,
51
51
  useData: Noop,
52
52
  useFont: Noop,
@@ -87,6 +87,7 @@ export const Mock: typeof SkiaExports &
87
87
  // ValueExports
88
88
  ...Values,
89
89
  ...ValuesHooks,
90
+ Selector,
90
91
  // Animations
91
92
  ...timingFunctions,
92
93
  ...springFunctions,
@@ -3,7 +3,7 @@ import type { RefObject } from "react";
3
3
  import type { SkiaView } from "../views";
4
4
  import type { SkiaValue } from "../values";
5
5
 
6
- import { isValue } from "./processors";
6
+ import { isSelector, isValue } from "./processors";
7
7
  import type { Node } from "./nodes";
8
8
 
9
9
  type Unsubscribe = () => void;
@@ -29,7 +29,10 @@ export class DependencyManager {
29
29
  }
30
30
 
31
31
  subscribeNode(node: Node, props: Props) {
32
- const values = Object.values(props).filter(isValue);
32
+ const values = Object.values(props)
33
+ .filter((v) => isValue(v) || isSelector(v))
34
+ .map((v) => (isSelector(v) ? v.value : (v as SkiaValue<unknown>)));
35
+
33
36
  if (values.length > 0) {
34
37
  this.subscriptions.set(node, { values, unsubscribe: null });
35
38
  }
@@ -1,4 +1,4 @@
1
- import type { SkiaValue } from "../../../values";
1
+ import type { SkiaSelector, SkiaValue } from "../../../values";
2
2
  import { mapKeys } from "../../typeddash";
3
3
 
4
4
  export const isValue = (value: unknown): value is SkiaValue<unknown> => {
@@ -17,6 +17,24 @@ export const isValue = (value: unknown): value is SkiaValue<unknown> => {
17
17
  return false;
18
18
  };
19
19
 
20
+ export const isSelector = <T, R>(
21
+ value: unknown
22
+ ): value is {
23
+ selector: (v: T) => R;
24
+ value: SkiaValue<T>;
25
+ } => {
26
+ if (value) {
27
+ return (
28
+ typeof value === "object" &&
29
+ "selector" in value &&
30
+ "value" in value &&
31
+ (value as Record<string, unknown>).selector !== undefined &&
32
+ (value as Record<string, unknown>).value !== undefined
33
+ );
34
+ }
35
+ return false;
36
+ };
37
+
20
38
  export const isAnimated = <T>(props: AnimatedProps<T>) => {
21
39
  for (const value of Object.values(props)) {
22
40
  if (isValue(value)) {
@@ -29,14 +47,18 @@ export const isAnimated = <T>(props: AnimatedProps<T>) => {
29
47
  export const materialize = <T>(props: AnimatedProps<T>) => {
30
48
  const result = { ...props };
31
49
  mapKeys(props).forEach((key) => {
32
- const value = props[key];
33
- if (isValue(value)) {
34
- result[key] = (value as SkiaValue<T[typeof key]>).current;
50
+ const prop = props[key];
51
+ if (isValue(prop)) {
52
+ result[key] = (prop as SkiaValue<T[typeof key]>).current;
53
+ } else if (isSelector(prop)) {
54
+ result[key] = prop.selector(prop.value.current) as T[typeof key];
35
55
  }
36
56
  });
37
57
  return result as T;
38
58
  };
39
59
 
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ export type AnimatedProp<T, P = any> = T | SkiaValue<T> | SkiaSelector<T, P>;
40
62
  export type AnimatedProps<T> = {
41
- [K in keyof T]: T[K] | SkiaValue<T[K]>;
63
+ [K in keyof T]: AnimatedProp<T[K]>;
42
64
  };