From d14a4fda11dc03d64ec39c7bcf8e902a1cbf79ae Mon Sep 17 00:00:00 2001 From: Alex Anegon Date: Thu, 16 Sep 2021 16:27:05 +0200 Subject: [PATCH] =?UTF-8?q?fix(EmptyState):=20Controlador=20de=20estado=20?= =?UTF-8?q?vac=C3=ADo=20de=20botones=20IOS-7012=20(#137)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(EmptyState): Empty state buttons handler IOS-7012 --- .../Components/EmptyState/EmptyState.swift | 9 +++++++++ .../EmptyState/EmptyStateConfiguration.swift | 4 ++-- .../Internals/EmptyStateButtons.swift | 13 ++++++++----- .../Internals/EmptyStateContentBase.swift | 9 +++++++++ .../MisticaTests/UI/EmptyStatesTests.swift | 6 +++--- .../UICatalogEmptyStateViewController.swift | 18 +++++++++++------- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/Mistica/Source/Components/EmptyState/EmptyState.swift b/Mistica/Source/Components/EmptyState/EmptyState.swift index b56395ab2..2e8d7c9b3 100644 --- a/Mistica/Source/Components/EmptyState/EmptyState.swift +++ b/Mistica/Source/Components/EmptyState/EmptyState.swift @@ -73,6 +73,15 @@ public extension EmptyState { } } + var iconTintColor: UIColor { + get { + emptyStateContentBase.iconTintColor + } + set { + emptyStateContentBase.iconTintColor = newValue + } + } + var primaryButton: Button { emptyStateContentBase.emptyStateButtons.primaryButton } diff --git a/Mistica/Source/Components/EmptyState/EmptyStateConfiguration.swift b/Mistica/Source/Components/EmptyState/EmptyStateConfiguration.swift index b246276c9..6416b46b4 100644 --- a/Mistica/Source/Components/EmptyState/EmptyStateConfiguration.swift +++ b/Mistica/Source/Components/EmptyState/EmptyStateConfiguration.swift @@ -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) @@ -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 diff --git a/Mistica/Source/Components/EmptyState/Internals/EmptyStateButtons.swift b/Mistica/Source/Components/EmptyState/Internals/EmptyStateButtons.swift index c93178292..5d01eacde 100644 --- a/Mistica/Source/Components/EmptyState/Internals/EmptyStateButtons.swift +++ b/Mistica/Source/Components/EmptyState/Internals/EmptyStateButtons.swift @@ -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) @@ -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 @@ -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 diff --git a/Mistica/Source/Components/EmptyState/Internals/EmptyStateContentBase.swift b/Mistica/Source/Components/EmptyState/Internals/EmptyStateContentBase.swift index 632440272..51fb512ae 100644 --- a/Mistica/Source/Components/EmptyState/Internals/EmptyStateContentBase.swift +++ b/Mistica/Source/Components/EmptyState/Internals/EmptyStateContentBase.swift @@ -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 diff --git a/Mistica/Tests/MisticaTests/UI/EmptyStatesTests.swift b/Mistica/Tests/MisticaTests/UI/EmptyStatesTests.swift index 3ecba11ad..29ce732bc 100644 --- a/Mistica/Tests/MisticaTests/UI/EmptyStatesTests.swift +++ b/Mistica/Tests/MisticaTests/UI/EmptyStatesTests.swift @@ -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) } @@ -136,7 +136,7 @@ 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) } @@ -144,7 +144,7 @@ final class EmptyStatesTests: XCTestCase { 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) } diff --git a/MisticaCatalog/Source/ComponentsCatalogs/UICatalogEmptyStateViewController.swift b/MisticaCatalog/Source/ComponentsCatalogs/UICatalogEmptyStateViewController.swift index ac7f20d77..739e843da 100644 --- a/MisticaCatalog/Source/ComponentsCatalogs/UICatalogEmptyStateViewController.swift +++ b/MisticaCatalog/Source/ComponentsCatalogs/UICatalogEmptyStateViewController.swift @@ -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: @@ -246,6 +249,7 @@ extension UICatalogEmptyStateViewController: UITableViewDataSource, UITableViewD } let vc = EmptyStateViewSampleViewController() vc.emptyState.contentConfiguration = configuration + vc.emptyState.iconTintColor = .systemPink show(vc, sender: self) }