From 5516ccf7b224644236007844d8cd1051bb10f698 Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Mon, 14 Jun 2021 14:52:35 -0500 Subject: [PATCH 1/2] Refactor show method in BottomSheetViewController to force a formSheet presentation style when needed --- WordPressUI.podspec | 2 +- WordPressUI/BottomSheet/BottomSheetViewController.swift | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/WordPressUI.podspec b/WordPressUI.podspec index 3902f48..602ea3f 100644 --- a/WordPressUI.podspec +++ b/WordPressUI.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "WordPressUI" - s.version = "1.12.1-beta.1" + s.version = "1.12.1-beta.2" s.summary = "Home of reusable WordPress UI components." s.description = <<-DESC diff --git a/WordPressUI/BottomSheet/BottomSheetViewController.swift b/WordPressUI/BottomSheet/BottomSheetViewController.swift index 788f97e..f5a043d 100644 --- a/WordPressUI/BottomSheet/BottomSheetViewController.swift +++ b/WordPressUI/BottomSheet/BottomSheetViewController.swift @@ -49,8 +49,14 @@ public class BottomSheetViewController: UIViewController { /// - sourceView: optional anchor view for the popover on iPad. /// - sourceBarButtonItem: optional anchor bar button item for the popover on iPad. If non-nil, `sourceView` and `arrowDirections` are not used. /// - arrowDirections: optional arrow directions for the popover on iPad. - public func show(from presenting: UIViewController, sourceView: UIView? = nil, sourceBarButtonItem: UIBarButtonItem? = nil, arrowDirections: UIPopoverArrowDirection = .any) { + /// - useFormSheet: if set to true, the presentation style on iPad will always be `formSheet` + public func show(from presenting: UIViewController, sourceView: UIView? = nil, sourceBarButtonItem: UIBarButtonItem? = nil, arrowDirections: UIPopoverArrowDirection = .any, useFormSheet: Bool = false) { if UIDevice.isPad() { + guard !useFormSheet else { + modalPresentationStyle = .formSheet + presenting.present(self, animated: true) + return + } // If the user is using a larger text option we'll display the content in a sheet since // the font may be too large to display in a popover if traitCollection.preferredContentSizeCategory.isAccessibilityCategory { From 63b9b477d36cacbad159bbd6021785b18d667a04 Mon Sep 17 00:00:00 2001 From: Giorgio Ruscigno Date: Tue, 15 Jun 2021 13:53:39 -0500 Subject: [PATCH 2/2] Refactor show method in BottomSheetViewController to better handle cases on iPad --- .../BottomSheetViewController.swift | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/WordPressUI/BottomSheet/BottomSheetViewController.swift b/WordPressUI/BottomSheet/BottomSheetViewController.swift index f5a043d..a235e18 100644 --- a/WordPressUI/BottomSheet/BottomSheetViewController.swift +++ b/WordPressUI/BottomSheet/BottomSheetViewController.swift @@ -44,42 +44,42 @@ public class BottomSheetViewController: UIViewController { } /// Presents the bottom sheet given an optional anchor and arrow directions for the popover on iPad. + /// If no anchors are provided, on iPad it will present a form sheet. /// - Parameters: /// - presenting: the view controller that presents the bottom sheet. /// - sourceView: optional anchor view for the popover on iPad. /// - sourceBarButtonItem: optional anchor bar button item for the popover on iPad. If non-nil, `sourceView` and `arrowDirections` are not used. /// - arrowDirections: optional arrow directions for the popover on iPad. - /// - useFormSheet: if set to true, the presentation style on iPad will always be `formSheet` - public func show(from presenting: UIViewController, sourceView: UIView? = nil, sourceBarButtonItem: UIBarButtonItem? = nil, arrowDirections: UIPopoverArrowDirection = .any, useFormSheet: Bool = false) { + public func show(from presenting: UIViewController, + sourceView: UIView? = nil, + sourceBarButtonItem: UIBarButtonItem? = nil, + arrowDirections: UIPopoverArrowDirection = .any) { if UIDevice.isPad() { - guard !useFormSheet else { - modalPresentationStyle = .formSheet - presenting.present(self, animated: true) - return - } - // If the user is using a larger text option we'll display the content in a sheet since - // the font may be too large to display in a popover - if traitCollection.preferredContentSizeCategory.isAccessibilityCategory { + + // If the anchor views are not set, or the user is using a larger text option + // we'll display the content in a sheet + if (sourceBarButtonItem == nil && sourceView == nil) || + traitCollection.preferredContentSizeCategory.isAccessibilityCategory { modalPresentationStyle = .formSheet } else { modalPresentationStyle = .popover - } - if let sourceBarButtonItem = sourceBarButtonItem { - popoverPresentationController?.barButtonItem = sourceBarButtonItem - } else { - popoverPresentationController?.permittedArrowDirections = arrowDirections - popoverPresentationController?.sourceView = sourceView ?? UIView() - popoverPresentationController?.sourceRect = sourceView?.bounds ?? .zero + if let sourceBarButtonItem = sourceBarButtonItem { + popoverPresentationController?.barButtonItem = sourceBarButtonItem + } else { + popoverPresentationController?.permittedArrowDirections = arrowDirections + popoverPresentationController?.sourceView = sourceView + popoverPresentationController?.sourceRect = sourceView?.bounds ?? .zero + } + + popoverPresentationController?.delegate = self + popoverPresentationController?.backgroundColor = view.backgroundColor } - popoverPresentationController?.delegate = self - popoverPresentationController?.backgroundColor = view.backgroundColor } else { transitioningDelegate = self modalPresentationStyle = .custom } - presenting.present(self, animated: true) }