Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

prevent automatic log scrolling if user interacting with logs #1309

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/view/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class LogOutput extends Component {
super(props);
this._refresh = true;
this._ref = React.createRef();
this._scrolledToBottom = false;
this.handleScroll = this.handleScroll.bind(this);
}

shouldComponentUpdate() {
Expand Down Expand Up @@ -101,12 +103,26 @@ class LogOutput extends Component {

tailLogs() {
const view = this._ref && this._ref.current;
view && view.scrollToEnd({ animated: false });
view && !this._scrolledToBottom && view.scrollToEnd({ animated: false });
}

handleScroll({
nativeEvent: { contentOffset, contentSize, layoutMeasurement },
}) {
const threshold = 10;
this._scrolledToBottom =
layoutMeasurement.height + contentOffset.y + threshold >=
contentSize.height;
}

render() {
return (
<ScrollView ref={this._ref} contentContainerStyle={logStyles.content}>
<ScrollView
ref={this._ref}
contentContainerStyle={logStyles.content}
onScroll={this.handleScroll}
scrollEventThrottle={16}
>
<Text style={logStyles.text}>{this.printLogs}</Text>
</ScrollView>
);
Expand Down