From 0bef872f3fc8b1cd78c574d03eacc886bef4e239 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 27 Nov 2017 16:30:59 -0800 Subject: [PATCH] TextInput: Fixed autoscroll to cursor on Android Summary: This feature was disabled for multiline textinputs in D3528202 ... seems without a good reason. The broken autoscroll-to-cursor feature is terribly harmful and counter-intuitive in ALL cases. I also add a contentSize tracking in the example app to make sure that it is unaffected by this change. https://pxl.cl/9RHP https://github.com/facebook/react-native/issues/12799 https://github.com/facebook/react-native/issues/15778 Special thanks to konradkierus! Reviewed By: sahrens Differential Revision: D6405985 fbshipit-source-id: 337a390a9db7b3528200ef66c4a079b87608294e --- RNTester/js/TextInputExample.android.js | 8 +++++++- .../facebook/react/views/textinput/ReactEditText.java | 11 +---------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/RNTester/js/TextInputExample.android.js b/RNTester/js/TextInputExample.android.js index d682f2044..04d438684 100644 --- a/RNTester/js/TextInputExample.android.js +++ b/RNTester/js/TextInputExample.android.js @@ -320,10 +320,14 @@ class AutogrowingTextInputExample extends React.Component<{}> { width: 100, multiline: true, text: '', + contentSize: { + width: 0, + height: 0, + }, }; } - componentDidReceiveProps(props) { + componentWillReceiveProps(props) { this.setState({ multiline: props.multiline, }); @@ -351,10 +355,12 @@ class AutogrowingTextInputExample extends React.Component<{}> { multiline={this.state.multiline} style={[style, {width: this.state.width + '%'}]} onChangeText={(value) => this.setState({text: value})} + onContentSizeChange={(event) => this.setState({contentSize: event.nativeEvent.contentSize})} {...props} /> Plain text value representation: {this.state.text} + Content Size: {JSON.stringify(this.state.contentSize)} ); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java index 7b06e8897..49dad09bf 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java @@ -117,16 +117,7 @@ public class ReactEditText extends EditText { // TODO: t6408636 verify if we should schedule a layout after a View does a requestLayout() @Override public boolean isLayoutRequested() { - // If we are watching and updating container height based on content size - // then we don't want to scroll right away. This isn't perfect -- you might - // want to limit the height the text input can grow to. Possible solution - // is to add another prop that determines whether we should scroll to end - // of text. - if (mContentSizeWatcher != null) { - return isMultiline(); - } else { - return false; - } + return false; } @Override