feat(modals): option to make dialogs cancelable in Android (#6765)

This commit is contained in:
Nikolay Tsonev
2019-01-08 16:56:30 +02:00
committed by Alexander Vakrilov
parent a6d561e549
commit 3a8c3fca75
3 changed files with 13 additions and 2 deletions

View File

@@ -81,6 +81,12 @@ export interface ShowModalOptions {
*/
presentationStyle: any /* UIModalPresentationStyle */
}
android?: {
/**
* An optional parameter specifying whether the modal view can be dismissed when not in full-screen mode.
*/
cancelable?: boolean
}
}
export abstract class ViewBase extends Observable {

View File

@@ -37,6 +37,7 @@ interface DialogOptions {
owner: View;
fullscreen: boolean;
stretched: boolean;
cancelable: boolean;
shownCallback: () => void;
dismissCallback: () => void;
}
@@ -117,6 +118,7 @@ function initializeDialogFragment() {
public owner: View;
private _fullscreen: boolean;
private _stretched: boolean;
private _cancelable: boolean;
private _shownCallback: () => void;
private _dismissCallback: () => void;
@@ -130,6 +132,7 @@ function initializeDialogFragment() {
const options = getModalOptions(ownerId);
this.owner = options.owner;
this._fullscreen = options.fullscreen;
this._cancelable = options.cancelable;
this._stretched = options.stretched;
this._dismissCallback = options.dismissCallback;
this._shownCallback = options.shownCallback;
@@ -155,6 +158,7 @@ function initializeDialogFragment() {
this.owner.verticalAlignment = "stretch";
}
dialog.setCanceledOnTouchOutside(this._cancelable);
return dialog;
}
@@ -589,7 +593,7 @@ export class View extends ViewCommon {
return result | (childMeasuredState & layout.MEASURED_STATE_MASK);
}
protected _showNativeModalView(parent: View, options: ShowModalOptions) { //context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, iosOpts?: any) {
protected _showNativeModalView(parent: View, options: ShowModalOptions) {
super._showNativeModalView(parent, options);
if (!this.backgroundColor) {
this.backgroundColor = new Color("White");
@@ -606,6 +610,7 @@ export class View extends ViewCommon {
owner: this,
fullscreen: !!options.fullscreen,
stretched: !!options.stretched,
cancelable: options.android ? !!options.android.cancelable : true,
shownCallback: () => this._raiseShownModallyEvent(),
dismissCallback: () => this.closeModal()
}

View File

@@ -370,7 +370,7 @@ export class View extends ViewCommon {
return this._suspendCATransaction || this._suspendNativeUpdatesCount;
}
protected _showNativeModalView(parent: View, options: ShowModalOptions) { //context: any, closeCallback: Function, fullscreen?: boolean, animated?: boolean, stretched?: boolean, iosOpts?: any) {
protected _showNativeModalView(parent: View, options: ShowModalOptions) {
const parentWithController = ios.getParentWithViewController(parent);
if (!parentWithController) {
traceWrite(`Could not find parent with viewController for ${parent} while showing modal view.`,