Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Dec 2, 2023
2 parents eb862ce + 58f477a commit a43b9e0
Show file tree
Hide file tree
Showing 37 changed files with 2,834 additions and 3,328 deletions.
28 changes: 26 additions & 2 deletions android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(react-native-skia-skottie)
project(react-native-skottie)
cmake_minimum_required(VERSION 3.4.1)

set(PACKAGE_NAME "react-native-skia-skottie")
set(PACKAGE_NAME "react-native-skottie")

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 17)
Expand Down Expand Up @@ -39,8 +39,27 @@ include_directories(
"${NODE_MODULES_DIR}/react-native/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/jni"

# include skia headers
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/rnskia"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/skia/include/config/"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/skia/include/core/"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/skia/include/effects/"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/skia/include/utils/"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/skia/include/pathops/"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/skia/modules/"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/skia/modules/skparagraph/include/"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/skia/include/"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/skia"

"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/api"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/jsi"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/rnskia"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/rnskia/values"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/rnskia/dom"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/rnskia/dom/base"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/rnskia/dom/nodes"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/rnskia/dom/props"
"${NODE_MODULES_DIR}/@shopify/react-native-skia/cpp/utils"

${libfbjni_include_DIRS}
)

Expand All @@ -63,6 +82,10 @@ set(SKIA_MODULE_SKSG_LIB "sksg")
add_library(sksg STATIC IMPORTED)
set_property(TARGET sksg PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libsksg.a")

set(SKIA_MODULE_SKUNICODE_LIB "skunicode")
add_library(skunicode STATIC IMPORTED)
set_property(TARGET skunicode PROPERTY IMPORTED_LOCATION "${SKIA_LIBS_PATH}/libskunicode.a")

# Import react native libs
find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
Expand Down Expand Up @@ -92,6 +115,7 @@ target_link_libraries(
${SKIA_MODULE_SKOTTIE_LIB}
${SKIA_SKSHAPER_LIB}
${SKIA_MODULE_SKSG_LIB}
${SKIA_MODULE_SKUNICODE_LIB}
${SKIA_LIB}
shopify_react-native-skia::rnskia
-ljnigraphics
Expand Down
20 changes: 17 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ buildscript {
}

dependencies {
classpath("com.android.tools.build:gradle:7.2.2")
classpath("com.android.tools.build:gradle")
classpath("com.facebook.react:react-native-gradle-plugin")
}
}

Expand All @@ -27,9 +28,12 @@ def isNewArchitectureEnabled() {
return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

apply plugin: 'com.facebook.react'
apply plugin: 'com.android.library'

if (isNewArchitectureEnabled()) {
apply plugin: "com.facebook.react"
}

import java.nio.file.Paths

static def findNodeModules(baseDir) {
Expand Down Expand Up @@ -138,7 +142,11 @@ android {

dependencies {
implementation 'com.facebook.react:react-android:+'
implementation project(":shopify_react-native-skia")
implementation(project(":shopify_react-native-skia")) {
exclude group: "com.facebook.react", module: "react-native"
}
// TODO: not sure if this is still needed, now that we have the task dependency at the bottom?
implementation(project(":react-native-reanimated"))
}

// Resolves "LOCAL_SRC_FILES points to a missing file, Check that libfb.so exists or that its path is correct".
Expand All @@ -163,3 +171,9 @@ if (isNewArchitectureEnabled()) {
codegenJavaPackageName = "com.skiaskottie"
}
}

if (isNewArchitectureEnabled()) {
tasks.named('generateCodegenSchemaFromJavaScript') {
dependsOn ':react-native-reanimated:prepareHeadersForPrefab'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public SkiaSkottieModule(ReactApplicationContext context) {
@ReactMethod(isBlockingSynchronousMethod = true)
public boolean install() {
try {
System.loadLibrary("react-native-skia-skottie");
System.loadLibrary("react-native-skottie");
ReactApplicationContext context = getReactApplicationContext();

RNSkiaModule skiaModule = context.getNativeModule(RNSkiaModule.class);
Expand Down
2 changes: 1 addition & 1 deletion android/src/main/java/com/skiaskottie/SkiaSkottieView.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SkiaSkottieView extends SkiaBaseView {
private HybridData mHybridData;

public SkiaSkottieView(Context context) {
super(context);
super(context, true);
RNSkiaModule skiaModule = ((ReactContext) context).getNativeModule(RNSkiaModule.class);
mHybridData = initHybrid(skiaModule.getSkiaManager());
}
Expand Down
25 changes: 25 additions & 0 deletions cpp/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Config for clang-format version 16

# Standard
BasedOnStyle: llvm
Standard: c++14

# Indentation
IndentWidth: 2
ColumnLimit: 140

# Includes
SortIncludes: true
SortUsingDeclarations: true

# Pointer and reference alignment
PointerAlignment: Left
ReferenceAlignment: Left
ReflowComments: true

# Line breaking options
BreakBeforeBraces: Attach
BreakConstructorInitializers: BeforeColon
AllowShortFunctionsOnASingleLine: Empty
IndentCaseLabels: true
NamespaceIndentation: Inner
156 changes: 78 additions & 78 deletions cpp/JsiSkSkottie.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include <jsi/jsi.h>

#include <JsiSkHostObjects.h>
#include <JsiSkCanvas.h>
#include <JsiSkHostObjects.h>

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
Expand All @@ -13,81 +13,81 @@
#pragma clang diagnostic pop

namespace RNSkia {
using namespace facebook;

class JsiSkSkottie : public JsiSkWrappingSkPtrHostObject<skottie::Animation>
{
public:
//#region Properties
JSI_PROPERTY_GET(duration) { return static_cast<double>(getObject()->duration()); }
JSI_PROPERTY_GET(fps) { return static_cast<double>(getObject()->fps()); }

JSI_EXPORT_PROPERTY_GETTERS(
JSI_EXPORT_PROP_GET(JsiSkSkottie, duration),
JSI_EXPORT_PROP_GET(JsiSkSkottie, fps)
)
//#endregion


//#region Methods
JSI_HOST_FUNCTION(seek) {
getObject()->seek(arguments[0].asNumber());
return jsi::Value::undefined();
}

JSI_HOST_FUNCTION(render) {
auto canvas = arguments[0]
.asObject(runtime)
.asHostObject<JsiSkCanvas>(runtime)
->getCanvas();

auto rect = JsiSkRect::fromValue(runtime, arguments[1]);
if (canvas != nullptr && rect != nullptr) {
getObject()->render(canvas, rect.get());
}

return jsi::Value::undefined();
}

JSI_EXPORT_FUNCTIONS(
JSI_EXPORT_FUNC(JsiSkSkottie, seek),
JSI_EXPORT_FUNC(JsiSkSkottie, render),
)
//#endregion

/**
Constructor
*/
JsiSkSkottie(std::shared_ptr<RNSkPlatformContext> context, const sk_sp<skottie::Animation> animation)
: JsiSkWrappingSkPtrHostObject<skottie::Animation>(std::move(context), std::move(animation)){}

/**
Returns the jsi object from a host object of this type
*/
static sk_sp<skottie::Animation> fromValue(jsi::Runtime &runtime, const jsi::Value &obj) {
return obj.asObject(runtime)
.asHostObject<JsiSkSkottie>(runtime)
->getObject();
}

/**
* Creates the function for contructing a new instance of the
* JsiSkSkottie class.
*
* @param context platform context
* @return A function for creating a new host object wrapper for the JsiSkSkottie class.
*/
static const jsi::HostFunctionType
createCtor(std::shared_ptr<RNSkPlatformContext> context) {
return JSI_HOST_FUNCTION_LAMBDA {
auto jsonStr = arguments[0].asString(runtime).utf8(runtime);
auto animation = skottie::Animation::Builder()
.make(jsonStr.c_str(), jsonStr.size());

// Return the newly constructed object
return jsi::Object::createFromHostObject(
runtime, std::make_shared<JsiSkSkottie>(std::move(context), std::move(animation)));
};
}
using namespace facebook;

class JsiSkSkottie : public JsiSkWrappingSkPtrHostObject<skottie::Animation> {
public:
// #region Properties
JSI_PROPERTY_GET(duration) {
return static_cast<double>(getObject()->duration());
}
JSI_PROPERTY_GET(fps) {
return static_cast<double>(getObject()->fps());
}

JSI_PROPERTY_GET(__typename__) { \
return jsi::String::createFromUtf8(runtime, "Skottie"); \
}

JSI_EXPORT_PROPERTY_GETTERS(
JSI_EXPORT_PROP_GET(JsiSkSkottie, duration),
JSI_EXPORT_PROP_GET(JsiSkSkottie, fps),
JSI_EXPORT_PROP_GET(JsiSkSkottie, __typename__)
)
// #endregion

// #region Methods
JSI_HOST_FUNCTION(seek) {
getObject()->seek(arguments[0].asNumber());
return jsi::Value::undefined();
}

JSI_HOST_FUNCTION(render) {
auto canvas = arguments[0].asObject(runtime).asHostObject<JsiSkCanvas>(runtime)->getCanvas();

auto rect = JsiSkRect::fromValue(runtime, arguments[1]);
if (canvas != nullptr && rect != nullptr) {
getObject()->render(canvas, rect.get());
}

return jsi::Value::undefined();
}

JSI_EXPORT_FUNCTIONS(
JSI_EXPORT_FUNC(JsiSkSkottie, seek),
JSI_EXPORT_FUNC(JsiSkSkottie, render),
JSI_EXPORT_FUNC(JsiSkSkottie, dispose)
)
// #endregion

/**
Constructor
*/
JsiSkSkottie(std::shared_ptr<RNSkPlatformContext> context, const sk_sp<skottie::Animation> animation)
: JsiSkWrappingSkPtrHostObject<skottie::Animation>(std::move(context), std::move(animation)) {}

/**
Returns the jsi object from a host object of this type
*/
static sk_sp<skottie::Animation> fromValue(jsi::Runtime& runtime, const jsi::Value& obj) {
return obj.asObject(runtime).asHostObject<JsiSkSkottie>(runtime)->getObject();
}

/**
* Creates the function for contructing a new instance of the
* JsiSkSkottie class.
*
* @param context platform context
* @return A function for creating a new host object wrapper for the JsiSkSkottie class.
*/
static const jsi::HostFunctionType createCtor(std::shared_ptr<RNSkPlatformContext> context) {
return JSI_HOST_FUNCTION_LAMBDA {
auto jsonStr = arguments[0].asString(runtime).utf8(runtime);
auto animation = skottie::Animation::Builder().make(jsonStr.c_str(), jsonStr.size());

// Return the newly constructed object
return jsi::Object::createFromHostObject(runtime, std::make_shared<JsiSkSkottie>(std::move(context), std::move(animation)));
};
}
}
};
} // namespace RNSkia
Loading

0 comments on commit a43b9e0

Please sign in to comment.