Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #1951: Present action sheets as a popover on iPads to fix crashes (
Browse files Browse the repository at this point in the history
…#1955)

Starting in iOS 13.2 there is a regression on iPads which causes action sheets to require presentation as a popover even when being presented within view controllers which have compact width size classes. In previous iOS versions they would present as an over-current-context iPhone action sheet
  • Loading branch information
kylehickinson authored and iccub committed Nov 14, 2019
1 parent 38db355 commit 6c431e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ class ClearPrivateDataTableViewController: UITableViewController {
tableView.deselectRow(at: indexPath, animated: false)

let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
if UIDevice.current.userInterfaceIdiom == .pad {
let cell = tableView.cellForRow(at: indexPath)
actionSheet.popoverPresentationController?.sourceView = cell
actionSheet.popoverPresentationController?.sourceRect = cell?.bounds ?? .zero
actionSheet.popoverPresentationController?.permittedArrowDirections = [.up, .down]
}
let clearAction = UIAlertAction(title: Strings.ClearPrivateData, style: .destructive) { (_) in
Preferences.Privacy.clearPrivateDataToggles.value = self.toggles
self.clearButtonEnabled = false
Expand Down
14 changes: 10 additions & 4 deletions Client/Frontend/Sync/SyncSettingsTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,13 @@ class SyncSettingsTableViewController: UITableViewController {
guard let frc = frc, let deviceCount = frc.fetchedObjects?.count else { return }
let device = frc.object(at: indexPath)

let actionShet = UIAlertController(title: device.name, message: nil, preferredStyle: .actionSheet)
let actionSheet = UIAlertController(title: device.name, message: nil, preferredStyle: .actionSheet)
if UIDevice.current.userInterfaceIdiom == .pad {
let cell = tableView.cellForRow(at: indexPath)
actionSheet.popoverPresentationController?.sourceView = cell
actionSheet.popoverPresentationController?.sourceRect = cell?.bounds ?? .zero
actionSheet.popoverPresentationController?.permittedArrowDirections = [.up, .down]
}

let removeAction = UIAlertAction(title: Strings.SyncRemoveDeviceAction, style: .destructive) { _ in
if !DeviceInfo.hasConnectivity() {
Expand All @@ -129,10 +135,10 @@ class SyncSettingsTableViewController: UITableViewController {

let cancelAction = UIAlertAction(title: Strings.CancelButtonTitle, style: .cancel, handler: nil)

actionShet.addAction(removeAction)
actionShet.addAction(cancelAction)
actionSheet.addAction(removeAction)
actionSheet.addAction(cancelAction)

present(actionShet, animated: true)
present(actionSheet, animated: true)
}

private func presentAlertPopup(for type: DeviceRemovalType, device: Device) {
Expand Down

0 comments on commit 6c431e7

Please sign in to comment.