Hi,
I would like to create a button which when pressed shows a toast message saying that the application is recording something and the recording is started. When the button is released the toast disappears and of course the recording is stopped.
This is the code I’ve created:
import { Component } from '@angular/core';
import { NavController, IonicPage, Toast } from 'ionic-angular';
import { AlertController, ToastController} from "ionic-angular";
@IonicPage()
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
recording = false;
toast:Toast;
constructor(
public navCtrl: NavController,
public alertCtrl: AlertController,
private toastController: ToastController
) {
}
startRecording() {
console.log('start recording');
this.recording = true;
this.presentToast();
}
stopRecording() {
console.log('stop recording');
this.recording = false;
this.toast.dismiss();
}
presentToast() {
this.toast = this.toastController.create({
message: 'Recording...',
position: 'top'
});
this.toast.onDidDismiss(() => {
console.log('Dismissed toast');
});
this.toast.present();
}
}
On the HTML page I have the following button:
<button ion-button [color] = "((recording) ? 'danger' : 'primary')" (mousedown)="startRecording()" (mouseup)="stopRecording()">
<ion-icon name="mic"></ion-icon>
</button>
The problem is that sometime the toast is not dismissed and remains on the screen. This behaviour is much more visible if I deploy the application on my iPhone (in this case I’ve of course to replace the button events with ‘touchstart’ and ‘touchend’ respectively).
How can I achieve this?