Skip to content

Commit 833fc06

Browse files
committed
Merge branch 'main' into @jpiasecki/display-contents
2 parents d20dee8 + 9f0f2a7 commit 833fc06

7 files changed

+52
-188
lines changed

apple/MarkdownTextInputDecoratorComponentView.mm

+43-43
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
1+
#import <react/debug/react_native_assert.h>
12
#import <react/renderer/components/RNLiveMarkdownSpec/Props.h>
2-
3-
#import <RNLiveMarkdown/MarkdownTextInputDecoratorComponentView.h>
4-
#import <RNLiveMarkdown/RCTMarkdownStyle.h>
5-
6-
#import <RNLiveMarkdown/MarkdownTextInputDecoratorViewComponentDescriptor.h>
7-
#import "RCTFabricComponentsPlugins.h"
8-
3+
#import <React/RCTFabricComponentsPlugins.h>
94
#import <React/RCTUITextField.h>
10-
#import "react_native_assert.h"
115

126
#import <RNLiveMarkdown/MarkdownLayoutManager.h>
13-
#import <RNLiveMarkdown/MarkdownTextInputDecoratorView.h>
7+
#import <RNLiveMarkdown/MarkdownTextInputDecoratorComponentView.h>
8+
#import <RNLiveMarkdown/MarkdownTextInputDecoratorViewComponentDescriptor.h>
149
#import <RNLiveMarkdown/RCTBackedTextFieldDelegateAdapter+Markdown.h>
15-
#import <RNLiveMarkdown/RCTUITextView+Markdown.h>
16-
10+
#import <RNLiveMarkdown/RCTMarkdownStyle.h>
1711
#import <RNLiveMarkdown/RCTTextInputComponentView+Markdown.h>
12+
#import <RNLiveMarkdown/RCTUITextView+Markdown.h>
1813

1914
#import <objc/runtime.h>
2015

2116
using namespace facebook::react;
2217

2318
@implementation MarkdownTextInputDecoratorComponentView {
24-
RCTMarkdownUtils *_markdownUtils;
25-
RCTMarkdownStyle *_markdownStyle;
26-
NSNumber *_parserId;
27-
__weak RCTTextInputComponentView *_textInput;
28-
__weak UIView<RCTBackedTextInputViewProtocol> *_backedTextInputView;
29-
__weak RCTBackedTextFieldDelegateAdapter *_adapter;
30-
__weak RCTUITextView *_textView;
19+
RCTMarkdownUtils *_markdownUtils;
20+
RCTMarkdownStyle *_markdownStyle;
21+
NSNumber *_parserId;
22+
__weak RCTTextInputComponentView *_textInput;
23+
__weak UIView<RCTBackedTextInputViewProtocol> *_backedTextInputView;
24+
__weak RCTBackedTextFieldDelegateAdapter *_adapter;
25+
__weak RCTUITextView *_textView;
3126
}
3227

3328
+ (ComponentDescriptorProvider)componentDescriptorProvider
@@ -88,21 +83,21 @@ - (void)didAddSubview:(UIView *)subview
8883

8984
- (void)willMoveToWindow:(UIWindow *)newWindow
9085
{
91-
if (newWindow == nil) {
92-
if (_textInput != nil) {
93-
[_textInput setMarkdownUtils:nil];
94-
}
95-
if (_adapter != nil) {
96-
[_adapter setMarkdownUtils:nil];
97-
}
98-
if (_textView != nil) {
99-
[_textView setMarkdownUtils:nil];
100-
if (_textView.layoutManager != nil && [object_getClass(_textView.layoutManager) isEqual:[MarkdownLayoutManager class]]) {
101-
[_textView.layoutManager setValue:nil forKey:@"markdownUtils"];
102-
object_setClass(_textView.layoutManager, [NSLayoutManager class]);
103-
}
104-
}
86+
if (newWindow == nil) {
87+
if (_textInput != nil) {
88+
[_textInput setMarkdownUtils:nil];
10589
}
90+
if (_adapter != nil) {
91+
[_adapter setMarkdownUtils:nil];
92+
}
93+
if (_textView != nil) {
94+
[_textView setMarkdownUtils:nil];
95+
if (_textView.layoutManager != nil && [object_getClass(_textView.layoutManager) isEqual:[MarkdownLayoutManager class]]) {
96+
[_textView.layoutManager setValue:nil forKey:@"markdownUtils"];
97+
object_setClass(_textView.layoutManager, [NSLayoutManager class]);
98+
}
99+
}
100+
}
106101
}
107102

108103
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
@@ -111,26 +106,31 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
111106
const auto &newViewProps = *std::static_pointer_cast<MarkdownTextInputDecoratorViewProps const>(props);
112107

113108
if (oldViewProps.parserId != newViewProps.parserId) {
114-
_parserId = [NSNumber numberWithInt:newViewProps.parserId];
109+
_parserId = @(newViewProps.parserId);
115110
[_markdownUtils setParserId:_parserId];
116111
}
117112

118113
// TODO: if (oldViewProps.markdownStyle != newViewProps.markdownStyle)
119-
RCTMarkdownStyle *markdownStyle = [[RCTMarkdownStyle alloc] initWithStruct:newViewProps.markdownStyle];
120-
_markdownStyle = markdownStyle;
121-
[_markdownUtils setMarkdownStyle:markdownStyle];
114+
_markdownStyle = [[RCTMarkdownStyle alloc] initWithStruct:newViewProps.markdownStyle];
115+
[_markdownUtils setMarkdownStyle:_markdownStyle];
122116

123-
if (_textView != nil) {
124-
// We want to use `textStorage` for applying markdown when possible. Currently it's only available for UITextView
125-
[_textView textDidChange];
126-
} else {
127-
// apply new styles
128-
[_textInput _setAttributedString:_backedTextInputView.attributedText];
129-
}
117+
// TODO: call applyNewStyles only if needed
118+
[self applyNewStyles];
130119

131120
[super updateProps:props oldProps:oldProps];
132121
}
133122

123+
- (void)applyNewStyles
124+
{
125+
if (_textView != nil) {
126+
// We want to use `textStorage` for applying markdown when possible. Currently it's only available for UITextView
127+
[_textView textDidChange];
128+
} else {
129+
// apply new styles
130+
[_textInput _setAttributedString:_backedTextInputView.attributedText];
131+
}
132+
}
133+
134134
Class<RCTComponentViewProtocol> MarkdownTextInputDecoratorViewCls(void)
135135
{
136136
return MarkdownTextInputDecoratorComponentView.class;

apple/MarkdownTextInputDecoratorView.h

-14
This file was deleted.

apple/MarkdownTextInputDecoratorView.mm

-110
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
#import <RNLiveMarkdown/MarkdownTextInputDecoratorViewManager.h>
2-
#import <RNLiveMarkdown/MarkdownTextInputDecoratorView.h>
32

43
@implementation MarkdownTextInputDecoratorViewManager
54

65
RCT_EXPORT_MODULE(MarkdownTextInputDecoratorView)
76

8-
- (UIView *)view
9-
{
10-
return [[MarkdownTextInputDecoratorView alloc] init];
11-
}
7+
RCT_EXPORT_VIEW_PROPERTY(markdownStyle, NSDictionary)
128

13-
RCT_CUSTOM_VIEW_PROPERTY(markdownStyle, NSDictionary, MarkdownTextInputDecoratorView)
14-
{
15-
// implemented in MarkdownTextInputDecoratorView updateProps:
16-
}
17-
18-
RCT_CUSTOM_VIEW_PROPERTY(parserId, NSNumber, MarkdownTextInputDecoratorView)
19-
{
20-
// implemented in MarkdownTextInputDecoratorView updateProps:
21-
}
9+
RCT_EXPORT_VIEW_PROPERTY(parserId, NSNumber)
2210

2311
@end

example/ios/Podfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ PODS:
14991499
- React-logger (= 0.77.0)
15001500
- React-perflogger (= 0.77.0)
15011501
- React-utils (= 0.77.0)
1502-
- RNLiveMarkdown (0.1.245):
1502+
- RNLiveMarkdown (0.1.247):
15031503
- DoubleConversion
15041504
- glog
15051505
- hermes-engine
@@ -1519,10 +1519,10 @@ PODS:
15191519
- ReactCodegen
15201520
- ReactCommon/turbomodule/bridging
15211521
- ReactCommon/turbomodule/core
1522-
- RNLiveMarkdown/newarch (= 0.1.245)
1522+
- RNLiveMarkdown/newarch (= 0.1.247)
15231523
- RNReanimated/worklets
15241524
- Yoga
1525-
- RNLiveMarkdown/newarch (0.1.245):
1525+
- RNLiveMarkdown/newarch (0.1.247):
15261526
- DoubleConversion
15271527
- glog
15281528
- hermes-engine
@@ -1947,7 +1947,7 @@ SPEC CHECKSUMS:
19471947
ReactAppDependencyProvider: 6e8d68583f39dc31ee65235110287277eb8556ef
19481948
ReactCodegen: b793571cdd05c69db98095ccfca381d45f709d89
19491949
ReactCommon: 1bd2dc684d7992acbf0dfee887b89a57a1ead86d
1950-
RNLiveMarkdown: 4c890c3b7d182b39d04153d2f636147a55ebe078
1950+
RNLiveMarkdown: cc21d7eed5a7addab9db31853b35b5a19a54f2f9
19511951
RNReanimated: 087d081f33387098097765f5a845f52c4abe2a3f
19521952
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
19531953
Yoga: c0d8564af14a858f962607cd7306539cb2ace926

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@expensify/react-native-live-markdown",
3-
"version": "0.1.245",
3+
"version": "0.1.247",
44
"description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
 (0)