mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 21:15:24 +08:00
refactor(picker): using DomController
Removed NativeRafDebouncer
This commit is contained in:
@ -10,8 +10,8 @@ import { Picker } from './picker';
|
|||||||
import { PickerOptions, PickerColumn, PickerColumnOption } from './picker-options';
|
import { PickerOptions, PickerColumn, PickerColumnOption } from './picker-options';
|
||||||
import { Haptic } from '../../util/haptic';
|
import { Haptic } from '../../util/haptic';
|
||||||
import { UIEventManager } from '../../util/ui-event-manager';
|
import { UIEventManager } from '../../util/ui-event-manager';
|
||||||
|
import { DomController, DomDebouncer } from '../../util/dom-controller';
|
||||||
import { ViewController } from '../../navigation/view-controller';
|
import { ViewController } from '../../navigation/view-controller';
|
||||||
import { Debouncer, NativeRafDebouncer } from '../../util/debouncer';
|
|
||||||
import { GestureController, BlockerDelegate, BLOCK_ALL } from '../../gestures/gesture-controller';
|
import { GestureController, BlockerDelegate, BLOCK_ALL } from '../../gestures/gesture-controller';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +53,7 @@ export class PickerColumnCmp {
|
|||||||
lastIndex: number;
|
lastIndex: number;
|
||||||
lastTempIndex: number;
|
lastTempIndex: number;
|
||||||
decelerateFunc: Function;
|
decelerateFunc: Function;
|
||||||
debouncer: Debouncer = new NativeRafDebouncer();
|
debouncer: DomDebouncer;
|
||||||
events: UIEventManager = new UIEventManager(false);
|
events: UIEventManager = new UIEventManager(false);
|
||||||
|
|
||||||
@Output() ionChange: EventEmitter<any> = new EventEmitter();
|
@Output() ionChange: EventEmitter<any> = new EventEmitter();
|
||||||
@ -63,11 +63,13 @@ export class PickerColumnCmp {
|
|||||||
private elementRef: ElementRef,
|
private elementRef: ElementRef,
|
||||||
private _sanitizer: DomSanitizer,
|
private _sanitizer: DomSanitizer,
|
||||||
private _zone: NgZone,
|
private _zone: NgZone,
|
||||||
private _haptic: Haptic
|
private _haptic: Haptic,
|
||||||
|
domCtrl: DomController,
|
||||||
) {
|
) {
|
||||||
this.rotateFactor = config.getNumber('pickerRotateFactor', 0);
|
this.rotateFactor = config.getNumber('pickerRotateFactor', 0);
|
||||||
this.scaleFactor = config.getNumber('pickerScaleFactor', 1);
|
this.scaleFactor = config.getNumber('pickerScaleFactor', 1);
|
||||||
this.decelerateFunc = this.decelerate.bind(this);
|
this.decelerateFunc = this.decelerate.bind(this);
|
||||||
|
this.debouncer = domCtrl.debouncer();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngAfterViewInit() {
|
ngAfterViewInit() {
|
||||||
@ -145,7 +147,7 @@ export class PickerColumnCmp {
|
|||||||
let currentY = pointerCoord(ev).y;
|
let currentY = pointerCoord(ev).y;
|
||||||
this.pos.push(currentY, Date.now());
|
this.pos.push(currentY, Date.now());
|
||||||
|
|
||||||
this.debouncer.debounce(() => {
|
this.debouncer.write(() => {
|
||||||
if (this.startY === null) {
|
if (this.startY === null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,10 @@
|
|||||||
|
|
||||||
import { nativeRaf } from './dom';
|
|
||||||
|
|
||||||
export interface Debouncer {
|
export interface Debouncer {
|
||||||
debounce(Function);
|
debounce(Function);
|
||||||
cancel();
|
cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class FakeDebouncer implements Debouncer {
|
|
||||||
debounce(callback: Function) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
cancel() {}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TimeoutDebouncer implements Debouncer {
|
export class TimeoutDebouncer implements Debouncer {
|
||||||
private timer: number = null;
|
private timer: number = null;
|
||||||
callback: Function;
|
callback: Function;
|
||||||
@ -42,36 +33,3 @@ export class TimeoutDebouncer implements Debouncer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class NativeRafDebouncer implements Debouncer {
|
|
||||||
callback: Function = null;
|
|
||||||
fireFunc: Function;
|
|
||||||
ptr: number = null;
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.fireFunc = this.fire.bind(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
debounce(callback: Function) {
|
|
||||||
if (this.callback === null) {
|
|
||||||
this.callback = callback;
|
|
||||||
this.ptr = nativeRaf(this.fireFunc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fire() {
|
|
||||||
this.callback();
|
|
||||||
this.callback = null;
|
|
||||||
this.ptr = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
cancel() {
|
|
||||||
if (this.ptr !== null) {
|
|
||||||
cancelAnimationFrame(this.ptr);
|
|
||||||
this.ptr = null;
|
|
||||||
this.callback = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user