react-native-skia 3.0.1 → 3.0.3
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.
- package/Package.swift +14 -13
- package/README.md +19 -2
- package/android/CMakeLists.txt +13 -42
- package/android/build.gradle +54 -63
- package/android/cpp/jni/JniLoad.cpp +2 -4
- package/android/cpp/jni/include/JniSkiaView.h +123 -0
- package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.cpp → RNSkAndroidCanvasProvider.cpp} +45 -100
- package/android/cpp/rnskia-android/{RNSkOpenGLCanvasProvider.h → RNSkAndroidCanvasProvider.h} +24 -22
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +0 -83
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +0 -8
- package/android/src/main/java/com/reactnative/skia/RNSkiaPackage.java +1 -2
- package/android/src/main/java/com/reactnative/skia/SkiaSurfaceView.java +1 -3
- package/android/src/main/java/com/reactnative/skia/SkiaTextureView.java +1 -17
- package/android/src/main/java/com/reactnative/skia/{SkiaBaseView.java → SkiaView.java} +78 -16
- package/android/src/main/java/com/reactnative/skia/SkiaViewManager.java +85 -0
- package/apple/MetalLayerColorSpace.mm +10 -12
- package/apple/RNSkApplePlatformContext.h +12 -14
- package/apple/RNSkApplePlatformContext.mm +19 -112
- package/apple/RNSkMetalCanvasProvider.h +14 -19
- package/apple/RNSkMetalCanvasProvider.mm +39 -70
- package/apple/RNSkiaModule.mm +10 -0
- package/apple/SkiaView.h +20 -0
- package/apple/SkiaView.mm +210 -0
- package/cpp/api/JsiSkApi.h +2 -13
- package/cpp/api/JsiSkCanvas.h +4 -18
- package/cpp/api/JsiSkGraphiteContext.h +1 -5
- package/cpp/api/JsiSkGraphiteRecording.h +1 -5
- package/cpp/api/JsiSkImage.h +7 -41
- package/cpp/api/JsiSkImageFactory.h +0 -14
- package/cpp/api/JsiSkSurface.h +2 -16
- package/cpp/api/JsiSkSurfaceFactory.h +0 -8
- package/cpp/rnskia/RNDawnContext.h +3 -2
- package/cpp/rnskia/RNDawnInterop.cpp +0 -4
- package/cpp/rnskia/RNDawnUtils.h +12 -1
- package/cpp/rnskia/RNDawnWindowContext.cpp +12 -1
- package/cpp/rnskia/RNDawnWindowContext.h +19 -7
- package/cpp/rnskia/RNMetalLayerColorSpace.h +4 -2
- package/cpp/rnskia/RNSkCanvasProvider.h +231 -0
- package/cpp/rnskia/RNSkGraphiteProducer.cpp +36 -14
- package/cpp/rnskia/RNSkGraphiteProducer.h +23 -8
- package/cpp/rnskia/RNSkGraphiteTarget.h +396 -0
- package/cpp/rnskia/RNSkJsiViewApi.h +9 -18
- package/cpp/rnskia/RNSkPlatformContext.h +17 -15
- package/cpp/rnskia/RNSkView.h +362 -246
- package/jestSetup.js +1 -3
- package/lib/commonjs/Platform/Platform.web.js +1 -1
- package/lib/commonjs/Platform/Platform.web.js.map +1 -1
- package/lib/commonjs/external/reanimated/interpolators.js +1 -1
- package/lib/commonjs/external/reanimated/interpolators.js.map +1 -1
- package/lib/commonjs/index.d.ts +1 -3
- package/lib/commonjs/index.js +3 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mock/index.js +0 -1
- package/lib/commonjs/mock/index.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +15 -12
- package/lib/commonjs/renderer/Canvas.js +25 -21
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/skia/types/Graphite.d.ts +3 -3
- package/lib/commonjs/skia/types/Graphite.js.map +1 -1
- package/lib/commonjs/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/commonjs/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +1 -2
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/commonjs/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/commonjs/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/commonjs/specs/NativeSkiaModule.web.js +5 -9
- package/lib/commonjs/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/{typescript/src/specs/SkiaPictureViewNativeComponent.d.ts → commonjs/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/commonjs/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
- package/lib/commonjs/specs/SkiaViewNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.js +27 -0
- package/lib/commonjs/specs/SkiaViewNativeComponent.web.js.map +1 -0
- package/lib/commonjs/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/commonjs/views/SkiaGraphiteView.js +23 -12
- package/lib/commonjs/views/SkiaGraphiteView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +4 -1
- package/lib/commonjs/views/SkiaPictureView.js +12 -10
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaView.web.d.ts +12 -0
- package/lib/commonjs/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +82 -38
- package/lib/commonjs/views/SkiaView.web.js.map +1 -0
- package/lib/commonjs/views/SkiaWebRenderer.js +1 -1
- package/lib/commonjs/views/SkiaWebRenderer.js.map +1 -1
- package/lib/commonjs/views/android.d.ts +6 -0
- package/lib/commonjs/views/android.js +17 -0
- package/lib/commonjs/views/android.js.map +1 -0
- package/lib/commonjs/views/types.d.ts +3 -12
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/Platform/Platform.web.js +1 -1
- package/lib/module/Platform/Platform.web.js.map +1 -1
- package/lib/module/external/reanimated/interpolators.js +1 -1
- package/lib/module/external/reanimated/interpolators.js.map +1 -1
- package/lib/module/index.d.ts +1 -3
- package/lib/module/index.js +1 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/mock/index.js +0 -1
- package/lib/module/mock/index.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +15 -12
- package/lib/module/renderer/Canvas.js +25 -20
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/skia/types/Graphite.d.ts +3 -3
- package/lib/module/skia/types/Graphite.js.map +1 -1
- package/lib/module/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/module/skia/types/Image/ImageFactory.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +1 -2
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/module/skia/types/Surface/SurfaceFactory.js.map +1 -1
- package/lib/module/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/module/specs/NativeSkiaModule.web.js +5 -9
- package/lib/module/specs/NativeSkiaModule.web.js.map +1 -1
- package/lib/{commonjs/specs/SkiaPictureViewNativeComponent.d.ts → module/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/module/specs/{SkiaPictureViewNativeComponent.js → SkiaViewNativeComponent.js} +2 -2
- package/lib/module/specs/SkiaViewNativeComponent.js.map +1 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.js +21 -0
- package/lib/module/specs/SkiaViewNativeComponent.web.js.map +1 -0
- package/lib/module/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/module/views/SkiaGraphiteView.js +23 -12
- package/lib/module/views/SkiaGraphiteView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +4 -1
- package/lib/module/views/SkiaPictureView.js +12 -10
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaView.web.d.ts +12 -0
- package/lib/module/views/{SkiaGraphiteView.web.js → SkiaView.web.js} +80 -36
- package/lib/module/views/SkiaView.web.js.map +1 -0
- package/lib/module/views/SkiaWebRenderer.js +1 -1
- package/lib/module/views/SkiaWebRenderer.js.map +1 -1
- package/lib/module/views/android.d.ts +6 -0
- package/lib/module/views/android.js +10 -0
- package/lib/module/views/android.js.map +1 -0
- package/lib/module/views/types.d.ts +3 -12
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -3
- package/lib/typescript/src/renderer/Canvas.d.ts +15 -12
- package/lib/typescript/src/skia/types/Graphite.d.ts +3 -3
- package/lib/typescript/src/skia/types/Image/ImageFactory.d.ts +2 -2
- package/lib/typescript/src/skia/types/Skia.d.ts +1 -2
- package/lib/typescript/src/skia/types/Surface/SurfaceFactory.d.ts +1 -1
- package/lib/typescript/src/specs/NativeSkiaModule.web.d.ts +5 -4
- package/lib/{module/specs/SkiaPictureViewNativeComponent.d.ts → typescript/src/specs/SkiaViewNativeComponent.d.ts} +0 -3
- package/lib/typescript/src/specs/SkiaViewNativeComponent.web.d.ts +10 -0
- package/lib/typescript/src/views/SkiaGraphiteView.d.ts +3 -4
- package/lib/typescript/src/views/SkiaPictureView.d.ts +4 -1
- package/lib/typescript/src/views/SkiaView.web.d.ts +12 -0
- package/lib/typescript/src/views/android.d.ts +6 -0
- package/lib/typescript/src/views/types.d.ts +3 -12
- package/package.json +5 -13
- package/react-native-skia.podspec +34 -58
- package/src/Platform/Platform.web.tsx +1 -1
- package/src/external/reanimated/interpolators.ts +1 -1
- package/src/index.ts +1 -3
- package/src/mock/index.ts +0 -1
- package/src/renderer/Canvas.tsx +24 -28
- package/src/skia/types/Graphite.ts +3 -3
- package/src/skia/types/Image/ImageFactory.ts +2 -2
- package/src/skia/types/Skia.ts +1 -2
- package/src/skia/types/Surface/SurfaceFactory.ts +1 -1
- package/src/specs/NativeSkiaModule.web.ts +9 -21
- package/src/specs/{SkiaPictureViewNativeComponent.ts → SkiaViewNativeComponent.ts} +1 -4
- package/src/specs/{SkiaPictureViewNativeComponent.web.ts → SkiaViewNativeComponent.web.ts} +8 -10
- package/src/views/SkiaGraphiteView.tsx +27 -16
- package/src/views/SkiaPictureView.tsx +11 -10
- package/src/views/{SkiaGraphiteView.web.tsx → SkiaView.web.tsx} +100 -53
- package/src/views/SkiaWebRenderer.ts +1 -1
- package/src/views/android.ts +16 -0
- package/src/views/types.ts +3 -14
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -92
- package/android/cpp/jni/include/JniSkiaGraphiteView.h +0 -176
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -172
- package/android/cpp/rnskia-android/GrAHardwareBufferUtils.cpp +0 -245
- package/android/cpp/rnskia-android/GrAHardwareBufferUtils.h +0 -33
- package/android/cpp/rnskia-android/OpenGLContext.h +0 -248
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +0 -67
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +0 -75
- package/android/cpp/rnskia-android/RNSkAndroidView.h +0 -67
- package/android/cpp/rnskia-android/gl/Context.h +0 -80
- package/android/cpp/rnskia-android/gl/Display.h +0 -123
- package/android/cpp/rnskia-android/gl/Error.cpp +0 -45
- package/android/cpp/rnskia-android/gl/Error.h +0 -8
- package/android/cpp/rnskia-android/gl/Surface.h +0 -43
- package/android/src/main/java/com/reactnative/skia/SkiaBaseViewManager.java +0 -65
- package/android/src/main/java/com/reactnative/skia/SkiaGraphiteView.java +0 -78
- package/android/src/main/java/com/reactnative/skia/SkiaGraphiteViewManager.java +0 -32
- package/android/src/main/java/com/reactnative/skia/SkiaPictureView.java +0 -105
- package/android/src/main/java/com/reactnative/skia/SkiaPictureViewManager.java +0 -44
- package/apple/MetalContext.h +0 -116
- package/apple/MetalContext.mm +0 -38
- package/apple/MetalWindowContext.h +0 -42
- package/apple/MetalWindowContext.mm +0 -95
- package/apple/RNSkAppleView.h +0 -49
- package/apple/RNSkAppleView.mm +0 -35
- package/apple/SkiaCVPixelBufferUtils.h +0 -122
- package/apple/SkiaCVPixelBufferUtils.mm +0 -535
- package/apple/SkiaGraphiteView.h +0 -26
- package/apple/SkiaGraphiteView.mm +0 -180
- package/apple/SkiaPictureView.h +0 -7
- package/apple/SkiaPictureView.mm +0 -70
- package/apple/SkiaUIView.h +0 -31
- package/apple/SkiaUIView.mm +0 -164
- package/cpp/rnskia/RNSkGraphiteView.h +0 -708
- package/cpp/rnskia/RNSkPictureView.cpp +0 -69
- package/cpp/rnskia/RNSkPictureView.h +0 -211
- package/cpp/skia/src/gpu/ganesh/gl/GrGLDefines.h +0 -1162
- package/lib/commonjs/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/commonjs/renderer/DefaultCanvas.js +0 -42
- package/lib/commonjs/renderer/DefaultCanvas.js.map +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/commonjs/renderer/GraphiteCanvas.js +0 -64
- package/lib/commonjs/renderer/GraphiteCanvas.js.map +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/commonjs/renderer/GraphiteCanvas.web.js +0 -13
- package/lib/commonjs/renderer/GraphiteCanvas.web.js.map +0 -1
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js +0 -12
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js +0 -28
- package/lib/commonjs/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js +0 -29
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
- package/lib/commonjs/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/commonjs/views/SkiaGraphiteView.web.js.map +0 -1
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +0 -11
- package/lib/commonjs/views/SkiaPictureView.web.js +0 -165
- package/lib/commonjs/views/SkiaPictureView.web.js.map +0 -1
- package/lib/module/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/module/renderer/DefaultCanvas.js +0 -34
- package/lib/module/renderer/DefaultCanvas.js.map +0 -1
- package/lib/module/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/module/renderer/GraphiteCanvas.js +0 -57
- package/lib/module/renderer/GraphiteCanvas.js.map +0 -1
- package/lib/module/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/module/renderer/GraphiteCanvas.web.js +0 -4
- package/lib/module/renderer/GraphiteCanvas.web.js.map +0 -1
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.js +0 -8
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.js.map +0 -1
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js +0 -22
- package/lib/module/specs/SkiaGraphiteViewNativeComponent.web.js.map +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.js +0 -23
- package/lib/module/specs/SkiaPictureViewNativeComponent.web.js.map +0 -1
- package/lib/module/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/module/views/SkiaGraphiteView.web.js.map +0 -1
- package/lib/module/views/SkiaPictureView.web.d.ts +0 -11
- package/lib/module/views/SkiaPictureView.web.js +0 -156
- package/lib/module/views/SkiaPictureView.web.js.map +0 -1
- package/lib/typescript/src/renderer/DefaultCanvas.d.ts +0 -8
- package/lib/typescript/src/renderer/GraphiteCanvas.d.ts +0 -22
- package/lib/typescript/src/renderer/GraphiteCanvas.web.d.ts +0 -1
- package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.d.ts +0 -10
- package/lib/typescript/src/specs/SkiaGraphiteViewNativeComponent.web.d.ts +0 -9
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.web.d.ts +0 -10
- package/lib/typescript/src/views/SkiaGraphiteView.web.d.ts +0 -14
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +0 -11
- package/libs/.graphite +0 -1
- package/src/renderer/DefaultCanvas.tsx +0 -41
- package/src/renderer/GraphiteCanvas.tsx +0 -61
- package/src/renderer/GraphiteCanvas.web.tsx +0 -3
- package/src/specs/SkiaGraphiteViewNativeComponent.ts +0 -17
- package/src/specs/SkiaGraphiteViewNativeComponent.web.ts +0 -31
- package/src/views/SkiaPictureView.web.tsx +0 -224
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# react-native-skia.podspec
|
|
2
2
|
|
|
3
3
|
require "json"
|
|
4
4
|
require "fileutils"
|
|
5
5
|
|
|
6
6
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
7
7
|
|
|
8
|
-
# Check if Graphite is enabled via marker file (created by install-skia-graphite)
|
|
9
|
-
use_graphite = File.exist?(File.join(__dir__, 'libs', '.graphite'))
|
|
10
|
-
puts "-- SK_GRAPHITE: #{use_graphite ? 'ON' : 'OFF'} (detected via libs/.graphite marker file)"
|
|
11
|
-
|
|
12
8
|
# Resolve a node package directory using Node's own module resolution
|
|
13
9
|
# (mirrors `require.resolve(pkg/package.json)`). Returns nil if it can't be found.
|
|
14
10
|
# Defined as a lambda (not a `def`) because CocoaPods evaluates the podspec inside
|
|
@@ -40,12 +36,22 @@ install_apple_skia_libs = lambda do |base_dir, packages|
|
|
|
40
36
|
# Graphite packages carry the Dawn release tag they ship (libs/.dawn-version),
|
|
41
37
|
# used below for the react-native-webgpu version check.
|
|
42
38
|
dawn_version = File.join(src, '.dawn-version')
|
|
43
|
-
|
|
39
|
+
if File.exist?(dawn_version)
|
|
40
|
+
FileUtils.mkdir_p(File.join(base_dir, 'libs'))
|
|
41
|
+
FileUtils.cp(dawn_version, File.join(base_dir, 'libs', '.dawn-version'))
|
|
42
|
+
end
|
|
44
43
|
|
|
45
44
|
version = JSON.parse(File.read(File.join(pkg_dir, 'package.json')))['version'].to_s
|
|
46
45
|
dest = File.join(base_dir, 'libs', platform)
|
|
47
46
|
marker = File.join(dest, '.version')
|
|
48
47
|
|
|
48
|
+
# Frameworks without a .version stamp were built locally (`yarn build-skia`):
|
|
49
|
+
# keep them instead of overwriting them with the npm package.
|
|
50
|
+
if !File.exist?(marker) && !Dir.glob(File.join(dest, '*.xcframework')).empty?
|
|
51
|
+
Pod::UI.puts "react-native-skia: using locally built #{platform} Skia frameworks"
|
|
52
|
+
next
|
|
53
|
+
end
|
|
54
|
+
|
|
49
55
|
# Already up to date: leave the files untouched so CocoaPods keeps its cache.
|
|
50
56
|
next if File.exist?(marker) && File.read(marker).strip == version
|
|
51
57
|
|
|
@@ -57,23 +63,15 @@ install_apple_skia_libs = lambda do |base_dir, packages|
|
|
|
57
63
|
end
|
|
58
64
|
end
|
|
59
65
|
|
|
60
|
-
# The
|
|
61
|
-
#
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
{ 'ios' => 'react-native-skia-graphite-apple-ios',
|
|
67
|
-
'macos' => 'react-native-skia-graphite-apple-macos' } :
|
|
68
|
-
{ 'ios' => 'react-native-skia-apple-ios',
|
|
69
|
-
'macos' => 'react-native-skia-apple-macos',
|
|
70
|
-
'tvos' => 'react-native-skia-apple-tvos' }
|
|
66
|
+
# The Graphite binaries ship in the react-native-skia-graphite-apple-* npm
|
|
67
|
+
# packages (no tvOS), together with the shared Dawn (libwebgpu_dawn.xcframework).
|
|
68
|
+
apple_skia_packages = {
|
|
69
|
+
'ios' => 'react-native-skia-graphite-apple-ios',
|
|
70
|
+
'macos' => 'react-native-skia-graphite-apple-macos'
|
|
71
|
+
}
|
|
71
72
|
install_apple_skia_libs.call(__dir__, apple_skia_packages)
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
preprocessor_defs = use_graphite ?
|
|
75
|
-
'$(inherited) SK_GRAPHITE=1 SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API=1 SK_DISABLE_LEGACY_SHAPER_FACTORY=1' :
|
|
76
|
-
'$(inherited) SK_METAL=1 SK_GANESH=1 SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API=1 SK_DISABLE_LEGACY_SHAPER_FACTORY=1'
|
|
74
|
+
preprocessor_defs = '$(inherited) SK_GRAPHITE=1 SK_IMAGE_READ_PIXELS_DISABLE_LEGACY_API=1 SK_DISABLE_LEGACY_SHAPER_FACTORY=1'
|
|
77
75
|
|
|
78
76
|
# Define framework names
|
|
79
77
|
framework_names = ['libskia', 'libsvg', 'libskshaper', 'libskparagraph',
|
|
@@ -86,14 +84,18 @@ framework_names = ['libskia', 'libsvg', 'libskshaper', 'libskparagraph',
|
|
|
86
84
|
# vendoring the framework here as well would fail CocoaPods'
|
|
87
85
|
# duplicate-framework-name check, so Skia only vendors it when alone. The
|
|
88
86
|
# skia pod's dawn::native references resolve from webgpu's copy at app link.
|
|
87
|
+
# An app that installs react-native-webgpu but keeps it out of a platform's
|
|
88
|
+
# Pods (e.g. a macOS target that filters it out of autolinking) sets
|
|
89
|
+
# RNSKIA_VENDOR_DAWN=1 before `pod install` so Skia vendors Dawn itself there.
|
|
89
90
|
webgpu_pkg_dir = resolve_node_package.call('react-native-webgpu', __dir__)
|
|
90
|
-
has_webgpu_pkg = !webgpu_pkg_dir.nil?
|
|
91
|
-
if
|
|
91
|
+
has_webgpu_pkg = !webgpu_pkg_dir.nil? && ENV['RNSKIA_VENDOR_DAWN'] != '1'
|
|
92
|
+
if has_webgpu_pkg
|
|
92
93
|
Pod::UI.puts 'react-native-skia: react-native-webgpu detected, Dawn is provided by its libwebgpu_dawn'
|
|
93
94
|
|
|
94
95
|
# Both packages must link the exact same Dawn artifact. Compare the release
|
|
95
|
-
# tag
|
|
96
|
-
# the tag react-native-webgpu declares in
|
|
96
|
+
# tag the Skia binaries were packaged with (libs/.dawn-version, copied in from
|
|
97
|
+
# the binary package above) against the tag react-native-webgpu declares in
|
|
98
|
+
# its package.json `dawn` field.
|
|
97
99
|
dawn_marker = File.join(__dir__, 'libs', '.dawn-version')
|
|
98
100
|
if File.exist?(dawn_marker)
|
|
99
101
|
skia_dawn = File.read(dawn_marker).strip
|
|
@@ -115,7 +117,7 @@ if use_graphite && has_webgpu_pkg
|
|
|
115
117
|
Pod::UI.puts "react-native-skia: Dawn versions match (#{skia_dawn})"
|
|
116
118
|
end
|
|
117
119
|
end
|
|
118
|
-
|
|
120
|
+
unless has_webgpu_pkg
|
|
119
121
|
# CocoaPods silently skips missing vendored frameworks, which would surface
|
|
120
122
|
# later as undefined dawn::native symbols at link time. Fail early instead.
|
|
121
123
|
%w[ios macos].each do |platform|
|
|
@@ -130,7 +132,7 @@ if use_graphite && !has_webgpu_pkg
|
|
|
130
132
|
end
|
|
131
133
|
|
|
132
134
|
# Verify that the prebuilt binaries are available (copied in above from the npm
|
|
133
|
-
# packages, or
|
|
135
|
+
# packages, or built locally with `yarn build-skia`).
|
|
134
136
|
unless Dir.exist?(File.join(__dir__, 'libs', 'ios')) && Dir.exist?(File.join(__dir__, 'libs', 'macos'))
|
|
135
137
|
expected_packages = apple_skia_packages.values.join(', ')
|
|
136
138
|
Pod::UI.warn "#{'-' * 72}"
|
|
@@ -143,33 +145,26 @@ unless Dir.exist?(File.join(__dir__, 'libs', 'ios')) && Dir.exist?(File.join(__d
|
|
|
143
145
|
end
|
|
144
146
|
|
|
145
147
|
# Build platform-specific framework paths (relative to pod's libs directory)
|
|
146
|
-
# xcframeworks are copied into libs/ by install_apple_skia_libs above
|
|
147
|
-
# or downloaded by install-skia-graphite (Graphite build).
|
|
148
|
+
# xcframeworks are copied into libs/ by install_apple_skia_libs above.
|
|
148
149
|
ios_frameworks = framework_names.map { |f| "libs/ios/#{f}.xcframework" }
|
|
149
150
|
osx_frameworks = framework_names.map { |f| "libs/macos/#{f}.xcframework" }
|
|
150
|
-
# tvOS frameworks - check if libs/tvos/ exists (only populated for the default build)
|
|
151
|
-
tvos_frameworks = if use_graphite || !Dir.exist?(File.join(__dir__, 'libs', 'tvos'))
|
|
152
|
-
[]
|
|
153
|
-
else
|
|
154
|
-
framework_names.map { |f| "libs/tvos/#{f}.xcframework" }
|
|
155
|
-
end
|
|
156
151
|
|
|
157
152
|
Pod::Spec.new do |s|
|
|
158
153
|
s.name = "react-native-skia"
|
|
159
154
|
s.version = package["version"]
|
|
160
155
|
s.summary = package["description"]
|
|
161
156
|
s.description = <<-DESC
|
|
162
|
-
|
|
157
|
+
react-native-skia
|
|
163
158
|
DESC
|
|
164
|
-
s.homepage = "https://github.com/
|
|
159
|
+
s.homepage = "https://github.com/wcandillon/react-native-skia"
|
|
165
160
|
s.license = "MIT"
|
|
166
161
|
s.license = { :type => "MIT", :file => "LICENSE.md" }
|
|
167
162
|
s.authors = {
|
|
168
163
|
"Christian Falch" => "christian.falch@gmail.com",
|
|
169
164
|
"William Candillon" => "wcandillon@gmail.com"
|
|
170
165
|
}
|
|
171
|
-
s.platforms = { :ios => "
|
|
172
|
-
s.source = { :git => "https://github.com/
|
|
166
|
+
s.platforms = { :ios => "15.1", :osx => "11" }
|
|
167
|
+
s.source = { :git => "https://github.com/wcandillon/react-native-skia.git", :tag => "#{s.version}" }
|
|
173
168
|
|
|
174
169
|
s.requires_arc = true
|
|
175
170
|
s.pod_target_xcconfig = {
|
|
@@ -185,11 +180,6 @@ Pod::Spec.new do |s|
|
|
|
185
180
|
s.ios.vendored_frameworks = ios_frameworks
|
|
186
181
|
s.osx.vendored_frameworks = osx_frameworks
|
|
187
182
|
|
|
188
|
-
# tvOS frameworks only available for non-Graphite builds
|
|
189
|
-
unless use_graphite
|
|
190
|
-
s.tvos.vendored_frameworks = tvos_frameworks
|
|
191
|
-
end
|
|
192
|
-
|
|
193
183
|
# Preserve the copied libs directory
|
|
194
184
|
s.preserve_paths = ["libs/**/*"]
|
|
195
185
|
|
|
@@ -199,20 +189,6 @@ Pod::Spec.new do |s|
|
|
|
199
189
|
"cpp/**/*.{h,cpp}"
|
|
200
190
|
]
|
|
201
191
|
|
|
202
|
-
graphite_exclusions = [
|
|
203
|
-
'cpp/rnskia/RNDawnContext.h',
|
|
204
|
-
'cpp/rnskia/RNDawnUtils.h',
|
|
205
|
-
'cpp/rnskia/RNMetalLayerColorSpace.h',
|
|
206
|
-
'cpp/rnskia/RNDawnWindowContext.h',
|
|
207
|
-
'cpp/rnskia/RNDawnWindowContext.cpp',
|
|
208
|
-
'cpp/rnskia/RNDawnInterop.cpp',
|
|
209
|
-
'cpp/rnskia/RNImageProvider.h',
|
|
210
|
-
'cpp/rnskia/RNSkGraphiteView.h',
|
|
211
|
-
'cpp/api/JsiSkGraphiteContext.h',
|
|
212
|
-
'cpp/api/JsiSkGraphiteRecording.h'
|
|
213
|
-
]
|
|
214
|
-
s.exclude_files = graphite_exclusions unless use_graphite
|
|
215
|
-
|
|
216
192
|
install_modules_dependencies(s)
|
|
217
193
|
s.dependency "React"
|
|
218
194
|
s.dependency "React-callinvoker"
|
|
@@ -7,7 +7,7 @@ import { isRNModule, unwrapModule } from "../skia/types";
|
|
|
7
7
|
|
|
8
8
|
import type { IPlatform } from "./IPlatform";
|
|
9
9
|
|
|
10
|
-
// Layout is observed by the views themselves (see
|
|
10
|
+
// Layout is observed by the views themselves (see SkiaView.web.tsx):
|
|
11
11
|
// this shim only reproduces react-native-web's default View styling.
|
|
12
12
|
const View = (({ children, style: rawStyle }: ViewProps) => {
|
|
13
13
|
const style = useMemo(() => (rawStyle ?? {}) as CSSProperties, [rawStyle]);
|
|
@@ -115,7 +115,7 @@ export const usePathInterpolation = (
|
|
|
115
115
|
// For example, throw an error or return early
|
|
116
116
|
throw new Error(
|
|
117
117
|
`Not all paths in the output range are interpolable.
|
|
118
|
-
See: https://
|
|
118
|
+
See: https://wcandillon.github.io/react-native-skia/docs/animations/hooks#usepathinterpolation`
|
|
119
119
|
);
|
|
120
120
|
}
|
|
121
121
|
return useInterpolator(
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import "./skia/NativeSetup";
|
|
2
2
|
export { JsiSkImage } from "./skia/web/JsiSkImage";
|
|
3
3
|
export * from "./renderer";
|
|
4
|
-
export { useCanvasRef, useCanvasSize } from "./renderer/Canvas";
|
|
4
|
+
export { Canvas, useCanvasRef, useCanvasSize } from "./renderer/Canvas";
|
|
5
5
|
export type { CanvasProps, CanvasRef } from "./renderer/Canvas";
|
|
6
|
-
export { GraphiteCanvas } from "./renderer/GraphiteCanvas";
|
|
7
|
-
export { Canvas } from "./renderer/DefaultCanvas";
|
|
8
6
|
export * from "./renderer/Offscreen";
|
|
9
7
|
export * from "./views";
|
|
10
8
|
export * from "./skia";
|
package/src/mock/index.ts
CHANGED
|
@@ -23,7 +23,6 @@ export const Mock = (CanvasKit: CanvasKit) => {
|
|
|
23
23
|
...require("../dom/types"),
|
|
24
24
|
...require("../dom/nodes"),
|
|
25
25
|
Canvas: require("react-native").View,
|
|
26
|
-
GraphiteCanvas: require("react-native").View,
|
|
27
26
|
getPreferredHighBitDepthCanvasFormat: () => "rgba16float",
|
|
28
27
|
SkiaPictureView: require("react-native").View,
|
|
29
28
|
SkiaGraphiteView: require("react-native").View,
|
package/src/renderer/Canvas.tsx
CHANGED
|
@@ -19,8 +19,9 @@ import type { SharedValue } from "react-native-reanimated";
|
|
|
19
19
|
|
|
20
20
|
import Rea from "../external/reanimated/ReanimatedProxy";
|
|
21
21
|
import { SkiaViewNativeId } from "../views/SkiaViewNativeId";
|
|
22
|
-
import
|
|
23
|
-
import
|
|
22
|
+
import { androidNativeProps } from "../views/android";
|
|
23
|
+
import type { AndroidCanvasProps } from "../views/types";
|
|
24
|
+
import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
|
|
24
25
|
import type { SkImage, SkRect, SkSize } from "../skia/types";
|
|
25
26
|
import { SkiaSGRoot } from "../sksg/Reconciler";
|
|
26
27
|
import { Skia } from "../skia";
|
|
@@ -61,7 +62,6 @@ export const useCanvasSize = (userRef?: RefObject<CanvasRef | null>) => {
|
|
|
61
62
|
};
|
|
62
63
|
|
|
63
64
|
export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
|
64
|
-
debug?: boolean;
|
|
65
65
|
/** @deprecated Not supported on native. Use `onSize` or `useCanvasSize()` instead. */
|
|
66
66
|
onLayout?: ViewProps["onLayout"];
|
|
67
67
|
/**
|
|
@@ -72,7 +72,6 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
|
|
72
72
|
*/
|
|
73
73
|
opaque?: boolean;
|
|
74
74
|
onSize?: SharedValue<SkSize>;
|
|
75
|
-
colorSpace?: "p3" | "srgb";
|
|
76
75
|
/**
|
|
77
76
|
* Renders into a surface with more than 8 bits per channel (16-bit float on
|
|
78
77
|
* iOS, 10-bit on Android) to avoid banding in subtle gradients. Colors are
|
|
@@ -85,25 +84,14 @@ export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
|
|
85
84
|
/** Android-only rendering options. Ignored on iOS and web. */
|
|
86
85
|
android?: AndroidCanvasProps;
|
|
87
86
|
ref?: React.Ref<CanvasRef>;
|
|
88
|
-
androidWarmup?: boolean;
|
|
89
87
|
__destroyWebGLContextAfterRender?: boolean;
|
|
90
88
|
}
|
|
91
89
|
|
|
92
|
-
// Anything else reaching the native component would hit the generated
|
|
93
|
-
// string-enum parser, which aborts on unknown values.
|
|
94
|
-
const resolveSurfaceType = (
|
|
95
|
-
surfaceType: AndroidSurfaceType | undefined
|
|
96
|
-
): "auto" | AndroidSurfaceType =>
|
|
97
|
-
surfaceType === "SurfaceView" || surfaceType === "TextureView"
|
|
98
|
-
? surfaceType
|
|
99
|
-
: "auto";
|
|
100
|
-
|
|
101
90
|
/**
|
|
102
|
-
* What
|
|
103
|
-
*
|
|
104
|
-
* imperative handle of the ref.
|
|
91
|
+
* What the canvas owns: the native id, the scene graph root rendered into it,
|
|
92
|
+
* the `onSize` measurement and the imperative handle of the ref.
|
|
105
93
|
*/
|
|
106
|
-
|
|
94
|
+
const useCanvasRoot = ({
|
|
107
95
|
children,
|
|
108
96
|
onSize,
|
|
109
97
|
ref,
|
|
@@ -111,7 +99,7 @@ export const useCanvasRoot = ({
|
|
|
111
99
|
}: Pick<CanvasProps, "children" | "onSize" | "ref" | "onLayout">) => {
|
|
112
100
|
if (onLayout && Platform.OS !== "web") {
|
|
113
101
|
console.error(
|
|
114
|
-
"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://
|
|
102
|
+
"<Canvas onLayout={onLayout} /> is not supported on the new architecture, to fix the issue, see: https://wcandillon.github.io/react-native-skia/docs/canvas/overview/#canvas-size"
|
|
115
103
|
);
|
|
116
104
|
}
|
|
117
105
|
const viewRef = useCanvasRefPriv(null);
|
|
@@ -186,14 +174,26 @@ export const useCanvasRoot = ({
|
|
|
186
174
|
return { nativeId, viewRef };
|
|
187
175
|
};
|
|
188
176
|
|
|
177
|
+
/**
|
|
178
|
+
* The declarative canvas. Its children are rendered by Skia's own React
|
|
179
|
+
* renderer; the frames are produced off the JS thread:
|
|
180
|
+
*
|
|
181
|
+
* - the JS thread records the scene graph into a native recorder once per
|
|
182
|
+
* React commit and hands it to the view;
|
|
183
|
+
* - the Reanimated UI runtime only reads the shared values into it (the one
|
|
184
|
+
* step that needs a JS runtime), it never replays anything;
|
|
185
|
+
* - a dedicated native thread pool replays the recorder into a Graphite
|
|
186
|
+
* recording whenever the content changed, at most once per presented frame;
|
|
187
|
+
* - the view presents the recording on the next vsync.
|
|
188
|
+
*
|
|
189
|
+
* On the web the scene is drawn into a picture on the JS thread and painted
|
|
190
|
+
* on a WebGL canvas.
|
|
191
|
+
*/
|
|
189
192
|
export const Canvas = ({
|
|
190
|
-
debug,
|
|
191
193
|
opaque,
|
|
192
194
|
children,
|
|
193
195
|
onSize,
|
|
194
|
-
colorSpace = "p3",
|
|
195
196
|
highBitDepth = false,
|
|
196
|
-
androidWarmup = false,
|
|
197
197
|
android,
|
|
198
198
|
ref,
|
|
199
199
|
onLayout,
|
|
@@ -219,17 +219,13 @@ export const Canvas = ({
|
|
|
219
219
|
[onLayout, onSize]
|
|
220
220
|
);
|
|
221
221
|
return (
|
|
222
|
-
<
|
|
222
|
+
<SkiaViewNativeComponent
|
|
223
223
|
ref={viewRef}
|
|
224
224
|
collapsable={false}
|
|
225
225
|
nativeID={`${nativeId}`}
|
|
226
|
-
debug={debug}
|
|
227
226
|
opaque={opaque}
|
|
228
|
-
colorSpace={colorSpace}
|
|
229
227
|
highBitDepth={highBitDepth}
|
|
230
|
-
|
|
231
|
-
androidSurfaceType={resolveSurfaceType(android?.surfaceType)}
|
|
232
|
-
androidZOrderOnTop={!!android?.zOrderOnTop}
|
|
228
|
+
{...androidNativeProps(android)}
|
|
233
229
|
onLayout={
|
|
234
230
|
Platform.OS === "web" && (onSize || onLayout) ? onLayoutWeb : onLayout
|
|
235
231
|
}
|
|
@@ -2,13 +2,13 @@ import type { SkCanvas } from "./Canvas";
|
|
|
2
2
|
import type { SkJSIInstance } from "./JsiInstance";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* A frame recorded for a
|
|
6
|
-
*
|
|
5
|
+
* A frame recorded for a view. Immutable once finished: submit it to the view
|
|
6
|
+
* as many times as needed, from any runtime.
|
|
7
7
|
*/
|
|
8
8
|
export type SkGraphiteRecording = SkJSIInstance<"GraphiteRecording">;
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* The recording side of a
|
|
11
|
+
* The recording side of a view, obtained from the ref of a SkiaGraphiteView.
|
|
12
12
|
*
|
|
13
13
|
* Frames are recorded on the calling thread and presented by the view on its
|
|
14
14
|
* display link, so the context can be captured into a worklet and used from
|
|
@@ -106,7 +106,7 @@ export interface ImageFactory {
|
|
|
106
106
|
* while the image is in use: destroy() releases the underlying GPU
|
|
107
107
|
* resource regardless of reference counts.
|
|
108
108
|
*
|
|
109
|
-
*
|
|
109
|
+
* Native only.
|
|
110
110
|
*
|
|
111
111
|
* @param pointer - The WGPUTexture pointer (texture.nativePointer)
|
|
112
112
|
* @returns An SkImage wrapping the texture, or throws if the texture is invalid
|
|
@@ -119,7 +119,7 @@ export interface ImageFactory {
|
|
|
119
119
|
* returned pointer carries one reference and must be adopted exactly once
|
|
120
120
|
* with react-native-webgpu's adoptTexture(), which owns it from then on.
|
|
121
121
|
*
|
|
122
|
-
*
|
|
122
|
+
* Native only.
|
|
123
123
|
*
|
|
124
124
|
* @param image - An SkImage to convert to a texture
|
|
125
125
|
* @returns A WGPUTexture pointer for adoptTexture(), or throws on failure
|
package/src/skia/types/Skia.ts
CHANGED
|
@@ -106,8 +106,7 @@ export interface Skia {
|
|
|
106
106
|
/**
|
|
107
107
|
* Raw WGPUDevice pointer of Skia's Graphite device, as a BigInt. Pass it to
|
|
108
108
|
* react-native-webgpu's importDevice() to get a GPUDevice sharing Skia's
|
|
109
|
-
* device (zero-copy interop).
|
|
110
|
-
* otherwise.
|
|
109
|
+
* device (zero-copy interop). Native only.
|
|
111
110
|
*/
|
|
112
111
|
getNativeDevice(): bigint;
|
|
113
112
|
}
|
|
@@ -43,7 +43,7 @@ export interface SurfaceFactory {
|
|
|
43
43
|
* surface exists. Calling destroy() on the GPUTexture still invalidates
|
|
44
44
|
* the surface.
|
|
45
45
|
*
|
|
46
|
-
*
|
|
46
|
+
* Native only.
|
|
47
47
|
*
|
|
48
48
|
* @param pointer - The WGPUTexture pointer (texture.nativePointer)
|
|
49
49
|
* @returns An SkSurface rendering into the texture, or throws if the texture is invalid
|
|
@@ -7,8 +7,12 @@ import type {
|
|
|
7
7
|
} from "../skia/types";
|
|
8
8
|
import type { ISkiaViewApi } from "../views/types";
|
|
9
9
|
|
|
10
|
-
/** What
|
|
10
|
+
/** What the web view registers under its native id. */
|
|
11
11
|
export interface SkiaWebViewHandle {
|
|
12
|
+
/** Shows a picture: the frame of a <Canvas> or a <SkiaPictureView>. */
|
|
13
|
+
setPicture(picture: SkPicture): void;
|
|
14
|
+
/** The recording side of the view, see SkiaGraphiteView. */
|
|
15
|
+
getContext(): SkGraphiteContext;
|
|
12
16
|
getSize(): { width: number; height: number };
|
|
13
17
|
redraw(): void;
|
|
14
18
|
makeImageSnapshot(rect?: SkRect): SkImage | null;
|
|
@@ -27,20 +31,6 @@ export interface SkiaWebViewHandle {
|
|
|
27
31
|
): void;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
export interface SkiaGraphiteViewHandle extends SkiaWebViewHandle {
|
|
31
|
-
getContext(): SkGraphiteContext;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
interface PictureHandle extends SkiaWebViewHandle {
|
|
35
|
-
setPicture(picture: SkPicture): void;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const hasPicture = (view: SkiaWebViewHandle): view is PictureHandle =>
|
|
39
|
-
"setPicture" in view;
|
|
40
|
-
|
|
41
|
-
const hasContext = (view: SkiaWebViewHandle): view is SkiaGraphiteViewHandle =>
|
|
42
|
-
"getContext" in view;
|
|
43
|
-
|
|
44
34
|
export type ISkiaViewApiWeb = ISkiaViewApi & {
|
|
45
35
|
views: Record<string, SkiaWebViewHandle>;
|
|
46
36
|
deferedPictures: Record<string, SkPicture>;
|
|
@@ -58,7 +48,7 @@ global.SkiaViewApi = {
|
|
|
58
48
|
registerView(nativeId: string, view: SkiaWebViewHandle) {
|
|
59
49
|
this.unregisteredViews.delete(nativeId);
|
|
60
50
|
// Maybe a picture for this view was already set
|
|
61
|
-
if (this.deferedPictures[nativeId]
|
|
51
|
+
if (this.deferedPictures[nativeId]) {
|
|
62
52
|
view.setPicture(this.deferedPictures[nativeId] as SkPicture);
|
|
63
53
|
delete this.deferedPictures[nativeId];
|
|
64
54
|
}
|
|
@@ -77,9 +67,7 @@ global.SkiaViewApi = {
|
|
|
77
67
|
const id = `${nativeId}`;
|
|
78
68
|
const view = this.views[id];
|
|
79
69
|
if (view) {
|
|
80
|
-
|
|
81
|
-
view.setPicture(value);
|
|
82
|
-
}
|
|
70
|
+
view.setPicture(value);
|
|
83
71
|
} else if (!this.unregisteredViews.has(id)) {
|
|
84
72
|
this.deferedPictures[id] = value;
|
|
85
73
|
}
|
|
@@ -114,9 +102,9 @@ global.SkiaViewApi = {
|
|
|
114
102
|
},
|
|
115
103
|
makeGraphiteContext(nativeId: number) {
|
|
116
104
|
const view = this.views[`${nativeId}`];
|
|
117
|
-
if (!view
|
|
105
|
+
if (!view) {
|
|
118
106
|
throw new Error(
|
|
119
|
-
`Cannot make a Graphite context: no
|
|
107
|
+
`Cannot make a Graphite context: no view with nativeID ${nativeId} is mounted`
|
|
120
108
|
);
|
|
121
109
|
}
|
|
122
110
|
return view.getContext();
|
|
@@ -4,11 +4,8 @@ import type { WithDefault } from "react-native/Libraries/Types/CodegenTypes";
|
|
|
4
4
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
5
5
|
// @ts-ignore - pointerEvents needs to be redeclared for codegen to generate native bindings
|
|
6
6
|
export interface NativeProps extends ViewProps {
|
|
7
|
-
debug?: boolean;
|
|
8
7
|
opaque?: boolean;
|
|
9
|
-
colorSpace?: string;
|
|
10
8
|
highBitDepth?: boolean;
|
|
11
|
-
androidWarmup?: boolean;
|
|
12
9
|
androidSurfaceType?: WithDefault<
|
|
13
10
|
"auto" | "SurfaceView" | "TextureView",
|
|
14
11
|
"auto"
|
|
@@ -21,4 +18,4 @@ export interface NativeProps extends ViewProps {
|
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
// eslint-disable-next-line import/no-default-export
|
|
24
|
-
export default codegenNativeComponent<NativeProps>("
|
|
21
|
+
export default codegenNativeComponent<NativeProps>("SkiaView");
|
|
@@ -1,33 +1,31 @@
|
|
|
1
1
|
import type { ViewProps } from "react-native";
|
|
2
2
|
import { createElement } from "react";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { SkiaView } from "../views/SkiaView.web";
|
|
5
5
|
|
|
6
6
|
export interface NativeProps extends ViewProps {
|
|
7
|
-
debug?: boolean;
|
|
8
7
|
opaque?: boolean;
|
|
8
|
+
highBitDepth?: boolean;
|
|
9
9
|
nativeID: string;
|
|
10
10
|
androidSurfaceType?: "auto" | "SurfaceView" | "TextureView";
|
|
11
11
|
androidZOrderOnTop?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const SkiaViewNativeComponent = ({
|
|
15
15
|
nativeID,
|
|
16
|
-
debug,
|
|
17
|
-
opaque,
|
|
18
16
|
onLayout,
|
|
19
|
-
//
|
|
17
|
+
// Surface settings, never reach the DOM
|
|
18
|
+
opaque: _opaque,
|
|
19
|
+
highBitDepth: _highBitDepth,
|
|
20
20
|
androidSurfaceType: _androidSurfaceType,
|
|
21
21
|
androidZOrderOnTop: _androidZOrderOnTop,
|
|
22
22
|
...viewProps
|
|
23
23
|
}: NativeProps) => {
|
|
24
|
-
return createElement(
|
|
24
|
+
return createElement(SkiaView, {
|
|
25
25
|
nativeID,
|
|
26
|
-
debug,
|
|
27
|
-
opaque,
|
|
28
26
|
onLayout,
|
|
29
27
|
...viewProps,
|
|
30
28
|
});
|
|
31
29
|
};
|
|
32
30
|
// eslint-disable-next-line import/no-default-export
|
|
33
|
-
export default
|
|
31
|
+
export default SkiaViewNativeComponent;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import React, { useImperativeHandle, useMemo, useRef } from "react";
|
|
2
2
|
|
|
3
3
|
import type { SkGraphiteContext } from "../skia/types";
|
|
4
|
-
import
|
|
4
|
+
import SkiaViewNativeComponent from "../specs/SkiaViewNativeComponent";
|
|
5
|
+
import { Platform } from "../Platform";
|
|
5
6
|
|
|
6
7
|
import { SkiaViewApi } from "./api";
|
|
8
|
+
import { androidNativeProps } from "./android";
|
|
7
9
|
import type { SkiaGraphiteViewNativeProps } from "./types";
|
|
8
10
|
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
|
9
11
|
|
|
@@ -20,40 +22,49 @@ export interface SkiaGraphiteViewProps extends SkiaGraphiteViewNativeProps {
|
|
|
20
22
|
ref?: React.Ref<SkiaGraphiteViewRef>;
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
// The layout is known synchronously on the new architecture;
|
|
26
|
+
// getBoundingClientRect became stable in React Native 0.83. On the web the
|
|
27
|
+
// view measures itself (see SkiaView.web).
|
|
28
|
+
const measureLayout = (view: unknown) => {
|
|
29
|
+
if (Platform.OS === "web") {
|
|
30
|
+
return { width: 0, height: 0 };
|
|
31
|
+
}
|
|
32
|
+
const host = view as {
|
|
33
|
+
getBoundingClientRect?: () => { width: number; height: number };
|
|
34
|
+
unstable_getBoundingClientRect: () => { width: number; height: number };
|
|
35
|
+
};
|
|
36
|
+
return host.getBoundingClientRect
|
|
37
|
+
? host.getBoundingClientRect()
|
|
38
|
+
: host.unstable_getBoundingClientRect();
|
|
39
|
+
};
|
|
40
|
+
|
|
23
41
|
/**
|
|
24
|
-
* A view
|
|
25
|
-
*
|
|
26
|
-
* nothing. See {@link SkGraphiteContext}.
|
|
42
|
+
* A view whose frames are recorded from JavaScript, on any runtime, through
|
|
43
|
+
* the context of its ref. See {@link SkGraphiteContext}.
|
|
27
44
|
*/
|
|
28
45
|
export const SkiaGraphiteView = ({
|
|
29
|
-
debug = false,
|
|
30
46
|
opaque = false,
|
|
31
47
|
highBitDepth = false,
|
|
48
|
+
android,
|
|
32
49
|
ref,
|
|
33
50
|
...viewProps
|
|
34
51
|
}: SkiaGraphiteViewProps) => {
|
|
35
52
|
const nativeId = useMemo(() => SkiaViewNativeId.current++, []);
|
|
36
53
|
const viewRef =
|
|
37
|
-
useRef<React.ComponentRef<typeof
|
|
54
|
+
useRef<React.ComponentRef<typeof SkiaViewNativeComponent>>(null);
|
|
38
55
|
useImperativeHandle(
|
|
39
56
|
ref,
|
|
40
57
|
() => ({
|
|
41
58
|
getNativeId: () => nativeId,
|
|
42
59
|
getContext: () => {
|
|
43
60
|
assertSkiaViewApi();
|
|
44
|
-
|
|
45
|
-
const view = viewRef.current as any;
|
|
61
|
+
const view = viewRef.current;
|
|
46
62
|
if (!view) {
|
|
47
63
|
throw new Error(
|
|
48
64
|
"SkiaGraphiteView: getContext() was called before the view was mounted."
|
|
49
65
|
);
|
|
50
66
|
}
|
|
51
|
-
|
|
52
|
-
// getBoundingClientRect became stable in React Native 0.83.
|
|
53
|
-
const size =
|
|
54
|
-
"getBoundingClientRect" in view
|
|
55
|
-
? view.getBoundingClientRect()
|
|
56
|
-
: view.unstable_getBoundingClientRect();
|
|
67
|
+
const size = measureLayout(view);
|
|
57
68
|
return SkiaViewApi.makeGraphiteContext(
|
|
58
69
|
nativeId,
|
|
59
70
|
size.width,
|
|
@@ -66,13 +77,13 @@ export const SkiaGraphiteView = ({
|
|
|
66
77
|
[nativeId, opaque, highBitDepth]
|
|
67
78
|
);
|
|
68
79
|
return (
|
|
69
|
-
<
|
|
80
|
+
<SkiaViewNativeComponent
|
|
70
81
|
ref={viewRef}
|
|
71
82
|
collapsable={false}
|
|
72
83
|
nativeID={`${nativeId}`}
|
|
73
|
-
debug={debug}
|
|
74
84
|
opaque={opaque}
|
|
75
85
|
highBitDepth={highBitDepth}
|
|
86
|
+
{...androidNativeProps(android)}
|
|
76
87
|
{...viewProps}
|
|
77
88
|
/>
|
|
78
89
|
);
|