@onekeyfe/react-native-auto-size-input 3.0.96 → 3.0.98

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.
@@ -37,6 +37,7 @@ using namespace margelo::nitro::autosizeinput::views;
37
37
 
38
38
  @implementation HybridAutoSizeInputComponent {
39
39
  std::shared_ptr<HybridAutoSizeInputSpecSwift> _hybridView;
40
+ BOOL _didDropView;
40
41
  }
41
42
 
42
43
  + (void) load {
@@ -50,6 +51,7 @@ using namespace margelo::nitro::autosizeinput::views;
50
51
 
51
52
  - (instancetype) init {
52
53
  if (self = [super init]) {
54
+ _props = HybridAutoSizeInputShadowNode::defaultSharedProps();
53
55
  std::shared_ptr<HybridAutoSizeInputSpec> hybridView = AutoSizeInput::AutoSizeInputAutolinking::createAutoSizeInput();
54
56
  _hybridView = std::dynamic_pointer_cast<HybridAutoSizeInputSpecSwift>(hybridView);
55
57
  [self updateView];
@@ -69,185 +71,235 @@ using namespace margelo::nitro::autosizeinput::views;
69
71
  [self setContentView:view];
70
72
  }
71
73
 
74
+ - (void) notifyOnDropView {
75
+ // A recycled component can later be invalidated. Notify only once per mount.
76
+ if (_didDropView) {
77
+ return;
78
+ }
79
+ AutoSizeInput::HybridAutoSizeInputSpec_cxx& swiftPart = _hybridView->getSwiftPart();
80
+ swiftPart.onDropView();
81
+ _didDropView = YES;
82
+ }
83
+
72
84
  - (void) updateProps:(const std::shared_ptr<const react::Props>&)props
73
85
  oldProps:(const std::shared_ptr<const react::Props>&)oldProps {
86
+ // A props update marks a newly mounted or still-active component.
87
+ _didDropView = NO;
88
+
74
89
  // 1. Downcast props
75
- const auto& newViewPropsConst = *std::static_pointer_cast<HybridAutoSizeInputProps const>(props);
76
- auto& newViewProps = const_cast<HybridAutoSizeInputProps&>(newViewPropsConst);
90
+ const auto& newViewProps = *std::static_pointer_cast<const HybridAutoSizeInputProps>(props);
91
+ const auto* oldViewProps = static_cast<const HybridAutoSizeInputProps*>(oldProps.get());
77
92
  AutoSizeInput::HybridAutoSizeInputSpec_cxx& swiftPart = _hybridView->getSwiftPart();
78
93
 
79
- // 2. Update each prop individually
80
- swiftPart.beforeUpdate();
94
+ // 2. Update only props that differ from the previous Props snapshot.
95
+ const bool hasTransactionPropChanges = oldViewProps == nullptr
96
+ ? newViewProps.hasAnyProvidedProps()
97
+ : !newViewProps.hasSameProps(*oldViewProps);
98
+ if (hasTransactionPropChanges) {
99
+ swiftPart.beforeUpdate();
81
100
 
82
- // mostRecentEventCount: optional
83
- if (newViewProps.mostRecentEventCount.isDirty) {
84
- swiftPart.setMostRecentEventCount(newViewProps.mostRecentEventCount.value);
85
- newViewProps.mostRecentEventCount.isDirty = false;
86
- }
87
- // text: optional
88
- if (newViewProps.text.isDirty) {
89
- swiftPart.setText(newViewProps.text.value);
90
- newViewProps.text.isDirty = false;
91
- }
92
- // prefix: optional
93
- if (newViewProps.prefix.isDirty) {
94
- swiftPart.setPrefix(newViewProps.prefix.value);
95
- newViewProps.prefix.isDirty = false;
96
- }
97
- // suffix: optional
98
- if (newViewProps.suffix.isDirty) {
99
- swiftPart.setSuffix(newViewProps.suffix.value);
100
- newViewProps.suffix.isDirty = false;
101
- }
102
- // placeholder: optional
103
- if (newViewProps.placeholder.isDirty) {
104
- swiftPart.setPlaceholder(newViewProps.placeholder.value);
105
- newViewProps.placeholder.isDirty = false;
106
- }
107
- // fontSize: optional
108
- if (newViewProps.fontSize.isDirty) {
109
- swiftPart.setFontSize(newViewProps.fontSize.value);
110
- newViewProps.fontSize.isDirty = false;
111
- }
112
- // minFontSize: optional
113
- if (newViewProps.minFontSize.isDirty) {
114
- swiftPart.setMinFontSize(newViewProps.minFontSize.value);
115
- newViewProps.minFontSize.isDirty = false;
116
- }
117
- // multiline: optional
118
- if (newViewProps.multiline.isDirty) {
119
- swiftPart.setMultiline(newViewProps.multiline.value);
120
- newViewProps.multiline.isDirty = false;
121
- }
122
- // maxNumberOfLines: optional
123
- if (newViewProps.maxNumberOfLines.isDirty) {
124
- swiftPart.setMaxNumberOfLines(newViewProps.maxNumberOfLines.value);
125
- newViewProps.maxNumberOfLines.isDirty = false;
126
- }
127
- // textColor: optional
128
- if (newViewProps.textColor.isDirty) {
129
- swiftPart.setTextColor(newViewProps.textColor.value);
130
- newViewProps.textColor.isDirty = false;
131
- }
132
- // prefixColor: optional
133
- if (newViewProps.prefixColor.isDirty) {
134
- swiftPart.setPrefixColor(newViewProps.prefixColor.value);
135
- newViewProps.prefixColor.isDirty = false;
136
- }
137
- // suffixColor: optional
138
- if (newViewProps.suffixColor.isDirty) {
139
- swiftPart.setSuffixColor(newViewProps.suffixColor.value);
140
- newViewProps.suffixColor.isDirty = false;
141
- }
142
- // placeholderColor: optional
143
- if (newViewProps.placeholderColor.isDirty) {
144
- swiftPart.setPlaceholderColor(newViewProps.placeholderColor.value);
145
- newViewProps.placeholderColor.isDirty = false;
146
- }
147
- // textAlign: optional
148
- if (newViewProps.textAlign.isDirty) {
149
- swiftPart.setTextAlign(newViewProps.textAlign.value);
150
- newViewProps.textAlign.isDirty = false;
151
- }
152
- // fontFamily: optional
153
- if (newViewProps.fontFamily.isDirty) {
154
- swiftPart.setFontFamily(newViewProps.fontFamily.value);
155
- newViewProps.fontFamily.isDirty = false;
156
- }
157
- // fontWeight: optional
158
- if (newViewProps.fontWeight.isDirty) {
159
- swiftPart.setFontWeight(newViewProps.fontWeight.value);
160
- newViewProps.fontWeight.isDirty = false;
161
- }
162
- // editable: optional
163
- if (newViewProps.editable.isDirty) {
164
- swiftPart.setEditable(newViewProps.editable.value);
165
- newViewProps.editable.isDirty = false;
166
- }
167
- // keyboardType: optional
168
- if (newViewProps.keyboardType.isDirty) {
169
- swiftPart.setKeyboardType(newViewProps.keyboardType.value);
170
- newViewProps.keyboardType.isDirty = false;
171
- }
172
- // returnKeyType: optional
173
- if (newViewProps.returnKeyType.isDirty) {
174
- swiftPart.setReturnKeyType(newViewProps.returnKeyType.value);
175
- newViewProps.returnKeyType.isDirty = false;
176
- }
177
- // autoCorrect: optional
178
- if (newViewProps.autoCorrect.isDirty) {
179
- swiftPart.setAutoCorrect(newViewProps.autoCorrect.value);
180
- newViewProps.autoCorrect.isDirty = false;
181
- }
182
- // autoCapitalize: optional
183
- if (newViewProps.autoCapitalize.isDirty) {
184
- swiftPart.setAutoCapitalize(newViewProps.autoCapitalize.value);
185
- newViewProps.autoCapitalize.isDirty = false;
186
- }
187
- // selectionColor: optional
188
- if (newViewProps.selectionColor.isDirty) {
189
- swiftPart.setSelectionColor(newViewProps.selectionColor.value);
190
- newViewProps.selectionColor.isDirty = false;
191
- }
192
- // prefixMarginRight: optional
193
- if (newViewProps.prefixMarginRight.isDirty) {
194
- swiftPart.setPrefixMarginRight(newViewProps.prefixMarginRight.value);
195
- newViewProps.prefixMarginRight.isDirty = false;
196
- }
197
- // suffixMarginLeft: optional
198
- if (newViewProps.suffixMarginLeft.isDirty) {
199
- swiftPart.setSuffixMarginLeft(newViewProps.suffixMarginLeft.value);
200
- newViewProps.suffixMarginLeft.isDirty = false;
201
- }
202
- // showBorder: optional
203
- if (newViewProps.showBorder.isDirty) {
204
- swiftPart.setShowBorder(newViewProps.showBorder.value);
205
- newViewProps.showBorder.isDirty = false;
206
- }
207
- // inputBackgroundColor: optional
208
- if (newViewProps.inputBackgroundColor.isDirty) {
209
- swiftPart.setInputBackgroundColor(newViewProps.inputBackgroundColor.value);
210
- newViewProps.inputBackgroundColor.isDirty = false;
211
- }
212
- // contentAutoWidth: optional
213
- if (newViewProps.contentAutoWidth.isDirty) {
214
- swiftPart.setContentAutoWidth(newViewProps.contentAutoWidth.value);
215
- newViewProps.contentAutoWidth.isDirty = false;
216
- }
217
- // contentCentered: optional
218
- if (newViewProps.contentCentered.isDirty) {
219
- swiftPart.setContentCentered(newViewProps.contentCentered.value);
220
- newViewProps.contentCentered.isDirty = false;
221
- }
222
- // onChangeText: optional
223
- if (newViewProps.onChangeText.isDirty) {
224
- swiftPart.setOnChangeText(newViewProps.onChangeText.value);
225
- newViewProps.onChangeText.isDirty = false;
226
- }
227
- // onFocus: optional
228
- if (newViewProps.onFocus.isDirty) {
229
- swiftPart.setOnFocus(newViewProps.onFocus.value);
230
- newViewProps.onFocus.isDirty = false;
231
- }
232
- // onBlur: optional
233
- if (newViewProps.onBlur.isDirty) {
234
- swiftPart.setOnBlur(newViewProps.onBlur.value);
235
- newViewProps.onBlur.isDirty = false;
236
- }
101
+ // mostRecentEventCount: optional
102
+ if (oldViewProps == nullptr
103
+ ? newViewProps.mostRecentEventCount.isProvided()
104
+ : !newViewProps.mostRecentEventCount.hasSameValue(oldViewProps->mostRecentEventCount)) {
105
+ swiftPart.setMostRecentEventCount(newViewProps.mostRecentEventCount.get());
106
+ }
107
+ // text: optional
108
+ if (oldViewProps == nullptr
109
+ ? newViewProps.text.isProvided()
110
+ : !newViewProps.text.hasSameValue(oldViewProps->text)) {
111
+ swiftPart.setText(newViewProps.text.get());
112
+ }
113
+ // prefix: optional
114
+ if (oldViewProps == nullptr
115
+ ? newViewProps.prefix.isProvided()
116
+ : !newViewProps.prefix.hasSameValue(oldViewProps->prefix)) {
117
+ swiftPart.setPrefix(newViewProps.prefix.get());
118
+ }
119
+ // suffix: optional
120
+ if (oldViewProps == nullptr
121
+ ? newViewProps.suffix.isProvided()
122
+ : !newViewProps.suffix.hasSameValue(oldViewProps->suffix)) {
123
+ swiftPart.setSuffix(newViewProps.suffix.get());
124
+ }
125
+ // placeholder: optional
126
+ if (oldViewProps == nullptr
127
+ ? newViewProps.placeholder.isProvided()
128
+ : !newViewProps.placeholder.hasSameValue(oldViewProps->placeholder)) {
129
+ swiftPart.setPlaceholder(newViewProps.placeholder.get());
130
+ }
131
+ // fontSize: optional
132
+ if (oldViewProps == nullptr
133
+ ? newViewProps.fontSize.isProvided()
134
+ : !newViewProps.fontSize.hasSameValue(oldViewProps->fontSize)) {
135
+ swiftPart.setFontSize(newViewProps.fontSize.get());
136
+ }
137
+ // minFontSize: optional
138
+ if (oldViewProps == nullptr
139
+ ? newViewProps.minFontSize.isProvided()
140
+ : !newViewProps.minFontSize.hasSameValue(oldViewProps->minFontSize)) {
141
+ swiftPart.setMinFontSize(newViewProps.minFontSize.get());
142
+ }
143
+ // multiline: optional
144
+ if (oldViewProps == nullptr
145
+ ? newViewProps.multiline.isProvided()
146
+ : !newViewProps.multiline.hasSameValue(oldViewProps->multiline)) {
147
+ swiftPart.setMultiline(newViewProps.multiline.get());
148
+ }
149
+ // maxNumberOfLines: optional
150
+ if (oldViewProps == nullptr
151
+ ? newViewProps.maxNumberOfLines.isProvided()
152
+ : !newViewProps.maxNumberOfLines.hasSameValue(oldViewProps->maxNumberOfLines)) {
153
+ swiftPart.setMaxNumberOfLines(newViewProps.maxNumberOfLines.get());
154
+ }
155
+ // textColor: optional
156
+ if (oldViewProps == nullptr
157
+ ? newViewProps.textColor.isProvided()
158
+ : !newViewProps.textColor.hasSameValue(oldViewProps->textColor)) {
159
+ swiftPart.setTextColor(newViewProps.textColor.get());
160
+ }
161
+ // prefixColor: optional
162
+ if (oldViewProps == nullptr
163
+ ? newViewProps.prefixColor.isProvided()
164
+ : !newViewProps.prefixColor.hasSameValue(oldViewProps->prefixColor)) {
165
+ swiftPart.setPrefixColor(newViewProps.prefixColor.get());
166
+ }
167
+ // suffixColor: optional
168
+ if (oldViewProps == nullptr
169
+ ? newViewProps.suffixColor.isProvided()
170
+ : !newViewProps.suffixColor.hasSameValue(oldViewProps->suffixColor)) {
171
+ swiftPart.setSuffixColor(newViewProps.suffixColor.get());
172
+ }
173
+ // placeholderColor: optional
174
+ if (oldViewProps == nullptr
175
+ ? newViewProps.placeholderColor.isProvided()
176
+ : !newViewProps.placeholderColor.hasSameValue(oldViewProps->placeholderColor)) {
177
+ swiftPart.setPlaceholderColor(newViewProps.placeholderColor.get());
178
+ }
179
+ // textAlign: optional
180
+ if (oldViewProps == nullptr
181
+ ? newViewProps.textAlign.isProvided()
182
+ : !newViewProps.textAlign.hasSameValue(oldViewProps->textAlign)) {
183
+ swiftPart.setTextAlign(newViewProps.textAlign.get());
184
+ }
185
+ // fontFamily: optional
186
+ if (oldViewProps == nullptr
187
+ ? newViewProps.fontFamily.isProvided()
188
+ : !newViewProps.fontFamily.hasSameValue(oldViewProps->fontFamily)) {
189
+ swiftPart.setFontFamily(newViewProps.fontFamily.get());
190
+ }
191
+ // fontWeight: optional
192
+ if (oldViewProps == nullptr
193
+ ? newViewProps.fontWeight.isProvided()
194
+ : !newViewProps.fontWeight.hasSameValue(oldViewProps->fontWeight)) {
195
+ swiftPart.setFontWeight(newViewProps.fontWeight.get());
196
+ }
197
+ // editable: optional
198
+ if (oldViewProps == nullptr
199
+ ? newViewProps.editable.isProvided()
200
+ : !newViewProps.editable.hasSameValue(oldViewProps->editable)) {
201
+ swiftPart.setEditable(newViewProps.editable.get());
202
+ }
203
+ // keyboardType: optional
204
+ if (oldViewProps == nullptr
205
+ ? newViewProps.keyboardType.isProvided()
206
+ : !newViewProps.keyboardType.hasSameValue(oldViewProps->keyboardType)) {
207
+ swiftPart.setKeyboardType(newViewProps.keyboardType.get());
208
+ }
209
+ // returnKeyType: optional
210
+ if (oldViewProps == nullptr
211
+ ? newViewProps.returnKeyType.isProvided()
212
+ : !newViewProps.returnKeyType.hasSameValue(oldViewProps->returnKeyType)) {
213
+ swiftPart.setReturnKeyType(newViewProps.returnKeyType.get());
214
+ }
215
+ // autoCorrect: optional
216
+ if (oldViewProps == nullptr
217
+ ? newViewProps.autoCorrect.isProvided()
218
+ : !newViewProps.autoCorrect.hasSameValue(oldViewProps->autoCorrect)) {
219
+ swiftPart.setAutoCorrect(newViewProps.autoCorrect.get());
220
+ }
221
+ // autoCapitalize: optional
222
+ if (oldViewProps == nullptr
223
+ ? newViewProps.autoCapitalize.isProvided()
224
+ : !newViewProps.autoCapitalize.hasSameValue(oldViewProps->autoCapitalize)) {
225
+ swiftPart.setAutoCapitalize(newViewProps.autoCapitalize.get());
226
+ }
227
+ // selectionColor: optional
228
+ if (oldViewProps == nullptr
229
+ ? newViewProps.selectionColor.isProvided()
230
+ : !newViewProps.selectionColor.hasSameValue(oldViewProps->selectionColor)) {
231
+ swiftPart.setSelectionColor(newViewProps.selectionColor.get());
232
+ }
233
+ // prefixMarginRight: optional
234
+ if (oldViewProps == nullptr
235
+ ? newViewProps.prefixMarginRight.isProvided()
236
+ : !newViewProps.prefixMarginRight.hasSameValue(oldViewProps->prefixMarginRight)) {
237
+ swiftPart.setPrefixMarginRight(newViewProps.prefixMarginRight.get());
238
+ }
239
+ // suffixMarginLeft: optional
240
+ if (oldViewProps == nullptr
241
+ ? newViewProps.suffixMarginLeft.isProvided()
242
+ : !newViewProps.suffixMarginLeft.hasSameValue(oldViewProps->suffixMarginLeft)) {
243
+ swiftPart.setSuffixMarginLeft(newViewProps.suffixMarginLeft.get());
244
+ }
245
+ // showBorder: optional
246
+ if (oldViewProps == nullptr
247
+ ? newViewProps.showBorder.isProvided()
248
+ : !newViewProps.showBorder.hasSameValue(oldViewProps->showBorder)) {
249
+ swiftPart.setShowBorder(newViewProps.showBorder.get());
250
+ }
251
+ // inputBackgroundColor: optional
252
+ if (oldViewProps == nullptr
253
+ ? newViewProps.inputBackgroundColor.isProvided()
254
+ : !newViewProps.inputBackgroundColor.hasSameValue(oldViewProps->inputBackgroundColor)) {
255
+ swiftPart.setInputBackgroundColor(newViewProps.inputBackgroundColor.get());
256
+ }
257
+ // contentAutoWidth: optional
258
+ if (oldViewProps == nullptr
259
+ ? newViewProps.contentAutoWidth.isProvided()
260
+ : !newViewProps.contentAutoWidth.hasSameValue(oldViewProps->contentAutoWidth)) {
261
+ swiftPart.setContentAutoWidth(newViewProps.contentAutoWidth.get());
262
+ }
263
+ // contentCentered: optional
264
+ if (oldViewProps == nullptr
265
+ ? newViewProps.contentCentered.isProvided()
266
+ : !newViewProps.contentCentered.hasSameValue(oldViewProps->contentCentered)) {
267
+ swiftPart.setContentCentered(newViewProps.contentCentered.get());
268
+ }
269
+ // onChangeText: optional
270
+ if (oldViewProps == nullptr
271
+ ? newViewProps.onChangeText.isProvided()
272
+ : !newViewProps.onChangeText.hasSameValue(oldViewProps->onChangeText)) {
273
+ swiftPart.setOnChangeText(newViewProps.onChangeText.get());
274
+ }
275
+ // onFocus: optional
276
+ if (oldViewProps == nullptr
277
+ ? newViewProps.onFocus.isProvided()
278
+ : !newViewProps.onFocus.hasSameValue(oldViewProps->onFocus)) {
279
+ swiftPart.setOnFocus(newViewProps.onFocus.get());
280
+ }
281
+ // onBlur: optional
282
+ if (oldViewProps == nullptr
283
+ ? newViewProps.onBlur.isProvided()
284
+ : !newViewProps.onBlur.hasSameValue(oldViewProps->onBlur)) {
285
+ swiftPart.setOnBlur(newViewProps.onBlur.get());
286
+ }
237
287
 
238
- swiftPart.afterUpdate();
288
+ // Update hybridRef if it changed
289
+ if (oldViewProps == nullptr
290
+ ? newViewProps.hybridRef.isProvided()
291
+ : !newViewProps.hybridRef.hasSameValue(oldViewProps->hybridRef)) {
292
+ // hybridRef changed - call it with new this
293
+ const auto& maybeFunc = newViewProps.hybridRef.get();
294
+ if (maybeFunc.has_value()) {
295
+ maybeFunc.value()(_hybridView);
296
+ }
297
+ }
239
298
 
240
- // 3. Update hybridRef if it changed
241
- if (newViewProps.hybridRef.isDirty) {
242
- // hybridRef changed - call it with new this
243
- const auto& maybeFunc = newViewProps.hybridRef.value;
244
- if (maybeFunc.has_value()) {
245
- maybeFunc.value()(_hybridView);
246
- }
247
- newViewProps.hybridRef.isDirty = false;
299
+ swiftPart.afterUpdate();
248
300
  }
249
301
 
250
- // 4. Continue in base class
302
+ // 3. Continue in base class
251
303
  [super updateProps:props oldProps:oldProps];
252
304
  }
253
305
 
@@ -256,6 +308,7 @@ using namespace margelo::nitro::autosizeinput::views;
256
308
  }
257
309
 
258
310
  - (void)prepareForRecycle {
311
+ [self notifyOnDropView];
259
312
  [super prepareForRecycle];
260
313
  AutoSizeInput::HybridAutoSizeInputSpec_cxx& swiftPart = _hybridView->getSwiftPart();
261
314
  swiftPart.maybePrepareForRecycle();
@@ -263,8 +316,7 @@ using namespace margelo::nitro::autosizeinput::views;
263
316
 
264
317
  #ifdef ENABLE_RCT_COMPONENT_VIEW_INVALIDATE
265
318
  - (void)invalidate {
266
- AutoSizeInput::HybridAutoSizeInputSpec_cxx& swiftPart = _hybridView->getSwiftPart();
267
- swiftPart.onDropView();
319
+ [self notifyOnDropView];
268
320
  [super invalidate];
269
321
  }
270
322
  #endif