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

feat: Add new initialization method to simplify the amount of code #42

Merged
merged 1 commit into from
Jun 11, 2024
Merged
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
17 changes: 17 additions & 0 deletions Sources/Epoxy/Row/ButtonRow/ButtonRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ extension ButtonRow: ContentConfigurableView {
self.title = title
self.titleColor = titleColor.color
}

public init(
image: (some ButtonImageContentProviding)? = nil,
title: TextRow.Content? = nil,
titleColor: ConvertibleToColor = UIColor.label
) {
self.init(image: .init(image), title: title, titleColor: titleColor)
}
}

case normal(StateContent)
Expand All @@ -200,6 +208,15 @@ extension ButtonRow: ContentConfigurableView {
) {
self = .normal(.init(image: image, title: title, titleColor: titleColor))
}

/// Conveniently set styles in `.normal` state
public init(
image: (some ButtonImageContentProviding)? = nil,
title: TextRow.Content? = nil,
titleColor: ConvertibleToColor = UIColor.label
) {
self.init(image: .init(image), title: title, titleColor: titleColor)
}
}

public func setContent(_ content: Content, animated _: Bool) {
Expand Down
8 changes: 7 additions & 1 deletion Sources/Epoxy/Row/ButtonRow/ButtonRowStateContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ import RAKCore
/// Used to indicate what data corresponds to each UIButton state.
///
/// Used internally to simplify the creation of `ButtonRow.Content` in `.normal` state.
protocol ButtonRowStateContent {
public protocol ButtonRowStateContent {
associatedtype ImageContent

init(
image: ImageContent?,
title: TextRow.Content?,
titleColor: ConvertibleToColor
)

init(
image: (some ButtonImageContentProviding)?,
title: TextRow.Content?,
titleColor: ConvertibleToColor
)
}
#endif