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

Commit 8464a95

Browse files
committed
prevent automatic log scrolling if user watching logs
1 parent 8cc1d96 commit 8464a95

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/view/cli.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class LogOutput extends Component {
7474
super(props);
7575
this._refresh = true;
7676
this._ref = React.createRef();
77+
this._scrolledToBottom = false;
7778
}
7879

7980
shouldComponentUpdate() {
@@ -101,12 +102,17 @@ class LogOutput extends Component {
101102

102103
tailLogs() {
103104
const view = this._ref && this._ref.current;
104-
view && view.scrollToEnd({ animated: false });
105+
view && !this._scrolledToBottom && view.scrollToEnd({ animated: false });
106+
}
107+
108+
handleScroll = ({ nativeEvent: { contentOffset, contentSize, layoutMeasurement } }) => {
109+
const threshold = 10;
110+
this._scrolledToBottom = (layoutMeasurement.height + contentOffset.y + threshold) >= contentSize.height;
105111
}
106112

107113
render() {
108114
return (
109-
<ScrollView ref={this._ref} contentContainerStyle={logStyles.content}>
115+
<ScrollView ref={this._ref} contentContainerStyle={logStyles.content} onScroll={this.handleScroll} scrollEventThrottle={16}>
110116
<Text style={logStyles.text}>{this.printLogs}</Text>
111117
</ScrollView>
112118
);

0 commit comments

Comments
 (0)