Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Sources/Loaf/Loaf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@ final public class Loaf {
///
/// - top: Top of the display
/// - bottom: Bottom of the display
/// - center: Center of the display
public enum Location {
case top
case bottom
case center
}

/// Defines either the presenting or dismissing direction of loaf. (Default is `.vertical`)
///
/// - left: To / from the left
/// - right: To / from the right
/// - vertical: To / from the top or bottom (depending on the location of the loaf)
/// - vertical: To / from the top, center or bottom (depending on the location of the loaf)
public enum Direction {
case left
case right
Expand Down
9 changes: 8 additions & 1 deletion Sources/Loaf/Presenter/Animator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@ extension Animator: UIViewControllerAnimatedTransitioning {

switch presenting ? loaf.presentingDirection : loaf.dismissingDirection {
case .vertical:
dismissedFrame.origin.y = (loaf.location == .bottom) ? controller.view.frame.height + 60 : -size.height - 60
switch loaf.location {
case .top:
dismissedFrame.origin.y = -size.height - 60
case .bottom:
dismissedFrame.origin.y = controller.view.bounds.height + 60
Copy link
Author

@Hayd25 Hayd25 Jul 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: for the bottom being the controller height + 60, I wondered if maybe it was meant to be just size.height + 60? That way it will animate up from 60 below its final bottom coordinate rather than shoot up from far below the screen.

Thanks again for the well written library!

case .center:
dismissedFrame.origin.y = 60
}
case .left:
dismissedFrame.origin.x = -controller.view.frame.width * 2
case .right:
Expand Down
4 changes: 4 additions & 0 deletions Sources/Loaf/Presenter/Controller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ final class Controller: UIPresentationController {
yPosition = containerView.frame.origin.y + containerView.frame.height - size.height - containerInsets.bottom
case .top:
yPosition = containerInsets.top
case .center:
yPosition = containerView.frame.midY - (size.height/2.0)
}

containerView.frame.origin = CGPoint(
Expand All @@ -81,6 +83,8 @@ final class Controller: UIPresentationController {
yPosition = containerView.bounds.height - containerSize.height
case .top:
yPosition = 0
case .center:
yPosition = containerView.bounds.midY - (containerSize.height/2.0)
}

let toastSize = CGRect(x: containerView.center.x - (containerSize.width / 2),
Expand Down