@shopify/react-native-skia 2.1.1 → 2.2.1
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/android/CMakeLists.txt +1 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +1 -1
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +1 -1
- package/android/cpp/rnskia-android/RNSkAndroidVideo.cpp +1 -1
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +1 -1
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.h +1 -1
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaPictureViewManager.java +6 -0
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaPictureViewManagerInterface.java +1 -0
- package/apple/MetalContext.h +2 -2
- package/apple/MetalWindowContext.h +2 -2
- package/apple/MetalWindowContext.mm +7 -4
- package/apple/RNSkApplePlatformContext.mm +1 -1
- package/apple/RNSkAppleView.h +7 -1
- package/apple/RNSkMetalCanvasProvider.h +4 -1
- package/apple/RNSkMetalCanvasProvider.mm +9 -4
- package/apple/SkiaPictureView.mm +4 -0
- package/apple/SkiaUIView.h +1 -0
- package/apple/SkiaUIView.mm +9 -0
- package/cpp/api/JsiSkImage.h +1 -1
- package/cpp/api/JsiSkSurface.h +1 -1
- package/cpp/api/JsiSkiaContext.h +1 -1
- package/cpp/api/recorder/ImageFilters.h +3 -3
- package/cpp/api/recorder/Paint.h +4 -0
- package/cpp/rnskia/{DawnContext.h → RNDawnContext.h} +3 -3
- package/cpp/rnskia/{DawnWindowContext.cpp → RNDawnWindowContext.cpp} +3 -3
- package/cpp/rnskia/{DawnWindowContext.h → RNDawnWindowContext.h} +2 -2
- package/cpp/rnskia/RNSkJsiViewApi.h +36 -1
- package/cpp/rnskia/RNSkPlatformContext.h +1 -1
- package/cpp/rnskia/RNSkView.h +10 -0
- package/lib/commonjs/dom/types/Drawings.d.ts +1 -1
- package/lib/commonjs/dom/types/Drawings.js.map +1 -1
- package/lib/commonjs/renderer/Canvas.d.ts +12 -4
- package/lib/commonjs/renderer/Canvas.js +49 -25
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/renderer/components/ImageFilter.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.d.ts +4 -0
- package/lib/commonjs/skia/types/Matrix4.js +18 -1
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
- package/lib/commonjs/sksg/Container.d.ts +13 -7
- package/lib/commonjs/sksg/Container.js +44 -18
- package/lib/commonjs/sksg/Container.js.map +1 -1
- package/lib/commonjs/sksg/Reconciler.d.ts +3 -2
- package/lib/commonjs/sksg/Reconciler.js +2 -2
- package/lib/commonjs/sksg/Reconciler.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +9 -3
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +2 -2
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +1 -0
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/dom/types/Drawings.d.ts +1 -1
- package/lib/module/dom/types/Drawings.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +12 -4
- package/lib/module/renderer/Canvas.js +48 -25
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/renderer/components/ImageFilter.js.map +1 -1
- package/lib/module/skia/types/Matrix4.d.ts +4 -0
- package/lib/module/skia/types/Matrix4.js +16 -0
- package/lib/module/skia/types/Matrix4.js.map +1 -1
- package/lib/module/sksg/Container.d.ts +13 -7
- package/lib/module/sksg/Container.js +44 -18
- package/lib/module/sksg/Container.js.map +1 -1
- package/lib/module/sksg/Reconciler.d.ts +3 -2
- package/lib/module/sksg/Reconciler.js +2 -2
- package/lib/module/sksg/Reconciler.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +9 -3
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js +2 -2
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/types.d.ts +1 -0
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/renderer/Canvas.d.ts +8 -2
- package/lib/typescript/lib/commonjs/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/Container.d.ts +11 -3
- package/lib/typescript/lib/commonjs/sksg/Reconciler.d.ts +7 -4
- package/lib/typescript/lib/module/mock/index.d.ts +1 -0
- package/lib/typescript/lib/module/renderer/Canvas.d.ts +11 -2
- package/lib/typescript/lib/module/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/Container.d.ts +11 -3
- package/lib/typescript/lib/module/sksg/Reconciler.d.ts +7 -4
- package/lib/typescript/src/dom/types/Drawings.d.ts +1 -1
- package/lib/typescript/src/renderer/Canvas.d.ts +12 -4
- package/lib/typescript/src/skia/types/Matrix4.d.ts +4 -0
- package/lib/typescript/src/sksg/Container.d.ts +13 -7
- package/lib/typescript/src/sksg/Reconciler.d.ts +3 -2
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +1 -0
- package/lib/typescript/src/views/types.d.ts +1 -0
- package/libs/android/arm64-v8a/libskia.a +0 -0
- package/libs/android/armeabi-v7a/libskia.a +0 -0
- package/libs/android/x86/libskia.a +0 -0
- package/libs/android/x86_64/libskia.a +0 -0
- package/libs/apple/libpathops.xcframework/Info.plist +15 -15
- package/libs/apple/libskia.xcframework/Info.plist +11 -11
- package/libs/apple/libskia.xcframework/ios-arm64_arm64e/libskia.a +0 -0
- package/libs/apple/libskia.xcframework/ios-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/apple/libskia.xcframework/macos-arm64_x86_64/libskia.a +0 -0
- package/libs/apple/libskia.xcframework/tvos-arm64_arm64e/libskia.a +0 -0
- package/libs/apple/libskia.xcframework/tvos-arm64_arm64e_x86_64-simulator/libskia.a +0 -0
- package/libs/apple/libskottie.xcframework/Info.plist +16 -16
- package/libs/apple/libskparagraph.xcframework/Info.plist +8 -8
- package/libs/apple/libsksg.xcframework/Info.plist +6 -6
- package/libs/apple/libskshaper.xcframework/Info.plist +10 -10
- package/libs/apple/libskunicode_core.xcframework/Info.plist +10 -10
- package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +14 -14
- package/libs/apple/libsvg.xcframework/Info.plist +15 -15
- package/package.json +1 -1
- package/react-native-skia.podspec +5 -5
- package/src/dom/types/Drawings.ts +1 -1
- package/src/renderer/Canvas.tsx +53 -30
- package/src/renderer/__tests__/FitBox.spec.tsx +556 -4
- package/src/renderer/__tests__/e2e/ImageFilter.spec.tsx +4 -4
- package/src/renderer/__tests__/e2e/Paint.spec.tsx +18 -0
- package/src/renderer/__tests__/e2e/Skottie.spec.tsx +24 -1
- package/src/renderer/__tests__/setup.tsx +2 -0
- package/src/renderer/components/ImageFilter.tsx +1 -1
- package/src/skia/types/Matrix4.ts +16 -0
- package/src/sksg/Container.ts +73 -20
- package/src/sksg/Reconciler.ts +5 -3
- package/src/sksg/Recorder/Player.ts +7 -7
- package/src/sksg/Recorder/commands/ImageFilters.ts +3 -6
- package/src/specs/SkiaPictureViewNativeComponent.ts +1 -0
- package/src/views/types.ts +1 -0
- /package/cpp/rnskia/{DawnUtils.h → RNDawnUtils.h} +0 -0
- /package/cpp/rnskia/{ImageProvider.h → RNImageProvider.h} +0 -0
- /package/cpp/rnskia/{WindowContext.h → RNWindowContext.h} +0 -0
package/android/CMakeLists.txt
CHANGED
@@ -85,7 +85,7 @@ if(SK_GRAPHITE)
|
|
85
85
|
add_definitions(-DSK_GRAPHITE)
|
86
86
|
set(BACKEND_SOURCES
|
87
87
|
#TODO: is this source needed to be added?
|
88
|
-
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/
|
88
|
+
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNDawnWindowContext.cpp"
|
89
89
|
)
|
90
90
|
else()
|
91
91
|
add_definitions(-DSK_GL -DSK_GANESH)
|
@@ -5,6 +5,7 @@ import com.facebook.react.viewmanagers.SkiaPictureViewManagerDelegate;
|
|
5
5
|
import com.facebook.react.viewmanagers.SkiaPictureViewManagerInterface;
|
6
6
|
|
7
7
|
import androidx.annotation.NonNull;
|
8
|
+
import androidx.annotation.Nullable;
|
8
9
|
|
9
10
|
public class SkiaPictureViewManager extends SkiaBaseViewManager<SkiaPictureView> implements SkiaPictureViewManagerInterface<SkiaPictureView> {
|
10
11
|
|
@@ -30,4 +31,9 @@ public class SkiaPictureViewManager extends SkiaBaseViewManager<SkiaPictureView>
|
|
30
31
|
public SkiaPictureView createViewInstance(@NonNull ThemedReactContext reactContext) {
|
31
32
|
return new SkiaPictureView(reactContext);
|
32
33
|
}
|
34
|
+
|
35
|
+
@Override
|
36
|
+
public void setColorSpace(SkiaPictureView view, @Nullable String value) {
|
37
|
+
// nothing to do here at the moment
|
38
|
+
}
|
33
39
|
}
|
package/apple/MetalContext.h
CHANGED
@@ -113,10 +113,10 @@ public:
|
|
113
113
|
}
|
114
114
|
|
115
115
|
std::unique_ptr<RNSkia::WindowContext> MakeWindow(CALayer *window, int width,
|
116
|
-
int height) {
|
116
|
+
int height, bool useP3ColorSpace = true) {
|
117
117
|
auto device = MetalSharedContext::getInstance().getDevice();
|
118
118
|
return std::make_unique<MetalWindowContext>(
|
119
|
-
_directContext.get(), device, _commandQueue, window, width, height);
|
119
|
+
_directContext.get(), device, _commandQueue, window, width, height, useP3ColorSpace);
|
120
120
|
}
|
121
121
|
|
122
122
|
GrDirectContext *getDirectContext() { return _directContext.get(); }
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
#import <MetalKit/MetalKit.h>
|
4
4
|
|
5
|
-
#include "
|
5
|
+
#include "RNWindowContext.h"
|
6
6
|
|
7
7
|
class SkiaMetalContext;
|
8
8
|
|
@@ -10,7 +10,7 @@ class MetalWindowContext : public RNSkia::WindowContext {
|
|
10
10
|
public:
|
11
11
|
MetalWindowContext(GrDirectContext *directContext, id<MTLDevice> device,
|
12
12
|
id<MTLCommandQueue> commandQueue, CALayer *layer,
|
13
|
-
int width, int height);
|
13
|
+
int width, int height, bool useP3ColorSpace = true);
|
14
14
|
~MetalWindowContext() = default;
|
15
15
|
|
16
16
|
sk_sp<SkSurface> getSurface() override;
|
@@ -6,7 +6,8 @@
|
|
6
6
|
MetalWindowContext::MetalWindowContext(GrDirectContext *directContext,
|
7
7
|
id<MTLDevice> device,
|
8
8
|
id<MTLCommandQueue> commandQueue,
|
9
|
-
CALayer *layer, int width, int height
|
9
|
+
CALayer *layer, int width, int height,
|
10
|
+
bool useP3ColorSpace)
|
10
11
|
: _directContext(directContext), _commandQueue(commandQueue) {
|
11
12
|
#pragma clang diagnostic push
|
12
13
|
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
@@ -24,9 +25,11 @@ MetalWindowContext::MetalWindowContext(GrDirectContext *directContext,
|
|
24
25
|
_layer.contentsGravity = kCAGravityBottomLeft;
|
25
26
|
_layer.drawableSize = CGSizeMake(width, height);
|
26
27
|
BOOL supportsWideColor = NO;
|
27
|
-
if (
|
28
|
-
|
29
|
-
|
28
|
+
if (useP3ColorSpace) {
|
29
|
+
if (@available(iOS 10.0, *)) {
|
30
|
+
supportsWideColor =
|
31
|
+
[UIScreen mainScreen].traitCollection.displayGamut == UIDisplayGamutP3;
|
32
|
+
}
|
30
33
|
}
|
31
34
|
if (supportsWideColor) {
|
32
35
|
CGColorSpaceRef colorSpace =
|
package/apple/RNSkAppleView.h
CHANGED
@@ -10,6 +10,7 @@ class RNSkBaseAppleView {
|
|
10
10
|
public:
|
11
11
|
virtual CALayer *getLayer() = 0;
|
12
12
|
virtual void setSize(int width, int height) = 0;
|
13
|
+
virtual void setUseP3ColorSpace(bool useP3ColorSpace) = 0;
|
13
14
|
virtual std::shared_ptr<RNSkia::RNSkView> getDrawView() = 0;
|
14
15
|
};
|
15
16
|
|
@@ -18,7 +19,7 @@ public:
|
|
18
19
|
RNSkAppleView(std::shared_ptr<RNSkia::RNSkPlatformContext> context)
|
19
20
|
: T(context,
|
20
21
|
std::make_shared<RNSkMetalCanvasProvider>(
|
21
|
-
std::bind(&RNSkia::RNSkView::requestRedraw, this), context)) {}
|
22
|
+
std::bind(&RNSkia::RNSkView::requestRedraw, this), context, true)) {}
|
22
23
|
|
23
24
|
CALayer *getLayer() override {
|
24
25
|
return std::static_pointer_cast<RNSkMetalCanvasProvider>(
|
@@ -31,6 +32,11 @@ public:
|
|
31
32
|
->setSize(width, height);
|
32
33
|
}
|
33
34
|
|
35
|
+
void setUseP3ColorSpace(bool useP3ColorSpace) override {
|
36
|
+
std::static_pointer_cast<RNSkMetalCanvasProvider>(this->getCanvasProvider())
|
37
|
+
->setUseP3ColorSpace(useP3ColorSpace);
|
38
|
+
}
|
39
|
+
|
34
40
|
std::shared_ptr<RNSkia::RNSkView> getDrawView() override {
|
35
41
|
return this->shared_from_this();
|
36
42
|
}
|
@@ -16,7 +16,8 @@
|
|
16
16
|
class RNSkMetalCanvasProvider : public RNSkia::RNSkCanvasProvider {
|
17
17
|
public:
|
18
18
|
RNSkMetalCanvasProvider(std::function<void()> requestRedraw,
|
19
|
-
std::shared_ptr<RNSkia::RNSkPlatformContext> context
|
19
|
+
std::shared_ptr<RNSkia::RNSkPlatformContext> context,
|
20
|
+
bool useP3ColorSpace = true);
|
20
21
|
|
21
22
|
~RNSkMetalCanvasProvider();
|
22
23
|
|
@@ -26,6 +27,7 @@ public:
|
|
26
27
|
bool renderToCanvas(const std::function<void(SkCanvas *)> &cb) override;
|
27
28
|
|
28
29
|
void setSize(int width, int height);
|
30
|
+
void setUseP3ColorSpace(bool useP3ColorSpace);
|
29
31
|
CALayer *getLayer();
|
30
32
|
|
31
33
|
private:
|
@@ -35,4 +37,5 @@ private:
|
|
35
37
|
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
36
38
|
CAMetalLayer *_layer;
|
37
39
|
#pragma clang diagnostic pop
|
40
|
+
bool _useP3ColorSpace = true;
|
38
41
|
};
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#import "RNSkLog.h"
|
4
4
|
|
5
5
|
#if defined(SK_GRAPHITE)
|
6
|
-
#import "
|
6
|
+
#import "RNDawnContext.h"
|
7
7
|
#else
|
8
8
|
#import "MetalContext.h"
|
9
9
|
#endif
|
@@ -23,8 +23,9 @@
|
|
23
23
|
|
24
24
|
RNSkMetalCanvasProvider::RNSkMetalCanvasProvider(
|
25
25
|
std::function<void()> requestRedraw,
|
26
|
-
std::shared_ptr<RNSkia::RNSkPlatformContext> context
|
27
|
-
|
26
|
+
std::shared_ptr<RNSkia::RNSkPlatformContext> context,
|
27
|
+
bool useP3ColorSpace)
|
28
|
+
: RNSkCanvasProvider(requestRedraw), _context(context), _useP3ColorSpace(useP3ColorSpace) {
|
28
29
|
#pragma clang diagnostic push
|
29
30
|
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
|
30
31
|
_layer = [CAMetalLayer layer];
|
@@ -100,9 +101,13 @@ void RNSkMetalCanvasProvider::setSize(int width, int height) {
|
|
100
101
|
_ctx = RNSkia::DawnContext::getInstance().MakeWindow((__bridge void *)_layer,
|
101
102
|
w, h);
|
102
103
|
#else
|
103
|
-
_ctx = MetalContext::getInstance().MakeWindow(_layer, w, h);
|
104
|
+
_ctx = MetalContext::getInstance().MakeWindow(_layer, w, h, _useP3ColorSpace);
|
104
105
|
#endif
|
105
106
|
_requestRedraw();
|
106
107
|
}
|
107
108
|
|
108
109
|
CALayer *RNSkMetalCanvasProvider::getLayer() { return _layer; }
|
110
|
+
|
111
|
+
void RNSkMetalCanvasProvider::setUseP3ColorSpace(bool useP3ColorSpace) {
|
112
|
+
_useP3ColorSpace = useP3ColorSpace;
|
113
|
+
}
|
package/apple/SkiaPictureView.mm
CHANGED
@@ -55,6 +55,10 @@ using namespace facebook::react;
|
|
55
55
|
[self setNativeId:nativeId];
|
56
56
|
[self setDebugMode:newProps.debug];
|
57
57
|
[self setOpaque:newProps.opaque];
|
58
|
+
if (newProps.colorSpace == "" || newProps.colorSpace == "srgb") {
|
59
|
+
bool useP3 = false;
|
60
|
+
[self setUseP3ColorSpace:useP3];
|
61
|
+
}
|
58
62
|
}
|
59
63
|
|
60
64
|
@end
|
package/apple/SkiaUIView.h
CHANGED
package/apple/SkiaUIView.mm
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
_factory;
|
17
17
|
bool _debugMode;
|
18
18
|
bool _opaque;
|
19
|
+
bool _useP3ColorSpace;
|
19
20
|
size_t _nativeId;
|
20
21
|
}
|
21
22
|
|
@@ -73,6 +74,7 @@
|
|
73
74
|
_manager->setSkiaView(_nativeId, _impl->getDrawView());
|
74
75
|
}
|
75
76
|
_impl->getDrawView()->setShowDebugOverlays(_debugMode);
|
77
|
+
_impl->setUseP3ColorSpace(_useP3ColorSpace);
|
76
78
|
}
|
77
79
|
}
|
78
80
|
}
|
@@ -163,6 +165,13 @@
|
|
163
165
|
}
|
164
166
|
}
|
165
167
|
|
168
|
+
- (void)setUseP3ColorSpace:(bool)useP3ColorSpace {
|
169
|
+
_useP3ColorSpace = useP3ColorSpace;
|
170
|
+
if (_impl != nullptr) {
|
171
|
+
_impl->setUseP3ColorSpace(_useP3ColorSpace);
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
166
175
|
#pragma mark External API
|
167
176
|
|
168
177
|
- (std::shared_ptr<RNSkBaseAppleView>)impl {
|
package/cpp/api/JsiSkImage.h
CHANGED
package/cpp/api/JsiSkSurface.h
CHANGED
package/cpp/api/JsiSkiaContext.h
CHANGED
@@ -290,7 +290,7 @@ public:
|
|
290
290
|
};
|
291
291
|
|
292
292
|
struct ImageFilterCmdProps {
|
293
|
-
sk_sp<SkImageFilter>
|
293
|
+
sk_sp<SkImageFilter> filter;
|
294
294
|
};
|
295
295
|
|
296
296
|
class ImageFilterCmd : public Command {
|
@@ -301,11 +301,11 @@ public:
|
|
301
301
|
ImageFilterCmd(jsi::Runtime &runtime, const jsi::Object &object,
|
302
302
|
Variables &variables)
|
303
303
|
: Command(CommandType::PushImageFilter, "skImageFilter") {
|
304
|
-
convertProperty(runtime, object, "
|
304
|
+
convertProperty(runtime, object, "filter", props.filter, variables);
|
305
305
|
}
|
306
306
|
|
307
307
|
void pushImageFilter(DrawingCtx *ctx) {
|
308
|
-
ctx->imageFilters.push_back(props.
|
308
|
+
ctx->imageFilters.push_back(props.filter);
|
309
309
|
}
|
310
310
|
};
|
311
311
|
|
package/cpp/api/recorder/Paint.h
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
#include <memory>
|
4
4
|
#include <mutex>
|
5
5
|
|
6
|
-
#include "
|
7
|
-
#include "
|
8
|
-
#include "
|
6
|
+
#include "RNDawnWindowContext.h"
|
7
|
+
#include "RNImageProvider.h"
|
8
|
+
#include "RNDawnUtils.h"
|
9
9
|
|
10
10
|
#include "include/core/SkData.h"
|
11
11
|
#include "include/gpu/graphite/BackendTexture.h"
|
@@ -1,6 +1,6 @@
|
|
1
|
-
#include "
|
1
|
+
#include "RNDawnWindowContext.h"
|
2
2
|
|
3
|
-
#include "
|
3
|
+
#include "RNDawnContext.h"
|
4
4
|
|
5
5
|
namespace RNSkia {
|
6
6
|
|
@@ -16,4 +16,4 @@ void DawnWindowContext::present() {
|
|
16
16
|
_surface.Present();
|
17
17
|
}
|
18
18
|
|
19
|
-
} // namespace RNSkia
|
19
|
+
} // namespace RNSkia
|
@@ -232,10 +232,45 @@ public:
|
|
232
232
|
});
|
233
233
|
}
|
234
234
|
|
235
|
+
JSI_HOST_FUNCTION(size) {
|
236
|
+
if (count != 1) {
|
237
|
+
_platformContext->raiseError(
|
238
|
+
std::string("size: Expected 1 argument, got " +
|
239
|
+
std::to_string(count) + "."));
|
240
|
+
return jsi::Value::undefined();
|
241
|
+
}
|
242
|
+
|
243
|
+
if (!arguments[0].isNumber()) {
|
244
|
+
_platformContext->raiseError(
|
245
|
+
"size: First argument must be a number");
|
246
|
+
return jsi::Value::undefined();
|
247
|
+
}
|
248
|
+
|
249
|
+
// find Skia View
|
250
|
+
int nativeId = arguments[0].asNumber();
|
251
|
+
std::shared_ptr<RNSkView> view = ViewRegistry::getInstance().withViewInfo(
|
252
|
+
nativeId,
|
253
|
+
[](std::shared_ptr<RNSkViewInfo> info) { return info->view; });
|
254
|
+
if (view != nullptr) {
|
255
|
+
auto pixelDensity = _platformContext->getPixelDensity();
|
256
|
+
auto sizeObj = jsi::Object(runtime);
|
257
|
+
sizeObj.setProperty(runtime, "width", view->getScaledWidth() / pixelDensity);
|
258
|
+
sizeObj.setProperty(runtime, "height", view->getScaledHeight() / pixelDensity);
|
259
|
+
return sizeObj;
|
260
|
+
}
|
261
|
+
|
262
|
+
// Return default size if view not found
|
263
|
+
auto sizeObj = jsi::Object(runtime);
|
264
|
+
sizeObj.setProperty(runtime, "width", 0);
|
265
|
+
sizeObj.setProperty(runtime, "height", 0);
|
266
|
+
return sizeObj;
|
267
|
+
}
|
268
|
+
|
235
269
|
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(RNSkJsiViewApi, setJsiProperty),
|
236
270
|
JSI_EXPORT_FUNC(RNSkJsiViewApi, requestRedraw),
|
237
271
|
JSI_EXPORT_FUNC(RNSkJsiViewApi, makeImageSnapshotAsync),
|
238
|
-
JSI_EXPORT_FUNC(RNSkJsiViewApi, makeImageSnapshot)
|
272
|
+
JSI_EXPORT_FUNC(RNSkJsiViewApi, makeImageSnapshot),
|
273
|
+
JSI_EXPORT_FUNC(RNSkJsiViewApi, size))
|
239
274
|
|
240
275
|
/**
|
241
276
|
* Constructor
|
package/cpp/rnskia/RNSkView.h
CHANGED
@@ -203,6 +203,16 @@ public:
|
|
203
203
|
|
204
204
|
std::shared_ptr<RNSkRenderer> getRenderer() { return _renderer; }
|
205
205
|
|
206
|
+
/**
|
207
|
+
Returns the scaled width of the view
|
208
|
+
*/
|
209
|
+
int getScaledWidth() { return _canvasProvider->getScaledWidth(); }
|
210
|
+
|
211
|
+
/**
|
212
|
+
Returns the scaled height of the view
|
213
|
+
*/
|
214
|
+
int getScaledHeight() { return _canvasProvider->getScaledHeight(); }
|
215
|
+
|
206
216
|
protected:
|
207
217
|
std::shared_ptr<RNSkPlatformContext> getPlatformContext() {
|
208
218
|
return _platformContext;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":[],"sources":["Drawings.ts"],"sourcesContent":["import type {\n FillType,\n SkImage,\n StrokeOpts,\n Vector,\n Color,\n SkPoint,\n BlendMode,\n PointMode,\n VertexMode,\n SkFont,\n SkRRect,\n SkTextBlob,\n SkPicture,\n SkSVG,\n SkPaint,\n SkRect,\n SkRSXform,\n SkColor,\n SamplingOptions,\n SkSkottieAnimation,\n SkImageFilter,\n} from \"../../skia/types\";\n\nimport type {\n CircleDef,\n Fit,\n GroupProps,\n PathDef,\n RectDef,\n RRectDef,\n SkEnum,\n} from \"./Common\";\n\nexport interface DrawingNodeProps extends GroupProps {\n paint?: SkPaint;\n}\n\nexport type ImageProps = DrawingNodeProps &\n RectDef & {\n fit?: Fit;\n image: SkImage | null;\n sampling?: SamplingOptions;\n };\n\nexport type CircleProps = CircleDef & DrawingNodeProps;\n\nexport interface PathProps extends DrawingNodeProps {\n path: PathDef;\n start: number;\n end: number;\n stroke?: StrokeOpts;\n fillType?: SkEnum<typeof FillType>;\n}\n\nexport interface LineProps extends DrawingNodeProps {\n p1: Vector;\n p2: Vector;\n}\n\nexport type OvalProps = RectDef & DrawingNodeProps;\n\nexport type RectProps = RectDef & DrawingNodeProps;\n\nexport type RoundedRectProps = RRectDef & DrawingNodeProps;\n\nexport interface AtlasProps extends DrawingNodeProps {\n image: SkImage | null;\n sprites: SkRect[];\n transforms: SkRSXform[];\n colors?: SkColor[];\n sampling?: SamplingOptions;\n}\n\nexport interface CubicBezierHandle {\n pos: Vector;\n c1: Vector;\n c2: Vector;\n}\n\nexport interface PatchProps extends DrawingNodeProps {\n colors?: Color[];\n patch: [\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle\n ];\n texture?: readonly [SkPoint, SkPoint, SkPoint, SkPoint];\n blendMode?: SkEnum<typeof BlendMode>;\n}\n\nexport interface VerticesProps extends DrawingNodeProps {\n colors?: string[];\n vertices: SkPoint[];\n textures?: SkPoint[];\n mode: SkEnum<typeof VertexMode>;\n blendMode?: SkEnum<typeof BlendMode>;\n indices?: number[];\n}\n\nexport interface ImageSVGProps extends DrawingNodeProps {\n svg: SkSVG | null;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n rect?: SkRect;\n}\n\nexport interface SkottieProps extends DrawingNodeProps {\n animation: SkSkottieAnimation;\n frame: number;\n}\n\nexport interface PictureProps extends DrawingNodeProps {\n picture: SkPicture;\n}\n\nexport interface PointsProps extends DrawingNodeProps {\n points: SkPoint[];\n mode: SkEnum<typeof PointMode>;\n}\n\nexport interface DiffRectProps extends DrawingNodeProps {\n inner: SkRRect;\n outer: SkRRect;\n}\n\nexport interface TextProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n x: number;\n y: number;\n}\n\nexport interface TextPathProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n path: PathDef;\n initialOffset: number;\n}\n\nexport interface TextBlobProps extends DrawingNodeProps {\n blob: SkTextBlob;\n x: number;\n y: number;\n}\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport interface GlyphsProps extends DrawingNodeProps {\n font: SkFont | null;\n x: number;\n y: number;\n glyphs: Glyph[];\n}\n\nexport interface BoxProps extends DrawingNodeProps {\n box: SkRRect | SkRect;\n}\n\nexport interface BoxShadowProps {\n dx?: number;\n dy?: number;\n spread?: number;\n blur: number;\n color?: Color;\n inner?: boolean;\n}\n\nexport interface ImageFilterProps extends GroupProps {\n
|
1
|
+
{"version":3,"names":[],"sources":["Drawings.ts"],"sourcesContent":["import type {\n FillType,\n SkImage,\n StrokeOpts,\n Vector,\n Color,\n SkPoint,\n BlendMode,\n PointMode,\n VertexMode,\n SkFont,\n SkRRect,\n SkTextBlob,\n SkPicture,\n SkSVG,\n SkPaint,\n SkRect,\n SkRSXform,\n SkColor,\n SamplingOptions,\n SkSkottieAnimation,\n SkImageFilter,\n} from \"../../skia/types\";\n\nimport type {\n CircleDef,\n Fit,\n GroupProps,\n PathDef,\n RectDef,\n RRectDef,\n SkEnum,\n} from \"./Common\";\n\nexport interface DrawingNodeProps extends GroupProps {\n paint?: SkPaint;\n}\n\nexport type ImageProps = DrawingNodeProps &\n RectDef & {\n fit?: Fit;\n image: SkImage | null;\n sampling?: SamplingOptions;\n };\n\nexport type CircleProps = CircleDef & DrawingNodeProps;\n\nexport interface PathProps extends DrawingNodeProps {\n path: PathDef;\n start: number;\n end: number;\n stroke?: StrokeOpts;\n fillType?: SkEnum<typeof FillType>;\n}\n\nexport interface LineProps extends DrawingNodeProps {\n p1: Vector;\n p2: Vector;\n}\n\nexport type OvalProps = RectDef & DrawingNodeProps;\n\nexport type RectProps = RectDef & DrawingNodeProps;\n\nexport type RoundedRectProps = RRectDef & DrawingNodeProps;\n\nexport interface AtlasProps extends DrawingNodeProps {\n image: SkImage | null;\n sprites: SkRect[];\n transforms: SkRSXform[];\n colors?: SkColor[];\n sampling?: SamplingOptions;\n}\n\nexport interface CubicBezierHandle {\n pos: Vector;\n c1: Vector;\n c2: Vector;\n}\n\nexport interface PatchProps extends DrawingNodeProps {\n colors?: Color[];\n patch: [\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle,\n CubicBezierHandle\n ];\n texture?: readonly [SkPoint, SkPoint, SkPoint, SkPoint];\n blendMode?: SkEnum<typeof BlendMode>;\n}\n\nexport interface VerticesProps extends DrawingNodeProps {\n colors?: string[];\n vertices: SkPoint[];\n textures?: SkPoint[];\n mode: SkEnum<typeof VertexMode>;\n blendMode?: SkEnum<typeof BlendMode>;\n indices?: number[];\n}\n\nexport interface ImageSVGProps extends DrawingNodeProps {\n svg: SkSVG | null;\n x?: number;\n y?: number;\n width?: number;\n height?: number;\n rect?: SkRect;\n}\n\nexport interface SkottieProps extends DrawingNodeProps {\n animation: SkSkottieAnimation;\n frame: number;\n}\n\nexport interface PictureProps extends DrawingNodeProps {\n picture: SkPicture;\n}\n\nexport interface PointsProps extends DrawingNodeProps {\n points: SkPoint[];\n mode: SkEnum<typeof PointMode>;\n}\n\nexport interface DiffRectProps extends DrawingNodeProps {\n inner: SkRRect;\n outer: SkRRect;\n}\n\nexport interface TextProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n x: number;\n y: number;\n}\n\nexport interface TextPathProps extends DrawingNodeProps {\n font: SkFont | null;\n text: string;\n path: PathDef;\n initialOffset: number;\n}\n\nexport interface TextBlobProps extends DrawingNodeProps {\n blob: SkTextBlob;\n x: number;\n y: number;\n}\n\nexport interface Glyph {\n id: number;\n pos: SkPoint;\n}\n\nexport interface GlyphsProps extends DrawingNodeProps {\n font: SkFont | null;\n x: number;\n y: number;\n glyphs: Glyph[];\n}\n\nexport interface BoxProps extends DrawingNodeProps {\n box: SkRRect | SkRect;\n}\n\nexport interface BoxShadowProps {\n dx?: number;\n dy?: number;\n spread?: number;\n blur: number;\n color?: Color;\n inner?: boolean;\n}\n\nexport interface ImageFilterProps extends GroupProps {\n filter: SkImageFilter;\n}\n"],"mappings":"","ignoreList":[]}
|
@@ -1,19 +1,27 @@
|
|
1
1
|
import type { FC } from "react";
|
2
2
|
import React from "react";
|
3
|
-
import type { ViewProps } from "react-native";
|
4
|
-
import type
|
3
|
+
import type { MeasureInWindowOnSuccessCallback, MeasureOnSuccessCallback, ViewProps } from "react-native";
|
4
|
+
import { type SharedValue } from "react-native-reanimated";
|
5
5
|
import type { SkImage, SkRect, SkSize } from "../skia/types";
|
6
6
|
export interface CanvasRef extends FC<CanvasProps> {
|
7
7
|
makeImageSnapshot(rect?: SkRect): SkImage;
|
8
8
|
makeImageSnapshotAsync(rect?: SkRect): Promise<SkImage>;
|
9
9
|
redraw(): void;
|
10
10
|
getNativeId(): number;
|
11
|
+
measure(callback: MeasureOnSuccessCallback): void;
|
12
|
+
measureInWindow(callback: MeasureInWindowOnSuccessCallback): void;
|
11
13
|
}
|
12
14
|
export declare const useCanvasRef: () => React.RefObject<CanvasRef | null>;
|
13
|
-
export
|
15
|
+
export declare const useCanvasSize: () => {
|
16
|
+
ref: React.RefObject<CanvasRef | null>;
|
17
|
+
size: SkSize;
|
18
|
+
};
|
19
|
+
export declare const isFabric: boolean;
|
20
|
+
export interface CanvasProps extends Omit<ViewProps, "onLayout"> {
|
14
21
|
debug?: boolean;
|
15
22
|
opaque?: boolean;
|
16
23
|
onSize?: SharedValue<SkSize>;
|
24
|
+
colorSpace?: "p3" | "srgb";
|
17
25
|
ref?: React.Ref<CanvasRef>;
|
18
26
|
}
|
19
|
-
export declare const Canvas: ({ debug, opaque, children, onSize,
|
27
|
+
export declare const Canvas: ({ debug, opaque, children, onSize, colorSpace, ref, onLayout, ...viewProps }: CanvasProps) => React.JSX.Element;
|