Skip to content

Commit 0bef872

Browse files
sherginfacebook-github-bot
authored andcommitted
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 #12799 #15778 Special thanks to konradkierus! Reviewed By: sahrens Differential Revision: D6405985 fbshipit-source-id: 337a390a9db7b3528200ef66c4a079b87608294e
1 parent a7d46ea commit 0bef872

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

‎RNTester/js/TextInputExample.android.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,14 @@ class AutogrowingTextInputExample extends React.Component<{}> {
320320
width: 100,
321321
multiline: true,
322322
text: '',
323+
contentSize: {
324+
width: 0,
325+
height: 0,
326+
},
323327
};
324328
}
325329

326-
componentDidReceiveProps(props) {
330+
componentWillReceiveProps(props) {
327331
this.setState({
328332
multiline: props.multiline,
329333
});
@@ -351,10 +355,12 @@ class AutogrowingTextInputExample extends React.Component<{}> {
351355
multiline={this.state.multiline}
352356
style={[style, {width: this.state.width + '%'}]}
353357
onChangeText={(value) => this.setState({text: value})}
358+
onContentSizeChange={(event) => this.setState({contentSize: event.nativeEvent.contentSize})}
354359
{...props}
355360
/>
356361
<Text>Plain text value representation:</Text>
357362
<Text>{this.state.text}</Text>
363+
<Text>Content Size: {JSON.stringify(this.state.contentSize)}</Text>
358364
</View>
359365
);
360366
}

‎ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditText.java‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,7 @@ public ReactEditText(Context context) {
117117
// TODO: t6408636 verify if we should schedule a layout after a View does a requestLayout()
118118
@Override
119119
public boolean isLayoutRequested() {
120-
// If we are watching and updating container height based on content size
121-
// then we don't want to scroll right away. This isn't perfect -- you might
122-
// want to limit the height the text input can grow to. Possible solution
123-
// is to add another prop that determines whether we should scroll to end
124-
// of text.
125-
if (mContentSizeWatcher != null) {
126-
return isMultiline();
127-
} else {
128-
return false;
129-
}
120+
return false;
130121
}
131122

132123
@Override

0 commit comments

Comments
 (0)