diff --git a/.gitignore b/.gitignore
index 3b0a0c6..2add9d5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,7 +9,7 @@ demo/platforms
demo/node_modules
node_modules
.vscode
-.ideas
+.idea
.DS_Store
diff --git a/demo/app/main-page.ts b/demo/app/main-page.ts
index ce6fbc5..6058324 100644
--- a/demo/app/main-page.ts
+++ b/demo/app/main-page.ts
@@ -24,3 +24,11 @@ export function positionToast() {
toast.duration = ToastDuration.SHORT;
toast.show();
}
+
+export function cancelToast() {
+ const toast = new Toasty('Canceling after 1 sec');
+ toast.show();
+ setTimeout(() => {
+ toast.cancel();
+ }, 1000);
+}
diff --git a/demo/app/main-page.xml b/demo/app/main-page.xml
index 080983d..05c3eb8 100644
--- a/demo/app/main-page.xml
+++ b/demo/app/main-page.xml
@@ -12,6 +12,9 @@
+
+
+
\ No newline at end of file
diff --git a/src/toasty.ios.ts b/src/toasty.ios.ts
index 8709d6b..ec44032 100644
--- a/src/toasty.ios.ts
+++ b/src/toasty.ios.ts
@@ -1,6 +1,7 @@
///
-import * as app from 'tns-core-modules/application';
+import { device } from 'tns-core-modules/platform';
+import { DeviceType } from 'tns-core-modules/ui/enums';
import * as frameModule from 'tns-core-modules/ui/frame';
import { ToastDuration, ToastPosition } from './toast.common';
export * from './toast.common';
@@ -49,24 +50,12 @@ export class Toasty {
if (!this._text) {
throw new Error('Text is not set');
} else {
- if (!frameModule.topmost()) {
- throw new Error('There is no topmost');
- } else {
- let viewController = frameModule.topmost().viewController;
- let view = viewController.view;
- if (viewController.presentedViewController) {
- while (viewController.presentedViewController) {
- viewController = viewController.presentedViewController;
- }
- view = viewController.view;
- }
- view.makeToast(this._text);
- }
+ Toasty.getView().makeToast(this._text);
}
}
cancel() {
- app.ios.rootController.view.hideToasts();
+ Toasty.getView().hideToasts();
}
setToastPosition(value: ToastPosition) {
@@ -103,4 +92,21 @@ export class Toasty {
return this;
}
+
+ private static getView(): any {
+ if (!frameModule.topmost()) {
+ throw new Error('There is no topmost');
+ } else {
+ let viewController = frameModule.topmost().viewController;
+ if (viewController.presentedViewController) {
+ // on iPad, we don't want to show the toast in the modal, but on iPhone we do
+ if (device.deviceType !== DeviceType.Tablet) {
+ while (viewController.presentedViewController) {
+ viewController = viewController.presentedViewController;
+ }
+ }
+ }
+ return viewController.view;
+ }
+ }
}