Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions toast/ios/Sources/ToastPlugin/ToastPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,22 @@ public class ToastPlugin: CAPPlugin, CAPBridgedPlugin {
let duration = durationType == "long" ? 3500 : 2000
let position = call.getString("position", "bottom")

guard let viewController = bridge?.viewController else {
call.reject("Unable to display toast!")
return
DispatchQueue.main.async { [weak self] in
guard var viewController = self?.bridge?.viewController else {
call.reject("Unable to display toast!")
return
}
// A view controller presented over the webview (e.g. the Browser plugin) hides the
// bridge view controller's view, so show the toast in the topmost one instead.
// UIAlertController is skipped: its view is only the alert box.
while let presented = viewController.presentedViewController,
!presented.isBeingDismissed,
!(presented is UIAlertController) {
viewController = presented
}
Toast.showToast(in: viewController, text: text, duration: duration, position: position, completion: {(_) in
call.resolve()
})
}
Toast.showToast(in: viewController, text: text, duration: duration, position: position, completion: {(_) in
call.resolve()
})
}
}