From 0cbd2638016b96a5a6165b27ef745bf9e390ebb4 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Thu, 16 Apr 2020 14:52:03 +0200 Subject: [PATCH] Fixed velocity prop not available on iOS --- src/components/Custom/AutoHideComponent.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/Custom/AutoHideComponent.js b/src/components/Custom/AutoHideComponent.js index 978df7c..eafebb3 100644 --- a/src/components/Custom/AutoHideComponent.js +++ b/src/components/Custom/AutoHideComponent.js @@ -21,6 +21,8 @@ export default class AutoHideComponent extends React.Component { downAnimation; upAnimation; + lastOffset: number; + state = { fabPosition: new Animated.Value(0), }; @@ -30,9 +32,8 @@ export default class AutoHideComponent extends React.Component { } onScroll({nativeEvent}: Object) { - if (nativeEvent.velocity === undefined) - return; - if (nativeEvent.velocity.y > 0.2) { // Go down + const speed = this.lastOffset - nativeEvent.contentOffset.y; + if (speed < -5) { // Go down if (!this.isAnimationDownPlaying) { this.isAnimationDownPlaying = true; if (this.isAnimationUpPlaying) @@ -46,7 +47,7 @@ export default class AutoHideComponent extends React.Component { this.isAnimationDownPlaying = false }); } - } else if (nativeEvent.velocity.y < -0.2) { // Go up + } else if (speed > 5) { // Go up if (!this.isAnimationUpPlaying) { this.isAnimationUpPlaying = true; if (this.isAnimationDownPlaying) @@ -61,6 +62,7 @@ export default class AutoHideComponent extends React.Component { }); } } + this.lastOffset = nativeEvent.contentOffset.y; } render() {