Revert D4680300: [RN] BREAKING: Better TextInput: contentSize property was removed from <TextInput>.onChange event.

Differential Revision: D4680300

fbshipit-source-id: 20f7299c53cc54215fb333e97d7e11de087e303d
This commit is contained in:
Valentin Shergin
2017-05-01 21:05:38 -07:00
committed by Facebook Github Bot
parent 3544b76c26
commit f73464851b
3 changed files with 55 additions and 0 deletions

View File

@@ -489,6 +489,35 @@ 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