(detail: GestureDetail)
| 596 | } |
| 597 | |
| 598 | private onEnd(detail: GestureDetail) { |
| 599 | if (!this.isAnimating || !this.animation) { |
| 600 | assert(false, 'isAnimating has to be true'); |
| 601 | return; |
| 602 | } |
| 603 | const isOpen = this._isOpen; |
| 604 | const isEndSide = this.isEndSide; |
| 605 | const delta = computeDelta(detail.deltaX, isOpen, isEndSide); |
| 606 | const width = this.width; |
| 607 | const stepValue = delta / width; |
| 608 | const velocity = detail.velocityX; |
| 609 | const z = width / 2.0; |
| 610 | const shouldCompleteRight = velocity >= 0 && (velocity > 0.2 || detail.deltaX > z); |
| 611 | |
| 612 | const shouldCompleteLeft = velocity <= 0 && (velocity < -0.2 || detail.deltaX < -z); |
| 613 | |
| 614 | const shouldComplete = isOpen |
| 615 | ? isEndSide |
| 616 | ? shouldCompleteRight |
| 617 | : shouldCompleteLeft |
| 618 | : isEndSide |
| 619 | ? shouldCompleteLeft |
| 620 | : shouldCompleteRight; |
| 621 | |
| 622 | let shouldOpen = !isOpen && shouldComplete; |
| 623 | if (isOpen && !shouldComplete) { |
| 624 | shouldOpen = true; |
| 625 | } |
| 626 | |
| 627 | this.lastOnEnd = detail.currentTime; |
| 628 | |
| 629 | // Account for rounding errors in JS |
| 630 | let newStepValue = shouldComplete ? 0.001 : -0.001; |
| 631 | |
| 632 | /** |
| 633 | * stepValue can sometimes return a negative |
| 634 | * value, but you can't have a negative time value |
| 635 | * for the cubic bezier curve (at least with web animations) |
| 636 | */ |
| 637 | const adjustedStepValue = stepValue < 0 ? 0.01 : stepValue; |
| 638 | |
| 639 | /** |
| 640 | * Animation will be reversed here, so need to |
| 641 | * reverse the easing curve as well |
| 642 | * |
| 643 | * Additionally, we need to account for the time relative |
| 644 | * to the new easing curve, as `stepValue` is going to be given |
| 645 | * in terms of a linear curve. |
| 646 | */ |
| 647 | newStepValue += |
| 648 | getTimeGivenProgression([0, 0], [0.4, 0], [0.6, 1], [1, 1], clamp(0, adjustedStepValue, 0.9999))[0] || 0; |
| 649 | |
| 650 | const playTo = this._isOpen ? !shouldComplete : shouldComplete; |
| 651 | |
| 652 | this.animation |
| 653 | .easing('cubic-bezier(0.4, 0.0, 0.6, 1)') |
| 654 | .onFinish(() => this.afterAnimation(shouldOpen, GESTURE), { oneTimeCallback: true }) |
| 655 | .progressEnd(playTo ? 1 : 0, this._isOpen ? 1 - newStepValue : newStepValue, 300); |
no test coverage detected