Skip to content

Commit

Permalink
Merge branch 'main' into @tomekzaw/fix-height-update-delay
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Sep 12, 2024
2 parents 1f1fe63 + 25b47bb commit 1c6ca0e
Show file tree
Hide file tree
Showing 22 changed files with 149 additions and 106 deletions.
6 changes: 3 additions & 3 deletions RNLiveMarkdown.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ Pod::Spec.new do |s|

install_modules_dependencies(s)

if ENV['USE_FRAMEWORKS'] && ENV['RCT_NEW_ARCH_ENABLED']
add_dependency(s, "React-Fabric", :additional_framework_paths => [
if ENV['USE_FRAMEWORKS'] != nil && ENV['RCT_NEW_ARCH_ENABLED'] == '1'
add_dependency(s, "React-FabricComponents", :additional_framework_paths => [
"react/renderer/textlayoutmanager/platform/ios",
"react/renderer/components/textinput/iostextinput",
"react/renderer/components/textinput/platform/ios",
])
end

Expand Down
20 changes: 15 additions & 5 deletions android/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,18 @@ find_package(fbjni REQUIRED CONFIG)
find_package(ReactAndroid REQUIRED CONFIG)
find_package(hermes-engine REQUIRED CONFIG)

target_link_libraries(${CMAKE_PROJECT_NAME}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::reactnativejni
hermes-engine::libhermes)
if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
target_link_libraries(${CMAKE_PROJECT_NAME}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::reactnative
hermes-engine::libhermes)
elseif (ReactAndroid_VERSION_MINOR GREATER_EQUAL 75)
target_link_libraries(${CMAKE_PROJECT_NAME}
fbjni::fbjni
ReactAndroid::jsi
ReactAndroid::reactnativejni
hermes-engine::libhermes)
else ()
message(FATAL_ERROR "react-native-live-markdown requires react-native 0.75 or newer.")
endif ()
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
public class MarkdownTextWatcher implements TextWatcher {
private final MarkdownUtils mMarkdownUtils;

private boolean mShouldSkip = false;

public MarkdownTextWatcher(@NonNull MarkdownUtils markdownUtils) {
mMarkdownUtils = markdownUtils;
}
Expand All @@ -22,17 +20,13 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) {

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (mShouldSkip) {
return;
}
if (s instanceof SpannableStringBuilder) {
mMarkdownUtils.applyMarkdownFormatting((SpannableStringBuilder) s);
mShouldSkip = true;
}

}

@Override
public void afterTextChanged(Editable editable) {
mShouldSkip = false;
if (editable instanceof SpannableStringBuilder) {
mMarkdownUtils.applyMarkdownFormatting((SpannableStringBuilder) editable);
}
}
}
83 changes: 47 additions & 36 deletions android/src/main/new_arch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,53 @@ target_include_directories(

find_package(ReactAndroid REQUIRED CONFIG)

target_link_libraries(
${LIB_TARGET_NAME}
ReactAndroid::rrc_text
ReactAndroid::rrc_textinput
ReactAndroid::react_render_textlayoutmanager
ReactAndroid::react_render_imagemanager
ReactAndroid::reactnativejni
ReactAndroid::mapbufferjni
fabricjni
fbjni
folly_runtime
glog
jsi
react_codegen_rncore
react_debug
react_nativemodule_core
react_render_core
react_render_debug
react_render_graphics
react_render_mapbuffer
ReactAndroid::react_render_uimanager
ReactAndroid::react_render_scheduler
react_utils
runtimeexecutor
rrc_view
turbomodulejsijni
yoga
android
log
mapbufferjni
reactnativejni
react_render_consistency
react_performance_timeline
react_render_observers_events
react_featureflags
)
if (ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
target_link_libraries(
${LIB_TARGET_NAME}
ReactAndroid::reactnative
ReactAndroid::jsi
fbjni::fbjni
)
elseif (ReactAndroid_VERSION_MINOR GREATER_EQUAL 75)
target_link_libraries(
${LIB_TARGET_NAME}
ReactAndroid::rrc_text
ReactAndroid::rrc_textinput
ReactAndroid::react_render_textlayoutmanager
ReactAndroid::react_render_imagemanager
ReactAndroid::reactnativejni
ReactAndroid::mapbufferjni
fabricjni
fbjni
folly_runtime
glog
jsi
react_codegen_rncore
react_debug
react_nativemodule_core
react_render_core
react_render_debug
react_render_graphics
react_render_mapbuffer
ReactAndroid::react_render_uimanager
ReactAndroid::react_render_scheduler
react_utils
runtimeexecutor
rrc_view
turbomodulejsijni
yoga
android
log
mapbufferjni
reactnativejni
react_render_consistency
react_performance_timeline
react_render_observers_events
react_featureflags
)
else ()
message(FATAL_ERROR "react-native-live-markdown requires react-native 0.75 or newer.")
endif ()

target_compile_options(
${LIB_TARGET_NAME}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "MarkdownShadowFamilyRegistry.h"

namespace expensify {
namespace livemarkdown {

std::set<facebook::react::ShadowNodeFamily::Shared>
MarkdownShadowFamilyRegistry::familiesToUpdate_;
std::set<facebook::react::Tag> MarkdownShadowFamilyRegistry::forcedUpdates_;
Expand Down Expand Up @@ -55,4 +58,7 @@ bool MarkdownShadowFamilyRegistry::shouldForceUpdate(facebook::react::Tag tag) {
return false;
}

} // namespace livemarkdown
} // namespace expensify

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#include <mutex>
#include <set>

namespace expensify {
namespace livemarkdown {

// A registry to store pointers to the ShadowNodeFamilies of markdown
// decorators. The only place we can _legally_ access the family of shadow node
// is in the constructor and we need it inside commit hook. To achieve it, we
Expand All @@ -32,4 +35,7 @@ class MarkdownShadowFamilyRegistry {
static std::mutex mutex_;
};

} // namespace livemarkdown
} // namespace expensify

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "MarkdownShadowFamilyRegistry.h"
#include "MarkdownTextInputDecoratorShadowNode.h"

using namespace expensify::livemarkdown;

namespace facebook {
namespace react {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <react/renderer/components/RNLiveMarkdownSpec/Props.h>
#include <react/renderer/components/view/ConcreteViewShadowNode.h>

using namespace expensify::livemarkdown;

namespace facebook {
namespace react {

Expand Down
16 changes: 8 additions & 8 deletions example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ extensions.configure(com.facebook.react.ReactSettingsExtension){ ex -> ex.autoli
rootProject.name = 'LiveMarkdownExample'
include ':app'
includeBuild('../node_modules/@react-native/gradle-plugin')
includeBuild('../node_modules/react-native') {
dependencySubstitution {
substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid"))
substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid"))
substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
}
}
// includeBuild('../node_modules/react-native') {
// dependencySubstitution {
// substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid"))
// substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid"))
// substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
// substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
// }
// }
10 changes: 5 additions & 5 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ PODS:
- React-logger (= 0.75.2)
- React-perflogger (= 0.75.2)
- React-utils (= 0.75.2)
- RNLiveMarkdown (0.1.128):
- RNLiveMarkdown (0.1.137):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -1517,9 +1517,9 @@ PODS:
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNLiveMarkdown/common (= 0.1.128)
- RNLiveMarkdown/common (= 0.1.137)
- Yoga
- RNLiveMarkdown/common (0.1.128):
- RNLiveMarkdown/common (0.1.137):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1805,10 +1805,10 @@ SPEC CHECKSUMS:
React-utils: 81a715d9c0a2a49047e77a86f3a2247408540deb
ReactCodegen: 60973d382704c793c605b9be0fc7f31cb279442f
ReactCommon: 6ef348087d250257c44c0204461c03f036650e9b
RNLiveMarkdown: 44cc9af8742cfd5355733d29fa54e64e4edf0f0d
RNLiveMarkdown: b2d706acf1bbd968b8dab0be0dc69f130a14db6d
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Yoga: 2a45d7e59592db061217551fd3bbe2dd993817ae

PODFILE CHECKSUM: 9b81b0f7bfba9e6fb4fa10efe8319f7860794e08

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
2 changes: 2 additions & 0 deletions ios/MarkdownCommitHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using namespace facebook::react;

namespace expensify {
namespace livemarkdown {

struct MarkdownTextInputDecoratorPair {
Expand Down Expand Up @@ -38,5 +39,6 @@ class MarkdownCommitHook : public UIManagerCommitHook {
};

} // namespace livemarkdown
} // namespace expensify

#endif // RCT_NEW_ARCH_ENABLED
2 changes: 2 additions & 0 deletions ios/MarkdownCommitHook.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using namespace facebook::react;

namespace expensify {
namespace livemarkdown {

MarkdownCommitHook::MarkdownCommitHook(
Expand Down Expand Up @@ -239,5 +240,6 @@
}

} // namespace livemarkdown
} // namespace expensify

#endif // RCT_NEW_ARCH_ENABLED
4 changes: 4 additions & 0 deletions ios/RCTLiveMarkdownModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
#import <React/RCTEventEmitter.h>
#import <React/RCTUIManager.h>

NS_ASSUME_NONNULL_BEGIN

// Without inheriting after RCTEventEmitter we don't get access to bridge
@interface RCTLiveMarkdownModule
: RCTEventEmitter <NativeLiveMarkdownModuleSpec>
@end

NS_ASSUME_NONNULL_END

#endif // RCT_NEW_ARCH_ENABLED
7 changes: 4 additions & 3 deletions ios/RCTLiveMarkdownModule.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
#import "MarkdownShadowFamilyRegistry.h"
#import "RCTLiveMarkdownModule.h"

using namespace expensify::livemarkdown;

// A turbomodule used to register the commit hook
// I think this is the easiest way to access the UIManager, which we need to
// actually register the hook

@implementation RCTLiveMarkdownModule {
BOOL installed_;
std::shared_ptr<livemarkdown::MarkdownCommitHook> commitHook_;
std::shared_ptr<MarkdownCommitHook> commitHook_;
__weak RCTSurfacePresenter *surfacePresenter_;
}

Expand All @@ -23,8 +25,7 @@ - (NSNumber *)install {
if (!installed_ && surfacePresenter_ != nil) {
RCTScheduler *scheduler = [surfacePresenter_ scheduler];

commitHook_ =
std::make_shared<livemarkdown::MarkdownCommitHook>(scheduler.uiManager);
commitHook_ = std::make_shared<MarkdownCommitHook>(scheduler.uiManager);
installed_ = YES;
}
return @1;
Expand Down
2 changes: 2 additions & 0 deletions ios/RCTTextInputComponentView+Markdown.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#import "MarkdownShadowFamilyRegistry.h"

using namespace expensify::livemarkdown;

@implementation RCTTextInputComponentView (Markdown)

- (void)setMarkdownUtils:(RCTMarkdownUtils *)markdownUtils {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@expensify/react-native-live-markdown",
"version": "0.1.133",
"version": "0.1.141",
"description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
2 changes: 1 addition & 1 deletion parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
"typescript": "^5.3.3"
},
"dependencies": {
"expensify-common": "2.0.76"
"expensify-common": "2.0.85"
}
}
32 changes: 16 additions & 16 deletions parser/react-native-live-markdown-parser.js

Large diffs are not rendered by default.

Loading

0 comments on commit 1c6ca0e

Please sign in to comment.