Skip to content

Commit

Permalink
fix(EmptyState): Controlador de estado vacío de botones IOS-7012 (#137)
Browse files Browse the repository at this point in the history
* fix(EmptyState): Empty state buttons handler IOS-7012
  • Loading branch information
alexanegon committed Sep 16, 2021
1 parent 6830ea9 commit d14a4fd
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
9 changes: 9 additions & 0 deletions Mistica/Source/Components/EmptyState/EmptyState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public extension EmptyState {
}
}

var iconTintColor: UIColor {
get {
emptyStateContentBase.iconTintColor
}
set {
emptyStateContentBase.iconTintColor = newValue
}
}

var primaryButton: Button {
emptyStateContentBase.emptyStateButtons.primaryButton
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
import UIKit

public struct EmptyStateConfiguration {
static let empty = EmptyStateConfiguration(type: .default(.icon(UIImage(color: .success))), title: "Basic configuration", description: "This is a basic configuration for the empty state", actions: nil)
static let empty = EmptyStateConfiguration(type: .default(.icon(UIImage())), title: "Basic configuration", description: "This is a basic configuration for the empty state", actions: nil)

public enum EmptyStateActions {
case primary(EmptyStateButton)
Expand Down Expand Up @@ -43,7 +43,7 @@ public struct EmptyStateConfiguration {
let description: String?
let actions: EmptyStateActions?

public init(type: EmptyStateType = .default(.icon(UIImage())), title: String, description: String?, actions: EmptyStateActions? = nil) {
public init(type: EmptyStateType, title: String, description: String?, actions: EmptyStateActions? = nil) {
self.type = type
self.title = title
self.description = description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ class EmptyStateButtons: UIStackView {

extension EmptyStateButtons {
func configureButtons(primaryButton: EmptyStateButton? = nil, secondaryButton: EmptyStateButton? = nil, linkButton: EmptyStateLinkButton? = nil, isCard: Bool = false) {
configure(for: self.primaryButton, with: primaryButton, isCard: isCard, actionHandler: primaryActionHandler)
configure(for: self.secondaryButton, with: secondaryButton, isCard: isCard, actionHandler: secondaryActionHandler)
configure(for: self.linkButton, with: linkButton, isCard: isCard, actionHandler: linkActionHandler)
configure(for: self.primaryButton, with: primaryButton, isCard: isCard)
primaryActionHandler = primaryButton?.tapHandler
configure(for: self.secondaryButton, with: secondaryButton, isCard: isCard)
secondaryActionHandler = secondaryButton?.tapHandler
configure(for: self.linkButton, with: linkButton, isCard: isCard)
linkActionHandler = linkButton?.tapHandler

if !arrangedSubviews.isEmpty {
addArrangedSubview(dummyView)
Expand Down Expand Up @@ -76,7 +79,7 @@ private extension EmptyStateButtons {
linkButton.style = .link
}

func configure(for button: Button, with emptyButton: EmptyStateButton?, isCard: Bool = false, actionHandler: (() -> Void)?) {
func configure(for button: Button, with emptyButton: EmptyStateButton?, isCard: Bool = false) {
if let configButton = emptyButton {
button.title = configButton.title
button.loadingTitle = configButton.loadingTitle
Expand All @@ -89,7 +92,7 @@ private extension EmptyStateButtons {
}
}

func configure(for link: Button, with emptyLinkButton: EmptyStateLinkButton?, isCard: Bool = false, actionHandler: (() -> Void)?) {
func configure(for link: Button, with emptyLinkButton: EmptyStateLinkButton?, isCard: Bool = false) {
if let linkButton = emptyLinkButton {
link.title = linkButton.title
link.contentMode = .left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ extension EmptyStateContentBase {
}
}

var iconTintColor: UIColor {
get {
iconImage.tintColor
}
set {
iconImage.tintColor = newValue
}
}

func configure(withConfiguration configuration: EmptyStateConfiguration) {
configureMessagesContent(withConfiguration: configuration)
// Asset is mandatory
Expand Down
6 changes: 3 additions & 3 deletions Mistica/Tests/MisticaTests/UI/EmptyStatesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ final class EmptyStatesTests: XCTestCase {
func testSecondaryAndLinkButtonsOnlyAsACard() {
MisticaConfig.brandStyle = .movistar

let view = makeEmptyStateWithContentAndButtons(type: .card(.icon(AnyValues.smallImage)), actions: .secondaryAndLink(secondary: AnyValues.secondary, link: AnyValues.link))
let view = makeEmptyStateWithContentAndButtons(type: .card(.icon(AnyValues.iconImage)), actions: .secondaryAndLink(secondary: AnyValues.secondary, link: AnyValues.link))

assertSnapshot(matching: view, as: .image)
}
Expand All @@ -136,15 +136,15 @@ final class EmptyStatesTests: XCTestCase {
func testEmptyButtonOnlyAsACard() {
MisticaConfig.brandStyle = .movistar

let view = makeEmptyStateWithContentAndButtons(type: .card(.icon(AnyValues.smallImage)), actions: .empty)
let view = makeEmptyStateWithContentAndButtons(type: .card(.icon(AnyValues.iconImage)), actions: .empty)

assertSnapshot(matching: view, as: .image)
}

func testLinkButtonOnlyAsACard() {
MisticaConfig.brandStyle = .movistar

let view = makeEmptyStateWithContentAndButtons(type: .card(.icon(AnyValues.smallImage)), actions: .link(AnyValues.link))
let view = makeEmptyStateWithContentAndButtons(type: .card(.icon(AnyValues.iconImage)), actions: .link(AnyValues.link))

assertSnapshot(matching: view, as: .image)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,26 @@ extension UICatalogEmptyStateViewController: UITableViewDataSource, UITableViewD
view.endEditing(true)

let actions: EmptyStateConfiguration.EmptyStateActions
let handler: () -> Void = {
CroutonController.shared.showCrouton(withText: "The user has tapped any button")
}
switch buttonsCell.segmentedControl.selectedSegmentIndex {
case 0:
actions = .primary(EmptyStateButton(title: "Button small", loadingTitle: nil, tapHandler: nil))
actions = .primary(EmptyStateButton(title: "Button small", loadingTitle: nil, tapHandler: handler))
case 1:
actions = .primaryAndLink(
primary: EmptyStateButton(title: "Button small", loadingTitle: nil, tapHandler: nil),
link: EmptyStateLinkButton(title: "Link", tapHandler: nil)
primary: EmptyStateButton(title: "Button small", loadingTitle: nil, tapHandler: handler),
link: EmptyStateLinkButton(title: "Link", tapHandler: handler)
)
case 2:
actions = .secondary(EmptyStateButton(title: "Secondary", loadingTitle: nil, tapHandler: nil))
actions = .secondary(EmptyStateButton(title: "Secondary", loadingTitle: nil, tapHandler: handler))
case 3:
actions = .secondaryAndLink(
secondary: EmptyStateButton(title: "Secondary", loadingTitle: nil, tapHandler: nil),
link: EmptyStateLinkButton(title: "Link", tapHandler: nil)
secondary: EmptyStateButton(title: "Secondary", loadingTitle: nil, tapHandler: handler),
link: EmptyStateLinkButton(title: "Link", tapHandler: handler)
)
case 4:
actions = .link(EmptyStateLinkButton(title: "Link", tapHandler: nil))
actions = .link(EmptyStateLinkButton(title: "Link", tapHandler: handler))
case 5:
actions = .empty
default:
Expand Down Expand Up @@ -246,6 +249,7 @@ extension UICatalogEmptyStateViewController: UITableViewDataSource, UITableViewD
}
let vc = EmptyStateViewSampleViewController()
vc.emptyState.contentConfiguration = configuration
vc.emptyState.iconTintColor = .systemPink

show(vc, sender: self)
}
Expand Down

0 comments on commit d14a4fd

Please sign in to comment.