react-native-skia 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (261) hide show
  1. package/Package.swift +14 -13
  2. package/android/CMakeLists.txt +13 -42
  3. package/android/build.gradle +55 -47
  4. package/android/cpp/jni/JniLoad.cpp +2 -4
  5. package/android/cpp/jni/include/JniSkiaView.h +123 -0
  6. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
  7. package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
  8. package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
  9. package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
  10. package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
  11. package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
  12. package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
  13. package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
  14. package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
  15. package/apple/MetalLayerColorSpace.mm +0 -4
  16. package/apple/RNSkApplePlatformContext.h +0 -14
  17. package/apple/RNSkApplePlatformContext.mm +2 -112
  18. package/apple/RNSkMetalCanvasProvider.h +14 -19
  19. package/apple/RNSkMetalCanvasProvider.mm +35 -68
  20. package/apple/SkiaView.h +20 -0
  21. package/apple/SkiaView.mm +210 -0
  22. package/cpp/api/JsiSkApi.h +2 -13
  23. package/cpp/api/JsiSkCanvas.h +4 -18
  24. package/cpp/api/JsiSkGraphiteContext.h +1 -5
  25. package/cpp/api/JsiSkGraphiteRecording.h +1 -5
  26. package/cpp/api/JsiSkImage.h +7 -41
  27. package/cpp/api/JsiSkImageFactory.h +0 -14
  28. package/cpp/api/JsiSkSurface.h +2 -16
  29. package/cpp/api/JsiSkSurfaceFactory.h +0 -8
  30. package/cpp/rnskia/RNDawnContext.h +6 -0
  31. package/cpp/rnskia/RNDawnInterop.cpp +0 -4
  32. package/cpp/rnskia/RNDawnUtils.h +0 -1
  33. package/cpp/rnskia/RNDawnWindowContext.cpp +10 -0
  34. package/cpp/rnskia/RNDawnWindowContext.h +4 -0
  35. package/cpp/rnskia/RNSkCanvasProvider.h +221 -0
  36. package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
  37. package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
  38. package/cpp/rnskia/RNSkGraphiteTarget.h +383 -0
  39. package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
  40. package/cpp/rnskia/RNSkPlatformContext.h +9 -15
  41. package/cpp/rnskia/RNSkView.h +340 -245
  42. package/jestSetup.js +1 -3
  43. package/lib/commonjs/Platform/Platform.web.js +1 -1
  44. package/lib/commonjs/Platform/Platform.web.js.map +1 -1
  45. package/lib/commonjs/index.d.ts +1 -3
  46. package/lib/commonjs/index.js +3 -12
  47. package/lib/commonjs/index.js.map +1 -1
  48. package/lib/commonjs/mock/index.js +0 -1
  49. package/lib/commonjs/mock/index.js.map +1 -1
  50. package/lib/commonjs/renderer/Canvas.d.ts +15 -12
  51. package/lib/commonjs/renderer/Canvas.js +24 -20
  52. package/lib/commonjs/renderer/Canvas.js.map +1 -1
  53. package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
  54. package/lib/commonjs/skia/types/Graphite.js.map +1 -1
  55. package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
  56. package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
  57. package/lib/commonjs/skia/types/Skia.d.ts +1 -2
  58. package/lib/commonjs/skia/types/Skia.js.map +1 -1
  59. package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  60. package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
  61. package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
  62. package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
  63. package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
  64. package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
  65. package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  66. package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
  67. package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  68. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
  69. package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
  70. package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
  71. package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
  72. package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
  73. package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
  74. package/lib/commonjs/views/SkiaPictureView.js +12 -10
  75. package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
  76. package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
  77. package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
  78. package/lib/commonjs/views/SkiaView.web.js.map +1 -0
  79. package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
  80. package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
  81. package/lib/commonjs/views/android.d.ts +6 -0
  82. package/lib/commonjs/views/android.js +17 -0
  83. package/lib/commonjs/views/android.js.map +1 -0
  84. package/lib/commonjs/views/types.d.ts +3 -12
  85. package/lib/commonjs/views/types.js.map +1 -1
  86. package/lib/module/Platform/Platform.web.js +1 -1
  87. package/lib/module/Platform/Platform.web.js.map +1 -1
  88. package/lib/module/index.d.ts +1 -3
  89. package/lib/module/index.js +1 -3
  90. package/lib/module/index.js.map +1 -1
  91. package/lib/module/mock/index.js +0 -1
  92. package/lib/module/mock/index.js.map +1 -1
  93. package/lib/module/renderer/Canvas.d.ts +15 -12
  94. package/lib/module/renderer/Canvas.js +24 -19
  95. package/lib/module/renderer/Canvas.js.map +1 -1
  96. package/lib/module/skia/types/Graphite.d.ts +3 -3
  97. package/lib/module/skia/types/Graphite.js.map +1 -1
  98. package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
  99. package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
  100. package/lib/module/skia/types/Skia.d.ts +1 -2
  101. package/lib/module/skia/types/Skia.js.map +1 -1
  102. package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  103. package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
  104. package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
  105. package/lib/module/specs/NativeSkiaModule.web.js +5 -9
  106. package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
  107. package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
  108. package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
  109. package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
  110. package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  111. package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
  112. package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
  113. package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
  114. package/lib/module/views/SkiaGraphiteView.js +23 -12
  115. package/lib/module/views/SkiaGraphiteView.js.map +1 -1
  116. package/lib/module/views/SkiaPictureView.d.ts +4 -1
  117. package/lib/module/views/SkiaPictureView.js +12 -10
  118. package/lib/module/views/SkiaPictureView.js.map +1 -1
  119. package/lib/module/views/SkiaView.web.d.ts +12 -0
  120. package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
  121. package/lib/module/views/SkiaView.web.js.map +1 -0
  122. package/lib/module/views/SkiaWebRenderer.js +1 -1
  123. package/lib/module/views/SkiaWebRenderer.js.map +1 -1
  124. package/lib/module/views/android.d.ts +6 -0
  125. package/lib/module/views/android.js +10 -0
  126. package/lib/module/views/android.js.map +1 -0
  127. package/lib/module/views/types.d.ts +3 -12
  128. package/lib/module/views/types.js.map +1 -1
  129. package/lib/typescript/src/index.d.ts +1 -3
  130. package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
  131. package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
  132. package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
  133. package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
  134. package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
  135. package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
  136. package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
  137. package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
  138. package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
  139. package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
  140. package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
  141. package/lib/typescript/src/views/android.d.ts +6 -0
  142. package/lib/typescript/src/views/types.d.ts +3 -12
  143. package/package.json +8 -16
  144. package/react-native-skia.podspec +50 -57
  145. package/src/Platform/Platform.web.tsx +1 -1
  146. package/src/index.ts +1 -3
  147. package/src/mock/index.ts +0 -1
  148. package/src/renderer/Canvas.tsx +23 -27
  149. package/src/skia/types/Graphite.ts +3 -3
  150. package/src/skia/types/Image/ImageFactory.ts +2 -2
  151. package/src/skia/types/Skia.ts +1 -2
  152. package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
  153. package/src/specs/NativeSkiaModule.web.ts +9 -21
  154. package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
  155. package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
  156. package/src/views/SkiaGraphiteView.tsx +27 -16
  157. package/src/views/SkiaPictureView.tsx +11 -10
  158. package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
  159. package/src/views/SkiaWebRenderer.ts +1 -1
  160. package/src/views/android.ts +16 -0
  161. package/src/views/types.ts +3 -14
  162. package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
  163. package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
  164. package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
  165. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
  166. package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
  167. package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
  168. package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
  169. package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
  170. package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
  171. package/android/cpp/rnskia-android/gl/Context.h +0 -80
  172. package/android/cpp/rnskia-android/gl/Display.h +0 -123
  173. package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
  174. package/android/cpp/rnskia-android/gl/Error.h +0 -8
  175. package/android/cpp/rnskia-android/gl/Surface.h +0 -43
  176. package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
  177. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
  178. package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
  179. package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
  180. package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
  181. package/apple/MetalContext.h +0 -116
  182. package/apple/MetalContext.mm +0 -38
  183. package/apple/MetalWindowContext.h +0 -42
  184. package/apple/MetalWindowContext.mm +0 -95
  185. package/apple/RNSkAppleView.h +0 -49
  186. package/apple/RNSkAppleView.mm +0 -35
  187. package/apple/SkiaCVPixelBufferUtils.h +0 -122
  188. package/apple/SkiaCVPixelBufferUtils.mm +0 -535
  189. package/apple/SkiaGraphiteView.h +0 -26
  190. package/apple/SkiaGraphiteView.mm +0 -180
  191. package/apple/SkiaPictureView.h +0 -7
  192. package/apple/SkiaPictureView.mm +0 -70
  193. package/apple/SkiaUIView.h +0 -31
  194. package/apple/SkiaUIView.mm +0 -164
  195. package/cpp/rnskia/RNSkGraphiteView.h +0 -708
  196. package/cpp/rnskia/RNSkPictureView.cpp +0 -69
  197. package/cpp/rnskia/RNSkPictureView.h +0 -211
  198. package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
  199. package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
  200. package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
  201. package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
  202. package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
  203. package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
  204. package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
  205. package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
  206. package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
  207. package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
  208. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  209. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
  210. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  211. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  212. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
  213. package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  214. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  215. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  216. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
  217. package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  218. package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
  219. package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
  220. package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
  221. package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
  222. package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
  223. package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
  224. package/lib/module/renderer/DefaultCanvas.js +0 -34
  225. package/lib/module/renderer/DefaultCanvas.js.map +0 -1
  226. package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
  227. package/lib/module/renderer/GraphiteCanvas.js +0 -57
  228. package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
  229. package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
  230. package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
  231. package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
  232. package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  233. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
  234. package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
  235. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  236. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
  237. package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
  238. package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
  239. package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  240. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
  241. package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
  242. package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
  243. package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
  244. package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
  245. package/lib/module/views/SkiaPictureView.web.js +0 -156
  246. package/lib/module/views/SkiaPictureView.web.js.map +0 -1
  247. package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
  248. package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
  249. package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
  250. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
  251. package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
  252. package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
  253. package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
  254. package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
  255. package/libs/.graphite +0 -1
  256. package/src/renderer/DefaultCanvas.tsx +0 -41
  257. package/src/renderer/GraphiteCanvas.tsx +0 -61
  258. package/src/renderer/GraphiteCanvas.web.tsx +0 -3
  259. package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
  260. package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
  261. package/src/views/SkiaPictureView.web.tsx +0 -224
@@ -1,41 +0,0 @@
1
- import React from "react";
2
-
3
- import { Skia } from "../skia";
4
- import { Platform } from "../Platform";
5
-
6
- import type { CanvasProps } from "./Canvas";
7
- import { Canvas as PictureCanvas } from "./Canvas";
8
- import { GraphiteCanvas } from "./GraphiteCanvas";
9
-
10
- let useGraphite: boolean | null = null;
11
-
12
- // Whether this build runs the Graphite backend. Resolved on the first render
13
- // (the native API is installed by then) and cached: getNativeDevice() throws
14
- // on Ganesh builds. On the web, GraphiteCanvas is the regular canvas anyway.
15
- const hasGraphite = () => {
16
- if (useGraphite === null) {
17
- if (Platform.OS === "web") {
18
- useGraphite = false;
19
- } else {
20
- try {
21
- useGraphite = typeof Skia.getNativeDevice() === "bigint";
22
- } catch {
23
- useGraphite = false;
24
- }
25
- }
26
- }
27
- return useGraphite;
28
- };
29
-
30
- /**
31
- * `<Canvas>` renders {@link GraphiteCanvas} when React Native Skia is
32
- * configured with the Graphite backend (install-skia-graphite), and the
33
- * picture view based canvas otherwise. Both take the same props and ref.
34
- */
35
- export const Canvas = (props: CanvasProps) => {
36
- return hasGraphite() ? (
37
- <GraphiteCanvas {...props} />
38
- ) : (
39
- <PictureCanvas {...props} />
40
- );
41
- };
@@ -1,61 +0,0 @@
1
- import React from "react";
2
-
3
- import SkiaGraphiteViewNativeComponent from "../specs/SkiaGraphiteViewNativeComponent";
4
-
5
- import type { CanvasProps } from "./Canvas";
6
- import { useCanvasRoot } from "./Canvas";
7
-
8
- /**
9
- * The declarative canvas on the Graphite view. It takes the same props and
10
- * exposes the same ref as {@link Canvas}, and draws the same children, but
11
- * the frames are produced differently:
12
- *
13
- * - the JS thread records the scene graph into a native recorder once per
14
- * React commit and hands it to the view;
15
- * - the Reanimated UI runtime only reads the shared values into it (the one
16
- * step that needs a JS runtime), it never replays anything;
17
- * - a dedicated native thread pool replays the recorder into a Graphite
18
- * recording whenever the content changed, at most once per presented frame;
19
- * - the view presents the recording on the next vsync.
20
- *
21
- * Neither the JS thread nor the UI thread pays for drawing. It requires the
22
- * Graphite backend (install-skia-graphite); with the default backend the view
23
- * renders nothing. `colorSpace`, `android` and `androidWarmup` are accepted
24
- * for API compatibility and ignored: the Graphite view renders in sRGB and
25
- * uses its own backing view.
26
- */
27
- export const GraphiteCanvas = ({
28
- debug,
29
- opaque,
30
- children,
31
- onSize,
32
-
33
- colorSpace,
34
- highBitDepth = false,
35
-
36
- androidWarmup,
37
-
38
- android,
39
- ref,
40
- onLayout,
41
- ...viewProps
42
- }: CanvasProps) => {
43
- const { nativeId, viewRef } = useCanvasRoot({
44
- children,
45
- onSize,
46
- ref,
47
- onLayout,
48
- });
49
- return (
50
- <SkiaGraphiteViewNativeComponent
51
- ref={viewRef}
52
- collapsable={false}
53
- nativeID={`${nativeId}`}
54
- debug={debug}
55
- opaque={opaque}
56
- highBitDepth={highBitDepth}
57
- onLayout={onLayout}
58
- {...viewProps}
59
- />
60
- );
61
- };
@@ -1,3 +0,0 @@
1
- // The Graphite view is native only: on the web, GraphiteCanvas is the regular
2
- // Canvas.
3
- export { Canvas as GraphiteCanvas } from "./Canvas";
@@ -1,17 +0,0 @@
1
- import { codegenNativeComponent, type ViewProps } from "react-native";
2
- import type { WithDefault } from "react-native/Libraries/Types/CodegenTypes";
3
-
4
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
- // @ts-ignore - pointerEvents needs to be redeclared for codegen to generate native bindings
6
- export interface NativeProps extends ViewProps {
7
- debug?: boolean;
8
- opaque?: boolean;
9
- highBitDepth?: boolean;
10
- pointerEvents?: WithDefault<
11
- "auto" | "none" | "box-none" | "box-only",
12
- "auto"
13
- >;
14
- }
15
-
16
- // eslint-disable-next-line import/no-default-export
17
- export default codegenNativeComponent<NativeProps>("SkiaGraphiteView");
@@ -1,31 +0,0 @@
1
- import type { ViewProps } from "react-native";
2
- import { createElement } from "react";
3
-
4
- import { SkiaGraphiteView } from "../views/SkiaGraphiteView.web";
5
-
6
- export interface NativeProps extends ViewProps {
7
- debug?: boolean;
8
- opaque?: boolean;
9
- highBitDepth?: boolean;
10
- nativeID: string;
11
- }
12
-
13
- const SkiaGraphiteViewNativeComponent = ({
14
- nativeID,
15
- debug,
16
- opaque,
17
- highBitDepth,
18
- onLayout,
19
- ...viewProps
20
- }: NativeProps) => {
21
- return createElement(SkiaGraphiteView, {
22
- nativeID,
23
- debug,
24
- opaque,
25
- highBitDepth,
26
- onLayout,
27
- ...viewProps,
28
- });
29
- };
30
- // eslint-disable-next-line import/no-default-export
31
- export default SkiaGraphiteViewNativeComponent;
@@ -1,224 +0,0 @@
1
- /* global HTMLCanvasElement */
2
- import React, {
3
- useRef,
4
- useEffect,
5
- useCallback,
6
- useImperativeHandle,
7
- } from "react";
8
-
9
- import type { SkRect, SkPicture, SkImage } from "../skia/types";
10
- import { Platform } from "../Platform";
11
- import type {
12
- ISkiaViewApiWeb,
13
- SkiaWebViewHandle,
14
- } from "../specs/NativeSkiaModule.web";
15
-
16
- import type { SkiaPictureViewNativeProps } from "./types";
17
- import { SkiaViewNativeId } from "./SkiaViewNativeId";
18
- import { useSkiaWebRenderer } from "./SkiaWebRenderer";
19
- import type { Renderer } from "./SkiaWebRenderer";
20
-
21
- export interface SkiaPictureViewHandle extends SkiaWebViewHandle {
22
- setPicture(picture: SkPicture): void;
23
- }
24
-
25
- export interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
26
- ref?: React.Ref<SkiaPictureViewHandle>;
27
- }
28
-
29
- export const SkiaPictureView = (props: SkiaPictureViewProps) => {
30
- const { ref, picture, onLayout } = props;
31
- const canvasRef = useRef<HTMLCanvasElement | null>(null);
32
- const pictureRef = useRef<SkPicture | null>(null);
33
- // Redraw requests coalesce into a single microtask. A microtask (not an
34
- // animation frame) so that a picture produced inside a rAF callback (the
35
- // Reanimated mapper) is drawn before the current frame paints: deferring
36
- // to the next rAF alternates between "flush pending in this frame" and
37
- // "flush scheduled for the next frame", drawing on every other frame
38
- // only and halving the effective frame rate. A picture dispatched before
39
- // the canvas has a size stays in pictureRef (drawing while unmeasured is
40
- // a no-op) and is painted by the resize path once the canvas becomes
41
- // measurable, so it is never lost.
42
- const redrawPendingRef = useRef(false);
43
- const flushScheduledRef = useRef(false);
44
-
45
- const isStatic = props.__destroyWebGLContextAfterRender === true;
46
-
47
- const paint = useCallback((renderer: Renderer) => {
48
- if (pictureRef.current) {
49
- redrawPendingRef.current = false;
50
- renderer.draw([pictureRef.current]);
51
- }
52
- }, []);
53
- const rendererRef = useSkiaWebRenderer(canvasRef, isStatic, {
54
- paint,
55
- onLayout,
56
- });
57
-
58
- const flushRedraw = useCallback(() => {
59
- flushScheduledRef.current = false;
60
- if (redrawPendingRef.current && rendererRef.current && pictureRef.current) {
61
- redrawPendingRef.current = false;
62
- rendererRef.current.draw([pictureRef.current]);
63
- }
64
- // If the renderer or picture isn't available yet, the request stays
65
- // pending and is flushed by whichever arrives last.
66
- }, [rendererRef]);
67
-
68
- const redraw = useCallback(() => {
69
- redrawPendingRef.current = true;
70
- if (!flushScheduledRef.current) {
71
- flushScheduledRef.current = true;
72
- queueMicrotask(flushRedraw);
73
- }
74
- }, [flushRedraw]);
75
-
76
- const getSize = useCallback(() => {
77
- return {
78
- width: canvasRef.current?.clientWidth || 0,
79
- height: canvasRef.current?.clientHeight || 0,
80
- };
81
- }, []);
82
-
83
- const setPicture = useCallback(
84
- (newPicture: SkPicture) => {
85
- pictureRef.current = newPicture;
86
- redraw();
87
- },
88
- [redraw]
89
- );
90
-
91
- const makeImageSnapshot = useCallback(
92
- (rect?: SkRect): SkImage | null => {
93
- if (rendererRef.current && pictureRef.current) {
94
- return rendererRef.current.makeImageSnapshot(
95
- [pictureRef.current],
96
- rect
97
- );
98
- }
99
- return null;
100
- },
101
- [rendererRef]
102
- );
103
-
104
- const measure = useCallback(
105
- (
106
- callback: (
107
- x: number,
108
- y: number,
109
- width: number,
110
- height: number,
111
- pageX: number,
112
- pageY: number
113
- ) => void
114
- ) => {
115
- if (canvasRef.current) {
116
- const rect = canvasRef.current.getBoundingClientRect();
117
- const parentElement = canvasRef.current.offsetParent as HTMLElement;
118
- const parentRect = parentElement?.getBoundingClientRect() || {
119
- left: 0,
120
- top: 0,
121
- };
122
-
123
- // x, y are relative to the parent
124
- const x = rect.left - parentRect.left;
125
- const y = rect.top - parentRect.top;
126
-
127
- // pageX, pageY are absolute screen coordinates
128
- const pageX = rect.left + window.scrollX;
129
- const pageY = rect.top + window.scrollY;
130
-
131
- callback(x, y, rect.width, rect.height, pageX, pageY);
132
- }
133
- },
134
- []
135
- );
136
-
137
- const measureInWindow = useCallback(
138
- (
139
- callback: (x: number, y: number, width: number, height: number) => void
140
- ) => {
141
- if (canvasRef.current) {
142
- const rect = canvasRef.current.getBoundingClientRect();
143
-
144
- // x, y are the absolute coordinates in the window
145
- const x = rect.left;
146
- const y = rect.top;
147
-
148
- callback(x, y, rect.width, rect.height);
149
- }
150
- },
151
- []
152
- );
153
-
154
- // No flush cancellation is needed on unmount: a microtask queued before
155
- // unmount runs within the same task, and flushRedraw no-ops once the
156
- // layout-effect cleanup has nulled rendererRef.
157
-
158
- useImperativeHandle(
159
- ref,
160
- () => ({
161
- setPicture,
162
- getSize,
163
- redraw,
164
- makeImageSnapshot,
165
- measure,
166
- measureInWindow,
167
- get canvasRef() {
168
- return () => canvasRef.current;
169
- },
170
- }),
171
- [setPicture, getSize, redraw, makeImageSnapshot, measure, measureInWindow]
172
- );
173
-
174
- useEffect(() => {
175
- const nativeID = props.nativeID ?? `${SkiaViewNativeId.current++}`;
176
- const api = global.SkiaViewApi as ISkiaViewApiWeb;
177
- api.registerView(nativeID, {
178
- setPicture,
179
- getSize,
180
- redraw,
181
- makeImageSnapshot,
182
- measure,
183
- measureInWindow,
184
- } as SkiaPictureViewHandle);
185
- return () => {
186
- api.unregisterView(nativeID);
187
- };
188
- }, [
189
- setPicture,
190
- getSize,
191
- redraw,
192
- makeImageSnapshot,
193
- measure,
194
- measureInWindow,
195
- props.nativeID,
196
- ]);
197
-
198
- useEffect(() => {
199
- if (picture) {
200
- setPicture(picture);
201
- }
202
- }, [setPicture, picture]);
203
-
204
- const {
205
- debug: _debug,
206
- ref: _ref,
207
- onLayout: _onLayout,
208
- picture: _picture,
209
- __destroyWebGLContextAfterRender: _isStatic,
210
- ...viewProps
211
- } = props;
212
- return (
213
- <Platform.View {...viewProps}>
214
- <canvas
215
- // A canvas element is bound to one context kind for life (WebGL for
216
- // the live renderer, 2D for the static one), so switching renderers
217
- // needs a fresh element.
218
- key={isStatic ? "static" : "webgl"}
219
- ref={canvasRef}
220
- style={{ display: "block", width: "100%", height: "100%" }}
221
- />
222
- </Platform.View>
223
- );
224
- };