ionic resume pause event prevent from fire on file browse only fire at press the home button
I wrote a small Service to solve that problem:
import {Injectable} from '@angular/core';
import {Subject} from "rxjs/Subject";
@Injectable()
export class EventService {
protected resumeHalted = false;
protected resumeSubject = new Subject<any>();
protected resumeListener = () => {
if (this.resumeHalted) {
return;
}
this.resumeSubject.next();
};
constructor() {
document.addEventListener('resume', this.resumeListener);
}
haltResume() {
this.resumeHalted = true;
}
continueResume() {
this.resumeHalted = false;
}
resume() {
return this.resumeSubject;
}
}
The gallery call is also wrapped in a service. Every time I call it, I "halt" the event and "continue" it after the user interaction finishes:
getPicture(options: CameraOptions) {
let subject = new Subject<any>();
this.eventService.haltResume();
this.camera.getPicture(options).then((path) => {
// ...
subject.next();
subject.complete();
this.eventService.continueResume();
}, () => {
this.eventService.continueResume();
});
return subject.asObservable();
}
The last step: Instead of listening for the resume event, I subscribe to the resume Oberservable:
this.eventService.resume().subscribe(() => {
this.statusBar.hide();
});