Skip to content

Commit c42367a

Browse files
author
aforge
committed
Show toasts above the keyboard if visible.
It appears there's no way to show toasts over the keyboard since iOS 16.
1 parent 6e44ed0 commit c42367a

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ PODS:
100100
- Kingfisher (5.15.8):
101101
- Kingfisher/Core (= 5.15.8)
102102
- Kingfisher/Core (5.15.8)
103-
- MobileVLCKit (3.4.1b9)
103+
- MobileVLCKit (3.4.1b13)
104104
- nanopb (2.30908.0):
105105
- nanopb/decode (= 2.30908.0)
106106
- nanopb/encode (= 2.30908.0)
@@ -165,7 +165,7 @@ SPEC CHECKSUMS:
165165
GoogleDataTransport: 629c20a4d363167143f30ea78320d5a7eb8bd940
166166
GoogleUtilities: 684ee790a24f73ebb2d1d966e9711c203f2a4237
167167
Kingfisher: a3c03d702433fa6cfedabb2bddbe076fb8f2e902
168-
MobileVLCKit: 63fd88297505b97027f23842ae9df3a7bf17b31e
168+
MobileVLCKit: 685736e6bb92ed2107b0f083f094b61709413122
169169
nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
170170
PhoneNumberKit: 441e8b26ec88d598e3591de9061eff18f5dd12e8
171171
PromisesObjC: 68159ce6952d93e17b2dfe273b8c40907db5ba58

Tinodios/MessageInteractor.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,14 +330,13 @@ class MessageInteractor: DefaultComTopic.Listener, MessageBusinessLogic, Message
330330
onFailure: { err in
331331
Cache.log.error("sendMessage error: %@", err.localizedDescription)
332332
if let e = err as? TinodeError {
333-
switch e {
334-
case .notConnected(_):
333+
if case .notConnected(_) = e {
335334
DispatchQueue.main.async { UiUtils.showToast(message: NSLocalizedString("You are offline.", comment: "Toast notification")) }
336335
Cache.tinode.reconnectNow(interactively: false, reset: false)
337-
default:
338-
DispatchQueue.main.async { UiUtils.showToast(message: NSLocalizedString("Message not sent.", comment: "Toast notification")) }
336+
return nil
339337
}
340338
}
339+
DispatchQueue.main.async { UiUtils.showToast(message: NSLocalizedString("Message not sent.", comment: "Toast notification")) }
341340
return nil
342341
}
343342
).thenFinally {

Tinodios/UiUtils.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,19 @@ class UiUtils {
389389
public static func showToast(message: String, duration: TimeInterval = 3.0, level: ToastLevel = .error) {
390390
// Grab the last window (instead the key window) so we can show
391391
// the toast over they keyboard when it's presented.
392-
guard let parent = UIApplication.shared.windows.last else {
392+
guard let topWindow = UIApplication.shared.windows.last else {
393393
Cache.log.error("UiUtils.showToast - parent window not set")
394394
return
395395
}
396+
var parent: UIView = topWindow
397+
if #available(iOS 16, *) {
398+
// UIRemoteKeyboardWindow is no longer available in iOS 16 so keyboard (if presented) may
399+
// cover the toast.
400+
// Show toast over the input accessory view if visible.
401+
if let inputView = UiUtils.topViewController(rootViewController: (UIApplication.shared.delegate as! AppDelegate).window?.rootViewController)?.inputAccessoryView {
402+
parent = inputView
403+
}
404+
}
396405

397406
let iconSize: CGFloat = 32
398407
let spacing: CGFloat = 8
@@ -600,17 +609,17 @@ class UiUtils {
600609
}
601610

602611
public static func topViewController(rootViewController: UIViewController?) -> UIViewController? {
603-
guard let rootViewController = rootViewController else { return nil }
604-
guard let presented = rootViewController.presentedViewController else {
605-
return rootViewController
612+
guard let controller = rootViewController else { return nil }
613+
if let presented = controller.presentedViewController {
614+
return topViewController(rootViewController: presented)
606615
}
607-
switch presented {
616+
switch controller {
608617
case let navigationController as UINavigationController:
609618
return topViewController(rootViewController: navigationController.viewControllers.last)
610619
case let tabBarController as UITabBarController:
611620
return topViewController(rootViewController: tabBarController.selectedViewController)
612621
default:
613-
return topViewController(rootViewController: presented)
622+
return controller
614623
}
615624
}
616625

0 commit comments

Comments
 (0)