Browse Source

Fixed velocity prop not available on iOS

Arnaud Vergnet 4 years ago
parent
commit
0cbd263801
1 changed files with 6 additions and 4 deletions
  1. 6
    4
      src/components/Custom/AutoHideComponent.js

+ 6
- 4
src/components/Custom/AutoHideComponent.js View File

@@ -21,6 +21,8 @@ export default class AutoHideComponent extends React.Component<Props, State> {
21 21
     downAnimation;
22 22
     upAnimation;
23 23
 
24
+    lastOffset: number;
25
+
24 26
     state = {
25 27
         fabPosition: new Animated.Value(0),
26 28
     };
@@ -30,9 +32,8 @@ export default class AutoHideComponent extends React.Component<Props, State> {
30 32
     }
31 33
 
32 34
     onScroll({nativeEvent}: Object) {
33
-        if (nativeEvent.velocity === undefined)
34
-            return;
35
-        if (nativeEvent.velocity.y > 0.2) { // Go down
35
+        const speed = this.lastOffset - nativeEvent.contentOffset.y;
36
+        if (speed < -5) { // Go down
36 37
             if (!this.isAnimationDownPlaying) {
37 38
                 this.isAnimationDownPlaying = true;
38 39
                 if (this.isAnimationUpPlaying)
@@ -46,7 +47,7 @@ export default class AutoHideComponent extends React.Component<Props, State> {
46 47
                     this.isAnimationDownPlaying = false
47 48
                 });
48 49
             }
49
-        } else if (nativeEvent.velocity.y < -0.2) { // Go up
50
+        } else if (speed > 5) { // Go up
50 51
             if (!this.isAnimationUpPlaying) {
51 52
                 this.isAnimationUpPlaying = true;
52 53
                 if (this.isAnimationDownPlaying)
@@ -61,6 +62,7 @@ export default class AutoHideComponent extends React.Component<Props, State> {
61 62
                 });
62 63
             }
63 64
         }
65
+        this.lastOffset = nativeEvent.contentOffset.y;
64 66
     }
65 67
 
66 68
     render() {

Loading…
Cancel
Save