Skip to content

Commit

Permalink
Merge branch 'main' into @tjzel/worklets/move-ui-worklet-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
tjzel committed Dec 12, 2024
2 parents 91cb027 + 643f8ca commit a47e6d4
Show file tree
Hide file tree
Showing 28 changed files with 1,366 additions and 25 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"packages/react-native-reanimated",
"packages/eslint-plugin-reanimated",
"packages/react-native-reanimated/plugin",
"packages/react-native-worklets",
"apps/common-app",
"apps/paper-example",
"apps/fabric-example",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ jsi::Value makeShareableClone(
if (value.isObject()) {
auto object = value.asObject(rt);
if (!object.getProperty(rt, "__workletHash").isUndefined()) {
shareable = std::make_shared<ShareableWorklet>(rt, object);
if (shouldRetainRemote.isBool() && shouldRetainRemote.getBool()) {
shareable =
std::make_shared<RetainingShareable<ShareableWorklet>>(rt, object);
} else {
shareable = std::make_shared<ShareableWorklet>(rt, object);
}
} else if (!object.getProperty(rt, "__init").isUndefined()) {
shareable = std::make_shared<ShareableHandle>(rt, object);
} else if (object.isFunction(rt)) {
Expand Down Expand Up @@ -284,7 +289,12 @@ jsi::Value ShareableHandle::toJSValue(jsi::Runtime &rt) {
remoteRuntime_ = &rt;
}
}
return jsi::Value(rt, *remoteValue_);
if (&rt == remoteRuntime_) {
return jsi::Value(rt, *remoteValue_);
}
auto initObj = initializer_->toJSValue(rt);
return getValueUnpacker(rt).call(
rt, initObj, jsi::String::createFromAscii(rt, "Handle"));
}

jsi::Value ShareableString::toJSValue(jsi::Runtime &rt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ elseif(${JS_RUNTIME} STREQUAL "v8")
PRIVATE
"${JS_RUNTIME_DIR}/src"
)
file(GLOB V8_SO_DIR "${JS_RUNTIME_DIR}/android/build/intermediates/library_jni/*/jni/${ANDROID_ABI}")
file(GLOB V8_SO_DIR "${JS_RUNTIME_DIR}/android/build/intermediates/library_jni/**/jni/${ANDROID_ABI}")
find_library(
V8EXECUTOR_LIB
v8executor
Expand Down
3 changes: 1 addition & 2 deletions packages/react-native-reanimated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,5 @@
"./lib/module/core.js",
"./lib/module/initializers.js",
"./lib/module/index.js"
],
"packageManager": "[email protected]"
]
}
6 changes: 5 additions & 1 deletion packages/react-native-reanimated/src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ const hook = {
useAnimatedReaction: NOOP,
useAnimatedRef: () => ({ current: null }),
useAnimatedScrollHandler: NOOP_FACTORY,
useDerivedValue: <Value>(processor: () => Value) => ({ value: processor() }),
useDerivedValue: <Value>(processor: () => Value) => {
const result = processor();

return { value: result, get: () => result };
},
useAnimatedSensor: () => ({
sensor: {
value: {
Expand Down
3 changes: 2 additions & 1 deletion packages/react-native-reanimated/src/shareables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ Offending code was: \`${getWorkletCode(value)}\``);
}
const clone = WorkletsModule.makeShareableClone(
clonedProps,
shouldPersistRemote,
// retain all worklets
true,
value
) as ShareableRef<T>;
shareableMappingCache.set(value, clone);
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native-worklets/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('eslint').ESLint.ConfigData} */
module.exports = {
extends: ['../../.eslintrc.js'],
};
3 changes: 3 additions & 0 deletions packages/react-native-worklets/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.pbxproj -text
# specific for windows script files
*.bat text eol=crlf
62 changes: 62 additions & 0 deletions packages/react-native-worklets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# OSX
.DS_Store

# VSCode
.vscode/
jsconfig.json

# Xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate
project.xcworkspace

# Android/IJ
.classpath
.cxx
.gradle
.idea
.project
.settings
local.properties
android.iml

# node.js
node_modules/
npm-debug.log
yarn-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
android/app/libs
android/keystores/debug.keystore

# Yarn
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

# generated by bob
lib/

# React Native Codegen
apple/generated
android/generated
1 change: 1 addition & 0 deletions packages/react-native-worklets/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
20 changes: 20 additions & 0 deletions packages/react-native-worklets/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIT License

Copyright (c) 2024 nobody
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
64 changes: 64 additions & 0 deletions packages/react-native-worklets/RNWorklets.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'

Pod::Spec.new do |s|
s.name = "RNWorklets"
s.version = package["version"]
s.summary = package["description"]
s.homepage = "https://github.com/software-mansion/react-native-reanimated"
s.license = package["license"]
s.authors = { "author" => "[email protected]" }
s.platforms = { :ios => min_ios_version_supported }
s.source = { :git => "https://github.com/software-mansion/react-native-reanimated.git", :tag => "#{s.version}" }

s.source_files = "apple/*.{h,m,mm,cpp}"

s.subspec "worklets" do |ss|
ss.source_files = "Common/cpp/worklets/**/*.{cpp,h}"
ss.header_dir = "worklets"
ss.header_mappings_dir = "Common/cpp/worklets"

ss.subspec "apple" do |sss|
# Please be careful with the snakes.
# 🐍🐍🐍
# Thank you for your understanding.
sss.source_files = "apple/worklets/**/*.{mm,h,m}"
sss.header_dir = "worklets"
sss.header_mappings_dir = "apple/worklets"
end
end

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
install_modules_dependencies(s)
else
s.dependency "React-Core"

# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end

s.pod_target_xcconfig = {
"USE_HEADERMAP" => "YES",
"DEFINES_MODULE" => "YES",
"HEADER_SEARCH_PATHS" => '"$(PODS_TARGET_SRCROOT)/ReactCommon" "$(PODS_TARGET_SRCROOT)" "$(PODS_ROOT)/RCT-Folly" "$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/DoubleConversion" "$(PODS_ROOT)/Headers/Private/React-Core" "$(PODS_ROOT)/Headers/Private/Yoga"',
"FRAMEWORK_SEARCH_PATHS" => '"${PODS_CONFIGURATION_BUILD_DIR}/React-hermes"',
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
}

end
60 changes: 60 additions & 0 deletions packages/react-native-worklets/android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
project(Worklets)
cmake_minimum_required(VERSION 3.8)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE INTERNAL "")

set(CMAKE_CXX_STANDARD 20)

# default CMAKE_CXX_FLAGS: "-g -DANDROID -fdata-sections -ffunction-sections
# -funwind-tables -fstack-protector-strong -no-canonical-prefixes
# -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fstack-protector-all"
include("${REACT_NATIVE_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake")
add_compile_options(${folly_FLAGS})

string(
APPEND
CMAKE_CXX_FLAGS
" -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION} -DREANIMATED_VERSION=${REANIMATED_VERSION} -DHERMES_ENABLE_DEBUGGER=${HERMES_ENABLE_DEBUGGER}"
)

string(
APPEND
CMAKE_CXX_FLAGS
" -fexceptions -fno-omit-frame-pointer -frtti -fstack-protector-all -std=c++${CMAKE_CXX_STANDARD} -Wall -Werror"
)

if(${IS_NEW_ARCHITECTURE_ENABLED})
string(APPEND CMAKE_CXX_FLAGS " -DRCT_NEW_ARCH_ENABLED")
endif()

if(${IS_REANIMATED_EXAMPLE_APP})
string(APPEND CMAKE_CXX_FLAGS " -DIS_REANIMATED_EXAMPLE_APP -Wpedantic")
endif()

if(NOT ${CMAKE_BUILD_TYPE} MATCHES "Debug")
string(APPEND CMAKE_CXX_FLAGS " -DNDEBUG")
endif()

if(${JS_RUNTIME} STREQUAL "hermes")
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_HERMES=1")
elseif(${JS_RUNTIME} STREQUAL "jsc")
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_JSC=1")
elseif(${JS_RUNTIME} STREQUAL "v8")
string(APPEND CMAKE_CXX_FLAGS " -DJS_RUNTIME_V8=1")
else()
message(FATAL_ERROR "Unknown JS runtime ${JS_RUNTIME}.")
endif()

# Resolves "CMake Warning: Manually-specified variables were not used by the
# project" when any of the following variables is not used in some build
# configuration.
set(ignoreMe "${JS_RUNTIME_DIR}")

set(BUILD_DIR "${CMAKE_SOURCE_DIR}/build")
set(ANDROID_CPP_DIR "${CMAKE_SOURCE_DIR}/src/main/cpp")
set(COMMON_CPP_DIR "${CMAKE_SOURCE_DIR}/../Common/cpp")

add_subdirectory("${ANDROID_CPP_DIR}/worklets")
Loading

0 comments on commit a47e6d4

Please sign in to comment.