Fixed velocity prop not available on iOS

This commit is contained in:
Arnaud Vergnet 2020-04-16 14:52:03 +02:00
parent 44f7a99bea
commit 0cbd263801

View file

@ -21,6 +21,8 @@ export default class AutoHideComponent extends React.Component<Props, State> {
downAnimation; downAnimation;
upAnimation; upAnimation;
lastOffset: number;
state = { state = {
fabPosition: new Animated.Value(0), fabPosition: new Animated.Value(0),
}; };
@ -30,9 +32,8 @@ export default class AutoHideComponent extends React.Component<Props, State> {
} }
onScroll({nativeEvent}: Object) { onScroll({nativeEvent}: Object) {
if (nativeEvent.velocity === undefined) const speed = this.lastOffset - nativeEvent.contentOffset.y;
return; if (speed < -5) { // Go down
if (nativeEvent.velocity.y > 0.2) { // Go down
if (!this.isAnimationDownPlaying) { if (!this.isAnimationDownPlaying) {
this.isAnimationDownPlaying = true; this.isAnimationDownPlaying = true;
if (this.isAnimationUpPlaying) if (this.isAnimationUpPlaying)
@ -46,7 +47,7 @@ export default class AutoHideComponent extends React.Component<Props, State> {
this.isAnimationDownPlaying = false this.isAnimationDownPlaying = false
}); });
} }
} else if (nativeEvent.velocity.y < -0.2) { // Go up } else if (speed > 5) { // Go up
if (!this.isAnimationUpPlaying) { if (!this.isAnimationUpPlaying) {
this.isAnimationUpPlaying = true; this.isAnimationUpPlaying = true;
if (this.isAnimationDownPlaying) if (this.isAnimationDownPlaying)
@ -61,6 +62,7 @@ export default class AutoHideComponent extends React.Component<Props, State> {
}); });
} }
} }
this.lastOffset = nativeEvent.contentOffset.y;
} }
render() { render() {