9
9
*/
10
10
11
11
import AnimatedImplementation from '../../Animated/AnimatedImplementation' ;
12
+ import AnimatedAddition from '../../Animated/nodes/AnimatedAddition' ;
13
+ import AnimatedDiffClamp from '../../Animated/nodes/AnimatedDiffClamp' ;
14
+ import AnimatedNode from '../../Animated/nodes/AnimatedNode' ;
15
+
12
16
import * as React from 'react' ;
13
17
import StyleSheet from '../../StyleSheet/StyleSheet' ;
14
18
import View from '../View/View' ;
@@ -29,6 +33,7 @@ export type Props = {
29
33
// The height of the parent ScrollView. Currently only set when inverted.
30
34
scrollViewHeight : ?number ,
31
35
nativeID ?: ?string ,
36
+ hiddenOnScroll ?: ?boolean ,
32
37
...
33
38
} ;
34
39
@@ -50,7 +55,7 @@ class ScrollViewStickyHeader extends React.Component<Props, State> {
50
55
translateY : null ,
51
56
} ;
52
57
53
- _translateY : ?AnimatedImplementation . Interpolation = null ;
58
+ _translateY : ?AnimatedNode = null ;
54
59
_shouldRecreateTranslateY : boolean = true ;
55
60
_haveReceivedInitialZeroTranslateY : boolean = true ;
56
61
_ref : any ; // TODO T53738161: flow type this, and the whole file
@@ -87,12 +92,15 @@ class ScrollViewStickyHeader extends React.Component<Props, State> {
87
92
updateTranslateListener (
88
93
translateY : AnimatedImplementation . Interpolation ,
89
94
isFabric : boolean ,
95
+ offset : AnimatedDiffClamp | null ,
90
96
) {
91
97
if ( this . _translateY != null && this . _animatedValueListenerId != null ) {
92
98
this . _translateY . removeListener ( this . _animatedValueListenerId ) ;
93
99
}
100
+ offset
101
+ ? ( this . _translateY = new AnimatedAddition ( translateY , offset ) )
102
+ : ( this . _translateY = translateY ) ;
94
103
95
- this . _translateY = translateY ;
96
104
this . _shouldRecreateTranslateY = false ;
97
105
98
106
if ( ! isFabric ) {
@@ -178,7 +186,6 @@ class ScrollViewStickyHeader extends React.Component<Props, State> {
178
186
// eslint-disable-next-line dot-notation
179
187
( this . _ref && this . _ref [ '_internalInstanceHandle' ] ?. stateNode ?. canonical )
180
188
) ;
181
-
182
189
// Initially and in the case of updated props or layout, we
183
190
// recreate this interpolated value. Otherwise, we do not recreate
184
191
// when there are state changes.
@@ -259,6 +266,22 @@ class ScrollViewStickyHeader extends React.Component<Props, State> {
259
266
outputRange ,
260
267
} ),
261
268
isFabric,
269
+ this.props.hiddenOnScroll
270
+ ? new AnimatedDiffClamp(
271
+ this.props.scrollAnimatedValue
272
+ .interpolate({
273
+ extrapolateLeft : 'clamp' ,
274
+ inputRange : [ layoutY , layoutY + 1 ] ,
275
+ outputRange : ( [ 0 , 1 ] : Array < number > ) ,
276
+ } )
277
+ .interpolate({
278
+ inputRange : [ 0 , 1 ] ,
279
+ outputRange : ( [ 0 , - 1 ] : Array < number > ) ,
280
+ } ),
281
+ -this.state.layoutHeight,
282
+ 0,
283
+ )
284
+ : null,
262
285
);
263
286
}
264
287
0 commit comments