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
21 changes: 18 additions & 3 deletions dialog/ios/Sources/DialogPlugin/DialogPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DialogPlugin: CAPPlugin, CAPBridgedPlugin {
alert.addAction(UIAlertAction(title: buttonTitle, style: UIAlertAction.Style.default, handler: { (_) in
call.resolve()
}))
self?.bridge?.viewController?.present(alert, animated: true, completion: nil)
self?.present(alert, for: call)
}
}

Expand All @@ -52,7 +52,7 @@ public class DialogPlugin: CAPPlugin, CAPBridgedPlugin {
"value": true
])
}))
self?.bridge?.viewController?.present(alert, animated: true, completion: nil)
self?.present(alert, for: call)
}
}

Expand Down Expand Up @@ -89,7 +89,22 @@ public class DialogPlugin: CAPPlugin, CAPBridgedPlugin {
])
}))

self?.bridge?.viewController?.present(alert, animated: true, completion: nil)
self?.present(alert, for: call)
}
}

// UIKit refuses to present from a view controller that already presents one, so climb to
// the topmost presented controller. A controller that is mid-dismissal cannot present, and
// neither can its presenter until the dismissal ends, so reject in that window.
private func present(_ alert: UIAlertController, for call: CAPPluginCall) {
var presenter = bridge?.viewController
while let presented = presenter?.presentedViewController, !presented.isBeingDismissed {
presenter = presented
}
guard let presenter, presenter.presentedViewController == nil else {
call.reject("Can't present a dialog while another view controller is being dismissed")
return
}
presenter.present(alert, animated: true, completion: nil)
}
}