Skip to content

Commit a35e3cd

Browse files
committed
fix(snackbar): android fix for app with no actionbar
1 parent 00699f3 commit a35e3cd

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/snackbar/snackbar.android.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,34 @@ export class SnackBar extends SnackBarBase {
5353
attachView = attachView['_modal'];
5454
}
5555
const page = (attachView instanceof Page ? attachView : attachView.page);
56-
let nView = (page.nativeViewProtected as android.view.View).getParent().getParent() as any;
56+
let nView = (page.nativeViewProtected as android.view.View).getParent();
57+
if ( page.hasActionBar) {
58+
nView = nView.getParent();
59+
}
5760
let nCoordinatorLayout: androidx.coordinatorlayout.widget.CoordinatorLayout = (page as any).nCoordinatorLayout;
5861
if (!nCoordinatorLayout && !(nView instanceof androidx.coordinatorlayout.widget.CoordinatorLayout) && nView instanceof android.view.ViewGroup) {
5962
nCoordinatorLayout = new androidx.coordinatorlayout.widget.CoordinatorLayout(attachView._context);
6063

6164
if (options.view) {
6265
const nAttachedView = options.view.nativeViewProtected as android.view.View;
6366
const params = new android.widget.FrameLayout.LayoutParams(nAttachedView.getWidth(), nAttachedView.getHeight());
64-
params.topMargin = Utils.layout.toDevicePixels(options.view.getLocationRelativeTo(page).y);
67+
const myArray = (Array).create('int', 2);
68+
nView.getLocationOnScreen(myArray);
69+
const otherArray = (Array).create('int', 2);
70+
options.view.nativeViewProtected.getLocationOnScreen(otherArray);
71+
72+
params.topMargin = otherArray[1] - myArray[1];
6573
(nView as any).addView(nCoordinatorLayout, params);
6674
} else {
6775
(nView as any).addView(nCoordinatorLayout, new android.view.ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.MATCH_PARENT, android.view.ViewGroup.LayoutParams.MATCH_PARENT));
6876
}
6977

7078
nView = nCoordinatorLayout;
7179
}
72-
this._snackbar = com.google.android.material.snackbar.Snackbar.make(nView, options.message, options.hideDelay);
80+
this._snackbar = com.google.android.material.snackbar.Snackbar.make(nView as any, options.message, options.hideDelay);
7381

74-
this._snackbar.setText(options.message);
75-
this._snackbar.setDuration(options.hideDelay);
82+
// this._snackbar.setText(options.message);
83+
// this._snackbar.setDuration(options.hideDelay);
7684

7785
// set text color of the TextView in the Android SnackBar
7886
if (options.textColor && Color.isValid(options.textColor)) {
@@ -159,7 +167,9 @@ export class SnackBar extends SnackBarBase {
159167
}
160168
},
161169

162-
onShown(snackbar: com.google.android.material.snackbar.Snackbar) {},
170+
onShown(snackbar: com.google.android.material.snackbar.Snackbar) {
171+
172+
},
163173
});
164174
cb.setListener(callbackListener);
165175
(cb as any).nListener = callbackListener; // handles the resolve of the promise

0 commit comments

Comments
 (0)