FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(modals): option to make dialogs cancelable in Android by tsonevn · Pull Request #6765 · NativeScript/NativeScript · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 6 additions & 0 deletions tns-core-modules/ui/core/view-base/view-base.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion tns-core-modules/ui/core/view/view.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ interface DialogOptions {
owner: View;
fullscreen: boolean;
stretched: boolean;
cancelable: boolean;
shownCallback: () => void;
dismissCallback: () => void;
}
Expand Down Expand Up @@ -117,6 +118,7 @@ function initializeDialogFragment() {
public owner: View;
private _fullscreen: boolean;
private _stretched: boolean;
private _cancelable: boolean;
private _shownCallback: () => void;
private _dismissCallback: () => void;

Expand All @@ -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;
Expand All @@ -155,6 +158,7 @@ function initializeDialogFragment() {
this.owner.verticalAlignment = "stretch";
}

dialog.setCanceledOnTouchOutside(this._cancelable);
return dialog;
}

Expand Down Expand Up @@ -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");
Expand All @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules/ui/core/view/view.ios.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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.`,
Expand Down

Back | FazBrowse Home | New Git URL