Skip to content

Commit b02038d

Browse files
authored
iOS 26: Remove BottomSheetPresentationController (#24780)
* Use native sheet to show CreateButtonActionSheet * Enable zoom-zoon * Remove BottomSheetPresentationController
1 parent 375f257 commit b02038d

8 files changed

Lines changed: 68 additions & 181 deletions

File tree

WordPress/Classes/ViewRelated/System/Action Sheet/ActionSheetViewController.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ class ActionSheetViewController: UIViewController {
3535
static let height: CGFloat = 54
3636
static let contentInsets = NSDirectionalEdgeInsets(top: 0, leading: 18, bottom: 0, trailing: 35)
3737
static let imagePadding: CGFloat = 16
38-
static let imageTintColor: UIColor = UIAppColor.neutral(.shade30)
39-
static let font: UIFont = .preferredFont(forTextStyle: .callout)
38+
static let imageTintColor: UIColor = .label
39+
static let font: UIFont = WPStyleGuide.fontForTextStyle(.headline, fontWeight: .medium)
4040
static let textColor: UIColor = .label
4141
static let badgeHorizontalPadding: CGFloat = 10
4242
}
@@ -203,6 +203,7 @@ class ActionSheetViewController: UIViewController {
203203

204204
override func viewDidLayoutSubviews() {
205205
super.viewDidLayoutSubviews()
206+
206207
updateScrollViewHeight()
207208
let compressedSize = view.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize)
208209
let width = min(max(Constants.minimumWidth, compressedSize.width), Constants.maximumWidth)

WordPress/Classes/ViewRelated/System/Action Sheet/BottomSheetPresentationController.swift

Lines changed: 0 additions & 127 deletions
This file was deleted.

WordPress/Classes/ViewRelated/System/Floating Create Button/CreateButtonCoordinator.swift

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ final class CreateButtonCoordinator: NSObject {
1010
private enum Constants {
1111
static let padding: CGFloat = -16 // Bottom and trailing padding to position the button along the bottom right corner
1212
static let heightWidth: CGFloat = 56 // Height and width of the button
13-
static let popoverOffset: CGFloat = -10 // The vertical offset of the iPad popover
13+
static let popoverOffset: CGFloat = -4 // The vertical offset of the iPad popover
1414
static let skippedPromptsUDKey = "wp_skipped_blogging_prompts"
1515
}
1616

1717
var button: UIButton = {
1818
let button: UIButton
19-
#if swift(>=6.2)
19+
#if compiler(>=6.2)
2020
if #available(iOS 26, *) {
2121
var configuration = UIButton.Configuration.prominentClearGlass()
2222
configuration.image = UIImage(systemName: "plus")
@@ -134,15 +134,22 @@ final class CreateButtonCoordinator: NSObject {
134134
}
135135

136136
private func setupPresentation(on viewController: UIViewController, for traitCollection: UITraitCollection) {
137-
if traitCollection.horizontalSizeClass == .regular && traitCollection.verticalSizeClass == .regular {
138-
viewController.modalPresentationStyle = .popover
139-
} else {
140-
viewController.modalPresentationStyle = .custom
141-
}
137+
viewController.modalPresentationStyle = .popover
138+
viewController.popoverPresentationController?.sourceView = button
139+
viewController.popoverPresentationController?.sourceRect = button.bounds.offsetBy(dx: 0, dy: Constants.popoverOffset)
140+
141+
// Pre-compute `preferredContentSize`
142+
viewController.view.layoutIfNeeded()
143+
144+
viewController.popoverPresentationController?.adaptiveSheetPresentationController.detents = [.custom { [weak viewController] context in
145+
viewController?.preferredContentSize.height ?? 320
146+
}]
142147

143-
viewController.popoverPresentationController?.sourceView = self.button
144-
viewController.popoverPresentationController?.sourceRect = self.button.bounds.offsetBy(dx: 0, dy: Constants.popoverOffset)
145-
viewController.transitioningDelegate = self
148+
if #available(iOS 18.0, *) {
149+
viewController.preferredTransition = .zoom { [weak self] _ in
150+
self?.button
151+
}
152+
}
146153
}
147154

148155
func hideCreateButton() {
@@ -171,27 +178,6 @@ final class CreateButtonCoordinator: NSObject {
171178
}
172179
}
173180

174-
// MARK: Tranisitioning Delegate
175-
176-
extension CreateButtonCoordinator: UIViewControllerTransitioningDelegate {
177-
public func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
178-
return BottomSheetAnimationController(transitionType: .presenting)
179-
}
180-
181-
public func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
182-
return BottomSheetAnimationController(transitionType: .dismissing)
183-
}
184-
185-
public func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
186-
let presentationController = BottomSheetPresentationController(presentedViewController: presented, presenting: presenting)
187-
return presentationController
188-
}
189-
190-
public func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
191-
return (viewController?.presentedViewController?.presentationController as? BottomSheetPresentationController)?.interactionController
192-
}
193-
}
194-
195181
// MARK: - Blogging Prompts Methods
196182

197183
private extension CreateButtonCoordinator {

WordPress/Classes/ViewRelated/System/Floating Create Button/SheetActions.swift

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ struct PostAction: ActionSheetItem {
99
private let action = "create_new_post"
1010

1111
func makeButton() -> ActionSheetButton {
12-
return ActionSheetButton(title: NSLocalizedString("Blog post", comment: "Create new Blog Post button title"),
13-
image: .gridicon(.posts),
14-
identifier: "blogPostButton",
15-
action: {
16-
WPAnalytics.track(.createSheetActionTapped, properties: ["source": source, "action": action])
17-
handler()
18-
})
12+
return ActionSheetButton(
13+
title: NSLocalizedString("Blog post", comment: "Create new Blog Post button title"),
14+
image: UIImage(named: "wpl-posts") ?? .init(),
15+
identifier: "blogPostButton",
16+
action: {
17+
WPAnalytics.track(.createSheetActionTapped, properties: ["source": source, "action": action])
18+
handler()
19+
})
1920
}
2021
}
2122

@@ -26,13 +27,14 @@ struct PostFromAudioAction: ActionSheetItem {
2627
private let action = "create_new_post_from_audio"
2728

2829
func makeButton() -> ActionSheetButton {
29-
return ActionSheetButton(title: NSLocalizedString("createFAB.postFromAudio", value: "Post from Audio", comment: "Create new Blog Post from Audio button title"),
30-
image: .gridicon(.microphone),
31-
identifier: "blogPostFromAudioButton",
32-
action: {
33-
WPAnalytics.track(.createSheetActionTapped, properties: ["source": source, "action": action])
34-
handler()
35-
})
30+
return ActionSheetButton(
31+
title: NSLocalizedString("createFAB.postFromAudio", value: "Post from Audio", comment: "Create new Blog Post from Audio button title"),
32+
image: .gridicon(.microphone),
33+
identifier: "blogPostFromAudioButton",
34+
action: {
35+
WPAnalytics.track(.createSheetActionTapped, properties: ["source": source, "action": action])
36+
handler()
37+
})
3638
}
3739
}
3840

@@ -43,12 +45,13 @@ struct PageAction: ActionSheetItem {
4345
private let action = "create_new_page"
4446

4547
func makeButton() -> ActionSheetButton {
46-
return ActionSheetButton(title: NSLocalizedString("Site page", comment: "Create new Site Page button title"),
47-
image: .gridicon(.pages),
48-
identifier: "sitePageButton",
49-
action: {
50-
WPAnalytics.track(.createSheetActionTapped, properties: ["source": source, "action": action])
51-
handler()
52-
})
48+
return ActionSheetButton(
49+
title: NSLocalizedString("Site page", comment: "Create new Site Page button title"),
50+
image: UIImage(named: "wpl-pages") ?? .init(),
51+
identifier: "sitePageButton",
52+
action: {
53+
WPAnalytics.track(.createSheetActionTapped, properties: ["source": source, "action": action])
54+
handler()
55+
})
5356
}
5457
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "pages.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "site-menu-posts.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}

0 commit comments

Comments
 (0)