Skip to content

Commit bac84ce

Browse files
sherginfacebook-github-bot
authored andcommitted
BREAKING: Better TextInput: contentSize property was removed from <TextInput>.onChange event (Second attempt)
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: D4989881 fbshipit-source-id: 674bb98c89ada1fca7b3b20b304736b2a3b8304e
1 parent 9fae268 commit bac84ce

File tree

3 files changed

+0
-47
lines changed

3 files changed

+0
-47
lines changed

Libraries/Text/RCTTextView.m

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ @implementation RCTTextView
3030
NSAttributedString *_pendingAttributedText;
3131

3232
UITextRange *_previousSelectionRange;
33-
NSUInteger _previousTextLength;
34-
CGFloat _previousContentHeight;
3533
NSString *_predictedText;
3634

3735
BOOL _blockTextShouldChange;
@@ -490,31 +488,12 @@ - (void)textViewDidChange:(UITextView *)textView
490488
_nativeUpdatesInFlight = NO;
491489
_nativeEventCount++;
492490

493-
// TODO: t16435709 This part will be removed soon.
494491
if (!self.reactTag || !_onChange) {
495492
return;
496493
}
497494

498-
// When the context size increases, iOS updates the contentSize twice; once
499-
// with a lower height, then again with the correct height. To prevent a
500-
// spurious event from being sent, we track the previous, and only send the
501-
// update event if it matches our expectation that greater text length
502-
// should result in increased height. This assumption is, of course, not
503-
// necessarily true because shorter text might include more linebreaks, but
504-
// in practice this works well enough.
505-
NSUInteger textLength = textView.text.length;
506-
CGFloat contentHeight = textView.contentSize.height;
507-
if (textLength >= _previousTextLength) {
508-
contentHeight = MAX(contentHeight, _previousContentHeight);
509-
}
510-
_previousTextLength = textLength;
511-
_previousContentHeight = contentHeight;
512495
_onChange(@{
513496
@"text": self.text,
514-
@"contentSize": @{
515-
@"height": @(contentHeight),
516-
@"width": @(textView.contentSize.width)
517-
},
518497
@"target": self.reactTag,
519498
@"eventCount": @(_nativeEventCount),
520499
});

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextChangedEvent.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,14 @@ public class ReactTextChangedEvent extends Event<ReactTextChangedEvent> {
2323
public static final String EVENT_NAME = "topChange";
2424

2525
private String mText;
26-
private float mContentWidth;
27-
private float mContentHeight;
2826
private int mEventCount;
2927

3028
public ReactTextChangedEvent(
3129
int viewId,
3230
String text,
33-
float contentSizeWidth,
34-
float contentSizeHeight,
3531
int eventCount) {
3632
super(viewId);
3733
mText = text;
38-
mContentWidth = contentSizeWidth;
39-
mContentHeight = contentSizeHeight;
4034
mEventCount = eventCount;
4135
}
4236

@@ -53,13 +47,7 @@ public void dispatch(RCTEventEmitter rctEventEmitter) {
5347
private WritableMap serializeEventData() {
5448
WritableMap eventData = Arguments.createMap();
5549
eventData.putString("text", mText);
56-
57-
WritableMap contentSize = Arguments.createMap();
58-
contentSize.putDouble("width", mContentWidth);
59-
contentSize.putDouble("height", mContentHeight);
60-
eventData.putMap("contentSize", contentSize);
6150
eventData.putInt("eventCount", mEventCount);
62-
6351
eventData.putInt("target", getViewTag());
6452
return eventData;
6553
}

ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -672,26 +672,12 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
672672
return;
673673
}
674674

675-
// TODO: remove contentSize from onTextChanged entirely now that onChangeContentSize exists?
676-
int contentWidth = mEditText.getWidth();
677-
int contentHeight = mEditText.getHeight();
678-
679-
// Use instead size of text content within EditText when available
680-
if (mEditText.getLayout() != null) {
681-
contentWidth = mEditText.getCompoundPaddingLeft() + mEditText.getLayout().getWidth() +
682-
mEditText.getCompoundPaddingRight();
683-
contentHeight = mEditText.getCompoundPaddingTop() + mEditText.getLayout().getHeight() +
684-
mEditText.getCompoundPaddingBottom();
685-
}
686-
687675
// The event that contains the event counter and updates it must be sent first.
688676
// TODO: t7936714 merge these events
689677
mEventDispatcher.dispatchEvent(
690678
new ReactTextChangedEvent(
691679
mEditText.getId(),
692680
s.toString(),
693-
PixelUtil.toDIPFromPixel(contentWidth),
694-
PixelUtil.toDIPFromPixel(contentHeight),
695681
mEditText.incrementAndGetEventCounter()));
696682

697683
mEventDispatcher.dispatchEvent(

0 commit comments

Comments
 (0)