@shopify/react-native-skia 0.1.137 → 0.1.140

Sign up to get free protection for your applications and to get access to all the features.
Files changed (187) hide show
  1. package/android/CMakeLists.txt +5 -1
  2. package/android/build.gradle +4 -3
  3. package/cpp/api/JsiSkApi.h +0 -4
  4. package/cpp/api/JsiSkFont.h +0 -19
  5. package/cpp/api/JsiSkTypeface.h +1 -29
  6. package/lib/commonjs/mock/index.js +0 -4
  7. package/lib/commonjs/mock/index.js.map +1 -1
  8. package/lib/commonjs/renderer/Canvas.js +5 -8
  9. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  10. package/lib/commonjs/renderer/components/text/Glyphs.js +4 -6
  11. package/lib/commonjs/renderer/components/text/Glyphs.js.map +1 -1
  12. package/lib/commonjs/renderer/components/text/Text.js +4 -6
  13. package/lib/commonjs/renderer/components/text/Text.js.map +1 -1
  14. package/lib/commonjs/renderer/components/text/TextPath.js +3 -4
  15. package/lib/commonjs/renderer/components/text/TextPath.js.map +1 -1
  16. package/lib/commonjs/renderer/processors/Font.js +1 -27
  17. package/lib/commonjs/renderer/processors/Font.js.map +1 -1
  18. package/lib/commonjs/skia/core/Data.js +3 -1
  19. package/lib/commonjs/skia/core/Data.js.map +1 -1
  20. package/lib/commonjs/skia/core/Image.js +4 -1
  21. package/lib/commonjs/skia/core/Image.js.map +1 -1
  22. package/lib/commonjs/skia/core/SVG.js +3 -1
  23. package/lib/commonjs/skia/core/SVG.js.map +1 -1
  24. package/lib/commonjs/skia/core/Typeface.js +4 -1
  25. package/lib/commonjs/skia/core/Typeface.js.map +1 -1
  26. package/lib/commonjs/skia/core/index.js +0 -26
  27. package/lib/commonjs/skia/core/index.js.map +1 -1
  28. package/lib/commonjs/skia/types/Font/Font.js.map +1 -1
  29. package/lib/commonjs/skia/types/Image/ImageFactory.js +0 -2
  30. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  31. package/lib/commonjs/skia/types/Matrix.js +1 -1
  32. package/lib/commonjs/skia/types/Matrix.js.map +1 -1
  33. package/lib/commonjs/skia/types/Path/Path.js.map +1 -1
  34. package/lib/commonjs/skia/types/index.js +0 -13
  35. package/lib/commonjs/skia/types/index.js.map +1 -1
  36. package/lib/commonjs/skia/web/JsiSkFont.js +0 -6
  37. package/lib/commonjs/skia/web/JsiSkFont.js.map +1 -1
  38. package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js +1 -1
  39. package/lib/commonjs/skia/web/JsiSkTextBlobFactory.js.map +1 -1
  40. package/lib/commonjs/skia/web/JsiSkia.js +0 -3
  41. package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
  42. package/lib/commonjs/values/hooks/useComputedValue.js +1 -8
  43. package/lib/commonjs/values/hooks/useComputedValue.js.map +1 -1
  44. package/lib/commonjs/views/SkiaView.web.js +62 -52
  45. package/lib/commonjs/views/SkiaView.web.js.map +1 -1
  46. package/lib/commonjs/views/useTouchHandler.js +8 -3
  47. package/lib/commonjs/views/useTouchHandler.js.map +1 -1
  48. package/lib/commonjs/web/LoadSkiaWeb.js +6 -2
  49. package/lib/commonjs/web/LoadSkiaWeb.js.map +1 -1
  50. package/lib/commonjs/web/WithSkiaWeb.js +5 -4
  51. package/lib/commonjs/web/WithSkiaWeb.js.map +1 -1
  52. package/lib/module/mock/index.js +0 -4
  53. package/lib/module/mock/index.js.map +1 -1
  54. package/lib/module/renderer/Canvas.js +5 -6
  55. package/lib/module/renderer/Canvas.js.map +1 -1
  56. package/lib/module/renderer/components/text/Glyphs.js +4 -5
  57. package/lib/module/renderer/components/text/Glyphs.js.map +1 -1
  58. package/lib/module/renderer/components/text/Text.js +4 -5
  59. package/lib/module/renderer/components/text/Text.js.map +1 -1
  60. package/lib/module/renderer/components/text/TextPath.js +3 -3
  61. package/lib/module/renderer/components/text/TextPath.js.map +1 -1
  62. package/lib/module/renderer/processors/Font.js +0 -23
  63. package/lib/module/renderer/processors/Font.js.map +1 -1
  64. package/lib/module/skia/core/Data.js +3 -1
  65. package/lib/module/skia/core/Data.js.map +1 -1
  66. package/lib/module/skia/core/Image.js +2 -1
  67. package/lib/module/skia/core/Image.js.map +1 -1
  68. package/lib/module/skia/core/SVG.js +2 -1
  69. package/lib/module/skia/core/SVG.js.map +1 -1
  70. package/lib/module/skia/core/Typeface.js +2 -1
  71. package/lib/module/skia/core/Typeface.js.map +1 -1
  72. package/lib/module/skia/core/index.js +0 -2
  73. package/lib/module/skia/core/index.js.map +1 -1
  74. package/lib/module/skia/types/Font/Font.js.map +1 -1
  75. package/lib/module/skia/types/Image/ImageFactory.js +0 -1
  76. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  77. package/lib/module/skia/types/Matrix.js +1 -1
  78. package/lib/module/skia/types/Matrix.js.map +1 -1
  79. package/lib/module/skia/types/Path/Path.js.map +1 -1
  80. package/lib/module/skia/types/index.js +0 -1
  81. package/lib/module/skia/types/index.js.map +1 -1
  82. package/lib/module/skia/web/JsiSkFont.js +0 -6
  83. package/lib/module/skia/web/JsiSkFont.js.map +1 -1
  84. package/lib/module/skia/web/JsiSkTextBlobFactory.js +1 -1
  85. package/lib/module/skia/web/JsiSkTextBlobFactory.js.map +1 -1
  86. package/lib/module/skia/web/JsiSkia.js +0 -2
  87. package/lib/module/skia/web/JsiSkia.js.map +1 -1
  88. package/lib/module/values/hooks/useComputedValue.js +0 -4
  89. package/lib/module/values/hooks/useComputedValue.js.map +1 -1
  90. package/lib/module/views/SkiaView.web.js +62 -53
  91. package/lib/module/views/SkiaView.web.js.map +1 -1
  92. package/lib/module/views/useTouchHandler.js +8 -3
  93. package/lib/module/views/useTouchHandler.js.map +1 -1
  94. package/lib/module/web/LoadSkiaWeb.js +6 -2
  95. package/lib/module/web/LoadSkiaWeb.js.map +1 -1
  96. package/lib/module/web/WithSkiaWeb.js +5 -4
  97. package/lib/module/web/WithSkiaWeb.js.map +1 -1
  98. package/lib/typescript/src/renderer/Canvas.d.ts +1 -3
  99. package/lib/typescript/src/renderer/DrawingContext.d.ts +1 -2
  100. package/lib/typescript/src/renderer/processors/Font.d.ts +1 -5
  101. package/lib/typescript/src/skia/core/index.d.ts +0 -2
  102. package/lib/typescript/src/skia/types/Font/Font.d.ts +0 -12
  103. package/lib/typescript/src/skia/types/Matrix.d.ts +1 -1
  104. package/lib/typescript/src/skia/types/Skia.d.ts +0 -2
  105. package/lib/typescript/src/skia/types/Typeface/Typeface.d.ts +1 -4
  106. package/lib/typescript/src/skia/types/index.d.ts +0 -1
  107. package/lib/typescript/src/skia/web/JsiSkFont.d.ts +1 -2
  108. package/lib/typescript/src/values/hooks/useComputedValue.d.ts +0 -1
  109. package/lib/typescript/src/views/SkiaView.web.d.ts +7 -9
  110. package/lib/typescript/src/web/LoadSkiaWeb.d.ts +3 -3
  111. package/lib/typescript/src/web/WithSkiaWeb.d.ts +4 -2
  112. package/package.json +9 -4
  113. package/src/mock/index.ts +0 -4
  114. package/src/renderer/Canvas.tsx +5 -8
  115. package/src/renderer/DrawingContext.ts +1 -2
  116. package/src/renderer/components/text/Glyphs.tsx +2 -6
  117. package/src/renderer/components/text/Text.tsx +2 -3
  118. package/src/renderer/components/text/TextPath.tsx +2 -3
  119. package/src/renderer/processors/Font.ts +2 -25
  120. package/src/skia/core/Data.ts +3 -1
  121. package/src/skia/core/Image.ts +3 -1
  122. package/src/skia/core/SVG.ts +3 -1
  123. package/src/skia/core/Typeface.ts +4 -6
  124. package/src/skia/core/index.ts +0 -2
  125. package/src/skia/types/Font/Font.ts +0 -13
  126. package/src/skia/types/Image/ImageFactory.ts +0 -1
  127. package/src/skia/types/Matrix.ts +1 -1
  128. package/src/skia/types/Path/Path.ts +0 -1
  129. package/src/skia/types/Skia.ts +0 -2
  130. package/src/skia/types/Typeface/Typeface.ts +1 -4
  131. package/src/skia/types/index.ts +0 -1
  132. package/src/skia/web/JsiSkFont.ts +0 -9
  133. package/src/skia/web/JsiSkTextBlobFactory.ts +1 -1
  134. package/src/skia/web/JsiSkia.ts +0 -2
  135. package/src/values/hooks/useComputedValue.ts +0 -5
  136. package/src/views/SkiaView.web.tsx +50 -65
  137. package/src/views/useTouchHandler.ts +4 -2
  138. package/src/web/LoadSkiaWeb.tsx +9 -3
  139. package/src/web/WithSkiaWeb.tsx +10 -5
  140. package/android/README.md +0 -14
  141. package/cpp/api/JsiSkFontMgr.h +0 -84
  142. package/cpp/api/JsiSkFontMgrFactory.h +0 -48
  143. package/cpp/skia/include/third_party/skcms/LICENSE +0 -29
  144. package/cpp/skia/include/third_party/vulkan/LICENSE +0 -29
  145. package/cpp/skia/readme.txt +0 -1
  146. package/lib/commonjs/skia/core/Paint.js +0 -28
  147. package/lib/commonjs/skia/core/Paint.js.map +0 -1
  148. package/lib/commonjs/skia/core/Path.js +0 -72
  149. package/lib/commonjs/skia/core/Path.js.map +0 -1
  150. package/lib/commonjs/skia/types/FontMgr/FontMgr.js +0 -6
  151. package/lib/commonjs/skia/types/FontMgr/FontMgr.js.map +0 -1
  152. package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js +0 -6
  153. package/lib/commonjs/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
  154. package/lib/commonjs/skia/types/FontMgr/index.js +0 -32
  155. package/lib/commonjs/skia/types/FontMgr/index.js.map +0 -1
  156. package/lib/commonjs/skia/web/JsiSkFontMgr.js +0 -33
  157. package/lib/commonjs/skia/web/JsiSkFontMgr.js.map +0 -1
  158. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js +0 -25
  159. package/lib/commonjs/skia/web/JsiSkFontMgrFactory.js.map +0 -1
  160. package/lib/module/skia/core/Paint.js +0 -17
  161. package/lib/module/skia/core/Paint.js.map +0 -1
  162. package/lib/module/skia/core/Path.js +0 -53
  163. package/lib/module/skia/core/Path.js.map +0 -1
  164. package/lib/module/skia/types/FontMgr/FontMgr.js +0 -2
  165. package/lib/module/skia/types/FontMgr/FontMgr.js.map +0 -1
  166. package/lib/module/skia/types/FontMgr/FontMgrFactory.js +0 -2
  167. package/lib/module/skia/types/FontMgr/FontMgrFactory.js.map +0 -1
  168. package/lib/module/skia/types/FontMgr/index.js +0 -3
  169. package/lib/module/skia/types/FontMgr/index.js.map +0 -1
  170. package/lib/module/skia/web/JsiSkFontMgr.js +0 -23
  171. package/lib/module/skia/web/JsiSkFontMgr.js.map +0 -1
  172. package/lib/module/skia/web/JsiSkFontMgrFactory.js +0 -14
  173. package/lib/module/skia/web/JsiSkFontMgrFactory.js.map +0 -1
  174. package/lib/typescript/src/skia/core/Paint.d.ts +0 -6
  175. package/lib/typescript/src/skia/core/Path.d.ts +0 -21
  176. package/lib/typescript/src/skia/types/FontMgr/FontMgr.d.ts +0 -18
  177. package/lib/typescript/src/skia/types/FontMgr/FontMgrFactory.d.ts +0 -4
  178. package/lib/typescript/src/skia/types/FontMgr/index.d.ts +0 -2
  179. package/lib/typescript/src/skia/web/JsiSkFontMgr.d.ts +0 -9
  180. package/lib/typescript/src/skia/web/JsiSkFontMgrFactory.d.ts +0 -8
  181. package/src/skia/core/Paint.ts +0 -22
  182. package/src/skia/core/Path.ts +0 -60
  183. package/src/skia/types/FontMgr/FontMgr.ts +0 -24
  184. package/src/skia/types/FontMgr/FontMgrFactory.ts +0 -12
  185. package/src/skia/types/FontMgr/index.ts +0 -2
  186. package/src/skia/web/JsiSkFontMgr.ts +0 -38
  187. package/src/skia/web/JsiSkFontMgrFactory.ts +0 -18
@@ -4,9 +4,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
4
4
 
5
5
  /* global HTMLCanvasElement */
6
6
  import React from "react";
7
- import { View } from "react-native";
7
+ import { PixelRatio, View } from "react-native";
8
8
  import { JsiSkSurface } from "../skia/web/JsiSkSurface";
9
9
  import { TouchType } from "./types";
10
+ const pd = PixelRatio.get();
10
11
  export class SkiaView extends React.Component {
11
12
  constructor(props) {
12
13
  var _props$mode;
@@ -27,12 +28,12 @@ export class SkiaView extends React.Component {
27
28
 
28
29
  _defineProperty(this, "_redrawRequests", 0);
29
30
 
30
- _defineProperty(this, "_unmounted", false);
31
+ _defineProperty(this, "width", 0);
32
+
33
+ _defineProperty(this, "height", 0);
34
+
35
+ _defineProperty(this, "requestId", 0);
31
36
 
32
- this.state = {
33
- width: -1,
34
- height: -1
35
- };
36
37
  this._mode = (_props$mode = props.mode) !== null && _props$mode !== void 0 ? _props$mode : "default";
37
38
  }
38
39
 
@@ -43,21 +44,30 @@ export class SkiaView extends React.Component {
43
44
  }
44
45
 
45
46
  onLayout(evt) {
46
- this.setState({
47
- width: evt.nativeEvent.layout.width,
48
- height: evt.nativeEvent.layout.height
49
- }, () => {
50
- // Reset canvas / surface on layout change
51
- if (this._canvasRef.current) {
52
- // Create surface
53
- this._surface = new JsiSkSurface(global.CanvasKit, global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)); // Get canvas and repaint
54
-
55
- if (this._surface) {
56
- this._canvas = this._surface.getCanvas();
57
- this.redraw();
58
- }
47
+ const {
48
+ CanvasKit
49
+ } = global;
50
+ const {
51
+ width,
52
+ height
53
+ } = evt.nativeEvent.layout;
54
+ this.width = width;
55
+ this.height = height; // Reset canvas / surface on layout change
56
+
57
+ if (this._canvasRef.current) {
58
+ const canvas = this._canvasRef.current;
59
+ canvas.width = canvas.clientWidth * pd;
60
+ canvas.height = canvas.clientHeight * pd;
61
+ const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);
62
+
63
+ if (!surface) {
64
+ throw new Error("Could not create surface");
59
65
  }
60
- });
66
+
67
+ this._surface = new JsiSkSurface(CanvasKit, surface);
68
+ this._canvas = this._surface.getCanvas();
69
+ this.redraw();
70
+ }
61
71
  }
62
72
 
63
73
  componentDidMount() {
@@ -65,11 +75,13 @@ export class SkiaView extends React.Component {
65
75
  this.tick();
66
76
  }
67
77
 
78
+ componentDidUpdate() {
79
+ this.redraw();
80
+ }
81
+
68
82
  componentWillUnmount() {
69
83
  this.unsubscribeAll();
70
- this._surface = null;
71
- this._canvas = null;
72
- this._unmounted = true;
84
+ cancelAnimationFrame(this.requestId);
73
85
  }
74
86
  /**
75
87
  * Creates a snapshot from the canvas in the surface
@@ -92,26 +104,31 @@ export class SkiaView extends React.Component {
92
104
  if (this._mode === "continuous" || this._redrawRequests > 0) {
93
105
  this._redrawRequests = 0;
94
106
 
95
- if (this._canvas && this.props.onDraw && this.state.height !== -1 && this.state.width !== -1) {
107
+ if (this._canvas && this.props.onDraw) {
96
108
  var _this$_surface2;
97
109
 
98
110
  const touches = [...this._touches];
99
111
  this._touches = [];
100
112
  const info = {
101
- height: this.state.height,
102
- width: this.state.width,
113
+ height: this.height,
114
+ width: this.width,
103
115
  timestamp: Date.now(),
104
- touches: [touches]
116
+ touches: touches.map(t => [t])
105
117
  };
106
- this.props.onDraw && this.props.onDraw(this._canvas, info);
107
- (_this$_surface2 = this._surface) === null || _this$_surface2 === void 0 ? void 0 : _this$_surface2.ref.flush();
108
- }
109
- } // Always request a new redraw as long as we're not unmounted
110
118
 
119
+ if (this.props.onDraw) {
120
+ const canvas = this._canvas;
121
+ canvas.save();
122
+ canvas.scale(pd, pd);
123
+ this.props.onDraw(canvas, info);
124
+ canvas.restore();
125
+ }
111
126
 
112
- if (!this._unmounted) {
113
- requestAnimationFrame(this.tick.bind(this));
127
+ (_this$_surface2 = this._surface) === null || _this$_surface2 === void 0 ? void 0 : _this$_surface2.ref.flush();
128
+ }
114
129
  }
130
+
131
+ this.requestId = requestAnimationFrame(this.tick.bind(this));
115
132
  }
116
133
 
117
134
  redraw() {
@@ -163,20 +180,8 @@ export class SkiaView extends React.Component {
163
180
  this.redraw();
164
181
  }
165
182
 
166
- handleTouchStart(evt) {
167
- this.handleTouchEvent(evt, TouchType.Start);
168
- }
169
-
170
- handleTouchMove(evt) {
171
- this.handleTouchEvent(evt, TouchType.Active);
172
- }
173
-
174
- handleTouchEnd(evt) {
175
- this.handleTouchEvent(evt, TouchType.Cancelled);
176
- }
177
-
178
- handleTouchCancel(evt) {
179
- this.handleTouchEvent(evt, TouchType.End);
183
+ createTouchHandler(touchType) {
184
+ return evt => this.handleTouchEvent(evt, touchType);
180
185
  }
181
186
 
182
187
  render() {
@@ -189,12 +194,16 @@ export class SkiaView extends React.Component {
189
194
  onLayout: this.onLayout.bind(this)
190
195
  }), /*#__PURE__*/React.createElement("canvas", {
191
196
  ref: this._canvasRef,
192
- width: this.state.width,
193
- height: this.state.height,
194
- onPointerDown: this.handleTouchStart.bind(this),
195
- onPointerMove: this.handleTouchMove.bind(this),
196
- onPointerUp: this.handleTouchEnd.bind(this),
197
- onPointerCancel: this.handleTouchCancel.bind(this)
197
+ style: {
198
+ display: "flex",
199
+ flex: 1
200
+ },
201
+ onPointerDown: this.createTouchHandler(TouchType.Start),
202
+ onPointerMove: this.createTouchHandler(TouchType.Active),
203
+ onPointerUp: this.createTouchHandler(TouchType.End),
204
+ onPointerCancel: this.createTouchHandler(TouchType.Cancelled),
205
+ onPointerLeave: this.createTouchHandler(TouchType.End),
206
+ onPointerOut: this.createTouchHandler(TouchType.End)
198
207
  }));
199
208
  }
200
209
 
@@ -1 +1 @@
1
- {"version":3,"sources":["SkiaView.web.tsx"],"names":["React","View","JsiSkSurface","TouchType","SkiaView","Component","constructor","props","createRef","state","width","height","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","setState","nativeEvent","layout","_canvasRef","current","_surface","global","CanvasKit","MakeWebGLCanvasSurface","_canvas","getCanvas","redraw","componentDidMount","tick","componentWillUnmount","_unmounted","makeImageSnapshot","rect","_redrawRequests","onDraw","touches","_touches","info","timestamp","Date","now","ref","flush","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","handleTouchStart","Start","handleTouchMove","Active","handleTouchEnd","Cancelled","handleTouchCancel","End","render","debug","viewProps"],"mappings":";;;;AAAA;AACA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,IAAT,QAAqB,cAArB;AAIA,SAASC,YAAT,QAA6B,0BAA7B;AAGA,SAASC,SAAT,QAA0B,SAA1B;AAEA,OAAO,MA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AS,CAACqE,KAArC;AACD;;AAEDC,EAAAA,eAAe,CAACtD,GAAD,EAAoB;AACjC,SAAKqC,gBAAL,CAAsBrC,GAAtB,EAA2BhB,SAAS,CAACuE,MAArC;AACD;;AAEDC,EAAAA,cAAc,CAACxD,GAAD,EAAoB;AAChC,SAAKqC,gBAAL,CAAsBrC,GAAtB,EAA2BhB,SAAS,CAACyE,SAArC;AACD;;AAEDC,EAAAA,iBAAiB,CAAC1D,GAAD,EAAoB;AACnC,SAAKqC,gBAAL,CAAsBrC,GAAtB,EAA2BhB,SAAS,CAAC2E,GAArC;AACD;;AAEDC,EAAAA,MAAM,GAAG;AACP,UAAM;AAAElE,MAAAA,IAAF;AAAQmE,MAAAA,KAAK,GAAG,KAAhB;AAAuB,SAAGC;AAA1B,QAAwC,KAAK1E,KAAnD;AACA,wBACE,oBAAC,IAAD,eAAU0E,SAAV;AAAqB,MAAA,QAAQ,EAAE,KAAK/D,QAAL,CAAc+B,IAAd,CAAmB,IAAnB;AAA/B,qBACE;AACE,MAAA,GAAG,EAAE,KAAK1B,UADZ;AAEE,MAAA,KAAK,EAAE,KAAKd,KAAL,CAAWC,KAFpB;AAGE,MAAA,MAAM,EAAE,KAAKD,KAAL,CAAWE,MAHrB;AAIE,MAAA,aAAa,EAAE,KAAK4D,gBAAL,CAAsBtB,IAAtB,CAA2B,IAA3B,CAJjB;AAKE,MAAA,aAAa,EAAE,KAAKwB,eAAL,CAAqBxB,IAArB,CAA0B,IAA1B,CALjB;AAME,MAAA,WAAW,EAAE,KAAK0B,cAAL,CAAoB1B,IAApB,CAAyB,IAAzB,CANf;AAOE,MAAA,eAAe,EAAE,KAAK4B,iBAAL,CAAuB5B,IAAvB,CAA4B,IAA5B;AAPnB,MADF,CADF;AAaD;;AA/KD","sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawingInfo, DrawMode, SkiaViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nexport class SkiaView extends React.Component<\n SkiaViewProps,\n { width: number; height: number }\n> {\n constructor(props: SkiaViewProps) {\n super(props);\n this.state = { width: -1, height: -1 };\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef: React.RefObject<HTMLCanvasElement> = React.createRef();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private _unmounted = false;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n this.setState(\n {\n width: evt.nativeEvent.layout.width,\n height: evt.nativeEvent.layout.height,\n },\n () => {\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n // Create surface\n this._surface = new JsiSkSurface(\n global.CanvasKit,\n global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)!\n );\n // Get canvas and repaint\n if (this._surface) {\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n }\n }\n );\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n this._surface = null;\n this._canvas = null;\n this._unmounted = true;\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (\n this._canvas &&\n this.props.onDraw &&\n this.state.height !== -1 &&\n this.state.width !== -1\n ) {\n const touches = [...this._touches];\n this._touches = [];\n const info: DrawingInfo = {\n height: this.state.height,\n width: this.state.width,\n timestamp: Date.now(),\n touches: [touches],\n };\n this.props.onDraw && this.props.onDraw(this._canvas!, info);\n this._surface?.ref.flush();\n }\n }\n // Always request a new redraw as long as we're not unmounted\n if (!this._unmounted) {\n requestAnimationFrame(this.tick.bind(this));\n }\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.tick();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n handleTouchStart(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Start);\n }\n\n handleTouchMove(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Active);\n }\n\n handleTouchEnd(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.Cancelled);\n }\n\n handleTouchCancel(evt: PointerEvent) {\n this.handleTouchEvent(evt, TouchType.End);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n width={this.state.width}\n height={this.state.height}\n onPointerDown={this.handleTouchStart.bind(this)}\n onPointerMove={this.handleTouchMove.bind(this)}\n onPointerUp={this.handleTouchEnd.bind(this)}\n onPointerCancel={this.handleTouchCancel.bind(this)}\n />\n </View>\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["SkiaView.web.tsx"],"names":["React","PixelRatio","View","JsiSkSurface","TouchType","pd","get","SkiaView","Component","constructor","props","createRef","_mode","mode","unsubscribeAll","_unsubscriptions","forEach","u","onLayout","evt","CanvasKit","global","width","height","nativeEvent","layout","_canvasRef","current","canvas","clientWidth","clientHeight","surface","MakeWebGLCanvasSurface","Error","_surface","_canvas","getCanvas","redraw","componentDidMount","tick","componentDidUpdate","componentWillUnmount","cancelAnimationFrame","requestId","makeImageSnapshot","rect","_redrawRequests","onDraw","touches","_touches","info","timestamp","Date","now","map","t","save","scale","restore","ref","flush","requestAnimationFrame","bind","setDrawMode","registerValues","_values","v","push","addListener","handleTouchEvent","touchType","id","pointerId","x","clientX","currentTarget","getClientRects","left","y","clientY","top","force","pressure","type","createTouchHandler","render","debug","viewProps","display","flex","Start","Active","End","Cancelled"],"mappings":";;;;AAAA;AACA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,SAASC,UAAT,EAAqBC,IAArB,QAAiC,cAAjC;AAIA,SAASC,YAAT,QAA6B,0BAA7B;AAGA,SAASC,SAAT,QAA0B,SAA1B;AAEA,MAAMC,EAAE,GAAGJ,UAAU,CAACK,GAAX,EAAX;AAEA,OAAO,MAAMC,QAAN,SAAuBP,KAAK,CAACQ,SAA7B,CAAsD;AAC3DC,EAAAA,WAAW,CAACC,KAAD,EAAuB;AAAA;;AAChC,UAAMA,KAAN;;AADgC,sCAKM,IALN;;AAAA,8CAMY,EANZ;;AAAA,sCAOG,EAPH;;AAAA,qCAQC,IARD;;AAAA,qDASbV,KAAK,CAACW,SAAN,EATa;;AAAA;;AAAA,6CAWR,CAXQ;;AAA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A3B,CAA9B;AACD;;AAEDe,EAAAA,MAAM,GAAG;AACP,UAAM;AAAExE,MAAAA,IAAF;AAAQyE,MAAAA,KAAK,GAAG,KAAhB;AAAuB,SAAGC;AAA1B,QAAwC,KAAK7E,KAAnD;AACA,wBACE,oBAAC,IAAD,eAAU6E,SAAV;AAAqB,MAAA,QAAQ,EAAE,KAAKrE,QAAL,CAAc4C,IAAd,CAAmB,IAAnB;AAA/B,qBACE;AACE,MAAA,GAAG,EAAE,KAAKpC,UADZ;AAEE,MAAA,KAAK,EAAE;AAAE8D,QAAAA,OAAO,EAAE,MAAX;AAAmBC,QAAAA,IAAI,EAAE;AAAzB,OAFT;AAGE,MAAA,aAAa,EAAE,KAAKL,kBAAL,CAAwBhF,SAAS,CAACsF,KAAlC,CAHjB;AAIE,MAAA,aAAa,EAAE,KAAKN,kBAAL,CAAwBhF,SAAS,CAACuF,MAAlC,CAJjB;AAKE,MAAA,WAAW,EAAE,KAAKP,kBAAL,CAAwBhF,SAAS,CAACwF,GAAlC,CALf;AAME,MAAA,eAAe,EAAE,KAAKR,kBAAL,CAAwBhF,SAAS,CAACyF,SAAlC,CANnB;AAOE,MAAA,cAAc,EAAE,KAAKT,kBAAL,CAAwBhF,SAAS,CAACwF,GAAlC,CAPlB;AAQE,MAAA,YAAY,EAAE,KAAKR,kBAAL,CAAwBhF,SAAS,CAACwF,GAAlC;AARhB,MADF,CADF;AAcD;;AAjK0D","sourcesContent":["/* global HTMLCanvasElement */\nimport React from \"react\";\nimport type { PointerEvent } from \"react\";\nimport type { LayoutChangeEvent } from \"react-native\";\nimport { PixelRatio, View } from \"react-native\";\n\nimport type { SkRect, SkCanvas } from \"../skia/types\";\nimport type { SkiaValue } from \"../values\";\nimport { JsiSkSurface } from \"../skia/web/JsiSkSurface\";\n\nimport type { DrawingInfo, DrawMode, SkiaViewProps, TouchInfo } from \"./types\";\nimport { TouchType } from \"./types\";\n\nconst pd = PixelRatio.get();\n\nexport class SkiaView extends React.Component<SkiaViewProps> {\n constructor(props: SkiaViewProps) {\n super(props);\n this._mode = props.mode ?? \"default\";\n }\n\n private _surface: JsiSkSurface | null = null;\n private _unsubscriptions: Array<() => void> = [];\n private _touches: Array<TouchInfo> = [];\n private _canvas: SkCanvas | null = null;\n private _canvasRef = React.createRef<HTMLCanvasElement>();\n private _mode: DrawMode;\n private _redrawRequests = 0;\n private width = 0;\n private height = 0;\n private requestId = 0;\n\n private unsubscribeAll() {\n this._unsubscriptions.forEach((u) => u());\n this._unsubscriptions = [];\n }\n\n private onLayout(evt: LayoutChangeEvent) {\n const { CanvasKit } = global;\n const { width, height } = evt.nativeEvent.layout;\n this.width = width;\n this.height = height;\n // Reset canvas / surface on layout change\n if (this._canvasRef.current) {\n const canvas = this._canvasRef.current;\n canvas.width = canvas.clientWidth * pd;\n canvas.height = canvas.clientHeight * pd;\n const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);\n if (!surface) {\n throw new Error(\"Could not create surface\");\n }\n this._surface = new JsiSkSurface(CanvasKit, surface);\n this._canvas = this._surface.getCanvas();\n this.redraw();\n }\n }\n\n componentDidMount() {\n // Start render loop\n this.tick();\n }\n\n componentDidUpdate() {\n this.redraw();\n }\n\n componentWillUnmount() {\n this.unsubscribeAll();\n cancelAnimationFrame(this.requestId);\n }\n\n /**\n * Creates a snapshot from the canvas in the surface\n * @param rect Rect to use as bounds. Optional.\n * @returns An Image object.\n */\n public makeImageSnapshot(rect?: SkRect) {\n return this._surface?.makeImageSnapshot(rect);\n }\n\n /**\n * Sends a redraw request to the native SkiaView.\n */\n private tick() {\n if (this._mode === \"continuous\" || this._redrawRequests > 0) {\n this._redrawRequests = 0;\n if (this._canvas && this.props.onDraw) {\n const touches = [...this._touches];\n this._touches = [];\n const info: DrawingInfo = {\n height: this.height,\n width: this.width,\n timestamp: Date.now(),\n touches: touches.map((t) => [t]),\n };\n if (this.props.onDraw) {\n const canvas = this._canvas!;\n canvas.save();\n canvas.scale(pd, pd);\n this.props.onDraw(canvas, info);\n canvas.restore();\n }\n this._surface?.ref.flush();\n }\n }\n this.requestId = requestAnimationFrame(this.tick.bind(this));\n }\n\n public redraw() {\n this._redrawRequests++;\n }\n\n /**\n * Updates the drawing mode for the skia view. This is the same\n * as declaratively setting the mode property on the SkiaView.\n * There are two drawing modes, \"continuous\" and \"default\",\n * where the continuous mode will continuously redraw the view and\n * the default mode will only redraw when any of the regular react\n * properties are changed like size and margins.\n * @param mode Drawing mode to use.\n */\n public setDrawMode(mode: DrawMode) {\n this._mode = mode;\n this.tick();\n }\n\n /**\n * Registers one or move values as a dependant value of the Skia View. The view will\n * The view will redraw itself when any of the values change.\n * @param values Values to register\n */\n public registerValues(_values: SkiaValue<unknown>[]) {\n // Unsubscribe from dependency values\n this.unsubscribeAll();\n // Register redraw dependencies on values\n _values.forEach((v) => {\n this._unsubscriptions.push(\n v.addListener(() => {\n this.redraw();\n })\n );\n });\n }\n\n private handleTouchEvent(evt: PointerEvent, touchType: TouchType) {\n this._touches.push({\n id: evt.pointerId,\n x: evt.clientX - evt.currentTarget.getClientRects()[0].left,\n y: evt.clientY - evt.currentTarget.getClientRects()[0].top,\n force: evt.pressure,\n type: touchType,\n timestamp: Date.now(),\n });\n this.redraw();\n }\n\n createTouchHandler(touchType: TouchType) {\n return (evt: PointerEvent) => this.handleTouchEvent(evt, touchType);\n }\n\n render() {\n const { mode, debug = false, ...viewProps } = this.props;\n return (\n <View {...viewProps} onLayout={this.onLayout.bind(this)}>\n <canvas\n ref={this._canvasRef}\n style={{ display: \"flex\", flex: 1 }}\n onPointerDown={this.createTouchHandler(TouchType.Start)}\n onPointerMove={this.createTouchHandler(TouchType.Active)}\n onPointerUp={this.createTouchHandler(TouchType.End)}\n onPointerCancel={this.createTouchHandler(TouchType.Cancelled)}\n onPointerLeave={this.createTouchHandler(TouchType.End)}\n onPointerOut={this.createTouchHandler(TouchType.End)}\n />\n </View>\n );\n }\n}\n"]}
@@ -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, _prevTouchInfoRef$cur2, _prevTouchInfoRef$cur3, _prevTouchInfoRef$cur4, _prevTouchInfoRef$cur5, _prevTouchInfoRef$cur6, _prevVelocityRef$curr, _prevVelocityRef$curr2;
15
+ var _prevTouchInfoRef$cur, _prevTouchInfoRef$cur2, _prevTouchInfoRef$cur3, _prevTouchInfoRef$cur4, _prevTouchInfoRef$cur5, _prevTouchInfoRef$cur6;
16
16
 
17
17
  if (!multiTouch && i > 0) {
18
18
  break;
@@ -30,12 +30,17 @@ const useInternalTouchHandler = function (handlers) {
30
30
  x: distX / timeDiffseconds / PixelRatio.get(),
31
31
  y: distY / timeDiffseconds / PixelRatio.get()
32
32
  };
33
+ } else {
34
+ prevVelocityRef.current[touch.id] = {
35
+ x: 0,
36
+ y: 0
37
+ };
33
38
  }
34
39
  }
35
40
 
36
41
  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
42
+ velocityX: prevVelocityRef.current[touch.id].x,
43
+ velocityY: prevVelocityRef.current[touch.id].y
39
44
  }; // Save previous touch
40
45
 
41
46
  prevTouchInfoRef.current[touch.id] = touch;
@@ -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":"AACA,S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AAT,CAAkBL,iBAAlB,CAArB;AACAxB,UAAAA,QAAQ,CAAC8B,KAAT,IAAkB9B,QAAQ,CAAC8B,KAAT,CAAeN,iBAAf,CAAlB;AACD;AACF;AACF,KAnDD,EAFuD,CAsDvD;AACD,GAvDiB,EAuDfvB,IAvDe,CAAlB;AAwDD,CAlED;AAoEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAM8B,eAAe,GAAG,UAC7B/B,QAD6B,EAGZ;AAAA,MADjBC,IACiB,uEADM,EACN;AACjB,SAAOF,uBAAuB,CAACC,QAAD,EAAWC,IAAX,EAAiB,KAAjB,CAA9B;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAM+B,oBAAoB,GAAG,UAClChC,QADkC,EAGjB;AAAA,MADjBC,IACiB,uEADM,EACN;AACjB,SAAOF,uBAAuB,CAACC,QAAD,EAAWC,IAAX,EAAiB,IAAjB,CAA9B;AACD,CALM","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","timeDiffseconds","timestamp","current","id","distX","x","distY","y","type","Start","End","Cancelled","get","extendedTouchInfo","velocityX","velocityY","onStart","Active","onActive","onEnd","useTouchHandler","useMultiTouchHandler"],"mappings":"AACA,SAASA,WAAT,EAAsBC,MAAtB,QAAoC,OAApC;AACA,SAASC,UAAT,QAA2B,cAA3B;AAQA,SAASC,SAAT,QAA0B,SAA1B;;AAEA,MAAMC,uBAAuB,GAAG,UAC9BC,QAD8B,EAIb;AAAA,MAFjBC,IAEiB,uEAFM,EAEN;AAAA,MADjBC,UACiB,uEADJ,KACI;AACjB,QAAMC,gBAAgB,GAAGP,MAAM,CAA+B,EAA/B,CAA/B;AACA,QAAMQ,eAAe,GAAGR,MAAM,CAC5B,EAD4B,CAA9B;AAIA,SAAOD,WAAW,CAAEU,OAAD,IAAsC;AACvD;AACAA,IAAAA,OAAO,CAACC,OAAR,CAAiBC,OAAD,IAAa;AAC3B;AACA,WAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGD,OAAO,CAACE,MAA5B,EAAoCD,CAAC,EAArC,EAAyC;AAAA;;AACvC,YAAI,CAACN,UAAD,IAAeM,CAAC,GAAG,CAAvB,EAA0B;AACxB;AACD;;AAED,cAAME,KAAK,GAAGH,OAAO,CAACC,CAAD,CAArB,CALuC,CAOvC;;AACA,cAAMG,eAAe,GACnBD,KAAK,CAACE,SAAN,uDACCT,gBAAgB,CAACU,OAAjB,CAAyBH,KAAK,CAACI,EAA/B,CADD,2DACC,uBAAoCF,SADrC,yEACkDF,KAAK,CAACE,SADxD,CADF;AAIA,cAAMG,KAAK,GACTL,KAAK,CAACM,CAAN,wDAAWb,gBAAgB,CAACU,OAAjB,CAAyBH,KAAK,CAACI,EAA/B,CAAX,2DAAW,uBAAoCE,CAA/C,2EAAoDN,KAAK,C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AwBH,KAAK,CAACI,EAA9B,CAAP;AACAd,UAAAA,QAAQ,CAAC2B,OAAT,IAAoB3B,QAAQ,CAAC2B,OAAT,CAAiBjB,KAAjB,CAApB;AACD,SAHD,MAGO,IAAIA,KAAK,CAACS,IAAN,KAAerB,SAAS,CAAC8B,MAA7B,EAAqC;AAC1C5B,UAAAA,QAAQ,CAAC6B,QAAT,IAAqB7B,QAAQ,CAAC6B,QAAT,CAAkBL,iBAAlB,CAArB;AACD,SAFM,MAEA;AACLxB,UAAAA,QAAQ,CAAC6B,QAAT,IAAqB7B,QAAQ,CAAC6B,QAAT,CAAkBL,iBAAlB,CAArB;AACAxB,UAAAA,QAAQ,CAAC8B,KAAT,IAAkB9B,QAAQ,CAAC8B,KAAT,CAAeN,iBAAf,CAAlB;AACD;AACF;AACF,KArDD,EAFuD,CAwDvD;AACD,GAzDiB,EAyDfvB,IAzDe,CAAlB;AA0DD,CApED;AAsEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,MAAM8B,eAAe,GAAG,UAC7B/B,QAD6B,EAGZ;AAAA,MADjBC,IACiB,uEADM,EACN;AACjB,SAAOF,uBAAuB,CAACC,QAAD,EAAWC,IAAX,EAAiB,KAAjB,CAA9B;AACD,CALM;AAOP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAM+B,oBAAoB,GAAG,UAClChC,QADkC,EAGjB;AAAA,MADjBC,IACiB,uEADM,EACN;AACjB,SAAOF,uBAAuB,CAACC,QAAD,EAAWC,IAAX,EAAiB,IAAjB,CAA9B;AACD,CALM","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 } else {\n prevVelocityRef.current[touch.id] = { x: 0, y: 0 };\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,8 +1,12 @@
1
1
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
2
2
  // @ts-expect-error
3
3
  import CanvasKitInit from "canvaskit-wasm/bin/full/canvaskit";
4
- export const LoadSkiaWeb = async () => {
5
- const CanvasKit = await CanvasKitInit(); // The CanvasKit API is stored on the global object and used
4
+ export const LoadSkiaWeb = async opts => {
5
+ if (global.CanvasKit !== undefined) {
6
+ return;
7
+ }
8
+
9
+ const CanvasKit = await CanvasKitInit(opts); // The CanvasKit API is stored on the global object and used
6
10
  // to create the JsiSKApi in the Skia.web.ts file.
7
11
 
8
12
  global.CanvasKit = CanvasKit;
@@ -1 +1 @@
1
- {"version":3,"sources":["LoadSkiaWeb.tsx"],"names":["CanvasKitInit","LoadSkiaWeb","CanvasKit","global","LoadSkia"],"mappings":"AAAA;AACA;AACA,OAAOA,aAAP,MAA0B,mCAA1B;AAOA,OAAO,MAAMC,WAAW,GAAG,YAAY;AACrC,QAAMC,SAAS,GAAG,MAAMF,aAAa,EAArC,CADqC,CAErC;AACA;;AACAG,EAAAA,MAAM,CAACD,SAAP,GAAmBA,SAAnB;AACD,CALM,C,CAOP;;AACA,OAAO,MAAME,QAAQ,GAAGH,WAAjB","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type { CanvasKit as CanvasKitType } from \"canvaskit-wasm\";\n\ndeclare global {\n var CanvasKit: CanvasKitType;\n}\n\nexport const LoadSkiaWeb = async () => {\n const CanvasKit = await CanvasKitInit();\n // The CanvasKit API is stored on the global object and used\n // to create the JsiSKApi in the Skia.web.ts file.\n global.CanvasKit = CanvasKit;\n};\n\n// We keep this function for backward compatibility\nexport const LoadSkia = LoadSkiaWeb;\n"]}
1
+ {"version":3,"sources":["LoadSkiaWeb.tsx"],"names":["CanvasKitInit","LoadSkiaWeb","opts","global","CanvasKit","undefined","LoadSkia"],"mappings":"AAAA;AACA;AACA,OAAOA,aAAP,MAA0B,mCAA1B;AAUA,OAAO,MAAMC,WAAW,GAAG,MAAOC,IAAP,IAAuC;AAChE,MAAIC,MAAM,CAACC,SAAP,KAAqBC,SAAzB,EAAoC;AAClC;AACD;;AACD,QAAMD,SAAS,GAAG,MAAMJ,aAAa,CAACE,IAAD,CAArC,CAJgE,CAKhE;AACA;;AACAC,EAAAA,MAAM,CAACC,SAAP,GAAmBA,SAAnB;AACD,CARM,C,CAUP;;AACA,OAAO,MAAME,QAAQ,GAAGL,WAAjB","sourcesContent":["// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-expect-error\nimport CanvasKitInit from \"canvaskit-wasm/bin/full/canvaskit\";\nimport type {\n CanvasKit as CanvasKitType,\n CanvasKitInitOptions,\n} from \"canvaskit-wasm\";\n\ndeclare global {\n var CanvasKit: CanvasKitType;\n}\n\nexport const LoadSkiaWeb = async (opts?: CanvasKitInitOptions) => {\n if (global.CanvasKit !== undefined) {\n return;\n }\n const CanvasKit = await CanvasKitInit(opts);\n // The CanvasKit API is stored on the global object and used\n // to create the JsiSKApi in the Skia.web.ts file.\n global.CanvasKit = CanvasKit;\n};\n\n// We keep this function for backward compatibility\nexport const LoadSkia = LoadSkiaWeb;\n"]}
@@ -4,19 +4,20 @@ import { LoadSkiaWeb } from "./LoadSkiaWeb";
4
4
  export const WithSkiaWeb = _ref => {
5
5
  let {
6
6
  getComponent,
7
- fallback
7
+ fallback,
8
+ opts
8
9
  } = _ref;
9
10
  const Inner = useMemo(() => /*#__PURE__*/lazy(async () => {
10
11
  if (Platform.OS === "web") {
11
- await LoadSkiaWeb();
12
+ await LoadSkiaWeb(opts);
12
13
  } else {
13
14
  console.warn("<WithSkiaWeb /> is only necessary on web. Consider not using on native.");
14
15
  }
15
16
 
16
17
  return getComponent();
17
- }), [getComponent]);
18
+ }), [getComponent, opts]);
18
19
  return /*#__PURE__*/React.createElement(Suspense, {
19
- fallback: fallback
20
+ fallback: fallback !== null && fallback !== void 0 ? fallback : null
20
21
  }, /*#__PURE__*/React.createElement(Inner, null));
21
22
  };
22
23
  //# sourceMappingURL=WithSkiaWeb.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["WithSkiaWeb.tsx"],"names":["React","useMemo","lazy","Suspense","Platform","LoadSkiaWeb","WithSkiaWeb","getComponent","fallback","Inner","OS","console","warn"],"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;AAOA,OAAO,MAAMC,WAAW,GAAG,QAA+C;AAAA,MAA9C;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA;AAAhB,GAA8C;AACxE,QAAMC,KAAK,GAAGR,OAAO,CACnB,mBACEC,IAAI,CAAC,YAAY;AACf,QAAIE,QAAQ,CAACM,EAAT,KAAgB,KAApB,EAA2B;AACzB,YAAML,WAAW,EAAjB;AACD,KAFD,MAEO;AACLM,MAAAA,OAAO,CAACC,IAAR,CACE,yEADF;AAGD;;AACD,WAAOL,YAAY,EAAnB;AACD,GATG,CAFa,EAYnB,CAACA,YAAD,CAZmB,CAArB;AAcA,sBACE,oBAAC,QAAD;AAAU,IAAA,QAAQ,EAAEC;AAApB,kBACE,oBAAC,KAAD,OADF,CADF;AAKD,CApBM","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}\n\nexport const WithSkiaWeb = ({ getComponent, fallback }: WithSkiaProps) => {\n const Inner = useMemo(\n () =>\n lazy(async () => {\n if (Platform.OS === \"web\") {\n await LoadSkiaWeb();\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]\n );\n return (\n <Suspense fallback={fallback}>\n <Inner />\n </Suspense>\n );\n};\n"]}
1
+ {"version":3,"sources":["WithSkiaWeb.tsx"],"names":["React","useMemo","lazy","Suspense","Platform","LoadSkiaWeb","WithSkiaWeb","getComponent","fallback","opts","Inner","OS","console","warn"],"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;AAAA,MAJO;AAC1BC,IAAAA,YAD0B;AAE1BC,IAAAA,QAF0B;AAG1BC,IAAAA;AAH0B,GAIP;AACnB,QAAMC,KAAK,GAAGT,OAAO,CACnB,mBACEC,IAAI,CAAC,YAAY;AACf,QAAIE,QAAQ,CAACO,EAAT,KAAgB,KAApB,EAA2B;AACzB,YAAMN,WAAW,CAACI,IAAD,CAAjB;AACD,KAFD,MAEO;AACLG,MAAAA,OAAO,CAACC,IAAR,CACE,yEADF;AAGD;;AACD,WAAON,YAAY,EAAnB;AACD,GATG,CAFa,EAYnB,CAACA,YAAD,EAAeE,IAAf,CAZmB,CAArB;AAcA,sBACE,oBAAC,QAAD;AAAU,IAAA,QAAQ,EAAED,QAAF,aAAEA,QAAF,cAAEA,QAAF,GAAc;AAAhC,kBACE,oBAAC,KAAD,OADF,CADF;AAKD,CAxBM","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 () =>\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"]}
@@ -3,7 +3,6 @@ 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 { SkFontMgr } from "../skia/types";
7
6
  import { Container } from "./nodes";
8
7
  export declare const skiaReconciler: ReactReconciler.Reconciler<Container, import("./nodes").Node<unknown>, import("./nodes").Node<unknown>, import("./nodes").Node<unknown>, import("./nodes").Node<unknown>>;
9
8
  export declare const useCanvasRef: () => React.RefObject<SkiaView>;
@@ -11,6 +10,5 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
11
10
  ref?: RefObject<SkiaView>;
12
11
  children: ReactNode;
13
12
  onTouch?: TouchHandler;
14
- fontMgr?: SkFontMgr;
15
13
  }
16
- export declare const Canvas: React.ForwardRefExoticComponent<Pick<CanvasProps, "children" | "mode" | "debug" | "onDraw" | "hitSlop" | "onLayout" | "pointerEvents" | "removeClippedSubviews" | "style" | "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" | "fontMgr" | "onTouch"> & React.RefAttributes<SkiaView>>;
14
+ export declare const Canvas: React.ForwardRefExoticComponent<Pick<CanvasProps, "children" | "mode" | "debug" | "onDraw" | "hitSlop" | "onLayout" | "pointerEvents" | "removeClippedSubviews" | "style" | "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>>;
@@ -1,12 +1,11 @@
1
1
  import type { RefObject } from "react";
2
2
  import type { DrawingInfo, SkiaView } from "../views";
3
- import type { SkFontMgr, SkCanvas, SkPaint, Skia, Vector } from "../skia/types";
3
+ import type { SkCanvas, SkPaint, Skia, Vector } from "../skia/types";
4
4
  export interface DrawingContext extends Omit<DrawingInfo, "touches"> {
5
5
  canvas: SkCanvas;
6
6
  paint: SkPaint;
7
7
  opacity: number;
8
8
  center: Vector;
9
9
  ref: RefObject<SkiaView>;
10
- fontMgr: SkFontMgr;
11
10
  Skia: Skia;
12
11
  }
@@ -1,11 +1,7 @@
1
- import type { SkFontMgr, SkFont, Skia } from "../../skia/types";
1
+ import type { SkFont } from "../../skia/types";
2
2
  export declare type FontDef = {
3
3
  font: SkFont;
4
- } | {
5
- familyName: string;
6
- size: number;
7
4
  };
8
5
  export declare const isFont: (fontDef: FontDef) => fontDef is {
9
6
  font: SkFont;
10
7
  };
11
- export declare const processFont: (Skia: Skia, fontMgr: SkFontMgr, fontDef: FontDef) => SkFont;
@@ -4,9 +4,7 @@ export * from "./Typeface";
4
4
  export * from "./Image";
5
5
  export * from "./Picture";
6
6
  export * from "./SVG";
7
- export * from "./Path";
8
7
  export * from "./Vector";
9
8
  export * from "./Rect";
10
9
  export * from "./RRect";
11
10
  export * from "./Matrix";
12
- export * from "./Paint";
@@ -24,18 +24,6 @@ export interface SkFont extends SkJSIInstance<"Font"> {
24
24
  * @param paint
25
25
  */
26
26
  getGlyphWidths(glyphs: number[], paint?: SkPaint): number[];
27
- /** Returns the advance width of text.
28
- The advance is the normal distance to move before drawing additional text.
29
- Returns the bounding box of text if bounds is not nullptr. The paint
30
- stroke settings, mask filter, or path effect may modify the bounds.
31
-
32
- @param text character storage encoded with SkTextEncoding
33
- @param byteLength length of character storage in bytes
34
- @param bounds returns bounding box relative to (0, 0) if not nullptr
35
- @param paint optional; may be nullptr
36
- @return number of glyphs represented by text of length byteLength
37
- */
38
- measureText: (text: string, paint?: SkPaint) => SkRect;
39
27
  /**
40
28
  * Returns the FontMetrics for this font.
41
29
  */
@@ -9,7 +9,7 @@ export declare enum MatrixIndex {
9
9
  TransY = 5,
10
10
  Persp0 = 6,
11
11
  Persp1 = 7,
12
- persp2 = 8
12
+ Persp2 = 8
13
13
  }
14
14
  export declare const isMatrix: (obj: unknown) => obj is SkMatrix;
15
15
  export interface SkMatrix extends SkJSIInstance<"Matrix"> {
@@ -17,7 +17,6 @@ import type { SkVertices, VertexMode } from "./Vertices/Vertices";
17
17
  import type { DataFactory } from "./Data";
18
18
  import type { SVGFactory } from "./SVG";
19
19
  import type { TextBlobFactory } from "./TextBlob";
20
- import type { FontMgrFactory } from "./FontMgr/FontMgrFactory";
21
20
  import type { SurfaceFactory } from "./Surface";
22
21
  import type { SkRSXform } from "./RSXform";
23
22
  import type { SkPath } from "./Path/Path";
@@ -62,7 +61,6 @@ export interface Skia {
62
61
  Data: DataFactory;
63
62
  Image: ImageFactory;
64
63
  SVG: SVGFactory;
65
- FontMgr: FontMgrFactory;
66
64
  TextBlob: TextBlobFactory;
67
65
  Surface: SurfaceFactory;
68
66
  }
@@ -1,5 +1,2 @@
1
1
  import type { SkJSIInstance } from "../JsiInstance";
2
- export interface SkTypeface extends SkJSIInstance<"Typeface"> {
3
- readonly bold: boolean;
4
- readonly italic: boolean;
5
- }
2
+ export declare type SkTypeface = SkJSIInstance<"Typeface">;
@@ -2,7 +2,6 @@ export * from "./Picture";
2
2
  export * from "./Data";
3
3
  export * from "./SVG";
4
4
  export * from "./Surface";
5
- export * from "./FontMgr";
6
5
  export * from "./Vertices";
7
6
  export * from "./RuntimeEffect";
8
7
  export * from "./Shader";
@@ -1,11 +1,10 @@
1
1
  import type { CanvasKit, Font } from "canvaskit-wasm";
2
- import type { FontEdging, FontHinting, SkFont, SkPaint, SkPoint, SkRect, SkTypeface } from "../types";
2
+ import type { FontEdging, FontHinting, SkFont, SkPaint, SkPoint, SkTypeface } from "../types";
3
3
  import { HostObject } from "./Host";
4
4
  import { JsiSkRect } from "./JsiSkRect";
5
5
  import { JsiSkTypeface } from "./JsiSkTypeface";
6
6
  export declare class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
7
7
  constructor(CanvasKit: CanvasKit, ref: Font);
8
- measureText(_text: string, _paint?: SkPaint): SkRect;
9
8
  getTextWidth(text: string, paint?: SkPaint | undefined): number;
10
9
  getMetrics(): {
11
10
  ascent: number;
@@ -6,4 +6,3 @@
6
6
  * @returns A readonly value
7
7
  */
8
8
  export declare const useComputedValue: <R>(cb: () => R, values: unknown[]) => import("..").SkiaValue<R>;
9
- export declare const useDerivedValue: <R>(cb: () => R, values: unknown[]) => import("..").SkiaValue<R>;
@@ -3,10 +3,8 @@ import type { PointerEvent } from "react";
3
3
  import type { SkRect } from "../skia/types";
4
4
  import type { SkiaValue } from "../values";
5
5
  import type { DrawMode, SkiaViewProps } from "./types";
6
- export declare class SkiaView extends React.Component<SkiaViewProps, {
7
- width: number;
8
- height: number;
9
- }> {
6
+ import { TouchType } from "./types";
7
+ export declare class SkiaView extends React.Component<SkiaViewProps> {
10
8
  constructor(props: SkiaViewProps);
11
9
  private _surface;
12
10
  private _unsubscriptions;
@@ -15,10 +13,13 @@ export declare class SkiaView extends React.Component<SkiaViewProps, {
15
13
  private _canvasRef;
16
14
  private _mode;
17
15
  private _redrawRequests;
18
- private _unmounted;
16
+ private width;
17
+ private height;
18
+ private requestId;
19
19
  private unsubscribeAll;
20
20
  private onLayout;
21
21
  componentDidMount(): void;
22
+ componentDidUpdate(): void;
22
23
  componentWillUnmount(): void;
23
24
  /**
24
25
  * Creates a snapshot from the canvas in the surface
@@ -48,9 +49,6 @@ export declare class SkiaView extends React.Component<SkiaViewProps, {
48
49
  */
49
50
  registerValues(_values: SkiaValue<unknown>[]): void;
50
51
  private handleTouchEvent;
51
- handleTouchStart(evt: PointerEvent): void;
52
- handleTouchMove(evt: PointerEvent): void;
53
- handleTouchEnd(evt: PointerEvent): void;
54
- handleTouchCancel(evt: PointerEvent): void;
52
+ createTouchHandler(touchType: TouchType): (evt: PointerEvent) => void;
55
53
  render(): JSX.Element;
56
54
  }
@@ -1,6 +1,6 @@
1
- import type { CanvasKit as CanvasKitType } from "canvaskit-wasm";
1
+ import type { CanvasKit as CanvasKitType, CanvasKitInitOptions } from "canvaskit-wasm";
2
2
  declare global {
3
3
  var CanvasKit: CanvasKitType;
4
4
  }
5
- export declare const LoadSkiaWeb: () => Promise<void>;
6
- export declare const LoadSkia: () => Promise<void>;
5
+ export declare const LoadSkiaWeb: (opts?: CanvasKitInitOptions | undefined) => Promise<void>;
6
+ export declare const LoadSkia: (opts?: CanvasKitInitOptions | undefined) => Promise<void>;
@@ -1,10 +1,12 @@
1
1
  import type { ComponentProps, ComponentType } from "react";
2
2
  import { Suspense } from "react";
3
+ import { LoadSkiaWeb } from "./LoadSkiaWeb";
3
4
  interface WithSkiaProps {
4
- fallback: ComponentProps<typeof Suspense>["fallback"];
5
+ fallback?: ComponentProps<typeof Suspense>["fallback"];
5
6
  getComponent: () => Promise<{
6
7
  default: ComponentType;
7
8
  }>;
9
+ opts?: Parameters<typeof LoadSkiaWeb>[0];
8
10
  }
9
- export declare const WithSkiaWeb: ({ getComponent, fallback }: WithSkiaProps) => JSX.Element;
11
+ export declare const WithSkiaWeb: ({ getComponent, fallback, opts, }: WithSkiaProps) => JSX.Element;
10
12
  export {};
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.137",
10
+ "version": "0.1.140",
11
11
  "description": "High-performance React Native Graphics using Skia",
12
12
  "main": "lib/module/index.js",
13
13
  "files": [
@@ -69,13 +69,18 @@
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
78
  "@types/jest": "^27.0.3",
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",
81
+ "eslint": "8.21.0",
82
+ "eslint-config-react-native-wcandillon": "3.9.0",
83
+ "eslint-plugin-reanimated": "2.0.0",
79
84
  "jest": "^27.4.3",
80
85
  "react": "17.0.2",
81
86
  "react-native": "0.66.2",
package/src/mock/index.ts CHANGED
@@ -52,12 +52,8 @@ export const Mock: typeof SkiaExports &
52
52
  useFont: Noop,
53
53
  useTypeface: Noop,
54
54
  useImage: Noop,
55
- usePath: Noop,
56
55
  useSVG: Noop,
57
- useTextPath: Noop,
58
- usePaint: Noop,
59
56
  usePicture: Noop,
60
- useSvgPath: Noop,
61
57
  // 3. Point/Rect/Transform utilities
62
58
  vec,
63
59
  rect: (x: number, y: number, width: number, height: number) => ({