-
Notifications
You must be signed in to change notification settings - Fork 176
Added layout guide option to notification presentation #2215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,24 @@ import UIKit | |
| return notification.tokenSet | ||
| } | ||
|
|
||
| // MARK: - Show/Hide Methods | ||
| /// `show` is used to present the view inside a container view: | ||
| /// insert into layout and show with optional animation. Constraints are used for the view positioning. | ||
| /// - Parameters: | ||
| /// - view: The container view where this view will be presented. | ||
| /// - anchorView: The view used as the bottom anchor for presentation | ||
| /// (notification view is always presented up from the anchor). When no anchor view is provided the | ||
| /// bottom anchor of the container's safe area is used. | ||
| /// - animated: Indicates whether to use animation during presentation or not. | ||
| /// - completion: The closure to be called after presentation is completed. | ||
| /// Can be used to call `hide` with a delay. | ||
| @objc public func show(in view: UIView, | ||
| from anchorView: UIView? = nil, | ||
| animated: Bool = true, | ||
| completion: ((MSFNotification) -> Void)? = nil) { | ||
| show(in: view, from: anchorView, with:nil, animated: animated, completion: completion); | ||
| } | ||
|
|
||
| // MARK: - Show/Hide Methods | ||
| /// `show` is used to present the view inside a container view: | ||
| /// insert into layout and show with optional animation. Constraints are used for the view positioning. | ||
|
|
@@ -61,11 +79,13 @@ import UIKit | |
| /// - anchorView: The view used as the bottom anchor for presentation | ||
| /// (notification view is always presented up from the anchor). When no anchor view is provided the | ||
| /// bottom anchor of the container's safe area is used. | ||
| /// - layoutGuide: The layout guide used to present the toast inside of when no `anchorView` is provided | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we describe "how" the layout guide is used? Which part of the notification is aligned with the layout guide? And probably worth explaining what happens if both an |
||
| /// - animated: Indicates whether to use animation during presentation or not. | ||
| /// - completion: The closure to be called after presentation is completed. | ||
| /// Can be used to call `hide` with a delay. | ||
| @objc public func show(in view: UIView, | ||
| from anchorView: UIView? = nil, | ||
| with layoutGuide: UILayoutGuide? = nil, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: preference - I've tended away from using argument labels (i.e. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed; I'd like to redo the MSFNotification API entirely one of these days (for lots of reasons, but this is one of them). |
||
| animated: Bool = true, | ||
| completion: ((MSFNotification) -> Void)? = nil) { | ||
| guard self.window == nil else { | ||
|
|
@@ -78,6 +98,7 @@ import UIKit | |
| currentToast.hide { | ||
| self.show(in: view, | ||
| from: anchorView, | ||
| with: layoutGuide, | ||
| animated: animated, | ||
| completion: completion) | ||
| } | ||
|
|
@@ -93,11 +114,11 @@ import UIKit | |
|
|
||
| let anchor: NSLayoutYAxisAnchor | ||
| if state.showFromBottom { | ||
| anchor = anchorView?.topAnchor ?? view.safeAreaLayoutGuide.bottomAnchor | ||
| anchor = anchorView?.topAnchor ?? layoutGuide?.bottomAnchor ?? view.safeAreaLayoutGuide.bottomAnchor | ||
| constraintWhenHidden = self.topAnchor.constraint(equalTo: anchor) | ||
| constraintWhenShown = self.bottomAnchor.constraint(equalTo: anchor, constant: -presentationOffset) | ||
| } else { | ||
| anchor = anchorView?.bottomAnchor ?? view.safeAreaLayoutGuide.topAnchor | ||
| anchor = anchorView?.bottomAnchor ?? layoutGuide?.topAnchor ?? view.safeAreaLayoutGuide.topAnchor | ||
| constraintWhenHidden = self.bottomAnchor.constraint(equalTo: anchor) | ||
| constraintWhenShown = self.topAnchor.constraint(equalTo: anchor, constant: presentationOffset) | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will adding this parameter cause any problems for our Objective-C clients?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think objC just ignores default parameters and forces us to add a value. I'm personally mixed as to whether that mismatch has enough practical badness to cause us to avoid it iff we feel there is substantial benefit to swift consumers of the API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ya this should be fine for our existing clients since they can still use the old method with fewer params since objC will require all parameters to be filled