When the user taps on the image, it goes to the modal then after a long hold action, it goes to an action sheet to select the action. Is there any way to save the image into the photo library?
This ionic app is ios only if it helps reduce the complexity
import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams, ActionSheetController } from '@ionic/angular';
import { FileTransfer, FileUploadOptions, FileTransferObject } from '@ionic-native/file-transfer/ngx';
import { File } from '@ionic-native/file';
@Component({
selector: 'app-modal-images',
templateUrl: './modal-images.page.html',
styleUrls: ['./modal-images.page.scss'],
})
export class ImagesModalPage implements OnInit {
image: any;
held: boolean;
constructor(
private modalCtrl: ModalController,
public actionSheetController: ActionSheetController,
private navParams: NavParams,
private transfer: FileTransfer,
private file: File
) { }
ngOnInit() {
this.imageUrl = this.navParams.data.imageUrl;
this.held = false;
}
async showActionSheet() {
if (!this.held) {
this.held = true;
const actionSheet = await this.actionSheetController.create({
buttons: [{
text: 'Save',
handler: () => {
this.saveImage();
}
}, {
text: 'Cancel',
role: 'cancel',
cssClass: 'cancel-as',
handler: () => {
// do nothing
}
}]
});
actionSheet.onDidDismiss().then(() => {
this.held = false;
});
await actionSheet.present();
}
}
private saveImage() {
var fileTransfer = new FileTransfer();
var uri = encodeURI(this.imageUrl);
// do I use this library to download image?
fileTransfer.create().download(
uri,
)
}
closeModal() {
this.modalCtrl.dismiss();
}
}