Skip to content
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

making IconAlignment property to define without making custom style #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 19 additions & 20 deletions Loaf/Loaf/Loaf.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ final public class Loaf {

/// Define a custom style for the loaf.
public struct Style {
/// Specifies the position of the icon on the loaf. (Default is `.left`)
///
/// - left: The icon will be on the left of the text
/// - right: The icon will be on the right of the text
public enum IconAlignment {
case left
case right
}
Copy link
Owner

Choose a reason for hiding this comment

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

We need to also removed the iconAlignment property from this struct too 👍


/// The background color of the loaf.
let backgroundColor: UIColor

Expand All @@ -38,19 +29,24 @@ final public class Loaf {
/// The icon on the loaf
let icon: UIImage?

/// The position of the icon
let iconAlignment: IconAlignment

public init(backgroundColor: UIColor, textColor: UIColor = .white, tintColor: UIColor = .white, font: UIFont = UIFont.systemFont(ofSize: 14, weight: .medium), icon: UIImage? = Icon.info, iconAlignment: IconAlignment = .left) {
public init(backgroundColor: UIColor, textColor: UIColor = .white, tintColor: UIColor = .white, font: UIFont = UIFont.systemFont(ofSize: 14, weight: .medium), icon: UIImage? = Icon.info) {
self.backgroundColor = backgroundColor
self.textColor = textColor
self.tintColor = tintColor
self.font = font
self.icon = icon
self.iconAlignment = iconAlignment
}
}

/// Specifies the position of the icon on the loaf. (Default is `.left`)
///
/// - left: The icon will be on the left of the text
/// - right: The icon will be on the right of the text
public enum IconAlignment {
case left
case right
}

/// Defines the loaf's status. (Default is `.info`)
///
/// - success: Represents a success message
Expand Down Expand Up @@ -120,6 +116,7 @@ final public class Loaf {
// MARK: - Properties
var message: String
var state: State
var iconAlignment: IconAlignment
var location: Location
var duration: Duration = .average
var presentingDirection: Direction
Expand All @@ -130,12 +127,14 @@ final public class Loaf {
// MARK: - Public methods
public init(_ message: String,
state: State = .info,
iconAlignment: IconAlignment = .left,
location: Location = .bottom,
presentingDirection: Direction = .vertical,
dismissingDirection: Direction = .vertical,
sender: UIViewController) {
self.message = message
self.state = state
self.iconAlignment = iconAlignment
self.location = location
self.presentingDirection = presentingDirection
self.dismissingDirection = dismissingDirection
Expand Down Expand Up @@ -226,26 +225,26 @@ final class LoafViewController: UIViewController {
case .success:
imageView.image = Loaf.Icon.success
view.backgroundColor = UIColor(hexString: "#2ecc71")
constrainWithIconAlignment(.left)
constrainWithIconAlignment(loaf.iconAlignment)
case .warning:
imageView.image = Loaf.Icon.warning
view.backgroundColor = UIColor(hexString: "##f1c40f")
constrainWithIconAlignment(.left)
constrainWithIconAlignment(loaf.iconAlignment)
case .error:
imageView.image = Loaf.Icon.error
view.backgroundColor = UIColor(hexString: "##e74c3c")
constrainWithIconAlignment(.left)
constrainWithIconAlignment(loaf.iconAlignment)
case .info:
imageView.image = Loaf.Icon.info
view.backgroundColor = UIColor(hexString: "##34495e")
constrainWithIconAlignment(.left)
constrainWithIconAlignment(loaf.iconAlignment)
case .custom(style: let style):
imageView.image = style.icon
view.backgroundColor = style.backgroundColor
imageView.tintColor = style.tintColor
label.textColor = style.textColor
label.font = style.font
constrainWithIconAlignment(style.iconAlignment, showsIcon: imageView.image != nil)
constrainWithIconAlignment(loaf.iconAlignment, showsIcon: imageView.image != nil)
}

let tapGesture = UITapGestureRecognizer(target: self, action: #selector(handleTap))
Expand All @@ -266,7 +265,7 @@ final class LoafViewController: UIViewController {
}
}

private func constrainWithIconAlignment(_ alignment: Loaf.Style.IconAlignment, showsIcon: Bool = true) {
private func constrainWithIconAlignment(_ alignment: Loaf.IconAlignment, showsIcon: Bool = true) {
view.addSubview(label)

if showsIcon {
Expand Down