Skip to content

Commit

Permalink
TextInput: Fixed autoscroll to cursor on Android
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shergin authored and facebook-github-bot committed Nov 28, 2017
1 parent a7d46ea commit 0bef872
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
8 changes: 7 additions & 1 deletion RNTester/js/TextInputExample.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down Expand Up @@ -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}
/>
<Text>Plain text value representation:</Text>
<Text>{this.state.text}</Text>
<Text>Content Size: {JSON.stringify(this.state.contentSize)}</Text>
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,7 @@ public ReactEditText(Context context) {
// 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
Expand Down

0 comments on commit 0bef872

Please sign in to comment.