Skip to content

Commit

Permalink
Update lifecycle for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
aheze committed Jan 5, 2022
1 parent 6dd27e5 commit 2d21fde
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DismissViewController: UIViewController {
let label = UILabel()
label.text = """
Super simple.
> popover.dismiss()
> self.dismiss(popover)
"""
label.numberOfLines = 0
label.textAlignment = .left
Expand Down Expand Up @@ -124,7 +124,7 @@ class DismissViewController: UIViewController {

@objc func dismissButtonPressed() {
if let popover = popover(tagged: "Dismissal Popover") {
popover.dismiss()
dismiss(popover)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class DismissViewController: UIViewController {
let label = UILabel()
label.text = """
Super simple.
> popover.dismiss()
> self.dismiss(popover)
"""
label.numberOfLines = 0
label.textAlignment = .left
Expand Down Expand Up @@ -124,7 +124,7 @@ class DismissViewController: UIViewController {

@objc func dismissButtonPressed() {
if let popover = popover(tagged: "Dismissal Popover") {
popover.dismiss()
dismiss(popover)
}
}
}
Expand Down
9 changes: 7 additions & 2 deletions Sources/Popover+Lifecycle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,18 @@ extension UIResponder {
public func replace(_ oldPopover: Popover, with newPopover: Popover) {
oldPopover.replace(with: newPopover)
}

/// Dismiss a popover. Convenience method for `Popover.dismiss(transaction:)`.
public func dismiss(_ popover: Popover) {
popover.dismiss()
}
}

extension UIViewController {
/// Present a `Popover` using this `UIViewController` as its presentation context.
public func present(_ popoverToPresent: Popover) {
public func present(_ popover: Popover) {
guard let window = view.window else { return }
popoverToPresent.present(in: window)
popover.present(in: window)
}

/// Get the frontmost view controller.
Expand Down

0 comments on commit 2d21fde

Please sign in to comment.