Skip to content

Commit 0264532

Browse files
committed
feat(toast): display the toast even on page change unless dismissOnPageChange is passed
fix animation and darken iOS background a bit. closes #5582
1 parent 9d3e008 commit 0264532

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

ionic/components/toast/test/basic/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import {App, Page, Toast, NavController} from 'ionic-angular';
22

3+
@Page({
4+
template: `
5+
<ion-navbar *navbar>
6+
<ion-title>Another Page</ion-title>
7+
</ion-navbar>
8+
<ion-content padding>
9+
<p>This is another page to show that the toast stays.</p>
10+
</ion-content>
11+
`
12+
})
13+
class AnotherPage {
14+
15+
}
16+
317
@Page({
418
templateUrl: 'main.html'
519
})
@@ -19,6 +33,10 @@ class E2EPage {
1933
});
2034

2135
this.nav.present(toast);
36+
37+
setTimeout(() => {
38+
this.nav.push(AnotherPage);
39+
}, 1000);
2240
}
2341

2442
showLongToast() {

ionic/components/toast/test/basic/main.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
</ion-navbar>
44

55
<ion-content padding>
6-
<button block (click)="showToast()">Show Toast</button>
6+
<button block (click)="showToast()">Show Toast and Navigate</button>
77
<button block (click)="showLongToast()">Show Long Toast</button>
88
<br />
99
<button block (click)="showDismissDurationToast()">Custom (1.5s) Duration</button>

ionic/components/toast/toast.ios.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// --------------------------------------------------
66

77
$toast-ios-text-align: left !default;
8-
$toast-ios-background: rgba(0, 0, 0, .7) !default;
8+
$toast-ios-background: rgba(0, 0, 0, .9) !default;
99
$toast-ios-border-radius: .65rem !default;
1010

1111
$toast-ios-title-color: #fff !default;

ionic/components/toast/toast.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ export class Toast extends ViewController {
6666

6767
constructor(opts: ToastOptions = {}) {
6868
opts.enableBackdropDismiss = isPresent(opts.enableBackdropDismiss) ? !!opts.enableBackdropDismiss : true;
69-
console.log(opts.enableBackdropDismiss);
70-
super(ToastCmp, opts);
71-
69+
opts.dismissOnPageChange = isPresent(opts.dismissOnPageChange) ? !!opts.dismissOnPageChange : false;
7270

71+
super(ToastCmp, opts);
7372
this.viewType = 'toast';
74-
this.isOverlay = false;
73+
this.isOverlay = true;
74+
this.usePortal = true;
7575

7676
// by default, toasts should not fire lifecycle events of other views
7777
// for example, when an toast enters, the current active view should
@@ -108,6 +108,7 @@ export class Toast extends ViewController {
108108
* | showCloseButton | `boolean` | false | Whether or not to show a button to close the toast. |
109109
* | closeButtonText | `string` | "Close" | Text to display in the close button. |
110110
* | enableBackdropDismiss | `boolean` | true | Whether the toast should be dismissed by tapping the backdrop. |
111+
* | dismissOnPageChange | `boolean` | false | Whether to dismiss the toast when navigating to a new page. |
111112
*
112113
* @param {object} opts Toast options. See the above table for available options.
113114
*/
@@ -226,6 +227,7 @@ export interface ToastOptions {
226227
showCloseButton?: boolean;
227228
closeButtonText?: string;
228229
enableBackdropDismiss?: boolean;
230+
dismissOnPageChange?: boolean;
229231
}
230232

231233
class ToastSlideIn extends Transition {
@@ -235,7 +237,7 @@ class ToastSlideIn extends Transition {
235237
let ele = enteringView.pageRef().nativeElement;
236238
let wrapper = new Animation(ele.querySelector('.toast-wrapper'));
237239

238-
wrapper.fromTo('translateY', '100%', '0%');
240+
wrapper.fromTo('translateY', '120%', '0%');
239241
this.easing('cubic-bezier(.36,.66,.04,1)').duration(400).add(wrapper);
240242
}
241243
}
@@ -247,7 +249,7 @@ class ToastSlideOut extends Transition {
247249
let ele = leavingView.pageRef().nativeElement;
248250
let wrapper = new Animation(ele.querySelector('.toast-wrapper'));
249251

250-
wrapper.fromTo('translateY', '0%', '100%');
252+
wrapper.fromTo('translateY', '0%', '120%');
251253
this.easing('cubic-bezier(.36,.66,.04,1)').duration(300).add(wrapper);
252254
}
253255
}
@@ -261,7 +263,7 @@ class ToastMdSlideIn extends Transition {
261263
let wrapper = new Animation(ele.querySelector('.toast-wrapper'));
262264

263265
backdrop.fromTo('opacity', 0, 0);
264-
wrapper.fromTo('translateY', '100%', '0%');
266+
wrapper.fromTo('translateY', '120%', '0%');
265267
this.easing('cubic-bezier(.36,.66,.04,1)').duration(400).add(backdrop).add(wrapper);
266268
}
267269
}
@@ -274,7 +276,7 @@ class ToastMdSlideOut extends Transition {
274276
let wrapper = new Animation(ele.querySelector('.toast-wrapper'));
275277
let backdrop = new Animation(ele.querySelector('.backdrop'));
276278

277-
wrapper.fromTo('translateY', '0%', '100%');
279+
wrapper.fromTo('translateY', '0%', '120%');
278280
backdrop.fromTo('opacity', 0, 0);
279281
this.easing('cubic-bezier(.36,.66,.04,1)').duration(450).add(backdrop).add(wrapper);
280282
}

0 commit comments

Comments
 (0)