Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 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
28 changes: 22 additions & 6 deletions RNLiveMarkdown.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ react_native_json = JSON.parse(File.read(File.join(react_native_node_modules_dir
react_native_minor_version = react_native_json['version'].split('.')[1].to_i

pods_root = Pod::Config.instance.project_pods_root
react_native_reanimated_node_modules_dir = ENV['REACT_NATIVE_REANIMATED_NODE_MODULES_DIR'] || File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native-reanimated/package.json')"`)
react_native_reanimated_node_modules_dir_from_pods_root = Pathname.new(react_native_reanimated_node_modules_dir).relative_path_from(pods_root).to_s

worklets_installed = system(%Q[
cd "#{Pod::Config.instance.installation_root}" &&
node -e "require.resolve('react-native-worklets/package.json')" > /dev/null 2>&1
])
package_name = worklets_installed ? 'react-native-worklets/package.json' : 'react-native-reanimated/package.json'

react_native_worklets_node_modules_dir = ENV['REACT_NATIVE_REANIMATED_NODE_MODULES_DIR'] ||
File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('#{package_name}')"`)
react_native_worklets_node_modules_dir_from_pods_root = Pathname.new(react_native_worklets_node_modules_dir).relative_path_from(pods_root).to_s

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'
Expand All @@ -24,15 +32,23 @@ Pod::Spec.new do |s|

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

s.dependency "RNReanimated/worklets"
if worklets_installed
s.dependency "RNWorklets"
else
s.dependency "RNReanimated/worklets"
end

s.xcconfig = {
xcconfig = {
"OTHER_CFLAGS" => "$(inherited) -DREACT_NATIVE_MINOR_VERSION=#{react_native_minor_version}",
"HEADER_SEARCH_PATHS" => [
"\"$(PODS_ROOT)/#{react_native_reanimated_node_modules_dir_from_pods_root}/apple\"",
"\"$(PODS_ROOT)/#{react_native_reanimated_node_modules_dir_from_pods_root}/Common/cpp\"",
"\"$(PODS_ROOT)/#{react_native_worklets_node_modules_dir_from_pods_root}/apple\"",
"\"$(PODS_ROOT)/#{react_native_worklets_node_modules_dir_from_pods_root}/Common/cpp\"",
].join(' '),
}
if worklets_installed
xcconfig["OTHER_CFLAGS"] << " -DWORKLETS_INSTALLED=1"
end
s.xcconfig = xcconfig
Comment on lines 43 to 53
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work if we modify s.xcconfig directly (without xcconfig variable)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately not, I tried that at first but there was an error about modifying s.xcconfig

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, alternatively we can just have other_cflags string variable and append to it instead of having xcconfig variable


s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/cpp\"" }

Expand Down
21 changes: 17 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def getReactNativeMinorVersion() {
}

def REACT_NATIVE_MINOR_VERSION = getReactNativeMinorVersion()
def workletsInstalled = rootProject.findProject(':react-native-worklets') != null

android {
if (supportsNamespace()) {
Expand Down Expand Up @@ -94,7 +95,9 @@ android {
arguments "-DANDROID_STL=c++_shared",
"-DANDROID_TOOLCHAIN=clang",
"-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
"-DREACT_NATIVE_ROOT_DIR=${resolveReactNativeDirectory().path}",
"-DWORKLETS_INSTALLED=${workletsInstalled}"
abiFilters (*reactNativeArchitectures())
}
}
Expand Down Expand Up @@ -177,14 +180,24 @@ repositories {
dependencies {
implementation "com.facebook.react:react-android" // version substituted by RNGP
implementation "com.facebook.react:hermes-android" // version substituted by RNGP
implementation project(":react-native-reanimated")

if (workletsInstalled) {
implementation project(":react-native-worklets")
} else {
implementation project(":react-native-reanimated")
}
}

// This fixes linking errors due to undefined symbols from libworklets.so.
// During Gradle Sync, Android Gradle Plugin runs Prefab and treats worklets
// like a header-only library. During build, config files are not regenerated
// because the cache key does not change and AGP thinks that they are up-to-date.
afterEvaluate {
prepareKotlinBuildScriptModel.dependsOn(":react-native-reanimated:prefabDebugPackage")
prepareKotlinBuildScriptModel.dependsOn(":react-native-reanimated:prefabReleasePackage")
if (workletsInstalled) {
prepareKotlinBuildScriptModel.dependsOn(":react-native-worklets:prefabDebugPackage")
prepareKotlinBuildScriptModel.dependsOn(":react-native-worklets:prefabReleasePackage")
} else {
prepareKotlinBuildScriptModel.dependsOn(":react-native-reanimated:prefabDebugPackage")
prepareKotlinBuildScriptModel.dependsOn(":react-native-reanimated:prefabReleasePackage")
}
}
27 changes: 24 additions & 3 deletions android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ cmake_minimum_required(VERSION 3.13)

set(CMAKE_VERBOSE_MAKEFILE on)

if(WORKLETS_INSTALLED)
include("${REACT_NATIVE_ROOT_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake")
add_compile_options(${folly_FLAGS})
endif()

add_compile_options(-fvisibility=hidden -fexceptions -frtti)

string(APPEND CMAKE_CXX_FLAGS " -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}")
Expand All @@ -15,16 +20,32 @@ file(GLOB CPP_SRC CONFIGURE_DEPENDS "${CPP_DIR}/*.cpp")

add_library(${CMAKE_PROJECT_NAME} SHARED ${ANDROID_SRC} ${CPP_SRC})

target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CPP_DIR})
if(WORKLETS_INSTALLED)
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CPP_DIR} "${REACT_NATIVE_ROOT_DIR}/ReactCommon/jsiexecutor")
else()
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CPP_DIR})
endif()

find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
find_package(react-native-reanimated REQUIRED CONFIG)

if(WORKLETS_INSTALLED)
find_package(react-native-worklets REQUIRED CONFIG)
add_definitions(-DWORKLETS_INSTALLED)
else()
find_package(react-native-reanimated REQUIRED CONFIG)
endif()


target_link_libraries(
${CMAKE_PROJECT_NAME}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::reactnative
react-native-reanimated::worklets
)

if(WORKLETS_INSTALLED)
target_link_libraries(${CMAKE_PROJECT_NAME} react-native-worklets::worklets)
else()
target_link_libraries(${CMAKE_PROJECT_NAME} react-native-reanimated::worklets)
endif()
4 changes: 4 additions & 0 deletions apple/MarkdownParser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ @implementation MarkdownParser {
const auto &markdownRuntime = expensify::livemarkdown::getMarkdownRuntime();
jsi::Runtime &rt = markdownRuntime->getJSIRuntime();

#ifdef WORKLETS_INSTALLED
std::shared_ptr<SerializableWorklet> markdownWorklet;
#else
std::shared_ptr<ShareableWorklet> markdownWorklet;
#endif
try {
markdownWorklet = expensify::livemarkdown::getMarkdownWorklet([parserId intValue]);
} catch (const std::out_of_range &error) {
Expand Down
12 changes: 12 additions & 0 deletions cpp/MarkdownGlobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ std::shared_ptr<WorkletRuntime> getMarkdownRuntime() {
return globalMarkdownWorkletRuntime;
}

#ifdef WORKLETS_INSTALLED
std::unordered_map<int, std::shared_ptr<SerializableWorklet>> globalMarkdownShareableWorklets;
#else
std::unordered_map<int, std::shared_ptr<ShareableWorklet>> globalMarkdownShareableWorklets;
#endif
std::mutex globalMarkdownShareableWorkletsMutex;
int nextParserId = 1;

#ifdef WORKLETS_INSTALLED
const int registerMarkdownWorklet(const std::shared_ptr<SerializableWorklet> &markdownWorklet) {
#else
const int registerMarkdownWorklet(const std::shared_ptr<ShareableWorklet> &markdownWorklet) {
#endif
assert(markdownWorklet != nullptr);
auto parserId = nextParserId++;
std::unique_lock<std::mutex> lock(globalMarkdownShareableWorkletsMutex);
Expand All @@ -34,7 +42,11 @@ void unregisterMarkdownWorklet(const int parserId) {
globalMarkdownShareableWorklets.erase(parserId);
}

#ifdef WORKLETS_INSTALLED
std::shared_ptr<SerializableWorklet> getMarkdownWorklet(const int parserId) {
#else
std::shared_ptr<ShareableWorklet> getMarkdownWorklet(const int parserId) {
#endif
std::unique_lock<std::mutex> lock(globalMarkdownShareableWorkletsMutex);
return globalMarkdownShareableWorklets.at(parserId);
}
Expand Down
8 changes: 8 additions & 0 deletions cpp/MarkdownGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ void setMarkdownRuntime(const std::shared_ptr<WorkletRuntime> &markdownWorkletRu

std::shared_ptr<WorkletRuntime> getMarkdownRuntime();

#ifdef WORKLETS_INSTALLED
const int registerMarkdownWorklet(const std::shared_ptr<SerializableWorklet> &markdownWorklet);
#else
const int registerMarkdownWorklet(const std::shared_ptr<ShareableWorklet> &markdownWorklet);
#endif

void unregisterMarkdownWorklet(const int parserId);

#ifdef WORKLETS_INSTALLED
std::shared_ptr<SerializableWorklet> getMarkdownWorklet(const int parserId);
#else
std::shared_ptr<ShareableWorklet> getMarkdownWorklet(const int parserId);
#endif

} // namespace livemarkdown
} // namespace expensify
4 changes: 4 additions & 0 deletions cpp/RuntimeDecorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ void injectJSIBindings(jsi::Runtime &rt) {
jsi::PropNameID::forAscii(rt, "jsi_registerMarkdownWorklet"),
1,
[](jsi::Runtime &rt, const jsi::Value &thisValue, const jsi::Value *args, size_t count) -> jsi::Value {
#ifdef WORKLETS_INSTALLED
auto parserId = registerMarkdownWorklet(extractSerializableOrThrow<SerializableWorklet>(rt, args[0]));
#else
auto parserId = registerMarkdownWorklet(extractShareableOrThrow<ShareableWorklet>(rt, args[0]));
#endif
return jsi::Value(parserId);
}));

Expand Down
10 changes: 9 additions & 1 deletion example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
const path = require('path');
const pak = require('../package.json');

let workletsPlugin = null;
try {
require.resolve('react-native-worklets');
workletsPlugin = 'react-native-worklets/plugin';
} catch (e) {
workletsPlugin = 'react-native-reanimated/plugin';
}

module.exports = {
presets: ['module:@react-native/babel-preset'],
plugins: [
Expand All @@ -13,6 +21,6 @@ module.exports = {
},
},
],
'react-native-reanimated/plugin',
workletsPlugin,
],
};
86 changes: 13 additions & 73 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2253,7 +2253,7 @@ PODS:
- React-perflogger (= 0.81.4)
- React-utils (= 0.81.4)
- SocketRocket
- RNLiveMarkdown (0.1.303):
- RNLiveMarkdown (0.1.305):
- boost
- DoubleConversion
- fast_float
Expand All @@ -2279,10 +2279,10 @@ PODS:
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/worklets
- RNWorklets
- SocketRocket
- Yoga
- RNReanimated (3.19.0):
- RNWorklets (0.6.0):
- boost
- DoubleConversion
- fast_float
Expand All @@ -2309,11 +2309,10 @@ PODS:
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/reanimated (= 3.19.0)
- RNReanimated/worklets (= 3.19.0)
- RNWorklets/worklets (= 0.6.0)
- SocketRocket
- Yoga
- RNReanimated/reanimated (3.19.0):
- RNWorklets/worklets (0.6.0):
- boost
- DoubleConversion
- fast_float
Expand All @@ -2340,69 +2339,10 @@ PODS:
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/reanimated/apple (= 3.19.0)
- RNWorklets/worklets/apple (= 0.6.0)
- SocketRocket
- Yoga
- RNReanimated/reanimated/apple (3.19.0):
- boost
- DoubleConversion
- fast_float
- fmt
- glog
- hermes-engine
- RCT-Folly
- RCT-Folly/Fabric
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-hermes
- React-ImageManager
- React-jsi
- React-NativeModulesApple
- React-RCTFabric
- React-renderercss
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- SocketRocket
- Yoga
- RNReanimated/worklets (3.19.0):
- boost
- DoubleConversion
- fast_float
- fmt
- glog
- hermes-engine
- RCT-Folly
- RCT-Folly/Fabric
- RCTRequired
- RCTTypeSafety
- React-Core
- React-debug
- React-Fabric
- React-featureflags
- React-graphics
- React-hermes
- React-ImageManager
- React-jsi
- React-NativeModulesApple
- React-RCTFabric
- React-renderercss
- React-rendererdebug
- React-utils
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNReanimated/worklets/apple (= 3.19.0)
- SocketRocket
- Yoga
- RNReanimated/worklets/apple (3.19.0):
- RNWorklets/worklets/apple (0.6.0):
- boost
- DoubleConversion
- fast_float
Expand Down Expand Up @@ -2507,7 +2447,7 @@ DEPENDENCIES:
- ReactCodegen (from `build/generated/ios`)
- ReactCommon/turbomodule/core (from `../../node_modules/react-native/ReactCommon`)
- RNLiveMarkdown (from `../..`)
- RNReanimated (from `../../node_modules/react-native-reanimated`)
- RNWorklets (from `../../node_modules/react-native-worklets`)
- SocketRocket (~> 0.7.1)
- Yoga (from `../../node_modules/react-native/ReactCommon/yoga`)

Expand Down Expand Up @@ -2659,8 +2599,8 @@ EXTERNAL SOURCES:
:path: "../../node_modules/react-native/ReactCommon"
RNLiveMarkdown:
:path: "../.."
RNReanimated:
:path: "../../node_modules/react-native-reanimated"
RNWorklets:
:path: "../../node_modules/react-native-worklets"
Yoga:
:path: "../../node_modules/react-native/ReactCommon/yoga"

Expand Down Expand Up @@ -2735,10 +2675,10 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: 433ddfb4536948630aadd5bd925aff8a632d2fe3
ReactCodegen: adf5027f30e34c68b5a09f0b68acb3e5ef9e1a5d
ReactCommon: 394c6b92765cf6d211c2c3f7f6bc601dffb316a6
RNLiveMarkdown: 0a98549fd315dc5fdc8b7ed937fdd6414d47565f
RNReanimated: 08fa7bb56d5f6d47c32245cf9cf53efb19befa0c
RNLiveMarkdown: 30f59122c1f27ea2ec2ad43935b1be214e10c697
RNWorklets: 3302bb9ae6518de0d19e37ae770fec85a8780a72
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: 922d794dce2af9c437f864bf4093abfa7a131adb
Yoga: a3ed390a19db0459bd6839823a6ac6d9c6db198d

PODFILE CHECKSUM: 3f53660915b3f926239de7f89ab29581306a2614

Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"expensify-common": "2.0.148",
"react": "19.1.0",
"react-native": "0.81.4",
"react-native-reanimated": "3.19.0"
"react-native-worklets": "0.6.0"
},
"devDependencies": {
"@babel/core": "^7.25.2",
Expand Down
Loading
Loading