Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/docs/docs/animations/reanimated3.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ sidebar_label: Animations
slug: /animations/animations
---

React Native Skia offers integration with [Reanimated v3 and above](https://docs.swmansion.com/react-native-reanimated/), enabling the execution of animations on the UI thread.
React Native Skia offers integration with [Reanimated](https://docs.swmansion.com/react-native-reanimated/), enabling the execution of animations on the UI thread.
Starting version `2.10` and above, this integration requires **Reanimated v4 or above**. For lower version numbers, you can use Reanimated v3.

React Native Skia supports the direct usage of Reanimated's shared and derived values as properties. There is no need for functions like `createAnimatedComponent` or `useAnimatedProps`; simply pass the Reanimated values directly as properties.

Expand Down
3 changes: 2 additions & 1 deletion apps/docs/docs/getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Skia serves as the graphics engine for Google Chrome and Chrome OS, Android, Flu
**Version compatibility:**
`react-native@>=0.79` and `react@>=19` are required. <br />
In addition you should make sure you're on at least `iOS 14` and `Android API level 21` or above. <br />
To use React Native Skia with video support, `Android API level 26` or above is required.
To use React Native Skia with video support, `Android API level 26` or above is required. <br />
To use React Native Skia with Reanimated on native platforms, `react-native-reanimated@>=4.0.0` (with `react-native-worklets@>=0.7.0`) is required.

For `react-native@<=0.78` and `react@<=18`, you need to use `@shopify/react-native-skia` version `1.12.4` or below.

Expand Down
4 changes: 2 additions & 2 deletions apps/example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3207,7 +3207,7 @@ SPEC CHECKSUMS:
FBLazyVector: 309703e71d3f2f1ed7dc7889d58309c9d77a95a4
fmt: a40bb5bd0294ea969aaaba240a927bd33d878cdd
glog: 5683914934d5b6e4240e497e0f4a3b42d1854183
hermes-engine: 11b010917f5f15150b2c015abddef1573d2bb05d
hermes-engine: ad676c360175e5b8af471b8ce1389e6cf4f9e1ee
RCT-Folly: 59ec0ac1f2f39672a0c6e6cecdd39383b764646f
RCTDeprecation: a41bbdd9af30bf2e5715796b313e44ec43eefff1
RCTRequired: 7be34aabb0b77c3cefe644528df0fa0afad4e4d0
Expand Down Expand Up @@ -3245,7 +3245,7 @@ SPEC CHECKSUMS:
React-Mapbuffer: 2e0e7cc5b7064eaed9c8b8afc3a87621cb7ef5cd
React-microtasksnativemodule: dd4d33b251b57e5027c572c6d0b45cbfbcfaa386
react-native-safe-area-context: 54d812805f3c4e08a4580ad086cbde1d8780c2e4
react-native-skia: b28747dc1cf8c344ad041f14a618eda7f429bfeb
react-native-skia: 4a90dfa21f4544d69c6be0c49958378169a88532
React-NativeModulesApple: 7f2f2fed3f6c858889eb61d09941be965d52df58
React-networking: 43e5e6773ac2ca2a93261a1388fed269c9fce092
React-oscompat: 80166b66da22e7af7fad94474e9997bd52d4c8c6
Expand Down
2 changes: 1 addition & 1 deletion externals/depot_tools
Submodule depot_tools updated from f48857 to c46c2e
6 changes: 1 addition & 5 deletions packages/skia/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ add_library(
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/AHardwareBufferUtils.cpp"
"${PROJECT_SOURCE_DIR}/cpp/rnskia-android/RNSkAndroidVideo.cpp"

"${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiHostObject.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeLifecycleMonitor.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/jsi/RuntimeAwareCache.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/jsi/JsiPromises.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/jsi/Promise.cpp"

"${PROJECT_SOURCE_DIR}/../cpp/rnskia/RNSkManager.cpp"

Expand All @@ -115,10 +115,7 @@ add_library(
)

if(SK_GRAPHITE)
# WebGPU JSI infrastructure (jsi2)
target_sources(${PACKAGE_NAME} PRIVATE
"${PROJECT_SOURCE_DIR}/../cpp/jsi2/Promise.cpp"

# WebGPU async system
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/async/AsyncTaskHandle.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/rnwgpu/async/RuntimeContext.cpp"
Expand Down Expand Up @@ -181,7 +178,6 @@ target_include_directories(

# WebGPU bindings
../cpp
../cpp/jsi2
../cpp/rnwgpu
../cpp/rnwgpu/api
../cpp/rnwgpu/api/descriptors
Expand Down
25 changes: 15 additions & 10 deletions packages/skia/cpp/api/JsiNativeBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <jsi/jsi.h>

#include "JsiSkImage.h"
#include "JsiSkNativeObjects.h"

namespace RNSkia {

Expand All @@ -15,8 +16,11 @@ namespace jsi = facebook::jsi;
Implementation of the ParagraphBuilderFactory for making ParagraphBuilder JSI
object
*/
class JsiNativeBufferFactory : public JsiSkHostObject {
class JsiNativeBufferFactory
: public JsiSkNativeObject<JsiNativeBufferFactory> {
public:
static constexpr const char *CLASS_NAME = "NativeBufferFactory";

JSI_HOST_FUNCTION(MakeFromImage) {
auto image = JsiSkImage::fromValue(runtime, arguments[0]);
image->makeNonTextureImage();
Expand All @@ -40,18 +44,19 @@ class JsiNativeBufferFactory : public JsiSkHostObject {
return jsi::Value::undefined();
}

JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiNativeBufferFactory, Release),
JSI_EXPORT_FUNC(JsiNativeBufferFactory, MakeFromImage),
JSI_EXPORT_FUNC(JsiNativeBufferFactory, MakeTestBuffer))

size_t getMemoryPressure() const override { return 1024; }

std::string getObjectType() const override {
return "JsiNativeBufferFactory";
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
installHostMethod(runtime, prototype, "Release",
&JsiNativeBufferFactory::Release);
installHostMethod(runtime, prototype, "MakeFromImage",
&JsiNativeBufferFactory::MakeFromImage);
installHostMethod(runtime, prototype, "MakeTestBuffer",
&JsiNativeBufferFactory::MakeTestBuffer);
}

size_t getMemoryPressure() override { return 1024; }

explicit JsiNativeBufferFactory(std::shared_ptr<RNSkPlatformContext> context)
: JsiSkHostObject(std::move(context)) {}
: JsiSkNativeObject<JsiNativeBufferFactory>(std::move(context)) {}
};

} // namespace RNSkia
40 changes: 21 additions & 19 deletions packages/skia/cpp/api/JsiSkAnimatedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <string>
#include <utility>

#include "JsiSkHostObjects.h"
#include "JsiSkNativeObjects.h"
#include "api/third_party/base64.h"

#pragma clang diagnostic push
Expand All @@ -29,15 +29,16 @@ namespace RNSkia {
namespace jsi = facebook::jsi;

class JsiSkAnimatedImage
: public JsiSkWrappingSkPtrHostObject<SkAnimatedImage> {
: public JsiSkWrappingSkPtrNativeObject<JsiSkAnimatedImage,
SkAnimatedImage> {
public:
static constexpr const char *CLASS_NAME = "AnimatedImage";

// TODO-API: Properties?
JSI_HOST_FUNCTION(getCurrentFrame) {
auto image = getObject()->getCurrentFrame();
auto hostObjectInstance =
std::make_shared<JsiSkImage>(getContext(), std::move(image));
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
runtime, hostObjectInstance, getContext());
return makeJsiObject(
runtime, std::make_shared<JsiSkImage>(getContext(), std::move(image)));
}

JSI_HOST_FUNCTION(getFrameCount) {
Expand All @@ -52,21 +53,24 @@ class JsiSkAnimatedImage
return static_cast<int>(getObject()->decodeNextFrame());
}

EXPORT_JSI_API_TYPENAME(JsiSkAnimatedImage, AnimatedImage)

JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkAnimatedImage, dispose),
JSI_EXPORT_FUNC(JsiSkAnimatedImage, getFrameCount),
JSI_EXPORT_FUNC(JsiSkAnimatedImage, getCurrentFrame),
JSI_EXPORT_FUNC(JsiSkAnimatedImage,
currentFrameDuration),
JSI_EXPORT_FUNC(JsiSkAnimatedImage, decodeNextFrame))
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
installCommon(runtime, prototype);
installHostMethod(runtime, prototype, "getFrameCount",
&JsiSkAnimatedImage::getFrameCount);
installHostMethod(runtime, prototype, "getCurrentFrame",
&JsiSkAnimatedImage::getCurrentFrame);
installHostMethod(runtime, prototype, "currentFrameDuration",
&JsiSkAnimatedImage::currentFrameDuration);
installHostMethod(runtime, prototype, "decodeNextFrame",
&JsiSkAnimatedImage::decodeNextFrame);
}

JsiSkAnimatedImage(std::shared_ptr<RNSkPlatformContext> context,
const sk_sp<SkAnimatedImage> image)
: JsiSkWrappingSkPtrHostObject<SkAnimatedImage>(std::move(context),
std::move(image)) {}
: JsiSkWrappingSkPtrNativeObject<JsiSkAnimatedImage, SkAnimatedImage>(
std::move(context), std::move(image)) {}

size_t getMemoryPressure() const override {
size_t getMemoryPressure() override {
auto animation = getObject();
if (!animation) {
return 0;
Expand Down Expand Up @@ -131,8 +135,6 @@ class JsiSkAnimatedImage

return estimated;
}

std::string getObjectType() const override { return "JsiSkAnimatedImage"; }
};

} // namespace RNSkia
27 changes: 13 additions & 14 deletions packages/skia/cpp/api/JsiSkAnimatedImageFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,41 @@

#include <jsi/jsi.h>

#include "jsi/JsiPromises.h"
#include "JsiSkAnimatedImage.h"
#include "JsiSkData.h"
#include "JsiSkHostObjects.h"
#include "JsiSkNativeObjects.h"
#include "jsi/JsiPromises.h"

namespace RNSkia {

namespace jsi = facebook::jsi;

class JsiSkAnimatedImageFactory : public JsiSkHostObject {
class JsiSkAnimatedImageFactory
: public JsiSkNativeObject<JsiSkAnimatedImageFactory> {
public:
static constexpr const char *CLASS_NAME = "AnimatedImageFactory";

JSI_HOST_FUNCTION(MakeAnimatedImageFromEncoded) {
auto data = JsiSkData::fromValue(runtime, arguments[0]);
auto codec = SkAndroidCodec::MakeFromData(data);
auto image = SkAnimatedImage::Make(std::move(codec));
if (image == nullptr) {
return jsi::Value::null();
}
auto hostObjectInstance =
std::make_shared<JsiSkAnimatedImage>(getContext(), std::move(image));
return JSI_CREATE_HOST_OBJECT_WITH_MEMORY_PRESSURE(
runtime, hostObjectInstance, getContext());
return makeJsiObject(runtime, std::make_shared<JsiSkAnimatedImage>(
getContext(), std::move(image)));
}

size_t getMemoryPressure() const override { return 1024; }
size_t getMemoryPressure() override { return 1024; }

std::string getObjectType() const override {
return "JsiSkAnimatedImageFactory";
static void definePrototype(jsi::Runtime &runtime, jsi::Object &prototype) {
installHostMethod(runtime, prototype, "MakeAnimatedImageFromEncoded",
&JsiSkAnimatedImageFactory::MakeAnimatedImageFromEncoded);
}

JSI_EXPORT_FUNCTIONS(JSI_EXPORT_FUNC(JsiSkAnimatedImageFactory,
MakeAnimatedImageFromEncoded))

explicit JsiSkAnimatedImageFactory(
std::shared_ptr<RNSkPlatformContext> context)
: JsiSkHostObject(std::move(context)) {}
: JsiSkNativeObject<JsiSkAnimatedImageFactory>(std::move(context)) {}
};

} // namespace RNSkia
Loading
Loading