From 39d12629dbc12e4a86037b09350ec1c49ed6e2e4 Mon Sep 17 00:00:00 2001 From: Andreas Greimel Date: Thu, 9 Jan 2020 19:35:01 +0100 Subject: [PATCH] fix(picker): pick correct option at low velocities (#19660) fixes #19659 --- core/src/components/picker-column/picker-column.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/components/picker-column/picker-column.tsx b/core/src/components/picker-column/picker-column.tsx index e268acf60d..7233d46cd1 100644 --- a/core/src/components/picker-column/picker-column.tsx +++ b/core/src/components/picker-column/picker-column.tsx @@ -313,6 +313,18 @@ export class PickerColumnCmp implements ComponentInterface { } else { this.y += detail.deltaY; + + if (Math.abs(detail.velocityY) < 0.05) { + const isScrollingUp = detail.deltaY > 0; + const optHeightFraction = (Math.abs(this.y) % this.optHeight) / this.optHeight; + + if (isScrollingUp && optHeightFraction > 0.5) { + this.velocity = Math.abs(this.velocity) * -1; + } else if (!isScrollingUp && optHeightFraction <= 0.5) { + this.velocity = Math.abs(this.velocity); + } + } + this.decelerate(); } }