feat(gesture): add option to run inside NgZone for Angular apps (#20685)

fixes #20529
This commit is contained in:
Liam DeBeasi
2020-04-27 12:50:44 -04:00
committed by GitHub
parent 15203de08b
commit 429edb053b

View File

@@ -1,14 +1,24 @@
import { Injectable } from '@angular/core';
import { Injectable, NgZone } from '@angular/core';
import { Gesture, GestureConfig, createGesture } from '@ionic/core';
@Injectable({
providedIn: 'root',
})
export class GestureController {
constructor(private zone: NgZone) {}
/**
* Create a new gesture
*/
create(opts: GestureConfig): Gesture {
create(opts: GestureConfig, runInsideAngularZone = false): Gesture {
if (runInsideAngularZone) {
Object.getOwnPropertyNames(opts).forEach(key => {
if (typeof opts[key] === 'function') {
const fn = opts[key];
opts[key] = (...props) => this.zone.run(() => fn(...props));
}
});
}
return createGesture(opts);
}
}