Skip to content

Commit

Permalink
Merge pull request rushisangani#115 from rursache/master
Browse files Browse the repository at this point in the history
Improved show in popover logic
  • Loading branch information
rushisangani authored May 19, 2021
2 parents 49bd5bb + 4cf2b63 commit f441457
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,11 @@ open class RSSelectionMenu<T: Equatable>: UIViewController, UIPopoverPresentatio
}

public func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return !showRightBarButton()
let shouldDismiss = !showRightBarButton()
if shouldDismiss {
self.menuWillDismiss()
}
return shouldDismiss
}

// MARK: - UIGestureRecognizerDelegate
Expand Down Expand Up @@ -393,14 +397,15 @@ extension RSSelectionMenu {
if case .present = with {
tobePresentController = UINavigationController(rootViewController: self)
}
else if case let .popover(sourceView, size) = with {
else if case let .popover(sourceView, size, arrowDirection, hideNavBar) = with {
tobePresentController = UINavigationController(rootViewController: self)
(tobePresentController as! UINavigationController).setNavigationBarHidden(hideNavBar, animated: false)
tobePresentController.modalPresentationStyle = .popover
if size != nil { tobePresentController.preferredContentSize = size! }

let popover = tobePresentController.popoverPresentationController!
popover.delegate = self
popover.permittedArrowDirections = .any
popover.permittedArrowDirections = arrowDirection
popover.sourceView = sourceView
popover.sourceRect = sourceView.bounds
}
Expand Down
2 changes: 1 addition & 1 deletion RSSelectionMenu/RSSelectionMenu/Utilities/Enums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum PresentationStyle {
case present // default
case push
case formSheet(size: CGSize?)
case popover(sourceView: UIView, size: CGSize?)
case popover(sourceView: UIView, size: CGSize?, arrowDirection: UIPopoverArrowDirection = .any, hideNavBar: Bool = false)
case alert(title: String?, action: String?, height: Double?)
case actionSheet(title: String?, action: String?, height: Double?)
case bottomSheet(barButton: UIBarButtonItem, height: Double?)
Expand Down

0 comments on commit f441457

Please sign in to comment.