Skip to content

Commit fcd6622

Browse files
committed
fix(snackbar): if no view passed ensure we show over any modal view
1 parent 2bee97b commit fcd6622

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/snackbar/snackbar.android.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Color, Frame, Page, Utils } from '@nativescript/core';
1+
import { Color, Frame, Page, Utils, View } from '@nativescript/core';
22
import { DismissReasons, SnackBarAction, SnackBarBase, SnackBarOptions } from './snackbar-common';
33

44
function _getReason(value: number) {
@@ -48,9 +48,13 @@ export class SnackBar extends SnackBarBase {
4848
public initSnack(options: SnackBarOptions, resolve?: Function) {
4949
options.hideDelay = options.hideDelay ? options.hideDelay : 3000;
5050

51-
let attachView = options.view || Frame.topmost().currentPage;
52-
while (attachView['_modal']) {
53-
attachView = attachView['_modal'];
51+
let attachView = options.view;
52+
if (!attachView) {
53+
attachView = Frame.topmost().currentPage;
54+
const modalViews = attachView._getRootModalViews();
55+
if (modalViews.length) {
56+
attachView = modalViews[modalViews.length - 1] as View;
57+
}
5458
}
5559
const page = attachView instanceof Page ? attachView : attachView.page;
5660
let nView = (page.nativeViewProtected as android.view.View).getParent();

src/snackbar/snackbar.ios.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ export class SnackBar extends SnackBarBase {
6161

6262
let nAttachedView: UIView;
6363
if (options.view) {
64-
let attachView = options.view || Frame.topmost().currentPage;
65-
while (attachView['_modal']) {
66-
attachView = attachView['_modal'];
67-
}
68-
nAttachedView = attachView.nativeViewProtected;
64+
nAttachedView = options.view.nativeViewProtected;
6965
} else {
7066
let viewController = Application.ios.rootController;
7167

0 commit comments

Comments
 (0)