Skip to content

Commit 3a8c3fc

Browse files
tsonevnAlexander Vakrilov
authored andcommitted
feat(modals): option to make dialogs cancelable in Android (#6765)
1 parent a6d561e commit 3a8c3fc

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

tns-core-modules/ui/core/view-base/view-base.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ export interface ShowModalOptions {
8181
*/
8282
presentationStyle: any /* UIModalPresentationStyle */
8383
}
84+
android?: {
85+
/**
86+
* An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode.
87+
*/
88+
cancelable?: boolean
89+
}
8490
}
8591

8692
export abstract class ViewBase extends Observable {

tns-core-modules/ui/core/view/view.android.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface DialogOptions {
3737
owner: View;
3838
fullscreen: boolean;
3939
stretched: boolean;
40+
cancelable: boolean;
4041
shownCallback: () => void;
4142
dismissCallback: () => void;
4243
}
@@ -117,6 +118,7 @@ function initializeDialogFragment() {
117118
public owner: View;
118119
private _fullscreen: boolean;
119120
private _stretched: boolean;
121+
private _cancelable: boolean;
120122
private _shownCallback: () => void;
121123
private _dismissCallback: () => void;
122124

@@ -130,6 +132,7 @@ function initializeDialogFragment() {
130132
const options = getModalOptions(ownerId);
131133
this.owner = options.owner;
132134
this._fullscreen = options.fullscreen;
135+
this._cancelable = options.cancelable;
133136
this._stretched = options.stretched;
134137
this._dismissCallback = options.dismissCallback;
135138
this._shownCallback = options.shownCallback;
@@ -155,6 +158,7 @@ function initializeDialogFragment() {
155158
this.owner.verticalAlignment = "stretch";
156159
}
157160

161+
dialog.setCanceledOnTouchOutside(this._cancelable);
158162
return dialog;
159163
}
160164

@@ -589,7 +593,7 @@ export class View extends ViewCommon {
589593

590594
return result | (childMeasuredState & layout.MEASURED_STATE_MASK);
591595
}
592-
protected _showNativeModalView(parent: View, options: ShowModalOptions) { //context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, iosOpts?: any) {
596+
protected _showNativeModalView(parent: View, options: ShowModalOptions) {
593597
super._showNativeModalView(parent, options);
594598
if (!this.backgroundColor) {
595599
this.backgroundColor = new Color("White");
@@ -606,6 +610,7 @@ export class View extends ViewCommon {
606610
owner: this,
607611
fullscreen: !!options.fullscreen,
608612
stretched: !!options.stretched,
613+
cancelable: options.android ? !!options.android.cancelable : true,
609614
shownCallback: () => this._raiseShownModallyEvent(),
610615
dismissCallback: () => this.closeModal()
611616
}

tns-core-modules/ui/core/view/view.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export class View extends ViewCommon {
370370
return this._suspendCATransaction || this._suspendNativeUpdatesCount;
371371
}
372372

373-
protected _showNativeModalView(parent: View, options: ShowModalOptions) { //context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, iosOpts?: any) {
373+
protected _showNativeModalView(parent: View, options: ShowModalOptions) {
374374
const parentWithController = ios.getParentWithViewController(parent);
375375
if (!parentWithController) {
376376
traceWrite(`Could not find parent with viewController for ${parent} while showing modal view.`,

0 commit comments

Comments
 (0)