mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-13 22:43:59 +08:00
BREAKING: Better TextInput: contentSize property was removed from <TextInput>.onChange event.
Summary: `contentSize` was removed from both iOS and Android, tests was updated. USE `onContentSizeChange` INSTEAD. Why? * It always was a hack; * We already have dedicated event for it: `onContentSizeChange`; * `onChange` has nothing to do with layout actually; * We have to maintain `onChange` handler as fast and simple as possible, this feature complicates it a lot; * It was undocumented feature; * We already have native auto-expandable <TextInput>, so it illuminates 99% current use cases of this feature. Reviewed By: mmmulani Differential Revision: D4680300 fbshipit-source-id: 337836deef0767e5f26350f5a8ce73adb4146a02
This commit is contained in:
committed by
Facebook Github Bot
parent
1c0e3b8b5b
commit
99e24ecc67
@@ -489,35 +489,6 @@ static BOOL findMismatch(NSString *first, NSString *second, NSRange *firstRange,
|
||||
|
||||
_nativeUpdatesInFlight = NO;
|
||||
_nativeEventCount++;
|
||||
|
||||
// TODO: t16435709 This part will be removed soon.
|
||||
if (!self.reactTag || !_onChange) {
|
||||
return;
|
||||
}
|
||||
|
||||
// When the context size increases, iOS updates the contentSize twice; once
|
||||
// with a lower height, then again with the correct height. To prevent a
|
||||
// spurious event from being sent, we track the previous, and only send the
|
||||
// update event if it matches our expectation that greater text length
|
||||
// should result in increased height. This assumption is, of course, not
|
||||
// necessarily true because shorter text might include more linebreaks, but
|
||||
// in practice this works well enough.
|
||||
NSUInteger textLength = textView.text.length;
|
||||
CGFloat contentHeight = textView.contentSize.height;
|
||||
if (textLength >= _previousTextLength) {
|
||||
contentHeight = MAX(contentHeight, _previousContentHeight);
|
||||
}
|
||||
_previousTextLength = textLength;
|
||||
_previousContentHeight = contentHeight;
|
||||
_onChange(@{
|
||||
@"text": self.text,
|
||||
@"contentSize": @{
|
||||
@"height": @(contentHeight),
|
||||
@"width": @(textView.contentSize.width)
|
||||
},
|
||||
@"target": self.reactTag,
|
||||
@"eventCount": @(_nativeEventCount),
|
||||
});
|
||||
}
|
||||
|
||||
- (void)textViewDidEndEditing:(UITextView *)textView
|
||||
|
||||
Reference in New Issue
Block a user