@bsky.app/react-native-uitextview 2.7.0 → 2.7.1

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.
Files changed (2) hide show
  1. package/ios/RNUITextView.mm +19 -13
  2. package/package.json +1 -1
@@ -135,6 +135,7 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(RNUITextViewEllipsize
135
135
  CFTimeInterval _highlightActivationTime;
136
136
  NSUInteger _highlightGeneration;
137
137
  BOOL _suppressSelectionChange;
138
+ BOOL _textLayoutNeedsUpdate;
138
139
  }
139
140
 
140
141
  + (ComponentDescriptorProvider)componentDescriptorProvider
@@ -224,11 +225,20 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(RNUITextViewEllipsize
224
225
  - (void)layoutSubviews
225
226
  {
226
227
  [super layoutSubviews];
227
- // _textView's frame is assigned inside drawRect, which only fires when
228
- // state changes. Trigger a redraw whenever the host frame moves out from
229
- // under it (rotation, parent relayout) so the text view resizes and
230
- // onTextLayout re-fires with the new line wrapping.
228
+ // Keep the inner view in sync synchronously, like RCTParagraphComponentView.
229
+ // Deferring this to drawRect can leave UITextView at an intermediate width
230
+ // after a rotation because display invalidations may be coalesced.
231
231
  if (!CGRectEqualToRect(_textView.frame, _view.frame)) {
232
+ const NSRange savedRange = _textView.selectedRange;
233
+ _suppressSelectionChange = YES;
234
+ _textView.frame = _view.frame;
235
+ if (savedRange.location != NSNotFound &&
236
+ NSMaxRange(savedRange) <= _textView.attributedText.length) {
237
+ _textView.selectedRange = savedRange;
238
+ }
239
+ _suppressSelectionChange = NO;
240
+
241
+ _textLayoutNeedsUpdate = YES;
232
242
  [self setNeedsDisplay];
233
243
  }
234
244
  }
@@ -244,13 +254,11 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(RNUITextViewEllipsize
244
254
  const auto attrString = _state->getData().attributedString;
245
255
  const auto convertedAttrString = RCTNSAttributedStringFromAttributedString(attrString);
246
256
 
247
- // Setting attributedText clears any active text selection, and re-assigning
248
- // the frame triggers a layout flush that has the same effect. Bail out
249
- // entirely when nothing actually changed so a JS-side state update made in
250
- // response to onSelectionChange doesn't deselect what the user is selecting.
257
+ // Setting attributedText clears any active text selection. Bail out entirely
258
+ // when neither the text nor its layout changed so a JS-side state update made
259
+ // in response to onSelectionChange doesn't deselect what the user is selecting.
251
260
  const BOOL textChanged = ![_textView.attributedText isEqualToAttributedString:convertedAttrString];
252
- const BOOL frameChanged = !CGRectEqualToRect(_textView.frame, _view.frame);
253
- if (!textChanged && !frameChanged) {
261
+ if (!textChanged && !_textLayoutNeedsUpdate) {
254
262
  return;
255
263
  }
256
264
  if (textChanged) {
@@ -266,9 +274,7 @@ static NSLineBreakMode RCTNSLineBreakModeFromEllipsizeMode(RNUITextViewEllipsize
266
274
  }
267
275
  _suppressSelectionChange = NO;
268
276
  }
269
- if (frameChanged) {
270
- _textView.frame = _view.frame;
271
- }
277
+ _textLayoutNeedsUpdate = NO;
272
278
 
273
279
  if (_activeHighlightGroup != nil) {
274
280
  [self updatePressHighlight];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsky.app/react-native-uitextview",
3
- "version": "2.7.0",
3
+ "version": "2.7.1",
4
4
  "description": "UITextView for React Native",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",