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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
First, install the library from npm with the package manager of your choice:

```sh
yarn add @expensify/react-native-live-markdown react-native-reanimated expensify-common [email protected]
npm install @expensify/react-native-live-markdown react-native-reanimated expensify-common [email protected] --save
npx expo install @expensify/react-native-live-markdown react-native-reanimated expensify-common [email protected]
yarn add @expensify/react-native-live-markdown react-native-worklets expensify-common [email protected]
npm install @expensify/react-native-live-markdown react-native-worklets expensify-common [email protected] --save
npx expo install @expensify/react-native-live-markdown react-native-worklets expensify-common [email protected]
```

React Native Live Markdown requires [react-native-reanimated](https://github.com/software-mansion/react-native-reanimated) 3.17.0 or newer as well as [expensify-common](https://github.com/Expensify/expensify-common) 2.0.115 and [html-entities](https://github.com/mdevils/html-entities) 2.5.3 exactly if using the default built-in ExpensiMark parser.
React Native Live Markdown requires [react-native-worklets](https://github.com/software-mansion/react-native-reanimated/tree/main/packages/react-native-worklets) 0.6.0 or newer as well as [expensify-common](https://github.com/Expensify/expensify-common) 2.0.115 and [html-entities](https://github.com/mdevils/html-entities) 2.5.3 exactly if using the default built-in ExpensiMark parser.

Then, install the iOS dependencies with CocoaPods:

Expand Down Expand Up @@ -148,7 +148,7 @@ Currently, only the following types are supported:
type MarkdownType = 'bold' | 'italic' | 'strikethrough' | 'emoji' | 'mention-here' | 'mention-user' | 'mention-report' | 'link' | 'code' | 'pre' | 'blockquote' | 'h1' | 'syntax';
```

Parser needs to be marked as a [worklet](https://docs.swmansion.com/react-native-reanimated/docs/guides/worklets/) because it's executed on the UI thread as the user types.
Parser needs to be marked as a [worklet](https://docs.swmansion.com/react-native-worklets/docs/fundamentals/glossary#worklet) because it's executed on the UI thread as the user types.

Here's a sample function that parses all substrings located between two asterisks as bold text:

Expand Down
27 changes: 7 additions & 20 deletions RNLiveMarkdown.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ 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_worklets_path = `cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native-worklets/package.json')"`
worklets_installed = react_native_worklets_path != ""
worklets_package_name = worklets_installed ? 'react-native-worklets' : 'react-native-reanimated'

react_native_worklets_or_reanimated_node_modules_dir = ENV['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('#{worklets_package_name}/package.json')"`)
react_native_worklets_or_reanimated_node_modules_dir_from_pods_root = Pathname.new(react_native_worklets_or_reanimated_node_modules_dir).relative_path_from(pods_root).to_s
react_native_worklets_node_modules_dir = ENV['REACT_NATIVE_WORKLETS_NODE_MODULES_DIR'] ||
File.dirname(`cd "#{Pod::Config.instance.installation_root.to_s}" && node --print "require.resolve('react-native-worklets/package.json')"`)
react_native_worklets_node_modules_dir_from_pods_root = Pathname.new(react_native_worklets_node_modules_dir).relative_path_from(pods_root).to_s

react_native_react_common_dir = File.join(react_native_node_modules_dir, 'react-native/ReactCommon')
react_native_react_common_dir_from_pods_root = Pathname.new(react_native_react_common_dir).relative_path_from(pods_root).to_s
Expand All @@ -33,24 +28,16 @@ Pod::Spec.new do |s|

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

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

xcconfig = {
s.xcconfig = {
"OTHER_CFLAGS" => "$(inherited) -DREACT_NATIVE_MINOR_VERSION=#{react_native_minor_version}",
"HEADER_SEARCH_PATHS" => [
"\"$(PODS_ROOT)/#{react_native_worklets_or_reanimated_node_modules_dir_from_pods_root}/apple\"",
"\"$(PODS_ROOT)/#{react_native_worklets_or_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\"",
"\"$(PODS_ROOT)/#{react_native_react_common_dir_from_pods_root}\"",
].join(' '),
}
if worklets_installed
xcconfig["OTHER_CFLAGS"] << " -DWORKLETS_INSTALLED=1"
end
s.xcconfig = xcconfig

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

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

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

android {
if (supportsNamespace()) {
Expand Down Expand Up @@ -96,8 +95,7 @@ android {
"-DANDROID_TOOLCHAIN=clang",
"-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
"-DREACT_NATIVE_ROOT_DIR=${resolveReactNativeDirectory().path}",
"-DWORKLETS_INSTALLED=${workletsInstalled}"
"-DREACT_NATIVE_ROOT_DIR=${resolveReactNativeDirectory().path}"
abiFilters (*reactNativeArchitectures())
}
}
Expand Down Expand Up @@ -180,24 +178,14 @@ repositories {
dependencies {
implementation "com.facebook.react:react-android" // version substituted by RNGP
implementation "com.facebook.react:hermes-android" // version substituted by RNGP

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

// 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 {
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")
}
prepareKotlinBuildScriptModel.dependsOn(":react-native-worklets:prefabDebugPackage")
prepareKotlinBuildScriptModel.dependsOn(":react-native-worklets:prefabReleasePackage")
}
28 changes: 5 additions & 23 deletions android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ 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()
include("${REACT_NATIVE_ROOT_DIR}/ReactAndroid/cmake-utils/folly-flags.cmake")
add_compile_options(${folly_FLAGS})

add_compile_options(-fvisibility=hidden -fexceptions -frtti)

Expand All @@ -20,32 +18,16 @@ file(GLOB CPP_SRC CONFIGURE_DEPENDS "${CPP_DIR}/*.cpp")

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

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()
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CPP_DIR} "${REACT_NATIVE_ROOT_DIR}/ReactCommon/jsiexecutor")

find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid 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()

find_package(react-native-worklets REQUIRED CONFIG)

target_link_libraries(
${CMAKE_PROJECT_NAME}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::reactnative
react-native-worklets::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: 0 additions & 4 deletions apple/MarkdownParser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ @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
4 changes: 0 additions & 4 deletions cpp/MarkdownGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ using namespace worklets;
namespace expensify {
namespace livemarkdown {

#ifndef WORKLETS_INSTALLED
using SerializableWorklet = ShareableWorklet; // ShareableWorklet was renamed to SerializableWorklet
#endif

void setMarkdownRuntime(const std::shared_ptr<WorkletRuntime> &markdownWorkletRuntime);

std::shared_ptr<WorkletRuntime> getMarkdownRuntime();
Expand Down
7 changes: 1 addition & 6 deletions cpp/RuntimeDecorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ 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 worklet = extractSerializableOrThrow<SerializableWorklet>(rt, args[0]);
#else
auto worklet = extractShareableOrThrow<SerializableWorklet>(rt, args[0]);
#endif
auto parserId = registerMarkdownWorklet(worklet);
const auto parserId = registerMarkdownWorklet(extractSerializableOrThrow<SerializableWorklet>(rt, args[0]));
return jsi::Value(parserId);
}));

Expand Down
10 changes: 1 addition & 9 deletions example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
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 @@ -21,6 +13,6 @@ module.exports = {
},
},
],
workletsPlugin,
'react-native-worklets/plugin',
],
};
100 changes: 2 additions & 98 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.314):
- RNLiveMarkdown (0.1.315):
- boost
- DoubleConversion
- fast_float
Expand Down Expand Up @@ -2282,98 +2282,6 @@ PODS:
- RNWorklets
- SocketRocket
- Yoga
- RNReanimated (4.1.3):
- 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/reanimated (= 4.1.3)
- RNWorklets
- SocketRocket
- Yoga
- RNReanimated/reanimated (4.1.3):
- 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/reanimated/apple (= 4.1.3)
- RNWorklets
- SocketRocket
- Yoga
- RNReanimated/reanimated/apple (4.1.3):
- 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
- RNWorklets
- SocketRocket
- Yoga
- RNWorklets (0.6.1):
- boost
- DoubleConversion
Expand Down Expand Up @@ -2539,7 +2447,6 @@ 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 @@ -2692,8 +2599,6 @@ 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:
Expand Down Expand Up @@ -2770,8 +2675,7 @@ SPEC CHECKSUMS:
ReactAppDependencyProvider: 433ddfb4536948630aadd5bd925aff8a632d2fe3
ReactCodegen: adf5027f30e34c68b5a09f0b68acb3e5ef9e1a5d
ReactCommon: 394c6b92765cf6d211c2c3f7f6bc601dffb316a6
RNLiveMarkdown: 438d2f94171d69be01ac4a32ec607a6339eede39
RNReanimated: e04fc279d4e0d936a27f50c9a170cfa269c3434d
RNLiveMarkdown: dc31d8eeff71886ccb18174114a77edb421829fc
RNWorklets: 879b69a98caa893353b964b6fece154a819145af
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: a3ed390a19db0459bd6839823a6ac6d9c6db198d
Expand Down
1 change: 0 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"expensify-common": "2.0.148",
"react": "19.1.0",
"react-native": "0.81.4",
"react-native-reanimated": "4.1.3",
"react-native-worklets": "0.6.1"
},
"devDependencies": {
Expand Down
Loading
Loading