Skip to content

Instantly share code, notes, and snippets.

@ktiays
Last active August 15, 2023 08:22
Show Gist options
  • Save ktiays/f30a7e7221c5487639801947b09086f5 to your computer and use it in GitHub Desktop.
Save ktiays/f30a7e7221c5487639801947b09086f5 to your computer and use it in GitHub Desktop.
iOS 15+ unresponsive bug
//
// Created by ktiays on 2023/8/15.
// Copyright (c) 2023 ktiays. All rights reserved.
//
/**
* The purpose of this example is to demonstrate a bug in iOS 15 and higher versions.
* This bug will cause the app to be completely unresponsive to any actions.
*
* When you open a `UISheetPresentationController` and there is a `UINavigationController` at the bottom,
* if you swipe down to close the sheet and try to swipe sideways to return to the first level **IMMEDIATELY**.
*
* ╭─────────────╮
* │ <Back │
* │ │
* │ │
* ├─────────────┤
* │ ▔ │ 1. Slide down to dismiss UISheetPresentationController.
* │ │ 2. Attempt to return to the first-level page by sliding sideways.
* │ │
* │ │
* ╰─────────────╯
*
* The bug is likely caused by UIViewController triggering a second animation while the previous one has not yet finished,
* and UIKit does not handle this situation properly.
*/
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(
_ scene: UIScene, willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = .init(windowScene: windowScene)
let navigationController = UINavigationController(rootViewController: RootViewController())
navigationController.view.backgroundColor = .systemBackground
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}
}
extension UIViewController {
func makeButtonOnCenter(title: String, action: @escaping () -> Void) {
var configuration = UIButton.Configuration.filled()
configuration.buttonSize = .large
configuration.cornerStyle = .large
configuration.title = title
let button = UIButton(
configuration: configuration,
primaryAction: .init { _ in
action()
}
)
self.view.addSubview(button)
button.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
button.centerYAnchor.constraint(equalTo: view.centerYAnchor),
])
}
}
class _SystemBackgroundViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .systemBackground
}
}
class RootViewController: _SystemBackgroundViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Root View Controller"
makeButtonOnCenter(title: "Push") { [unowned self] in
self.navigationController?.pushViewController(DetailViewController(), animated: true)
}
}
}
class DetailViewController: _SystemBackgroundViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Detail View Controller"
makeButtonOnCenter(title: "Open Sheet") { [unowned self] in
let viewController = _SystemBackgroundViewController()
if let sheet = viewController.sheetPresentationController {
sheet.detents = [.medium(), .large()]
sheet.prefersGrabberVisible = true
}
self.present(viewController, animated: true)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment