Skip to content

Commit f5027c7

Browse files
authored
Fix iPad crash caused by vote menu from toolbar (#1226)
- Convert actionsItem() from a method to a lazy stored property to ensure a single UIBarButtonItem instance is used. UIKit requires the popover's barButtonItem to match the exact toolbar instance on iPad.
1 parent c744be8 commit f5027c7

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

App/View Controllers/Posts/PostsPageViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,13 @@ final class PostsPageViewController: ViewController {
571571
}()
572572

573573

574-
private func actionsItem() -> UIBarButtonItem {
574+
private lazy var actionsItem: UIBarButtonItem = {
575575
let buttonItem = UIBarButtonItem(title: "Menu", image: UIImage(named: "steamed-ham"), menu: threadActionsMenu())
576576
if #available(iOS 16.0, *) {
577577
buttonItem.preferredMenuElementOrder = .fixed
578578
}
579579
return buttonItem
580-
}
580+
}()
581581

582582
private func refetchPosts() {
583583
guard case .specific(let pageNumber)? = page else {
@@ -1055,7 +1055,7 @@ final class PostsPageViewController: ViewController {
10551055
// update toolbar so menu reflects new bookmarked state
10561056
var newItems = postsView.toolbarItems
10571057
newItems.removeLast()
1058-
newItems.append(actionsItem())
1058+
newItems.append(actionsItem)
10591059
postsView.toolbarItems = newItems
10601060
}
10611061
} catch {
@@ -1161,7 +1161,7 @@ final class PostsPageViewController: ViewController {
11611161
present(actionSheet, animated: false)
11621162

11631163
if let popover = actionSheet.popoverPresentationController {
1164-
popover.barButtonItem = actionsItem()
1164+
popover.barButtonItem = actionsItem
11651165
}
11661166
}
11671167
}
@@ -1553,7 +1553,7 @@ final class PostsPageViewController: ViewController {
15531553
postsView.toolbarItems = [
15541554
settingsItem, .flexibleSpace(),
15551555
backItem, .fixedSpace(spacer), currentPageItem, .fixedSpace(spacer), forwardItem,
1556-
.flexibleSpace(), actionsItem()]
1556+
.flexibleSpace(), actionsItem]
15571557

15581558
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(didLongPressOnPostsView))
15591559
longPress.delegate = self

0 commit comments

Comments
 (0)