@expensify/react-native-live-markdown 0.1.282 → 0.1.283

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,6 +28,7 @@ using namespace facebook::react;
28
28
  MarkdownTextFieldObserver *_markdownTextFieldObserver;
29
29
  __weak RCTUITextView *_textView;
30
30
  __weak RCTUITextField *_textField;
31
+ bool _observersAdded;
31
32
  }
32
33
 
33
34
  + (ComponentDescriptorProvider)componentDescriptorProvider
@@ -46,6 +47,8 @@ using namespace facebook::react;
46
47
  if (self = [super initWithFrame:frame]) {
47
48
  static const auto defaultProps = std::make_shared<const MarkdownTextInputDecoratorViewProps>();
48
49
  _props = defaultProps;
50
+ _observersAdded = false;
51
+ _markdownUtils = [[RCTMarkdownUtils alloc] init];
49
52
  }
50
53
 
51
54
  return self;
@@ -53,13 +56,26 @@ using namespace facebook::react;
53
56
 
54
57
  - (void)didAddSubview:(UIView *)subview
55
58
  {
56
- react_native_assert([subview isKindOfClass:[RCTTextInputComponentView class]] && "Child component of MarkdownTextInputDecoratorComponentView is not an instance of RCTTextInputComponentView.");
57
- RCTTextInputComponentView *textInputComponentView = (RCTTextInputComponentView *)subview;
58
- UIView<RCTBackedTextInputViewProtocol> *backedTextInputView = [textInputComponentView valueForKey:@"_backedTextInputView"];
59
+ [super didAddSubview:subview];
60
+ [self addTextInputObservers];
61
+ }
59
62
 
60
- _markdownUtils = [[RCTMarkdownUtils alloc] init];
61
- [_markdownUtils setMarkdownStyle:_markdownStyle];
62
- [_markdownUtils setParserId:_parserId];
63
+ - (void)willRemoveSubview:(UIView *)subview
64
+ {
65
+ [self removeTextInputObservers];
66
+ [super willRemoveSubview:subview];
67
+ }
68
+
69
+ - (void)addTextInputObservers
70
+ {
71
+ react_native_assert(!_observersAdded && "MarkdownTextInputDecoratorComponentView tried to add TextInput observers while they were attached");
72
+ react_native_assert(self.subviews.count > 0 && "MarkdownTextInputDecoratorComponentView is mounted without any children")
73
+ UIView* childView = self.subviews[0];
74
+ react_native_assert([childView isKindOfClass:[RCTTextInputComponentView class]] && "Child component of MarkdownTextInputDecoratorComponentView is not an instance of RCTTextInputComponentView.");
75
+ RCTTextInputComponentView *textInputComponentView = (RCTTextInputComponentView *)childView;
76
+ UIView<RCTBackedTextInputViewProtocol> *backedTextInputView = [textInputComponentView valueForKey:@"_backedTextInputView"];
77
+
78
+ _observersAdded = true;
63
79
 
64
80
  if ([backedTextInputView isKindOfClass:[RCTUITextField class]]) {
65
81
  _textField = (RCTUITextField *)backedTextInputView;
@@ -115,11 +131,11 @@ using namespace facebook::react;
115
131
  }
116
132
  }
117
133
 
118
- - (void)willMoveToWindow:(UIWindow *)newWindow
134
+ - (void)removeTextInputObservers
119
135
  {
120
- if (newWindow != nil) {
121
- return;
122
- }
136
+ react_native_assert(_observersAdded && "MarkdownTextInputDecoratorComponentView tried to remove TextInput observers while they were detached");
137
+ _observersAdded = false;
138
+
123
139
  if (_textView != nil) {
124
140
  if (_textView.layoutManager != nil && [object_getClass(_textView.layoutManager) isEqual:[MarkdownLayoutManager class]]) {
125
141
  [_textView.layoutManager setValue:nil forKey:@"markdownUtils"];
@@ -173,6 +189,16 @@ using namespace facebook::react;
173
189
  }
174
190
  }
175
191
 
192
+ - (void)prepareForRecycle
193
+ {
194
+ react_native_assert(!_observersAdded && "MarkdownTextInputDecoratorComponentView was being recycled with TextInput observers still attached");
195
+ [super prepareForRecycle];
196
+
197
+ static const auto defaultProps = std::make_shared<const MarkdownTextInputDecoratorViewProps>();
198
+ _props = defaultProps;
199
+ _markdownUtils = [[RCTMarkdownUtils alloc] init];
200
+ }
201
+
176
202
  Class<RCTComponentViewProtocol> MarkdownTextInputDecoratorViewCls(void)
177
203
  {
178
204
  return MarkdownTextInputDecoratorComponentView.class;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expensify/react-native-live-markdown",
3
- "version": "0.1.282",
3
+ "version": "0.1.283",
4
4
  "description": "Drop-in replacement for React Native's TextInput component with Markdown formatting.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",