angularjs - Nativescript angular preventing modal closing on background tap -
i pretty new nativescript want able prevent custom modal have created being closed when user taps on background, android devices.
i can accomplish pretty when using provided dialogs nativescript i.e. action dialog can setting cancelable
false in options provided.
let options: actionoptions = { title: "sticky dialog", message: "will not disappear if background tapped", cancelable: false, actions: ["cancel", "ok"] }; dialogs.action(options).then(result => { console.log(result); });
but when showing custom modal using modaldialogservice
there no such property can set in options, have
let modaloptions: modaldialogoptions = { context: {}, fullscreen: false, viewcontainerref: this.vcref, }; this.modalservice.showmodal(deviceregistrationcomponent, modaloptions) .then(result => { if (result != null) { this.handledeviceotpentry(result.otp); } });
is there way accomplish this? not mind having set specific native android properties, cannot seem able handle actual modal gets displayed.
ok, after trial , error managed come solution (if there better way please let me know)
it seems looking @ source if create modal dialog using modaldialogservice
there no convenient way set cancelable
android, instead, in modal component listen shownmodally
event , once fired, can attempt find displayed fragment, created nativescript tag dialog
.
once have can set native property.
import {component} "@angular/core"; import {page} "tns-core-modules/ui/page"; import {modaldialogparams} "nativescript-angular"; import * application "tns-core-modules/application"; import {isandroid} "tns-core-modules/platform"; @component({ moduleid: module.id, selector: "app-device-registration", templateurl: "./device.registration.component.html", styleurls: ["./device.registration.component.css"] }) export class deviceregistrationcomponent { constructor(private params: modaldialogparams, private page: page) { this.page.on("shownmodally", data => { if (isandroid) { let fragmentmanger = application.android.foregroundactivity.getfragmentmanager(); let dialogfragment = fragmentmanger.findfragmentbytag("dialog"); if (dialogfragment !== null) { dialogfragment.setcancelable(false); } } }); }
Comments
Post a Comment