Skip to content

Commit 5fd5188

Browse files
j-piaseckifacebook-github-bot
authored andcommitted
Fix TextInput onContentSizeChange event being dispatched only once on iOS (facebook#50782)
Summary: Pull Request resolved: facebook#50782 Changelog: [IOS][FIXED] Fix TextInput `onContentSizeChange` event being dispatched only once on iOS on the new architecture Currently, the comparison to decide whether to send event happens between the content size before and after layout metrics update. Those values turn out to be the same in all but the first call. This updates the logic to use the previously send values in the comparison. Reviewed By: huntie Differential Revision: D73182563 fbshipit-source-id: 3b764a89c1844e203001d75022a3295a3fd747f2
1 parent 3e5c609 commit 5fd5188

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ @implementation RCTTextInputComponentView {
7171
NSDictionary<NSAttributedStringKey, id> *_originalTypingAttributes;
7272

7373
BOOL _hasInputAccessoryView;
74+
CGSize _previousContentSize;
7475
}
7576

7677
#pragma mark - UIView overrides
@@ -87,6 +88,7 @@ - (instancetype)initWithFrame:(CGRect)frame
8788
_comingFromJS = NO;
8889
_didMoveToWindow = NO;
8990
_originalTypingAttributes = [_backedTextInputView.typingAttributes copy];
91+
_previousContentSize = CGSizeZero;
9092

9193
[self addSubview:_backedTextInputView];
9294
[self initializeReturnKeyType];
@@ -336,16 +338,15 @@ - (void)updateState:(const State::Shared &)state oldState:(const State::Shared &
336338
- (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics
337339
oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics
338340
{
339-
CGSize previousContentSize = _backedTextInputView.contentSize;
340-
341341
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
342342

343343
_backedTextInputView.frame =
344344
UIEdgeInsetsInsetRect(self.bounds, RCTUIEdgeInsetsFromEdgeInsets(layoutMetrics.borderWidth));
345345
_backedTextInputView.textContainerInset =
346346
RCTUIEdgeInsetsFromEdgeInsets(layoutMetrics.contentInsets - layoutMetrics.borderWidth);
347347

348-
if (!CGSizeEqualToSize(previousContentSize, _backedTextInputView.contentSize) && _eventEmitter) {
348+
if (!CGSizeEqualToSize(_previousContentSize, _backedTextInputView.contentSize) && _eventEmitter) {
349+
_previousContentSize = _backedTextInputView.contentSize;
349350
static_cast<const TextInputEventEmitter &>(*_eventEmitter).onContentSizeChange([self _textInputMetrics]);
350351
}
351352
}

0 commit comments

Comments
 (0)