Skip to content

Commit

Permalink
apply react native patch for facebook/react-native#46973
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Oct 11, 2024
1 parent 4a9a7e9 commit c6c7031
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions patches/react-native+0.75.2+018.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
index db7cba4..1b54a43 100644
--- a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
+++ b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
@@ -479,8 +479,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount
if (value && ![value isEqualToString:_backedTextInputView.attributedText.string]) {
NSAttributedString *attributedString =
[[NSAttributedString alloc] initWithString:value attributes:_backedTextInputView.defaultTextAttributes];
- [self _setAttributedString:attributedString];
- [self _updateState];
+ [self _updateStateWithString:attributedString];
}

UITextPosition *startPosition = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument
@@ -490,6 +489,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount

if (startPosition && endPosition) {
UITextRange *range = [_backedTextInputView textRangeFromPosition:startPosition toPosition:endPosition];
+ // _updateStateWithString executes any state updates sync, so its safe to update the selection as the attributedString is already updated!
[_backedTextInputView setSelectedTextRange:range notifyDelegate:NO];
}
_comingFromJS = NO;
@@ -611,17 +611,27 @@ - (void)handleInputAccessoryDoneButton
}

- (void)_updateState
+{
+ NSAttributedString *attributedString = _backedTextInputView.attributedText;
+ [self _updateStateWithString:attributedString];
+}
+
+- (void)_updateStateWithString:(NSAttributedString*)attributedString
{
if (!_state) {
return;
}
- NSAttributedString *attributedString = _backedTextInputView.attributedText;
auto data = _state->getData();
_lastStringStateWasUpdatedWith = attributedString;
data.attributedStringBox = RCTAttributedStringBoxFromNSAttributedString(attributedString);
_mostRecentEventCount += _comingFromJS ? 0 : 1;
data.mostRecentEventCount = _mostRecentEventCount;
- _state->updateState(std::move(data));
+ const auto &textInputEventEmitter = static_cast<const TextInputEventEmitter &>(*_eventEmitter);
+ // When the textInputDidChange gets called, the text is already updated
+ // in the UI. We execute the state update synchronously so that the layout gets calculated immediately.
+ textInputEventEmitter.experimental_flushSync([state = _state, data = std::move(data)]() mutable {
+ state->updateState(std::move(data));
+ });
}

0 comments on commit c6c7031

Please sign in to comment.