@shopify/react-native-skia 2.0.7 → 2.1.0
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 +20 -1
- package/cpp/api/JsiSkApi.h +3 -0
- package/cpp/api/JsiSkImageFilterFactory.h +478 -39
- package/cpp/api/JsiSkSkottie.h +590 -0
- package/cpp/api/JsiSkottieFactory.h +65 -0
- package/cpp/api/recorder/Command.h +1 -0
- package/cpp/api/recorder/Convertor.h +16 -0
- package/cpp/api/recorder/Drawings.h +23 -0
- package/cpp/api/recorder/JsiRecorder.h +6 -0
- package/cpp/api/recorder/RNRecorder.h +9 -0
- package/cpp/api/third_party/SkottieUtils.cpp +333 -0
- package/cpp/api/third_party/SkottieUtils.h +172 -0
- package/cpp/skia/modules/jsonreader/SkJSONReader.cpp +980 -0
- package/cpp/skia/modules/jsonreader/SkJSONReader.h +389 -0
- package/cpp/skia/modules/skottie/include/ExternalLayer.h +56 -0
- package/cpp/skia/modules/skottie/include/Skottie.h +313 -0
- package/cpp/skia/modules/skottie/include/SkottieProperty.h +190 -0
- package/cpp/skia/modules/skottie/include/SlotManager.h +113 -0
- package/cpp/skia/modules/skottie/include/TextShaper.h +200 -0
- package/cpp/skia/modules/skottie/src/SkottieValue.h +56 -0
- package/cpp/skia/modules/skottie/src/animator/Animator.h +89 -0
- package/cpp/skia/modules/skottie/src/text/Font.h +82 -0
- package/cpp/skia/modules/skottie/src/text/TextAdapter.h +155 -0
- package/cpp/skia/modules/skottie/src/text/TextAnimator.h +121 -0
- package/cpp/skia/modules/skottie/src/text/TextValue.h +28 -0
- package/cpp/skia/modules/sksg/include/SkSGClipEffect.h +61 -0
- package/cpp/skia/modules/sksg/include/SkSGColorFilter.h +135 -0
- package/cpp/skia/modules/sksg/include/SkSGDraw.h +57 -0
- package/cpp/skia/modules/sksg/include/SkSGEffectNode.h +50 -0
- package/cpp/skia/modules/sksg/include/SkSGGeometryEffect.h +181 -0
- package/cpp/skia/modules/sksg/include/SkSGGeometryNode.h +54 -0
- package/cpp/skia/modules/sksg/include/SkSGGradient.h +108 -0
- package/cpp/skia/modules/sksg/include/SkSGGroup.h +65 -0
- package/cpp/skia/modules/sksg/include/SkSGImage.h +59 -0
- package/cpp/skia/modules/sksg/include/SkSGInvalidationController.h +46 -0
- package/cpp/skia/modules/sksg/include/SkSGMaskEffect.h +65 -0
- package/cpp/skia/modules/sksg/include/SkSGMerge.h +74 -0
- package/cpp/skia/modules/sksg/include/SkSGNode.h +128 -0
- package/cpp/skia/modules/sksg/include/SkSGOpacityEffect.h +54 -0
- package/cpp/skia/modules/sksg/include/SkSGPaint.h +112 -0
- package/cpp/skia/modules/sksg/include/SkSGPath.h +68 -0
- package/cpp/skia/modules/sksg/include/SkSGPlane.h +47 -0
- package/cpp/skia/modules/sksg/include/SkSGRect.h +122 -0
- package/cpp/skia/modules/sksg/include/SkSGRenderEffect.h +283 -0
- package/cpp/skia/modules/sksg/include/SkSGRenderNode.h +157 -0
- package/cpp/skia/modules/sksg/include/SkSGScene.h +47 -0
- package/cpp/skia/modules/sksg/include/SkSGText.h +82 -0
- package/cpp/skia/modules/sksg/include/SkSGTransform.h +127 -0
- package/cpp/skia/src/base/SkArenaAlloc.h +371 -0
- package/lib/commonjs/dom/nodes/datatypes/Gradient.d.ts +15 -15
- package/lib/commonjs/dom/types/Drawings.d.ts +5 -1
- package/lib/commonjs/dom/types/Drawings.js.map +1 -1
- package/lib/commonjs/dom/types/NodeType.d.ts +2 -1
- package/lib/commonjs/dom/types/NodeType.js +2 -0
- package/lib/commonjs/dom/types/NodeType.js.map +1 -1
- package/lib/commonjs/renderer/__tests__/e2e/AdvancedImageFilters.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/e2e/Camera.spec.d.ts +21 -0
- package/lib/commonjs/renderer/__tests__/e2e/LightingImageFilters.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/e2e/Skottie.spec.d.ts +1 -0
- package/lib/commonjs/renderer/__tests__/setup.d.ts +5 -0
- package/lib/commonjs/renderer/components/Skottie.d.ts +4 -0
- package/lib/commonjs/renderer/components/Skottie.js +13 -0
- package/lib/commonjs/renderer/components/Skottie.js.map +1 -0
- package/lib/commonjs/renderer/components/index.d.ts +1 -0
- package/lib/commonjs/renderer/components/index.js +11 -0
- package/lib/commonjs/renderer/components/index.js.map +1 -1
- package/lib/commonjs/skia/types/ImageFilter/ImageFilterFactory.d.ts +252 -15
- package/lib/commonjs/skia/types/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/types/Matrix4.d.ts +11 -2
- package/lib/commonjs/skia/types/Matrix4.js +42 -1
- package/lib/commonjs/skia/types/Matrix4.js.map +1 -1
- package/lib/commonjs/skia/types/Recorder.d.ts +2 -1
- package/lib/commonjs/skia/types/Recorder.js.map +1 -1
- package/lib/commonjs/skia/types/Skia.d.ts +2 -0
- package/lib/commonjs/skia/types/Skia.js.map +1 -1
- package/lib/commonjs/skia/types/Skottie.d.ts +223 -0
- package/lib/commonjs/skia/types/Skottie.js +73 -0
- package/lib/commonjs/skia/types/Skottie.js.map +1 -0
- package/lib/commonjs/skia/types/index.d.ts +1 -0
- package/lib/commonjs/skia/types/index.js +11 -0
- package/lib/commonjs/skia/types/index.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.d.ts +29 -12
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js +88 -19
- package/lib/commonjs/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkia.js +2 -0
- package/lib/commonjs/skia/web/JsiSkia.js.map +1 -1
- package/lib/commonjs/skia/web/JsiSkottieAnimation.d.ts +59 -0
- package/lib/commonjs/skia/web/JsiSkottieAnimation.js +243 -0
- package/lib/commonjs/skia/web/JsiSkottieAnimation.js.map +1 -0
- package/lib/commonjs/skia/web/JsiSkottieFactory.d.ts +9 -0
- package/lib/commonjs/skia/web/JsiSkottieFactory.js +26 -0
- package/lib/commonjs/skia/web/JsiSkottieFactory.js.map +1 -0
- package/lib/commonjs/sksg/Elements.d.ts +2 -1
- package/lib/commonjs/sksg/Elements.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Core.d.ts +4 -2
- package/lib/commonjs/sksg/Recorder/Core.js +1 -0
- package/lib/commonjs/sksg/Recorder/Core.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Player.js +2 -0
- package/lib/commonjs/sksg/Recorder/Player.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +2 -1
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js +4 -0
- package/lib/commonjs/sksg/Recorder/ReanimatedRecorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Recorder.d.ts +2 -1
- package/lib/commonjs/sksg/Recorder/Recorder.js +6 -0
- package/lib/commonjs/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/Visitor.js +3 -0
- package/lib/commonjs/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +2 -2
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js +11 -4
- package/lib/commonjs/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js +1 -1
- package/lib/commonjs/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/module/dom/nodes/datatypes/Gradient.d.ts +15 -15
- package/lib/module/dom/types/Drawings.d.ts +5 -1
- package/lib/module/dom/types/Drawings.js.map +1 -1
- package/lib/module/dom/types/NodeType.d.ts +2 -1
- package/lib/module/dom/types/NodeType.js +2 -0
- package/lib/module/dom/types/NodeType.js.map +1 -1
- package/lib/module/renderer/__tests__/e2e/AdvancedImageFilters.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/e2e/Camera.spec.d.ts +21 -0
- package/lib/module/renderer/__tests__/e2e/LightingImageFilters.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/e2e/Skottie.spec.d.ts +1 -0
- package/lib/module/renderer/__tests__/setup.d.ts +5 -0
- package/lib/module/renderer/components/Skottie.d.ts +4 -0
- package/lib/module/renderer/components/Skottie.js +5 -0
- package/lib/module/renderer/components/Skottie.js.map +1 -0
- package/lib/module/renderer/components/index.d.ts +1 -0
- package/lib/module/renderer/components/index.js +1 -0
- package/lib/module/renderer/components/index.js.map +1 -1
- package/lib/module/skia/types/ImageFilter/ImageFilterFactory.d.ts +252 -15
- package/lib/module/skia/types/ImageFilter/ImageFilterFactory.js.map +1 -1
- package/lib/module/skia/types/Matrix4.d.ts +11 -2
- package/lib/module/skia/types/Matrix4.js +40 -0
- package/lib/module/skia/types/Matrix4.js.map +1 -1
- package/lib/module/skia/types/Recorder.d.ts +2 -1
- package/lib/module/skia/types/Recorder.js.map +1 -1
- package/lib/module/skia/types/Skia.d.ts +2 -0
- package/lib/module/skia/types/Skia.js.map +1 -1
- package/lib/module/skia/types/Skottie.d.ts +223 -0
- package/lib/module/skia/types/Skottie.js +74 -0
- package/lib/module/skia/types/Skottie.js.map +1 -0
- package/lib/module/skia/types/index.d.ts +1 -0
- package/lib/module/skia/types/index.js +1 -0
- package/lib/module/skia/types/index.js.map +1 -1
- package/lib/module/skia/web/JsiSkImageFilterFactory.d.ts +29 -12
- package/lib/module/skia/web/JsiSkImageFilterFactory.js +88 -19
- package/lib/module/skia/web/JsiSkImageFilterFactory.js.map +1 -1
- package/lib/module/skia/web/JsiSkia.js +2 -0
- package/lib/module/skia/web/JsiSkia.js.map +1 -1
- package/lib/module/skia/web/JsiSkottieAnimation.d.ts +59 -0
- package/lib/module/skia/web/JsiSkottieAnimation.js +236 -0
- package/lib/module/skia/web/JsiSkottieAnimation.js.map +1 -0
- package/lib/module/skia/web/JsiSkottieFactory.d.ts +9 -0
- package/lib/module/skia/web/JsiSkottieFactory.js +19 -0
- package/lib/module/skia/web/JsiSkottieFactory.js.map +1 -0
- package/lib/module/sksg/Elements.d.ts +2 -1
- package/lib/module/sksg/Elements.js.map +1 -1
- package/lib/module/sksg/Recorder/Core.d.ts +4 -2
- package/lib/module/sksg/Recorder/Core.js +1 -0
- package/lib/module/sksg/Recorder/Core.js.map +1 -1
- package/lib/module/sksg/Recorder/Player.js +3 -1
- package/lib/module/sksg/Recorder/Player.js.map +1 -1
- package/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +2 -1
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js +4 -0
- package/lib/module/sksg/Recorder/ReanimatedRecorder.js.map +1 -1
- package/lib/module/sksg/Recorder/Recorder.d.ts +2 -1
- package/lib/module/sksg/Recorder/Recorder.js +6 -0
- package/lib/module/sksg/Recorder/Recorder.js.map +1 -1
- package/lib/module/sksg/Recorder/Visitor.js +3 -0
- package/lib/module/sksg/Recorder/Visitor.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/Drawing.d.ts +2 -2
- package/lib/module/sksg/Recorder/commands/Drawing.js +9 -2
- package/lib/module/sksg/Recorder/commands/Drawing.js.map +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js +1 -1
- package/lib/module/sksg/Recorder/commands/ImageFilters.js.map +1 -1
- package/lib/typescript/lib/commonjs/renderer/components/Skottie.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/commonjs/skia/types/Skottie.d.ts +6 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkImageFilterFactory.d.ts +22 -5
- package/lib/typescript/lib/commonjs/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkottieAnimation.d.ts +48 -0
- package/lib/typescript/lib/commonjs/skia/web/JsiSkottieFactory.d.ts +6 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/ReanimatedRecorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/commonjs/sksg/Recorder/commands/Drawing.d.ts +1 -1
- package/lib/typescript/lib/module/mock/index.d.ts +7 -0
- package/lib/typescript/lib/module/renderer/components/Skottie.d.ts +2 -0
- package/lib/typescript/lib/module/renderer/components/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/Skia.web.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/Matrix4.d.ts +1 -0
- package/lib/typescript/lib/module/skia/types/Skottie.d.ts +5 -0
- package/lib/typescript/lib/module/skia/types/index.d.ts +1 -0
- package/lib/typescript/lib/module/skia/web/JsiSkImageFilterFactory.d.ts +22 -5
- package/lib/typescript/lib/module/skia/web/JsiSkia.d.ts +2 -0
- package/lib/typescript/lib/module/skia/web/JsiSkottieAnimation.d.ts +47 -0
- package/lib/typescript/lib/module/skia/web/JsiSkottieFactory.d.ts +5 -0
- package/lib/typescript/lib/module/sksg/Recorder/ReanimatedRecorder.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/Recorder/Recorder.d.ts +1 -0
- package/lib/typescript/lib/module/sksg/Recorder/commands/Drawing.d.ts +1 -1
- package/lib/typescript/src/dom/nodes/datatypes/Gradient.d.ts +15 -15
- package/lib/typescript/src/dom/types/Drawings.d.ts +5 -1
- package/lib/typescript/src/dom/types/NodeType.d.ts +2 -1
- package/lib/typescript/src/renderer/__tests__/e2e/AdvancedImageFilters.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/e2e/Camera.spec.d.ts +21 -0
- package/lib/typescript/src/renderer/__tests__/e2e/LightingImageFilters.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/e2e/Skottie.spec.d.ts +1 -0
- package/lib/typescript/src/renderer/__tests__/setup.d.ts +5 -0
- package/lib/typescript/src/renderer/components/Skottie.d.ts +4 -0
- package/lib/typescript/src/renderer/components/index.d.ts +1 -0
- package/lib/typescript/src/skia/types/ImageFilter/ImageFilterFactory.d.ts +252 -15
- package/lib/typescript/src/skia/types/Matrix4.d.ts +11 -2
- package/lib/typescript/src/skia/types/Recorder.d.ts +2 -1
- package/lib/typescript/src/skia/types/Skia.d.ts +2 -0
- package/lib/typescript/src/skia/types/Skottie.d.ts +223 -0
- package/lib/typescript/src/skia/types/index.d.ts +1 -0
- package/lib/typescript/src/skia/web/JsiSkImageFilterFactory.d.ts +29 -12
- package/lib/typescript/src/skia/web/JsiSkottieAnimation.d.ts +59 -0
- package/lib/typescript/src/skia/web/JsiSkottieFactory.d.ts +9 -0
- package/lib/typescript/src/sksg/Elements.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/Core.d.ts +4 -2
- package/lib/typescript/src/sksg/Recorder/ReanimatedRecorder.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/Recorder.d.ts +2 -1
- package/lib/typescript/src/sksg/Recorder/commands/Drawing.d.ts +2 -2
- package/libs/android/arm64-v8a/libjsonreader.a +0 -0
- package/libs/android/armeabi-v7a/libjsonreader.a +0 -0
- package/libs/android/x86/libjsonreader.a +0 -0
- package/libs/android/x86_64/libjsonreader.a +0 -0
- package/libs/apple/libpathops.xcframework/Info.plist +8 -8
- package/libs/apple/libskia.xcframework/Info.plist +14 -14
- package/libs/apple/libskottie.xcframework/Info.plist +14 -14
- package/libs/apple/libskparagraph.xcframework/Info.plist +16 -16
- package/libs/apple/libsksg.xcframework/Info.plist +5 -5
- package/libs/apple/libskshaper.xcframework/Info.plist +14 -14
- package/libs/apple/libskunicode_libgrapheme.xcframework/Info.plist +14 -14
- package/libs/apple/libsvg.xcframework/Info.plist +14 -14
- package/package.json +1 -1
- package/react-native-skia.podspec +4 -2
- package/src/__tests__/snapshots/matrix4/camera-corner.png +0 -0
- package/src/__tests__/snapshots/matrix4/camera-offset.png +0 -0
- package/src/__tests__/snapshots/matrix4/camera-top-left-center.png +0 -0
- package/src/__tests__/snapshots/matrix4/camera-zoom-out.png +0 -0
- package/src/__tests__/snapshots/matrix4/full-rect.png +0 -0
- package/src/__tests__/snapshots/matrix4/rect.png +0 -0
- package/src/__tests__/snapshots/matrix4/scaled-rect.png +0 -0
- package/src/__tests__/snapshots/matrix4/test-perspective.png +0 -0
- package/src/__tests__/snapshots/matrix4/test-perspective2.png +0 -0
- package/src/dom/types/Drawings.ts +6 -0
- package/src/dom/types/NodeType.ts +2 -0
- package/src/renderer/__tests__/e2e/AdvancedImageFilters.spec.tsx +492 -0
- package/src/renderer/__tests__/e2e/Camera.spec.tsx +475 -0
- package/src/renderer/__tests__/e2e/LightingImageFilters.spec.tsx +1478 -0
- package/src/renderer/__tests__/e2e/Skottie.spec.tsx +440 -0
- package/src/renderer/__tests__/e2e/setup/skottie/basic_slots.json +1118 -0
- package/src/renderer/__tests__/e2e/setup/skottie/color-props.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/confetti.json +5899 -0
- package/src/renderer/__tests__/e2e/setup/skottie/drinks.json +43857 -0
- package/src/renderer/__tests__/e2e/setup/skottie/fingerprint.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/lego_loader.json +29540 -0
- package/src/renderer/__tests__/e2e/setup/skottie/new-drop.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/onboarding.json +1 -0
- package/src/renderer/__tests__/e2e/setup/skottie/text-layer.json +1 -0
- package/src/renderer/__tests__/setup.tsx +23 -0
- package/src/renderer/components/Skottie.tsx +8 -0
- package/src/renderer/components/index.ts +1 -0
- package/src/skia/__tests__/assets/Avenir-Heavy.ttf +0 -0
- package/src/skia/types/ImageFilter/ImageFilterFactory.ts +391 -21
- package/src/skia/types/Matrix4.ts +108 -2
- package/src/skia/types/Recorder.ts +2 -0
- package/src/skia/types/Skia.ts +2 -0
- package/src/skia/types/Skottie.ts +266 -0
- package/src/skia/types/index.ts +1 -0
- package/src/skia/web/JsiSkImageFilterFactory.ts +266 -31
- package/src/skia/web/JsiSkia.ts +2 -0
- package/src/skia/web/JsiSkottieAnimation.ts +259 -0
- package/src/skia/web/JsiSkottieFactory.ts +25 -0
- package/src/sksg/Elements.tsx +2 -0
- package/src/sksg/Recorder/Core.ts +3 -0
- package/src/sksg/Recorder/Player.ts +3 -0
- package/src/sksg/Recorder/ReanimatedRecorder.ts +6 -0
- package/src/sksg/Recorder/Recorder.ts +5 -0
- package/src/sksg/Recorder/Visitor.ts +3 -0
- package/src/sksg/Recorder/commands/Drawing.ts +7 -3
- package/src/sksg/Recorder/commands/ImageFilters.ts +1 -1
@@ -0,0 +1,590 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <jsi/jsi.h>
|
4
|
+
|
5
|
+
#include "JsiSkCanvas.h"
|
6
|
+
#include "JsiSkColor.h"
|
7
|
+
#include "JsiSkHostObjects.h"
|
8
|
+
#include "JsiSkPoint.h"
|
9
|
+
#include "JsiSkRect.h"
|
10
|
+
#include "third_party/SkottieUtils.h"
|
11
|
+
|
12
|
+
#pragma clang diagnostic push
|
13
|
+
#pragma clang diagnostic ignored "-Wdocumentation"
|
14
|
+
|
15
|
+
#include "include/codec/SkJpegDecoder.h"
|
16
|
+
#include "include/codec/SkPngDecoder.h"
|
17
|
+
#include "include/codec/SkWebpDecoder.h"
|
18
|
+
|
19
|
+
#include "modules/skottie/include/Skottie.h"
|
20
|
+
#include "modules/skottie/include/SkottieProperty.h"
|
21
|
+
#include "modules/skottie/include/SlotManager.h"
|
22
|
+
#include "modules/sksg/include/SkSGInvalidationController.h"
|
23
|
+
|
24
|
+
#pragma clang diagnostic pop
|
25
|
+
|
26
|
+
namespace RNSkia {
|
27
|
+
using namespace facebook;
|
28
|
+
|
29
|
+
std::unique_ptr<SkCodec> DecodeImageData(sk_sp<SkData> data) {
|
30
|
+
if (data == nullptr) {
|
31
|
+
return nullptr;
|
32
|
+
}
|
33
|
+
|
34
|
+
if (SkJpegDecoder::IsJpeg(data->data(), data->size())) {
|
35
|
+
return SkJpegDecoder::Decode(data, nullptr);
|
36
|
+
}
|
37
|
+
|
38
|
+
if (SkPngDecoder::IsPng(data->data(), data->size())) {
|
39
|
+
return SkPngDecoder::Decode(data, nullptr);
|
40
|
+
}
|
41
|
+
|
42
|
+
if (SkWebpDecoder::IsWebp(data->data(), data->size())) {
|
43
|
+
return SkWebpDecoder::Decode(data, nullptr);
|
44
|
+
}
|
45
|
+
return nullptr;
|
46
|
+
}
|
47
|
+
|
48
|
+
class SkottieAssetProvider : public skottie::ResourceProvider {
|
49
|
+
public:
|
50
|
+
using AssetMap = std::unordered_map<std::string, sk_sp<SkData>>;
|
51
|
+
|
52
|
+
static sk_sp<SkottieAssetProvider> Make(AssetMap assets,
|
53
|
+
sk_sp<SkFontMgr> fontMgr) {
|
54
|
+
return sk_sp<SkottieAssetProvider>(
|
55
|
+
new SkottieAssetProvider(std::move(assets), std::move(fontMgr)));
|
56
|
+
}
|
57
|
+
|
58
|
+
~SkottieAssetProvider() override = default;
|
59
|
+
|
60
|
+
sk_sp<skottie::ImageAsset>
|
61
|
+
loadImageAsset(const char[] /* path */, const char name[],
|
62
|
+
const char[] /* id */) const override {
|
63
|
+
// For CK/Skottie we ignore paths & IDs, and identify images based solely on
|
64
|
+
// name.
|
65
|
+
if (auto data = this->findAsset(name)) {
|
66
|
+
auto codec = DecodeImageData(data);
|
67
|
+
if (!codec) {
|
68
|
+
return nullptr;
|
69
|
+
}
|
70
|
+
return skresources::MultiFrameImageAsset::Make(std::move(codec));
|
71
|
+
}
|
72
|
+
|
73
|
+
return nullptr;
|
74
|
+
}
|
75
|
+
|
76
|
+
sk_sp<skresources::ExternalTrackAsset>
|
77
|
+
loadAudioAsset(const char[] /* path */, const char[] /* name */,
|
78
|
+
const char id[]) override {
|
79
|
+
|
80
|
+
return nullptr;
|
81
|
+
}
|
82
|
+
|
83
|
+
sk_sp<SkTypeface> loadTypeface(const char name[],
|
84
|
+
const char[] /* url */) const override {
|
85
|
+
RNSkLogger::logToConsole("loadTypeface %s", name);
|
86
|
+
sk_sp<SkData> faceData = this->findAsset(name);
|
87
|
+
if (!faceData) {
|
88
|
+
return nullptr;
|
89
|
+
}
|
90
|
+
return fFontMgr->makeFromData(std::move(faceData));
|
91
|
+
}
|
92
|
+
|
93
|
+
sk_sp<SkData> load(const char[] /*path*/, const char name[]) const override {
|
94
|
+
// Ignore paths.
|
95
|
+
return this->findAsset(name);
|
96
|
+
}
|
97
|
+
|
98
|
+
private:
|
99
|
+
explicit SkottieAssetProvider(AssetMap assets, sk_sp<SkFontMgr> fontMgr)
|
100
|
+
: fAssets(std::move(assets)), fFontMgr(std::move(fontMgr)) {}
|
101
|
+
const AssetMap fAssets;
|
102
|
+
const sk_sp<SkFontMgr> fFontMgr;
|
103
|
+
|
104
|
+
sk_sp<SkData> findAsset(const char name[]) const {
|
105
|
+
auto it = fAssets.find(name);
|
106
|
+
if (it != fAssets.end()) {
|
107
|
+
return it->second;
|
108
|
+
}
|
109
|
+
return nullptr;
|
110
|
+
}
|
111
|
+
};
|
112
|
+
|
113
|
+
class ManagedAnimation {
|
114
|
+
public:
|
115
|
+
ManagedAnimation(std::string json, SkottieAssetProvider::AssetMap assets,
|
116
|
+
sk_sp<SkFontMgr> fontMgr) {
|
117
|
+
_propManager = std::make_unique<CustomPropertyManager>(
|
118
|
+
CustomPropertyManager::Mode::kCollapseProperties, "");
|
119
|
+
_resourceProvider =
|
120
|
+
SkottieAssetProvider::Make(std::move(assets), std::move(fontMgr));
|
121
|
+
// There is a bug in the ref counting that we address here.
|
122
|
+
_resourceProvider->ref();
|
123
|
+
auto builder = std::make_shared<skottie::Animation::Builder>();
|
124
|
+
builder->setResourceProvider(_resourceProvider);
|
125
|
+
builder->setPropertyObserver(_propManager->getPropertyObserver());
|
126
|
+
_animation = builder->make(json.c_str(), json.size());
|
127
|
+
_slotManager = builder->getSlotManager();
|
128
|
+
}
|
129
|
+
|
130
|
+
~ManagedAnimation() {
|
131
|
+
_animation = nullptr;
|
132
|
+
_slotManager = nullptr;
|
133
|
+
// Here the ref count is 0 but it's because of a bug, we need to still
|
134
|
+
// delete the resource provider
|
135
|
+
if (_resourceProvider) {
|
136
|
+
auto *raw_ptr = _resourceProvider.get();
|
137
|
+
_resourceProvider = nullptr;
|
138
|
+
delete raw_ptr; // Direct delete - bypasses ref counting entirely
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
public:
|
143
|
+
sk_sp<skottie::Animation> _animation = nullptr;
|
144
|
+
sk_sp<skottie::SlotManager> _slotManager = nullptr;
|
145
|
+
sk_sp<SkottieAssetProvider> _resourceProvider = nullptr;
|
146
|
+
std::unique_ptr<CustomPropertyManager> _propManager = nullptr;
|
147
|
+
};
|
148
|
+
|
149
|
+
class JsiSkSkottie : public JsiSkWrappingSharedPtrHostObject<ManagedAnimation> {
|
150
|
+
public:
|
151
|
+
// #region Properties
|
152
|
+
JSI_HOST_FUNCTION(duration) {
|
153
|
+
return static_cast<double>(getObject()->_animation->duration());
|
154
|
+
}
|
155
|
+
JSI_HOST_FUNCTION(fps) {
|
156
|
+
return static_cast<double>(getObject()->_animation->fps());
|
157
|
+
}
|
158
|
+
|
159
|
+
JSI_PROPERTY_GET(__typename__) {
|
160
|
+
return jsi::String::createFromUtf8(runtime, "Skottie");
|
161
|
+
}
|
162
|
+
|
163
|
+
JSI_EXPORT_PROPERTY_GETTERS(JSI_EXPORT_PROP_GET(JsiSkSkottie, __typename__))
|
164
|
+
// #endregion
|
165
|
+
|
166
|
+
// #region Methods
|
167
|
+
JSI_HOST_FUNCTION(seekFrame) {
|
168
|
+
sksg::InvalidationController ic;
|
169
|
+
getObject()->_animation->seekFrame(arguments[0].asNumber(), &ic);
|
170
|
+
auto bounds = ic.bounds();
|
171
|
+
if (count >= 2) {
|
172
|
+
auto rect = JsiSkRect::fromValue(runtime, arguments[1]);
|
173
|
+
if (rect != nullptr) {
|
174
|
+
rect->setXYWH(bounds.x(), bounds.y(), bounds.width(), bounds.height());
|
175
|
+
}
|
176
|
+
}
|
177
|
+
return jsi::Value::undefined();
|
178
|
+
}
|
179
|
+
|
180
|
+
JSI_HOST_FUNCTION(size) {
|
181
|
+
auto size = getObject()->_animation->size();
|
182
|
+
jsi::Object jsiSize(runtime);
|
183
|
+
jsiSize.setProperty(runtime, "width", size.width());
|
184
|
+
jsiSize.setProperty(runtime, "height", size.height());
|
185
|
+
return jsiSize;
|
186
|
+
}
|
187
|
+
|
188
|
+
JSI_HOST_FUNCTION(render) {
|
189
|
+
auto canvas = arguments[0]
|
190
|
+
.asObject(runtime)
|
191
|
+
.asHostObject<JsiSkCanvas>(runtime)
|
192
|
+
->getCanvas();
|
193
|
+
if (count > 1) {
|
194
|
+
auto rect = JsiSkRect::fromValue(runtime, arguments[1]);
|
195
|
+
getObject()->_animation->render(canvas, rect.get());
|
196
|
+
} else {
|
197
|
+
getObject()->_animation->render(canvas);
|
198
|
+
}
|
199
|
+
|
200
|
+
return jsi::Value::undefined();
|
201
|
+
}
|
202
|
+
|
203
|
+
JSI_HOST_FUNCTION(version) {
|
204
|
+
return jsi::String::createFromUtf8(
|
205
|
+
runtime, getObject()->_animation->version().c_str());
|
206
|
+
}
|
207
|
+
|
208
|
+
JSI_HOST_FUNCTION(setColor) {
|
209
|
+
if (count < 2) {
|
210
|
+
return jsi::Value(false);
|
211
|
+
}
|
212
|
+
auto key = arguments[0].asString(runtime).utf8(runtime);
|
213
|
+
auto color = JsiSkColor::fromValue(runtime, arguments[1]);
|
214
|
+
return getObject()->_propManager->setColor(key, color);
|
215
|
+
}
|
216
|
+
|
217
|
+
JSI_HOST_FUNCTION(setOpacity) {
|
218
|
+
if (count < 2) {
|
219
|
+
return jsi::Value(false);
|
220
|
+
}
|
221
|
+
|
222
|
+
auto key = arguments[0].asString(runtime).utf8(runtime);
|
223
|
+
auto opacity = arguments[1].asNumber();
|
224
|
+
return getObject()->_propManager->setOpacity(key, opacity);
|
225
|
+
}
|
226
|
+
|
227
|
+
JSI_HOST_FUNCTION(setText) {
|
228
|
+
if (count < 3) {
|
229
|
+
return jsi::Value(false);
|
230
|
+
}
|
231
|
+
auto key = arguments[0].asString(runtime).utf8(runtime);
|
232
|
+
auto text = arguments[1].asString(runtime).utf8(runtime);
|
233
|
+
auto size = arguments[2].asNumber();
|
234
|
+
// preserve all other text fields
|
235
|
+
auto t = getObject()->_propManager->getText(key);
|
236
|
+
t.fText = SkString(text);
|
237
|
+
t.fTextSize = size;
|
238
|
+
return getObject()->_propManager->setText(key, t);
|
239
|
+
}
|
240
|
+
|
241
|
+
JSI_HOST_FUNCTION(getTextProps) {
|
242
|
+
auto textProps = getObject()->_propManager->getTextProps();
|
243
|
+
int i = 0;
|
244
|
+
auto props = jsi::Array(runtime, textProps.size());
|
245
|
+
for (const auto &prop : textProps) {
|
246
|
+
auto txt = getObject()->_propManager->getText(prop);
|
247
|
+
auto txtVal = jsi::Object(runtime);
|
248
|
+
txtVal.setProperty(runtime, "text", txt.fText.c_str());
|
249
|
+
txtVal.setProperty(runtime, "size", txt.fTextSize);
|
250
|
+
auto val = jsi::Object(runtime);
|
251
|
+
val.setProperty(runtime, "key", prop);
|
252
|
+
val.setProperty(runtime, "value", txtVal);
|
253
|
+
props.setValueAtIndex(runtime, i, val);
|
254
|
+
i++;
|
255
|
+
}
|
256
|
+
return props;
|
257
|
+
}
|
258
|
+
|
259
|
+
JSI_HOST_FUNCTION(setTransform) {
|
260
|
+
if (count < 7) {
|
261
|
+
return jsi::Value(false);
|
262
|
+
}
|
263
|
+
|
264
|
+
auto key = arguments[0].asString(runtime).utf8(runtime);
|
265
|
+
auto anchor = JsiSkPoint::fromValue(runtime, arguments[1]);
|
266
|
+
auto position = JsiSkPoint::fromValue(runtime, arguments[2]);
|
267
|
+
auto scale = JsiSkPoint::fromValue(runtime, arguments[3]);
|
268
|
+
auto rotation = arguments[4].asNumber();
|
269
|
+
auto skew = arguments[5].asNumber();
|
270
|
+
auto skewAxis = arguments[6].asNumber();
|
271
|
+
|
272
|
+
skottie::TransformPropertyValue transform;
|
273
|
+
transform.fAnchorPoint = {anchor->x(), anchor->y()};
|
274
|
+
transform.fPosition = {position->x(), position->y()};
|
275
|
+
transform.fScale = {scale->x(), scale->y()};
|
276
|
+
transform.fRotation = rotation;
|
277
|
+
transform.fSkew = skew;
|
278
|
+
transform.fSkewAxis = skewAxis;
|
279
|
+
return getObject()->_propManager->setTransform(key, transform);
|
280
|
+
}
|
281
|
+
|
282
|
+
JSI_HOST_FUNCTION(getSlotInfo) {
|
283
|
+
jsi::Object slotInfoJS = jsi::Object(runtime);
|
284
|
+
auto slotInfo = getObject()->_slotManager->getSlotInfo();
|
285
|
+
|
286
|
+
auto colorSlotIDs = jsi::Array(runtime, slotInfo.fColorSlotIDs.size());
|
287
|
+
for (size_t i = 0; i < slotInfo.fColorSlotIDs.size(); i++) {
|
288
|
+
colorSlotIDs.setValueAtIndex(
|
289
|
+
runtime, i,
|
290
|
+
jsi::String::createFromUtf8(runtime,
|
291
|
+
slotInfo.fColorSlotIDs[i].c_str()));
|
292
|
+
}
|
293
|
+
slotInfoJS.setProperty(runtime, "colorSlotIDs", colorSlotIDs);
|
294
|
+
|
295
|
+
auto scalarSlotIDs = jsi::Array(runtime, slotInfo.fScalarSlotIDs.size());
|
296
|
+
for (size_t i = 0; i < slotInfo.fScalarSlotIDs.size(); i++) {
|
297
|
+
scalarSlotIDs.setValueAtIndex(
|
298
|
+
runtime, i,
|
299
|
+
jsi::String::createFromUtf8(runtime,
|
300
|
+
slotInfo.fScalarSlotIDs[i].c_str()));
|
301
|
+
}
|
302
|
+
slotInfoJS.setProperty(runtime, "scalarSlotIDs", scalarSlotIDs);
|
303
|
+
|
304
|
+
auto vec2SlotIDs = jsi::Array(runtime, slotInfo.fVec2SlotIDs.size());
|
305
|
+
for (size_t i = 0; i < slotInfo.fVec2SlotIDs.size(); i++) {
|
306
|
+
vec2SlotIDs.setValueAtIndex(
|
307
|
+
runtime, i,
|
308
|
+
jsi::String::createFromUtf8(runtime,
|
309
|
+
slotInfo.fVec2SlotIDs[i].c_str()));
|
310
|
+
}
|
311
|
+
slotInfoJS.setProperty(runtime, "vec2SlotIDs", vec2SlotIDs);
|
312
|
+
|
313
|
+
auto imageSlotIDs = jsi::Array(runtime, slotInfo.fImageSlotIDs.size());
|
314
|
+
for (size_t i = 0; i < slotInfo.fImageSlotIDs.size(); i++) {
|
315
|
+
imageSlotIDs.setValueAtIndex(
|
316
|
+
runtime, i,
|
317
|
+
jsi::String::createFromUtf8(runtime,
|
318
|
+
slotInfo.fImageSlotIDs[i].c_str()));
|
319
|
+
}
|
320
|
+
slotInfoJS.setProperty(runtime, "imageSlotIDs", imageSlotIDs);
|
321
|
+
|
322
|
+
auto textSlotIDs = jsi::Array(runtime, slotInfo.fTextSlotIDs.size());
|
323
|
+
for (size_t i = 0; i < slotInfo.fTextSlotIDs.size(); i++) {
|
324
|
+
textSlotIDs.setValueAtIndex(
|
325
|
+
runtime, i,
|
326
|
+
jsi::String::createFromUtf8(runtime,
|
327
|
+
slotInfo.fTextSlotIDs[i].c_str()));
|
328
|
+
}
|
329
|
+
slotInfoJS.setProperty(runtime, "textSlotIDs", textSlotIDs);
|
330
|
+
return slotInfoJS;
|
331
|
+
}
|
332
|
+
|
333
|
+
JSI_HOST_FUNCTION(setColorSlot) {
|
334
|
+
if (count < 2) {
|
335
|
+
return jsi::Value(false);
|
336
|
+
}
|
337
|
+
auto slotID = arguments[0].asString(runtime).utf8(runtime);
|
338
|
+
auto color = JsiSkColor::fromValue(runtime, arguments[1]);
|
339
|
+
return getObject()->_slotManager->setColorSlot(SkString(slotID), color);
|
340
|
+
}
|
341
|
+
|
342
|
+
JSI_HOST_FUNCTION(setScalarSlot) {
|
343
|
+
if (count < 2) {
|
344
|
+
return jsi::Value(false);
|
345
|
+
}
|
346
|
+
auto slotID = arguments[0].asString(runtime).utf8(runtime);
|
347
|
+
auto scalar = arguments[1].asNumber();
|
348
|
+
return getObject()->_slotManager->setScalarSlot(SkString(slotID), scalar);
|
349
|
+
}
|
350
|
+
|
351
|
+
JSI_HOST_FUNCTION(setVec2Slot) {
|
352
|
+
if (count < 2) {
|
353
|
+
return jsi::Value(false);
|
354
|
+
}
|
355
|
+
auto slotID = arguments[0].asString(runtime).utf8(runtime);
|
356
|
+
auto point = JsiSkPoint::fromValue(runtime, arguments[1]);
|
357
|
+
SkV2 vec2{point->x(), point->y()};
|
358
|
+
return getObject()->_slotManager->setVec2Slot(SkString(slotID), vec2);
|
359
|
+
}
|
360
|
+
|
361
|
+
JSI_HOST_FUNCTION(setTextSlot) {
|
362
|
+
if (count < 2) {
|
363
|
+
return jsi::Value(false);
|
364
|
+
}
|
365
|
+
auto key = arguments[0].asString(runtime).utf8(runtime);
|
366
|
+
// TODO: Implement proper text slot setting
|
367
|
+
return jsi::Value(false);
|
368
|
+
}
|
369
|
+
|
370
|
+
JSI_HOST_FUNCTION(setImageSlot) {
|
371
|
+
if (count < 2) {
|
372
|
+
return jsi::Value(false);
|
373
|
+
}
|
374
|
+
auto slotID = arguments[0].asString(runtime).utf8(runtime);
|
375
|
+
auto assetName = arguments[1].asString(runtime).utf8(runtime);
|
376
|
+
return getObject()->_slotManager->setImageSlot(
|
377
|
+
SkString(slotID), getObject()->_resourceProvider->loadImageAsset(
|
378
|
+
nullptr, assetName.data(), nullptr));
|
379
|
+
}
|
380
|
+
|
381
|
+
JSI_HOST_FUNCTION(getColorSlot) {
|
382
|
+
if (count < 1) {
|
383
|
+
return jsi::Value::null();
|
384
|
+
}
|
385
|
+
auto slotID = arguments[0].asString(runtime).utf8(runtime);
|
386
|
+
if (auto v = getObject()->_slotManager->getColorSlot(SkString(slotID))) {
|
387
|
+
return JsiSkColor::toValue(runtime, v.value());
|
388
|
+
}
|
389
|
+
return jsi::Value::null();
|
390
|
+
}
|
391
|
+
|
392
|
+
JSI_HOST_FUNCTION(getScalarSlot) {
|
393
|
+
if (count < 1) {
|
394
|
+
return jsi::Value::null();
|
395
|
+
}
|
396
|
+
auto slotID = arguments[0].asString(runtime).utf8(runtime);
|
397
|
+
if (auto v = getObject()->_slotManager->getScalarSlot(SkString(slotID))) {
|
398
|
+
return jsi::Value(v.value());
|
399
|
+
}
|
400
|
+
return jsi::Value::null();
|
401
|
+
}
|
402
|
+
|
403
|
+
JSI_HOST_FUNCTION(getVec2Slot) {
|
404
|
+
if (count < 1) {
|
405
|
+
return jsi::Value::null();
|
406
|
+
}
|
407
|
+
auto slotID = arguments[0].asString(runtime).utf8(runtime);
|
408
|
+
if (auto v = getObject()->_slotManager->getVec2Slot(SkString(slotID))) {
|
409
|
+
auto point = jsi::Object(runtime);
|
410
|
+
point.setProperty(runtime, "x", static_cast<double>(v->x));
|
411
|
+
point.setProperty(runtime, "y", static_cast<double>(v->y));
|
412
|
+
return point;
|
413
|
+
}
|
414
|
+
return jsi::Value::null();
|
415
|
+
}
|
416
|
+
|
417
|
+
JSI_HOST_FUNCTION(getTextSlot) {
|
418
|
+
if (count < 1) {
|
419
|
+
return jsi::Value::null();
|
420
|
+
}
|
421
|
+
auto slotID = arguments[0].asString(runtime).utf8(runtime);
|
422
|
+
if (auto textProp =
|
423
|
+
getObject()->_slotManager->getTextSlot(SkString(slotID))) {
|
424
|
+
jsi::Object textVal(runtime);
|
425
|
+
// text_val.set("typeface", textProp->fTypeface);
|
426
|
+
// text_val.set("text", emscripten::val(textProp->fText.c_str()));
|
427
|
+
// text_val.set("textSize", textProp->fTextSize);
|
428
|
+
// text_val.set("minTextSize", textProp->fMinTextSize);
|
429
|
+
// text_val.set("maxTextSize", textProp->fMaxTextSize);
|
430
|
+
// text_val.set("strokeWidth", textProp->fStrokeWidth);
|
431
|
+
// text_val.set("lineHeight", textProp->fLineHeight);
|
432
|
+
// text_val.set("lineShift", textProp->fLineShift);
|
433
|
+
// text_val.set("ascent", textProp->fAscent);
|
434
|
+
// text_val.set("maxLines", textProp->fMaxLines);
|
435
|
+
|
436
|
+
// switch (textProp->fHAlign) {
|
437
|
+
// case SkTextUtils::Align::kLeft_Align:
|
438
|
+
// text_val.set("horizAlign", para::TextAlign::kLeft);
|
439
|
+
// break;
|
440
|
+
// case SkTextUtils::Align::kRight_Align:
|
441
|
+
// text_val.set("horizAlign", para::TextAlign::kRight);
|
442
|
+
// break;
|
443
|
+
// case SkTextUtils::Align::kCenter_Align:
|
444
|
+
// text_val.set("horizAlign", para::TextAlign::kCenter);
|
445
|
+
// break;
|
446
|
+
// default:
|
447
|
+
// text_val.set("horizAlign", para::TextAlign::kLeft);
|
448
|
+
// break;
|
449
|
+
// }
|
450
|
+
|
451
|
+
// text_val.set("vertAlign", textProp->fVAlign);
|
452
|
+
// text_val.set("resize", textProp->fResize);
|
453
|
+
|
454
|
+
// if (textProp->fLineBreak ==
|
455
|
+
// skottie::Shaper::LinebreakPolicy::kParagraph) {
|
456
|
+
// text_val.set("linebreak", SkUnicode::LineBreakType::kSoftLineBreak);
|
457
|
+
// } else {
|
458
|
+
// text_val.set("linebreak", SkUnicode::LineBreakType::kHardLineBreak);
|
459
|
+
// }
|
460
|
+
|
461
|
+
// if (textProp->fDirection == skottie::Shaper::Direction::kLTR) {
|
462
|
+
// text_val.set("direction", para::TextDirection::kLtr);
|
463
|
+
// } else {
|
464
|
+
// text_val.set("direction", para::TextDirection::kRtl);
|
465
|
+
// }
|
466
|
+
// text_val.set("strokeJoin", textProp->fStrokeJoin);
|
467
|
+
|
468
|
+
// text_val.set(
|
469
|
+
// "fillColor",
|
470
|
+
// MakeTypedArray(4,
|
471
|
+
// SkColor4f::FromColor(textProp->fFillColor).vec()));
|
472
|
+
|
473
|
+
// text_val.set("strokeColor",
|
474
|
+
// MakeTypedArray(
|
475
|
+
// 4,
|
476
|
+
// SkColor4f::FromColor(textProp->fStrokeColor).vec()));
|
477
|
+
|
478
|
+
// const float box[] = {textProp->fBox.fLeft, textProp->fBox.fTop,
|
479
|
+
// textProp->fBox.fRight, textProp->fBox.fBottom};
|
480
|
+
// text_val.set("boundingBox", MakeTypedArray(4, box));
|
481
|
+
return textVal;
|
482
|
+
}
|
483
|
+
return jsi::Value::null();
|
484
|
+
}
|
485
|
+
|
486
|
+
JSI_HOST_FUNCTION(getColorProps) {
|
487
|
+
auto props = getObject()->_propManager->getColorProps();
|
488
|
+
auto colorProps =
|
489
|
+
jsi::Array(runtime, getObject()->_propManager->getColorProps().size());
|
490
|
+
int i = 0;
|
491
|
+
for (const auto &cp : getObject()->_propManager->getColorProps()) {
|
492
|
+
auto colorProp = jsi::Object(runtime);
|
493
|
+
colorProp.setProperty(runtime, "key", cp);
|
494
|
+
auto colorPropValue = getObject()->_propManager->getColor(cp);
|
495
|
+
colorProp.setProperty(runtime, "value",
|
496
|
+
JsiSkColor::toValue(runtime, colorPropValue));
|
497
|
+
colorProps.setValueAtIndex(runtime, i, colorProp);
|
498
|
+
i++;
|
499
|
+
}
|
500
|
+
|
501
|
+
return colorProps;
|
502
|
+
}
|
503
|
+
|
504
|
+
JSI_HOST_FUNCTION(getOpacityProps) {
|
505
|
+
auto props = getObject()->_propManager->getOpacityProps();
|
506
|
+
auto opacityProps = jsi::Array(
|
507
|
+
runtime, getObject()->_propManager->getOpacityProps().size());
|
508
|
+
int i = 0;
|
509
|
+
for (const auto &op : getObject()->_propManager->getOpacityProps()) {
|
510
|
+
auto opacityProp = jsi::Object(runtime);
|
511
|
+
opacityProp.setProperty(runtime, "key", op);
|
512
|
+
opacityProp.setProperty(runtime, "value",
|
513
|
+
getObject()->_propManager->getOpacity(op));
|
514
|
+
opacityProps.setValueAtIndex(runtime, i, opacityProp);
|
515
|
+
i++;
|
516
|
+
}
|
517
|
+
return opacityProps;
|
518
|
+
}
|
519
|
+
|
520
|
+
JSI_HOST_FUNCTION(getTransformProps) {
|
521
|
+
auto props = getObject()->_propManager->getTransformProps();
|
522
|
+
auto transformProps = jsi::Array(
|
523
|
+
runtime, getObject()->_propManager->getTransformProps().size());
|
524
|
+
int i = 0;
|
525
|
+
for (const auto &tp : getObject()->_propManager->getTransformProps()) {
|
526
|
+
const auto transform = getObject()->_propManager->getTransform(tp);
|
527
|
+
|
528
|
+
auto transformProp = jsi::Object(runtime);
|
529
|
+
transformProp.setProperty(runtime, "key", tp);
|
530
|
+
jsi::Object transformPropValue(runtime);
|
531
|
+
auto anchor = jsi::Object(runtime);
|
532
|
+
|
533
|
+
anchor.setProperty(runtime, "x", transform.fAnchorPoint.x());
|
534
|
+
anchor.setProperty(runtime, "y", transform.fAnchorPoint.y());
|
535
|
+
transformPropValue.setProperty(runtime, "anchor", anchor);
|
536
|
+
|
537
|
+
auto position = jsi::Object(runtime);
|
538
|
+
position.setProperty(runtime, "x", transform.fPosition.x());
|
539
|
+
position.setProperty(runtime, "y", transform.fPosition.y());
|
540
|
+
transformPropValue.setProperty(runtime, "position", position);
|
541
|
+
|
542
|
+
auto scale = jsi::Object(runtime);
|
543
|
+
scale.setProperty(runtime, "x", transform.fScale.x());
|
544
|
+
scale.setProperty(runtime, "y", transform.fScale.y());
|
545
|
+
transformPropValue.setProperty(runtime, "scale", scale);
|
546
|
+
|
547
|
+
transformPropValue.setProperty(runtime, "rotation", transform.fRotation);
|
548
|
+
transformPropValue.setProperty(runtime, "skew", transform.fSkew);
|
549
|
+
transformPropValue.setProperty(runtime, "skewAxis", transform.fSkewAxis);
|
550
|
+
transformProp.setProperty(runtime, "value", transformPropValue);
|
551
|
+
transformProps.setValueAtIndex(runtime, i, transformProp);
|
552
|
+
i++;
|
553
|
+
}
|
554
|
+
return transformProps;
|
555
|
+
}
|
556
|
+
|
557
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkSkottie, duration),
|
558
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, fps),
|
559
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, seekFrame),
|
560
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, render),
|
561
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, size),
|
562
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, version),
|
563
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, getSlotInfo),
|
564
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, setColorSlot),
|
565
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, setScalarSlot),
|
566
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, setVec2Slot),
|
567
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, setTextSlot),
|
568
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, setImageSlot),
|
569
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, getColorSlot),
|
570
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, getScalarSlot),
|
571
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, getVec2Slot),
|
572
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, getTextSlot),
|
573
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, getColorProps),
|
574
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, getOpacityProps),
|
575
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, getTransformProps),
|
576
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, getTextProps),
|
577
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, setColor),
|
578
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, setText),
|
579
|
+
JSI_EXPORT_FUNC(JsiSkSkottie, dispose))
|
580
|
+
// #endregion
|
581
|
+
|
582
|
+
/**
|
583
|
+
Constructor
|
584
|
+
*/
|
585
|
+
JsiSkSkottie(std::shared_ptr<RNSkPlatformContext> context,
|
586
|
+
std::shared_ptr<ManagedAnimation> animation)
|
587
|
+
: JsiSkWrappingSharedPtrHostObject<ManagedAnimation>(
|
588
|
+
std::move(context), std::move(animation)) {}
|
589
|
+
};
|
590
|
+
} // namespace RNSkia
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
#include <memory>
|
4
|
+
#include <utility>
|
5
|
+
|
6
|
+
#include <jsi/jsi.h>
|
7
|
+
|
8
|
+
#include "JsiSkSkottie.h"
|
9
|
+
|
10
|
+
namespace RNSkia {
|
11
|
+
|
12
|
+
namespace jsi = facebook::jsi;
|
13
|
+
|
14
|
+
class JsiSkottieFactory : public JsiSkHostObject {
|
15
|
+
public:
|
16
|
+
JSI_HOST_FUNCTION(Make) {
|
17
|
+
auto fontMgr = JsiSkFontMgrFactory::getFontMgr(getContext());
|
18
|
+
auto json = arguments[0].asString(runtime).utf8(runtime);
|
19
|
+
SkottieAssetProvider::AssetMap assets;
|
20
|
+
if (count > 1 && arguments[1].isObject()) {
|
21
|
+
auto jsAssetMap = arguments[1].asObject(runtime);
|
22
|
+
|
23
|
+
// Convert JS object to C++ AssetMap
|
24
|
+
auto propertyNames = jsAssetMap.getPropertyNames(runtime);
|
25
|
+
size_t propertyCount = propertyNames.size(runtime);
|
26
|
+
|
27
|
+
for (size_t i = 0; i < propertyCount; i++) {
|
28
|
+
auto propertyName =
|
29
|
+
propertyNames.getValueAtIndex(runtime, i).asString(runtime);
|
30
|
+
auto key = propertyName.utf8(runtime);
|
31
|
+
auto jsValue = jsAssetMap.getProperty(runtime, propertyName);
|
32
|
+
|
33
|
+
if (jsValue.isObject()) {
|
34
|
+
auto jsObject = jsValue.asObject(runtime);
|
35
|
+
|
36
|
+
// Check if the object is a SkData host object
|
37
|
+
if (jsObject.isHostObject(runtime)) {
|
38
|
+
auto hostObject = jsObject.getHostObject(runtime);
|
39
|
+
auto skData = std::dynamic_pointer_cast<JsiSkData>(hostObject);
|
40
|
+
if (skData) {
|
41
|
+
std::string k = key;
|
42
|
+
assets[k] = skData->getObject();
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
auto managedAnimation = std::make_shared<ManagedAnimation>(
|
50
|
+
json, std::move(assets), std::move(fontMgr));
|
51
|
+
if (!managedAnimation->_animation) {
|
52
|
+
return jsi::Value::null();
|
53
|
+
}
|
54
|
+
return jsi::Object::createFromHostObject(
|
55
|
+
runtime, std::make_shared<JsiSkSkottie>(getContext(),
|
56
|
+
std::move(managedAnimation)));
|
57
|
+
}
|
58
|
+
|
59
|
+
JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkottieFactory, Make))
|
60
|
+
|
61
|
+
explicit JsiSkottieFactory(std::shared_ptr<RNSkPlatformContext> context)
|
62
|
+
: JsiSkHostObject(std::move(context)) {}
|
63
|
+
};
|
64
|
+
|
65
|
+
} // namespace RNSkia
|
@@ -434,6 +434,22 @@ sk_sp<SkSVGDOM> getPropertyValue(jsi::Runtime &runtime,
|
|
434
434
|
"Expected SkSvgDom object or null for the svg property.");
|
435
435
|
}
|
436
436
|
|
437
|
+
template <>
|
438
|
+
sk_sp<skottie::Animation> getPropertyValue(jsi::Runtime &runtime,
|
439
|
+
const jsi::Value &value) {
|
440
|
+
if (value.isObject() && value.asObject(runtime).isHostObject(runtime)) {
|
441
|
+
auto ptr = std::dynamic_pointer_cast<JsiSkSkottie>(
|
442
|
+
value.asObject(runtime).asHostObject(runtime));
|
443
|
+
if (ptr != nullptr) {
|
444
|
+
return ptr->getObject()->_animation;
|
445
|
+
}
|
446
|
+
} else if (value.isNull()) {
|
447
|
+
return nullptr;
|
448
|
+
}
|
449
|
+
throw std::runtime_error(
|
450
|
+
"Expected JsiSkSkottie object or null for the svg property.");
|
451
|
+
}
|
452
|
+
|
437
453
|
template <>
|
438
454
|
sk_sp<SkPicture> getPropertyValue(jsi::Runtime &runtime,
|
439
455
|
const jsi::Value &value) {
|