Skip to content

Commit

Permalink
Merge pull request #96 from wordpress-mobile/fix/blogging-reminders-i…
Browse files Browse the repository at this point in the history
…pad-navigation

BottomSheetViewController: allow forcing formSheet modal presentation on iPad
  • Loading branch information
Gio2018 authored Jun 15, 2021
2 parents c3a22a3 + 13a43ea commit e214c61
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions WordPressUI/BottomSheet/BottomSheetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,36 +48,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.
public func show(from presenting: UIViewController, sourceView: UIView? = nil, sourceBarButtonItem: UIBarButtonItem? = nil, arrowDirections: UIPopoverArrowDirection = .any) {
public func show(from presenting: UIViewController,
sourceView: UIView? = nil,
sourceBarButtonItem: UIBarButtonItem? = nil,
arrowDirections: UIPopoverArrowDirection = .any) {
if UIDevice.isPad() {
// 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)
}

Expand Down

0 comments on commit e214c61

Please sign in to comment.