This repository was archived by the owner on Feb 23, 2021. It is now read-only.
File tree 1 file changed +23
-3
lines changed
1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,9 @@ class LogOutput extends Component {
69
69
super ( props ) ;
70
70
this . _refresh = true ;
71
71
this . _ref = React . createRef ( ) ;
72
+ this . state = {
73
+ maxOffset : undefined ,
74
+ } ;
72
75
}
73
76
74
77
shouldComponentUpdate ( ) {
@@ -86,17 +89,34 @@ class LogOutput extends Component {
86
89
87
90
componentWillUnmount ( ) {
88
91
clearTimeout ( this . _tLast ) ;
89
- clearTimeout ( this . _tScroll ) ;
92
+ clearInterval ( this . _tScroll ) ;
90
93
}
91
94
92
95
get printLogs ( ) {
93
- this . _tScroll = setTimeout ( ( ) => this . _ref . current . scrollToEnd ( ) , 50 ) ;
94
96
return this . props . logs ;
95
97
}
96
98
99
+ onScroll ( scrollEvent ) {
100
+ const offset = scrollEvent . nativeEvent . contentOffset . y ;
101
+ if ( this . state . maxOffset === undefined || this . state . maxOffset <= offset ) {
102
+ this . setState ( { maxOffset : offset - 10 } )
103
+ if ( this . _tScroll === undefined ) {
104
+ this . _tScroll = setInterval ( ( ) => this . _ref . current . scrollToEnd ( ) , 1000 ) ;
105
+ }
106
+ } else if ( offset < this . state . maxOffset && this . _tScroll ) {
107
+ clearInterval ( this . _tScroll ) ;
108
+ this . _tScroll = undefined ;
109
+ }
110
+ }
111
+
97
112
render ( ) {
98
113
return (
99
- < ScrollView ref = { this . _ref } contentContainerStyle = { logStyles . content } >
114
+ < ScrollView
115
+ ref = { this . _ref }
116
+ contentContainerStyle = { logStyles . content }
117
+ onScroll = { event => this . onScroll ( event ) }
118
+ scrollEventThrottle = { 300 }
119
+ >
100
120
< Text style = { logStyles . text } > { this . printLogs } </ Text >
101
121
</ ScrollView >
102
122
) ;
You can’t perform that action at this time.
0 commit comments