Skip to content

Commit

Permalink
fix(events): touchmove position while transition
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-rr committed Nov 10, 2021
1 parent 1b0d082 commit 7c367a3
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 40 deletions.
33 changes: 22 additions & 11 deletions dist/cupertino-pane.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* Released under the MIT License
*
* Released on: November 9, 2021
* Released on: November 11, 2021
*/

/*! *****************************************************************************
Expand Down Expand Up @@ -426,10 +426,19 @@ class Events {
return;
}
let newVal = this.instance.getPanelTransformY() + diffY;
// Patch for 'touchmove' first event
// when start slowly events with small velocity
if (this.steps.length < 2 && velocityY < 1) {
newVal = this.instance.getPanelTransformY() + (diffY * velocityY);
// First event after touchmove only
if (this.steps.length < 2) {
// Patch for 'touchmove' first event
// when start slowly events with small velocity
if (velocityY < 1) {
newVal = this.instance.getPanelTransformY() + (diffY * velocityY);
}
// Move while transition patch next transitions
let computedTranslateY = new WebKitCSSMatrix(window.getComputedStyle(this.instance.paneEl).transform).m42;
let transitionYDiff = computedTranslateY - this.instance.getPanelTransformY();
if (Math.abs(transitionYDiff)) {
newVal += transitionYDiff;
}
}
// Detect if input was blured
// TODO: Check that blured from pane child instance
Expand Down Expand Up @@ -1335,7 +1344,7 @@ class CupertinoPane {
this.followerEl = document.querySelector(this.settings.followerElement);
this.followerEl.style.willChange = 'transform, border-radius';
this.followerEl.style.transform = `translateY(0px) translateZ(0px)`;
this.followerEl.style.transition = `all ${this.settings.animationDuration}ms ${this.getTimingFunction((_a = this.settings.breaks[this.currentBreak()]) === null || _a === void 0 ? void 0 : _a.bounce)} 0s`;
this.followerEl.style.transition = this.buildTransitionValue((_a = this.settings.breaks[this.currentBreak()]) === null || _a === void 0 ? void 0 : _a.bounce);
}
// Assign multiplicators for push elements
if (this.settings.zStack) {
Expand Down Expand Up @@ -1469,8 +1478,11 @@ class CupertinoPane {
/**
* Private Utils methods
*/
getTimingFunction(bounce) {
return bounce ? 'cubic-bezier(0.175, 0.885, 0.370, 1.120)' : this.settings.animationType;
buildTransitionValue(bounce) {
if (bounce) {
return `all 300ms cubic-bezier(.155,1.105,.295,1.12)`;
}
return `all ${this.settings.animationDuration}ms ${this.settings.animationType}`;
}
isBackdropPresented() {
return document.querySelector(`.cupertino-pane-wrapper .backdrop`)
Expand Down Expand Up @@ -1835,12 +1847,11 @@ class CupertinoPane {
// Get timing function && push for next
const nextBreak = Object.entries(this.breakpoints.breaks).find(val => val[1] === params.translateY);
let bounce = nextBreak && ((_a = this.settings.breaks[nextBreak[0]]) === null || _a === void 0 ? void 0 : _a.bounce);
const timingForNext = this.getTimingFunction(bounce);
// style
this.paneEl.style.transition = `transform ${this.settings.animationDuration}ms ${timingForNext} 0s`;
this.paneEl.style.transition = this.buildTransitionValue(bounce);
// Bind for follower same transitions
if (this.followerEl) {
this.followerEl.style.transition = `transform ${this.settings.animationDuration}ms ${timingForNext} 0s`;
this.followerEl.style.transition = this.buildTransitionValue(bounce);
}
// Push transition
if (this.settings.zStack) {
Expand Down
4 changes: 2 additions & 2 deletions dist/cupertino-pane.esm.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cupertino-pane.esm.min.js.map

Large diffs are not rendered by default.

33 changes: 22 additions & 11 deletions dist/cupertino-pane.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/cupertino-pane.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/cupertino-pane.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/types/cupertino-pane.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export declare class CupertinoPane {
/**
* Private Utils methods
*/
private getTimingFunction;
private buildTransitionValue;
private isBackdropPresented;
private renderBackdrop;
/**
Expand Down
2 changes: 1 addition & 1 deletion dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ declare class CupertinoPane {
/**
* Private Utils methods
*/
private getTimingFunction;
private buildTransitionValue;
private isBackdropPresented;
private renderBackdrop;
/**
Expand Down
15 changes: 9 additions & 6 deletions src/cupertino-pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export class CupertinoPane {
);
this.followerEl.style.willChange = 'transform, border-radius';
this.followerEl.style.transform = `translateY(0px) translateZ(0px)`;
this.followerEl.style.transition = `all ${this.settings.animationDuration}ms ${this.getTimingFunction(this.settings.breaks[this.currentBreak()]?.bounce)} 0s`;
this.followerEl.style.transition = this.buildTransitionValue(this.settings.breaks[this.currentBreak()]?.bounce);
}

// Assign multiplicators for push elements
Expand Down Expand Up @@ -493,8 +493,12 @@ export class CupertinoPane {
/**
* Private Utils methods
*/
private getTimingFunction(bounce) {
return bounce ? 'cubic-bezier(0.175, 0.885, 0.370, 1.120)' : this.settings.animationType;
private buildTransitionValue(bounce: boolean): string {
if (bounce) {
return `all 300ms cubic-bezier(.155,1.105,.295,1.12)`;
}

return `all ${this.settings.animationDuration}ms ${this.settings.animationType}`;
}

private isBackdropPresented() {
Expand Down Expand Up @@ -924,13 +928,12 @@ export class CupertinoPane {
val => val[1] === params.translateY
);
let bounce = nextBreak && this.settings.breaks[nextBreak[0]]?.bounce;
const timingForNext = this.getTimingFunction(bounce);

// style
this.paneEl.style.transition = `transform ${this.settings.animationDuration}ms ${timingForNext} 0s`;
this.paneEl.style.transition = this.buildTransitionValue(bounce);
// Bind for follower same transitions
if (this.followerEl) {
this.followerEl.style.transition = `transform ${this.settings.animationDuration}ms ${timingForNext} 0s`;
this.followerEl.style.transition = this.buildTransitionValue(bounce);
}

// Push transition
Expand Down
20 changes: 16 additions & 4 deletions src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,22 @@ export class Events {

let newVal = this.instance.getPanelTransformY() + diffY;

// Patch for 'touchmove' first event
// when start slowly events with small velocity
if (this.steps.length < 2 && velocityY < 1) {
newVal = this.instance.getPanelTransformY() + (diffY * velocityY);
// First event after touchmove only
if (this.steps.length < 2) {
// Patch for 'touchmove' first event
// when start slowly events with small velocity
if (velocityY < 1) {
newVal = this.instance.getPanelTransformY() + (diffY * velocityY);
}

// Move while transition patch next transitions
let computedTranslateY = new WebKitCSSMatrix(
window.getComputedStyle(this.instance.paneEl).transform
).m42;
let transitionYDiff = computedTranslateY - this.instance.getPanelTransformY();
if (Math.abs(transitionYDiff)) {
newVal += transitionYDiff;
}
}

// Detect if input was blured
Expand Down

0 comments on commit 7c367a3

Please sign in to comment.