1
+ #import < react/debug/react_native_assert.h>
1
2
#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>
9
4
#import < React/RCTUITextField.h>
10
- #import " react_native_assert.h"
11
5
12
6
#import < RNLiveMarkdown/MarkdownLayoutManager.h>
13
- #import < RNLiveMarkdown/MarkdownTextInputDecoratorView.h>
7
+ #import < RNLiveMarkdown/MarkdownTextInputDecoratorComponentView.h>
8
+ #import < RNLiveMarkdown/MarkdownTextInputDecoratorViewComponentDescriptor.h>
14
9
#import < RNLiveMarkdown/RCTBackedTextFieldDelegateAdapter+Markdown.h>
15
- #import < RNLiveMarkdown/RCTUITextView+Markdown.h>
16
-
10
+ #import < RNLiveMarkdown/RCTMarkdownStyle.h>
17
11
#import < RNLiveMarkdown/RCTTextInputComponentView+Markdown.h>
12
+ #import < RNLiveMarkdown/RCTUITextView+Markdown.h>
18
13
19
14
#import < objc/runtime.h>
20
15
21
16
using namespace facebook ::react;
22
17
23
18
@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;
31
26
}
32
27
33
28
+ (ComponentDescriptorProvider)componentDescriptorProvider
@@ -88,21 +83,21 @@ - (void)didAddSubview:(UIView *)subview
88
83
89
84
- (void )willMoveToWindow : (UIWindow *)newWindow
90
85
{
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 ];
105
89
}
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
+ }
106
101
}
107
102
108
103
- (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 &
111
106
const auto &newViewProps = *std::static_pointer_cast<MarkdownTextInputDecoratorViewProps const >(props);
112
107
113
108
if (oldViewProps.parserId != newViewProps.parserId ) {
114
- _parserId = [ NSNumber numberWithInt: newViewProps.parserId] ;
109
+ _parserId = @( newViewProps.parserId ) ;
115
110
[_markdownUtils setParserId: _parserId];
116
111
}
117
112
118
113
// 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];
122
116
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 ];
130
119
131
120
[super updateProps: props oldProps: oldProps];
132
121
}
133
122
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
+
134
134
Class <RCTComponentViewProtocol> MarkdownTextInputDecoratorViewCls (void )
135
135
{
136
136
return MarkdownTextInputDecoratorComponentView.class ;
0 commit comments