Skip to content

Commit 3290b24

Browse files
hannojgNodonisko
authored andcommitted
apply react native patch for facebook/react-native#46973
1 parent 00ac67b commit 3290b24

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

patches/react-native+0.75.2+018.patch

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
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
2+
index db7cba4..1b54a43 100644
3+
--- a/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
4+
+++ b/node_modules/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm
5+
@@ -479,8 +479,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount
6+
if (value && ![value isEqualToString:_backedTextInputView.attributedText.string]) {
7+
NSAttributedString *attributedString =
8+
[[NSAttributedString alloc] initWithString:value attributes:_backedTextInputView.defaultTextAttributes];
9+
- [self _setAttributedString:attributedString];
10+
- [self _updateState];
11+
+ [self _updateStateWithString:attributedString];
12+
}
13+
14+
UITextPosition *startPosition = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument
15+
@@ -490,6 +489,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount
16+
17+
if (startPosition && endPosition) {
18+
UITextRange *range = [_backedTextInputView textRangeFromPosition:startPosition toPosition:endPosition];
19+
+ // _updateStateWithString executes any state updates sync, so its safe to update the selection as the attributedString is already updated!
20+
[_backedTextInputView setSelectedTextRange:range notifyDelegate:NO];
21+
}
22+
_comingFromJS = NO;
23+
@@ -611,17 +611,27 @@ - (void)handleInputAccessoryDoneButton
24+
}
25+
26+
- (void)_updateState
27+
+{
28+
+ NSAttributedString *attributedString = _backedTextInputView.attributedText;
29+
+ [self _updateStateWithString:attributedString];
30+
+}
31+
+
32+
+- (void)_updateStateWithString:(NSAttributedString*)attributedString
33+
{
34+
if (!_state) {
35+
return;
36+
}
37+
- NSAttributedString *attributedString = _backedTextInputView.attributedText;
38+
auto data = _state->getData();
39+
_lastStringStateWasUpdatedWith = attributedString;
40+
data.attributedStringBox = RCTAttributedStringBoxFromNSAttributedString(attributedString);
41+
_mostRecentEventCount += _comingFromJS ? 0 : 1;
42+
data.mostRecentEventCount = _mostRecentEventCount;
43+
- _state->updateState(std::move(data));
44+
+ const auto &textInputEventEmitter = static_cast<const TextInputEventEmitter &>(*_eventEmitter);
45+
+ // When the textInputDidChange gets called, the text is already updated
46+
+ // in the UI. We execute the state update synchronously so that the layout gets calculated immediately.
47+
+ textInputEventEmitter.experimental_flushSync([state = _state, data = std::move(data)]() mutable {
48+
+ state->updateState(std::move(data));
49+
+ });
50+
}

0 commit comments

Comments
 (0)