@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
@@ -18,7 +18,6 @@ import ReactReconciler from "react-reconciler";
18
18
 
19
19
  import { SkiaView, useDrawCallback } from "../views";
20
20
  import type { TouchHandler } from "../views";
21
- import type { SkFontMgr } from "../skia/types";
22
21
  import { useValue } from "../values/hooks/useValue";
23
22
  import { Skia } from "../skia/Skia";
24
23
 
@@ -50,13 +49,10 @@ export interface CanvasProps extends ComponentProps<typeof SkiaView> {
50
49
  ref?: RefObject<SkiaView>;
51
50
  children: ReactNode;
52
51
  onTouch?: TouchHandler;
53
- fontMgr?: SkFontMgr;
54
52
  }
55
53
 
56
- const defaultFontMgr = Skia.FontMgr.RefDefault();
57
-
58
54
  export const Canvas = forwardRef<SkiaView, CanvasProps>(
59
- ({ children, style, debug, mode, onTouch, fontMgr }, forwardedRef) => {
55
+ ({ children, style, debug, mode, onTouch }, forwardedRef) => {
60
56
  const size = useValue({ width: 0, height: 0 });
61
57
  const canvasCtx = useMemo(() => ({ Skia, size }), [size]);
62
58
  const innerRef = useCanvasRef();
@@ -106,7 +102,6 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
106
102
  opacity: 1,
107
103
  ref,
108
104
  center: Skia.Point(width / 2, height / 2),
109
- fontMgr: fontMgr ?? defaultFontMgr,
110
105
  Skia,
111
106
  };
112
107
  container.draw(ctx);
@@ -116,9 +111,11 @@ export const Canvas = forwardRef<SkiaView, CanvasProps>(
116
111
 
117
112
  useEffect(() => {
118
113
  return () => {
119
- container.depMgr.unsubscribe();
114
+ skiaReconciler.updateContainer(null, root, null, () => {
115
+ container.depMgr.unsubscribe();
116
+ });
120
117
  };
121
- }, [container]);
118
+ }, [container, root]);
122
119
 
123
120
  return (
124
121
  <SkiaView
@@ -1,7 +1,7 @@
1
1
  import type { RefObject } from "react";
2
2
 
3
3
  import type { DrawingInfo, SkiaView } from "../views";
4
- import type { SkFontMgr, SkCanvas, SkPaint, Skia, Vector } from "../skia/types";
4
+ import type { SkCanvas, SkPaint, Skia, Vector } from "../skia/types";
5
5
 
6
6
  export interface DrawingContext extends Omit<DrawingInfo, "touches"> {
7
7
  canvas: SkCanvas;
@@ -9,6 +9,5 @@ export interface DrawingContext extends Omit<DrawingInfo, "touches"> {
9
9
  opacity: number;
10
10
  center: Vector;
11
11
  ref: RefObject<SkiaView>;
12
- fontMgr: SkFontMgr;
13
12
  Skia: Skia;
14
13
  }
@@ -4,7 +4,6 @@ import type { CustomPaintProps, AnimatedProps } from "../../processors";
4
4
  import { createDrawing } from "../../nodes/Drawing";
5
5
  import type { SkPoint } from "../../../skia/types";
6
6
  import type { FontDef } from "../../processors/Font";
7
- import { processFont } from "../../processors/Font";
8
7
 
9
8
  export interface Glyph {
10
9
  id: number;
@@ -24,11 +23,8 @@ interface ProcessedGlyphs {
24
23
  }
25
24
 
26
25
  const onDraw = createDrawing<GlyphsProps>(
27
- (
28
- { canvas, paint, fontMgr, Skia },
29
- { glyphs: rawGlyphs, x, y, ...fontDef }
30
- ) => {
31
- const font = processFont(Skia, fontMgr, fontDef);
26
+ ({ canvas, paint }, { glyphs: rawGlyphs, x, y, ...fontDef }) => {
27
+ const { font } = fontDef;
32
28
  const { glyphs, positions } = rawGlyphs.reduce<ProcessedGlyphs>(
33
29
  (acc, glyph) => {
34
30
  const { id, pos } = glyph;
@@ -6,7 +6,6 @@ import type {
6
6
  FontDef,
7
7
  } from "../../processors";
8
8
  import { createDrawing } from "../../nodes/Drawing";
9
- import { processFont } from "../../processors";
10
9
 
11
10
  type TextProps = CustomPaintProps &
12
11
  FontDef & {
@@ -16,8 +15,8 @@ type TextProps = CustomPaintProps &
16
15
  };
17
16
 
18
17
  const onDraw = createDrawing<TextProps>(
19
- ({ canvas, paint, fontMgr, Skia }, { text, x, y, ...fontDef }) => {
20
- const font = processFont(Skia, fontMgr, fontDef);
18
+ ({ canvas, paint }, { text, x, y, ...fontDef }) => {
19
+ const { font } = fontDef;
21
20
  canvas.drawText(text, x, y, paint, font);
22
21
  }
23
22
  );
@@ -4,7 +4,6 @@ import type { CustomPaintProps, AnimatedProps } from "../../processors";
4
4
  import { createDrawing } from "../../nodes";
5
5
  import type { SkPath, SkRSXform } from "../../../skia/types";
6
6
  import type { FontDef } from "../../processors/Font";
7
- import { processFont } from "../../processors/Font";
8
7
 
9
8
  export type TextPathProps = CustomPaintProps &
10
9
  FontDef & {
@@ -15,7 +14,7 @@ export type TextPathProps = CustomPaintProps &
15
14
 
16
15
  const onDraw = createDrawing<TextPathProps>(
17
16
  (
18
- { canvas, paint, fontMgr, Skia },
17
+ { canvas, paint, Skia },
19
18
  { text, initialOffset, path: pathDef, ...fontDef }
20
19
  ) => {
21
20
  const path =
@@ -25,7 +24,7 @@ const onDraw = createDrawing<TextPathProps>(
25
24
  if (path === null) {
26
25
  throw new Error("Invalid path: " + pathDef);
27
26
  }
28
- const font = processFont(Skia, fontMgr, fontDef);
27
+ const { font } = fontDef;
29
28
  const ids = font.getGlyphIDs(text);
30
29
  const widths = font.getGlyphWidths(ids, paint);
31
30
  const rsx: SkRSXform[] = [];
@@ -1,31 +1,8 @@
1
- import type { SkFontMgr, SkFont, Skia } from "../../skia/types";
1
+ import type { SkFont } from "../../skia/types";
2
2
 
3
- export type FontDef = { font: SkFont } | { familyName: string; size: number };
3
+ export type FontDef = { font: SkFont };
4
4
 
5
5
  export const isFont = (fontDef: FontDef): fontDef is { font: SkFont } =>
6
6
  // We have an issue to check property existence on JSI backed instances
7
7
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
8
  (fontDef as any).font !== undefined;
9
-
10
- export const processFont = (
11
- Skia: Skia,
12
- fontMgr: SkFontMgr,
13
- fontDef: FontDef
14
- ) => {
15
- let selectedFont: SkFont;
16
- if (isFont(fontDef)) {
17
- selectedFont = fontDef.font;
18
- } else {
19
- console.warn(
20
- // eslint-disable-next-line max-len
21
- "Using system fonts is deprecated. Please use the font property instead: https://shopify.github.io/react-native-skia/docs/text/fonts"
22
- );
23
- const { familyName, size } = fontDef;
24
- const typeface = fontMgr.matchFamilyStyle(familyName);
25
- if (typeface === null) {
26
- throw new Error(`No typeface found for ${familyName}`);
27
- }
28
- selectedFont = Skia.Font(typeface, size);
29
- }
30
- return selectedFont;
31
- };
@@ -37,7 +37,9 @@ const loadData = <T>(
37
37
  factory: (data: SkData) => T,
38
38
  onError?: (err: Error) => void
39
39
  ): Promise<T | null> => {
40
- if (source instanceof Uint8Array) {
40
+ if (source === null) {
41
+ return new Promise((resolve) => resolve(null));
42
+ } else if (source instanceof Uint8Array) {
41
43
  return new Promise((resolve) =>
42
44
  resolve(factoryWrapper(Skia.Data.fromBytes(source), factory, onError))
43
45
  );
@@ -3,10 +3,12 @@ import type { DataSource } from "../types";
3
3
 
4
4
  import { useRawData } from "./Data";
5
5
 
6
+ const imgFactory = Skia.Image.MakeImageFromEncoded.bind(Skia.Image);
7
+
6
8
  /**
7
9
  * Returns a Skia Image object
8
10
  * */
9
11
  export const useImage = (
10
12
  source: DataSource | null | undefined,
11
13
  onError?: (err: Error) => void
12
- ) => useRawData(source, Skia.Image.MakeImageFromEncoded, onError);
14
+ ) => useRawData(source, imgFactory, onError);
@@ -3,7 +3,9 @@ import type { DataSource } from "../types";
3
3
 
4
4
  import { useRawData } from "./Data";
5
5
 
6
+ const svgFactory = Skia.SVG.MakeFromData.bind(Skia.SVG);
7
+
6
8
  export const useSVG = (
7
9
  source: DataSource | null | undefined,
8
10
  onError?: (err: Error) => void
9
- ) => useRawData(source, Skia.SVG.MakeFromData, onError);
11
+ ) => useRawData(source, svgFactory, onError);
@@ -2,15 +2,13 @@ import { Skia } from "../Skia";
2
2
  import type { DataSource } from "../types";
3
3
 
4
4
  import { useRawData } from "./Data";
5
+
6
+ const tfFactory = Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface);
7
+
5
8
  /**
6
9
  * Returns a Skia Typeface object
7
10
  * */
8
11
  export const useTypeface = (
9
12
  source: DataSource | null | undefined,
10
13
  onError?: (err: Error) => void
11
- ) =>
12
- useRawData(
13
- source,
14
- Skia.Typeface.MakeFreeTypeFaceFromData.bind(Skia.Typeface),
15
- onError
16
- );
14
+ ) => useRawData(source, tfFactory, onError);
@@ -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";
@@ -28,19 +28,6 @@ export interface SkFont extends SkJSIInstance<"Font"> {
28
28
  */
29
29
  getGlyphWidths(glyphs: number[], paint?: SkPaint): number[];
30
30
 
31
- /** Returns the advance width of text.
32
- The advance is the normal distance to move before drawing additional text.
33
- Returns the bounding box of text if bounds is not nullptr. The paint
34
- stroke settings, mask filter, or path effect may modify the bounds.
35
-
36
- @param text character storage encoded with SkTextEncoding
37
- @param byteLength length of character storage in bytes
38
- @param bounds returns bounding box relative to (0, 0) if not nullptr
39
- @param paint optional; may be nullptr
40
- @return number of glyphs represented by text of length byteLength
41
- */
42
- measureText: (text: string, paint?: SkPaint) => SkRect;
43
-
44
31
  /**
45
32
  * Returns the FontMetrics for this font.
46
33
  */
@@ -1,4 +1,3 @@
1
- /* eslint-disable camelcase */
2
1
  import type { SkData } from "../Data";
3
2
 
4
3
  import type { SkImage } from "./Image";
@@ -9,7 +9,7 @@ export enum MatrixIndex {
9
9
  TransY = 5,
10
10
  Persp0 = 6,
11
11
  Persp1 = 7,
12
- persp2 = 8,
12
+ Persp2 = 8,
13
13
  }
14
14
 
15
15
  export const isMatrix = (obj: unknown): obj is SkMatrix =>
@@ -11,7 +11,6 @@ import type { SkJSIInstance } from "../JsiInstance";
11
11
  export interface StrokeOpts {
12
12
  /** The width of the stroked lines. */
13
13
  width?: number;
14
- // eslint-disable-next-line camelcase
15
14
  miter_limit?: number;
16
15
  /**
17
16
  * if > 1, increase precision, else if (0 < resScale < 1) reduce precision to
@@ -21,7 +21,6 @@ import type { SkVertices, VertexMode } from "./Vertices/Vertices";
21
21
  import type { DataFactory } from "./Data";
22
22
  import type { SVGFactory } from "./SVG";
23
23
  import type { TextBlobFactory } from "./TextBlob";
24
- import type { FontMgrFactory } from "./FontMgr/FontMgrFactory";
25
24
  import type { SurfaceFactory } from "./Surface";
26
25
  import type { SkRSXform } from "./RSXform";
27
26
  import type { SkPath } from "./Path/Path";
@@ -78,7 +77,6 @@ export interface Skia {
78
77
  Data: DataFactory;
79
78
  Image: ImageFactory;
80
79
  SVG: SVGFactory;
81
- FontMgr: FontMgrFactory;
82
80
  TextBlob: TextBlobFactory;
83
81
  Surface: SurfaceFactory;
84
82
  }
@@ -1,6 +1,3 @@
1
1
  import type { SkJSIInstance } from "../JsiInstance";
2
2
 
3
- export interface SkTypeface extends SkJSIInstance<"Typeface"> {
4
- readonly bold: boolean;
5
- readonly italic: boolean;
6
- }
3
+ export 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";
@@ -6,7 +6,6 @@ import type {
6
6
  SkFont,
7
7
  SkPaint,
8
8
  SkPoint,
9
- SkRect,
10
9
  SkTypeface,
11
10
  } from "../types";
12
11
 
@@ -19,14 +18,6 @@ export class JsiSkFont extends HostObject<Font, "Font"> implements SkFont {
19
18
  super(CanvasKit, ref, "Font");
20
19
  }
21
20
 
22
- measureText(_text: string, _paint?: SkPaint): SkRect {
23
- console.warn(
24
- `measureText() is deprecated an returns an empty rectangle on React Native Web.
25
- Clients should use "Font.getGlyphWidths" instead (the latter does no shaping)`
26
- );
27
- return new JsiSkRect(this.CanvasKit, this.CanvasKit.XYWHRect(0, 0, 0, 0));
28
- }
29
-
30
21
  getTextWidth(text: string, paint?: SkPaint | undefined) {
31
22
  const ids = this.getGlyphIDs(text);
32
23
  const widths = this.getGlyphWidths(ids, paint);
@@ -30,7 +30,7 @@ export class JsiSkTextBlobFactory extends Host implements TextBlobFactory {
30
30
  this.CanvasKit,
31
31
  this.CanvasKit.TextBlob.MakeFromRSXform(
32
32
  str,
33
- rsxforms.map((f) => toValue(f)),
33
+ rsxforms.map((f) => Array.from(toValue<Float32Array>(f))).flat(),
34
34
  toValue(font)
35
35
  )
36
36
  );
@@ -34,7 +34,6 @@ import { JsiSkDataFactory } from "./JsiSkDataFactory";
34
34
  import { JsiSkImageFactory } from "./JsiSkImageFactory";
35
35
  import { JsiSkSVGFactory } from "./JsiSkSVGFactory";
36
36
  import { JsiSkTextBlobFactory } from "./JsiSkTextBlobFactory";
37
- import { JsiSkFontMgrFactory } from "./JsiSkFontMgrFactory";
38
37
  import { JsiSkFont } from "./JsiSkFont";
39
38
  import { MakeVertices } from "./JsiSkVerticesFactory";
40
39
 
@@ -90,7 +89,6 @@ export const JsiSkApi = (CanvasKit: CanvasKit): Skia => ({
90
89
  Image: new JsiSkImageFactory(CanvasKit),
91
90
  SVG: new JsiSkSVGFactory(CanvasKit),
92
91
  TextBlob: new JsiSkTextBlobFactory(CanvasKit),
93
- FontMgr: new JsiSkFontMgrFactory(CanvasKit),
94
92
  XYWHRect: (x: number, y: number, width: number, height: number) => {
95
93
  return new JsiSkRect(CanvasKit, CanvasKit.XYWHRect(x, y, width, height));
96
94
  },
@@ -16,8 +16,3 @@ export const useComputedValue = <R>(cb: () => R, values: unknown[]) =>
16
16
  // eslint-disable-next-line react-hooks/exhaustive-deps
17
17
  values
18
18
  );
19
-
20
- export const useDerivedValue = <R>(cb: () => R, values: unknown[]) => {
21
- console.warn("useDerivedValue is deprecated. Use useComputedValue instead.");
22
- return useComputedValue(cb, values);
23
- };
@@ -2,7 +2,7 @@
2
2
  import React from "react";
3
3
  import type { PointerEvent } from "react";
4
4
  import type { LayoutChangeEvent } from "react-native";
5
- import { View } from "react-native";
5
+ import { PixelRatio, View } from "react-native";
6
6
 
7
7
  import type { SkRect, SkCanvas } from "../skia/types";
8
8
  import type { SkiaValue } from "../values";
@@ -11,13 +11,11 @@ import { JsiSkSurface } from "../skia/web/JsiSkSurface";
11
11
  import type { DrawingInfo, DrawMode, SkiaViewProps, TouchInfo } from "./types";
12
12
  import { TouchType } from "./types";
13
13
 
14
- export class SkiaView extends React.Component<
15
- SkiaViewProps,
16
- { width: number; height: number }
17
- > {
14
+ const pd = PixelRatio.get();
15
+
16
+ export class SkiaView extends React.Component<SkiaViewProps> {
18
17
  constructor(props: SkiaViewProps) {
19
18
  super(props);
20
- this.state = { width: -1, height: -1 };
21
19
  this._mode = props.mode ?? "default";
22
20
  }
23
21
 
@@ -25,10 +23,12 @@ export class SkiaView extends React.Component<
25
23
  private _unsubscriptions: Array<() => void> = [];
26
24
  private _touches: Array<TouchInfo> = [];
27
25
  private _canvas: SkCanvas | null = null;
28
- private _canvasRef: React.RefObject<HTMLCanvasElement> = React.createRef();
26
+ private _canvasRef = React.createRef<HTMLCanvasElement>();
29
27
  private _mode: DrawMode;
30
28
  private _redrawRequests = 0;
31
- private _unmounted = false;
29
+ private width = 0;
30
+ private height = 0;
31
+ private requestId = 0;
32
32
 
33
33
  private unsubscribeAll() {
34
34
  this._unsubscriptions.forEach((u) => u());
@@ -36,27 +36,23 @@ export class SkiaView extends React.Component<
36
36
  }
37
37
 
38
38
  private onLayout(evt: LayoutChangeEvent) {
39
- this.setState(
40
- {
41
- width: evt.nativeEvent.layout.width,
42
- height: evt.nativeEvent.layout.height,
43
- },
44
- () => {
45
- // Reset canvas / surface on layout change
46
- if (this._canvasRef.current) {
47
- // Create surface
48
- this._surface = new JsiSkSurface(
49
- global.CanvasKit,
50
- global.CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current)!
51
- );
52
- // Get canvas and repaint
53
- if (this._surface) {
54
- this._canvas = this._surface.getCanvas();
55
- this.redraw();
56
- }
57
- }
39
+ const { CanvasKit } = global;
40
+ const { width, height } = evt.nativeEvent.layout;
41
+ this.width = width;
42
+ this.height = height;
43
+ // Reset canvas / surface on layout change
44
+ if (this._canvasRef.current) {
45
+ const canvas = this._canvasRef.current;
46
+ canvas.width = canvas.clientWidth * pd;
47
+ canvas.height = canvas.clientHeight * pd;
48
+ const surface = CanvasKit.MakeWebGLCanvasSurface(this._canvasRef.current);
49
+ if (!surface) {
50
+ throw new Error("Could not create surface");
58
51
  }
59
- );
52
+ this._surface = new JsiSkSurface(CanvasKit, surface);
53
+ this._canvas = this._surface.getCanvas();
54
+ this.redraw();
55
+ }
60
56
  }
61
57
 
62
58
  componentDidMount() {
@@ -64,11 +60,13 @@ export class SkiaView extends React.Component<
64
60
  this.tick();
65
61
  }
66
62
 
63
+ componentDidUpdate() {
64
+ this.redraw();
65
+ }
66
+
67
67
  componentWillUnmount() {
68
68
  this.unsubscribeAll();
69
- this._surface = null;
70
- this._canvas = null;
71
- this._unmounted = true;
69
+ cancelAnimationFrame(this.requestId);
72
70
  }
73
71
 
74
72
  /**
@@ -86,28 +84,26 @@ export class SkiaView extends React.Component<
86
84
  private tick() {
87
85
  if (this._mode === "continuous" || this._redrawRequests > 0) {
88
86
  this._redrawRequests = 0;
89
- if (
90
- this._canvas &&
91
- this.props.onDraw &&
92
- this.state.height !== -1 &&
93
- this.state.width !== -1
94
- ) {
87
+ if (this._canvas && this.props.onDraw) {
95
88
  const touches = [...this._touches];
96
89
  this._touches = [];
97
90
  const info: DrawingInfo = {
98
- height: this.state.height,
99
- width: this.state.width,
91
+ height: this.height,
92
+ width: this.width,
100
93
  timestamp: Date.now(),
101
- touches: [touches],
94
+ touches: touches.map((t) => [t]),
102
95
  };
103
- this.props.onDraw && this.props.onDraw(this._canvas!, info);
96
+ if (this.props.onDraw) {
97
+ const canvas = this._canvas!;
98
+ canvas.save();
99
+ canvas.scale(pd, pd);
100
+ this.props.onDraw(canvas, info);
101
+ canvas.restore();
102
+ }
104
103
  this._surface?.ref.flush();
105
104
  }
106
105
  }
107
- // Always request a new redraw as long as we're not unmounted
108
- if (!this._unmounted) {
109
- requestAnimationFrame(this.tick.bind(this));
110
- }
106
+ this.requestId = requestAnimationFrame(this.tick.bind(this));
111
107
  }
112
108
 
113
109
  public redraw() {
@@ -158,20 +154,8 @@ export class SkiaView extends React.Component<
158
154
  this.redraw();
159
155
  }
160
156
 
161
- handleTouchStart(evt: PointerEvent) {
162
- this.handleTouchEvent(evt, TouchType.Start);
163
- }
164
-
165
- handleTouchMove(evt: PointerEvent) {
166
- this.handleTouchEvent(evt, TouchType.Active);
167
- }
168
-
169
- handleTouchEnd(evt: PointerEvent) {
170
- this.handleTouchEvent(evt, TouchType.Cancelled);
171
- }
172
-
173
- handleTouchCancel(evt: PointerEvent) {
174
- this.handleTouchEvent(evt, TouchType.End);
157
+ createTouchHandler(touchType: TouchType) {
158
+ return (evt: PointerEvent) => this.handleTouchEvent(evt, touchType);
175
159
  }
176
160
 
177
161
  render() {
@@ -180,12 +164,13 @@ export class SkiaView extends React.Component<
180
164
  <View {...viewProps} onLayout={this.onLayout.bind(this)}>
181
165
  <canvas
182
166
  ref={this._canvasRef}
183
- width={this.state.width}
184
- height={this.state.height}
185
- onPointerDown={this.handleTouchStart.bind(this)}
186
- onPointerMove={this.handleTouchMove.bind(this)}
187
- onPointerUp={this.handleTouchEnd.bind(this)}
188
- onPointerCancel={this.handleTouchCancel.bind(this)}
167
+ style={{ display: "flex", flex: 1 }}
168
+ onPointerDown={this.createTouchHandler(TouchType.Start)}
169
+ onPointerMove={this.createTouchHandler(TouchType.Active)}
170
+ onPointerUp={this.createTouchHandler(TouchType.End)}
171
+ onPointerCancel={this.createTouchHandler(TouchType.Cancelled)}
172
+ onPointerLeave={this.createTouchHandler(TouchType.End)}
173
+ onPointerOut={this.createTouchHandler(TouchType.End)}
189
174
  />
190
175
  </View>
191
176
  );
@@ -51,13 +51,15 @@ const useInternalTouchHandler = (
51
51
  x: distX / timeDiffseconds / PixelRatio.get(),
52
52
  y: distY / timeDiffseconds / PixelRatio.get(),
53
53
  };
54
+ } else {
55
+ prevVelocityRef.current[touch.id] = { x: 0, y: 0 };
54
56
  }
55
57
  }
56
58
 
57
59
  const extendedTouchInfo: ExtendedTouchInfo = {
58
60
  ...touch,
59
- velocityX: prevVelocityRef.current[touch.id]?.x,
60
- velocityY: prevVelocityRef.current[touch.id]?.y,
61
+ velocityX: prevVelocityRef.current[touch.id].x,
62
+ velocityY: prevVelocityRef.current[touch.id].y,
61
63
  };
62
64
 
63
65
  // Save previous touch
@@ -1,14 +1,20 @@
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
- import type { CanvasKit as CanvasKitType } from "canvaskit-wasm";
4
+ import type {
5
+ CanvasKit as CanvasKitType,
6
+ CanvasKitInitOptions,
7
+ } from "canvaskit-wasm";
5
8
 
6
9
  declare global {
7
10
  var CanvasKit: CanvasKitType;
8
11
  }
9
12
 
10
- export const LoadSkiaWeb = async () => {
11
- const CanvasKit = await CanvasKitInit();
13
+ export const LoadSkiaWeb = async (opts?: CanvasKitInitOptions) => {
14
+ if (global.CanvasKit !== undefined) {
15
+ return;
16
+ }
17
+ const CanvasKit = await CanvasKitInit(opts);
12
18
  // The CanvasKit API is stored on the global object and used
13
19
  // to create the JsiSKApi in the Skia.web.ts file.
14
20
  global.CanvasKit = CanvasKit;
@@ -5,16 +5,21 @@ import { Platform } from "react-native";
5
5
  import { LoadSkiaWeb } from "./LoadSkiaWeb";
6
6
 
7
7
  interface WithSkiaProps {
8
- fallback: ComponentProps<typeof Suspense>["fallback"];
8
+ fallback?: ComponentProps<typeof Suspense>["fallback"];
9
9
  getComponent: () => Promise<{ default: ComponentType }>;
10
+ opts?: Parameters<typeof LoadSkiaWeb>[0];
10
11
  }
11
12
 
12
- export const WithSkiaWeb = ({ getComponent, fallback }: WithSkiaProps) => {
13
+ export const WithSkiaWeb = ({
14
+ getComponent,
15
+ fallback,
16
+ opts,
17
+ }: WithSkiaProps) => {
13
18
  const Inner = useMemo(
14
19
  () =>
15
20
  lazy(async () => {
16
21
  if (Platform.OS === "web") {
17
- await LoadSkiaWeb();
22
+ await LoadSkiaWeb(opts);
18
23
  } else {
19
24
  console.warn(
20
25
  "<WithSkiaWeb /> is only necessary on web. Consider not using on native."
@@ -22,10 +27,10 @@ export const WithSkiaWeb = ({ getComponent, fallback }: WithSkiaProps) => {
22
27
  }
23
28
  return getComponent();
24
29
  }),
25
- [getComponent]
30
+ [getComponent, opts]
26
31
  );
27
32
  return (
28
- <Suspense fallback={fallback}>
33
+ <Suspense fallback={fallback ?? null}>
29
34
  <Inner />
30
35
  </Suspense>
31
36
  );
package/android/README.md DELETED
@@ -1,14 +0,0 @@
1
- README
2
- ======
3
-
4
- If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm:
5
-
6
- 1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed
7
- 2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK
8
- ```
9
- ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle
10
- sdk.dir=/Users/{username}/Library/Android/sdk
11
- ```
12
- 3. Delete the `maven` folder
13
- 4. Run `./gradlew installArchives`
14
- 5. Verify that latest set of generated files is in the maven folder with the correct version number