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

Commit

Permalink
prevent automatic log scrolling if user watching logs
Browse files Browse the repository at this point in the history
  • Loading branch information
skv-headless committed Sep 23, 2019
1 parent 8cc1d96 commit 33a5b54
Showing 1 changed file with 18 additions and 2 deletions.
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

0 comments on commit 33a5b54

Please sign in to comment.