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

Commit 33a5b54

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

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/view/cli.js

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

7981
shouldComponentUpdate() {
@@ -101,12 +103,26 @@ class LogOutput extends Component {
101103

102104
tailLogs() {
103105
const view = this._ref && this._ref.current;
104-
view && view.scrollToEnd({ animated: false });
106+
view && !this._scrolledToBottom && view.scrollToEnd({ animated: false });
107+
}
108+
109+
handleScroll({
110+
nativeEvent: { contentOffset, contentSize, layoutMeasurement },
111+
}) {
112+
const threshold = 10;
113+
this._scrolledToBottom =
114+
layoutMeasurement.height + contentOffset.y + threshold >=
115+
contentSize.height;
105116
}
106117

107118
render() {
108119
return (
109-
<ScrollView ref={this._ref} contentContainerStyle={logStyles.content}>
120+
<ScrollView
121+
ref={this._ref}
122+
contentContainerStyle={logStyles.content}
123+
onScroll={this.handleScroll}
124+
scrollEventThrottle={16}
125+
>
110126
<Text style={logStyles.text}>{this.printLogs}</Text>
111127
</ScrollView>
112128
);

0 commit comments

Comments
 (0)