Skip to content

Commit

Permalink
Merge branch 'main' into @tomekzaw/NSTextStorageDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Dec 21, 2024
2 parents b503121 + 6447ea9 commit 63f2af2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
11 changes: 10 additions & 1 deletion RNLiveMarkdown.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ react_native_node_modules_dir = ENV['REACT_NATIVE_NODE_MODULES_DIR'] || File.joi
react_native_json = JSON.parse(File.read(File.join(react_native_node_modules_dir, 'react-native/package.json')))
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

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 @@ -23,7 +27,11 @@ Pod::Spec.new do |s|
s.dependency "RNReanimated/worklets"

s.xcconfig = {
"OTHER_CFLAGS" => "$(inherited) -DREACT_NATIVE_MINOR_VERSION=#{react_native_minor_version}"
"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\"",
].join(' '),
}

install_modules_dependencies(s)
Expand All @@ -33,6 +41,7 @@ Pod::Spec.new do |s|
"react/renderer/textlayoutmanager/platform/ios",
"react/renderer/components/textinput/platform/ios",
])
add_dependency(s, "React-rendererconsistency")
end

if ENV['RCT_NEW_ARCH_ENABLED'] == '1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected void onAttachedToWindow() {
mReactEditText = (ReactEditText) previousSibling;
mTextWatcher = new MarkdownTextWatcher(mMarkdownUtils);
mReactEditText.addTextChangedListener(mTextWatcher);
applyNewStyles();
}
}

Expand Down
14 changes: 9 additions & 5 deletions apple/MarkdownFormatter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ - (void)formatAttributedString:(nonnull NSMutableAttributedString *)attributedSt
defaultTextAttributes:defaultTextAttributes];
}

RCTApplyBaselineOffset(attributedString);
[attributedString.string enumerateSubstringsInRange:NSMakeRange(0, attributedString.length)
options:NSStringEnumerationByLines | NSStringEnumerationSubstringNotRequired
usingBlock:^(NSString * _Nullable substring, NSRange substringRange, NSRange enclosingRange, BOOL * _Nonnull stop) {
RCTApplyBaselineOffset(attributedString, enclosingRange);
}];

/*
Calling `[attributedString addAttributes:defaultTextAttributes range:fullRange]` breaks the font for emojis.
Expand Down Expand Up @@ -133,12 +137,12 @@ - (void)applyRangeToAttributedString:(NSMutableAttributedString *)attributedStri
}
}

static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText, NSRange attributedTextRange)
{
__block CGFloat maximumLineHeight = 0;

[attributedText enumerateAttribute:NSParagraphStyleAttributeName
inRange:NSMakeRange(0, attributedText.length)
inRange:attributedTextRange
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
usingBlock:^(NSParagraphStyle *paragraphStyle, __unused NSRange range, __unused BOOL *stop) {
if (!paragraphStyle) {
Expand All @@ -156,7 +160,7 @@ static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
__block CGFloat maximumFontLineHeight = 0;

[attributedText enumerateAttribute:NSFontAttributeName
inRange:NSMakeRange(0, attributedText.length)
inRange:attributedTextRange
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
usingBlock:^(UIFont *font, NSRange range, __unused BOOL *stop) {
if (!font) {
Expand All @@ -173,7 +177,7 @@ static void RCTApplyBaselineOffset(NSMutableAttributedString *attributedText)
CGFloat baseLineOffset = (maximumLineHeight - maximumFontLineHeight) / 2.0;
[attributedText addAttribute:NSBaselineOffsetAttributeName
value:@(baseLineOffset)
range:NSMakeRange(0, attributedText.length)];
range:attributedTextRange];
}

@end
8 changes: 4 additions & 4 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.3)
- React-perflogger (= 0.75.3)
- React-utils (= 0.75.3)
- RNLiveMarkdown (0.1.208):
- RNLiveMarkdown (0.1.211):
- DoubleConversion
- glog
- hermes-engine
Expand All @@ -1517,10 +1517,10 @@ PODS:
- ReactCodegen
- ReactCommon/turbomodule/bridging
- ReactCommon/turbomodule/core
- RNLiveMarkdown/newarch (= 0.1.208)
- RNLiveMarkdown/newarch (= 0.1.211)
- RNReanimated/worklets
- Yoga
- RNLiveMarkdown/newarch (0.1.208):
- RNLiveMarkdown/newarch (0.1.211):
- DoubleConversion
- glog
- hermes-engine
Expand Down Expand Up @@ -1897,7 +1897,7 @@ SPEC CHECKSUMS:
React-utils: f2afa6acd905ca2ce7bb8ffb4a22f7f8a12534e8
ReactCodegen: e35c23cdd36922f6d2990c6c1f1b022ade7ad74d
ReactCommon: 289214026502e6a93484f4a46bcc0efa4f3f2864
RNLiveMarkdown: e8b7f5cf8a0e8027850a781ffc86119e21fb406a
RNLiveMarkdown: d14eeb66f85495e6d42829438cdd9cb72d253feb
RNReanimated: 75df06d3a81fc147b83056ae469512f573365b1d
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Yoga: 1354c027ab07c7736f99a3bef16172d6f1b12b47
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.208",
"version": "0.1.211",
"description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down

0 comments on commit 63f2af2

Please sign in to comment.