Skip to content

Commit cfbc5ea

Browse files
committed
perf(picker): improves picker UX feedback
1 parent 9469b4f commit cfbc5ea

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

src/animations/animation.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ export class Animation {
914914
_willChg(addWillChange: boolean) {
915915
let wc: string[];
916916
let effects = this._fx;
917+
let willChange: string;
917918
if (addWillChange && effects) {
918919
wc = [];
919920
for (var i = 0; i < effects.length; i++) {
@@ -925,8 +926,10 @@ export class Animation {
925926
wc.push(propWC);
926927
}
927928
}
929+
willChange = wc.join(',');
930+
} else {
931+
willChange = '';
928932
}
929-
let willChange = (wc && wc.length) ? wc.join(',') : '';
930933
for (var i = 0; i < this._eL; i++) {
931934
// ******** DOM WRITE ****************
932935
(<any>this._e[i]).style.willChange = willChange;

src/components/picker/picker-component.ts

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ export class PickerColumnCmp {
6363
private elementRef: ElementRef,
6464
private _sanitizer: DomSanitizer,
6565
private _zone: NgZone,
66-
private _haptic: Haptic) {
66+
private _haptic: Haptic
67+
) {
6768
this.rotateFactor = config.getNumber('pickerRotateFactor', 0);
6869
this.scaleFactor = config.getNumber('pickerScaleFactor', 1);
6970
this.decelerateFunc = this.decelerate.bind(this);
@@ -104,47 +105,46 @@ export class PickerColumnCmp {
104105
// some "click" events to capture
105106
ev.preventDefault();
106107

107-
this.debouncer.debounce(() => {
108-
// cancel any previous raf's that haven't fired yet
109-
if (this.rafId) {
110-
cancelRaf(this.rafId);
111-
this.rafId = null;
112-
}
108+
// cancel any previous raf's that haven't fired yet
109+
if (this.rafId) {
110+
cancelRaf(this.rafId);
111+
this.rafId = null;
112+
}
113113

114-
// remember where the pointer started from`
115-
this.startY = pointerCoord(ev).y;
116-
117-
// reset everything
118-
this.velocity = 0;
119-
this.pos.length = 0;
120-
this.pos.push(this.startY, Date.now());
121-
122-
let options = this.col.options;
123-
let minY = (options.length - 1);
124-
let maxY = 0;
125-
for (var i = 0; i < options.length; i++) {
126-
if (!options[i].disabled) {
127-
minY = Math.min(minY, i);
128-
maxY = Math.max(maxY, i);
129-
}
114+
// remember where the pointer started from`
115+
this.startY = pointerCoord(ev).y;
116+
117+
// reset everything
118+
this.velocity = 0;
119+
this.pos.length = 0;
120+
this.pos.push(this.startY, Date.now());
121+
122+
let options = this.col.options;
123+
let minY = (options.length - 1);
124+
let maxY = 0;
125+
for (var i = 0; i < options.length; i++) {
126+
if (!options[i].disabled) {
127+
minY = Math.min(minY, i);
128+
maxY = Math.max(maxY, i);
130129
}
130+
}
131131

132-
this.minY = (minY * this.optHeight * -1);
133-
this.maxY = (maxY * this.optHeight * -1);
134-
});
132+
this.minY = (minY * this.optHeight * -1);
133+
this.maxY = (maxY * this.optHeight * -1);
135134
return true;
136135
}
137136

138137
pointerMove(ev: UIEvent) {
139138
ev.preventDefault();
140139
ev.stopPropagation();
141140

141+
let currentY = pointerCoord(ev).y;
142+
this.pos.push(currentY, Date.now());
143+
142144
this.debouncer.debounce(() => {
143145
if (this.startY === null) {
144146
return;
145147
}
146-
let currentY = pointerCoord(ev).y;
147-
this.pos.push(currentY, Date.now());
148148

149149
// update the scroll position relative to pointer start position
150150
let y = this.y + (currentY - this.startY);
@@ -214,7 +214,8 @@ export class PickerColumnCmp {
214214
var movedTop = (this.pos[startPos - 1] - this.pos[endPos - 1]);
215215

216216
// based on XXms compute the movement to apply for each render step
217-
this.velocity = ((movedTop / timeOffset) * FRAME_MS);
217+
var velocity = ((movedTop / timeOffset) * FRAME_MS);
218+
this.velocity = clamp(-MAX_PICKER_SPEED, velocity, MAX_PICKER_SPEED);
218219
}
219220

220221
if (Math.abs(endY - this.startY) > 3) {
@@ -641,3 +642,4 @@ let pickerIds = -1;
641642
const PICKER_OPT_SELECTED = 'picker-opt-selected';
642643
const DECELERATION_FRICTION = 0.97;
643644
const FRAME_MS = (1000 / 60);
645+
const MAX_PICKER_SPEED = 50;

0 commit comments

Comments
 (0)