From b9bed6efd7d09feab0fffc531be9e75d5f4a3514 Mon Sep 17 00:00:00 2001 From: Jorge Ovalle Date: Thu, 1 Aug 2019 13:11:07 -0500 Subject: [PATCH 1/6] Add basic implementation for allowing enable/disable scrolling --- Example/Podfile.lock | 4 +-- .../Local Podspecs/WLEmptyState.podspec.json | 4 +-- Example/Pods/Manifest.lock | 4 +-- ...undle-WLEmptyState-WLEmptyState-Info.plist | 2 +- .../WLEmptyState/WLEmptyState-Info.plist | 2 +- .../UICollectionView+WLEmptyState.swift | 36 ++++++++++++++----- .../Extensions/UITableView+WLEmptyState.swift | 36 ++++++++++++++----- .../Protocols/WLEmptyStateDelegate.swift | 10 ++++-- .../Protocols/WLEmptyStateProtocol.swift | 1 + 9 files changed, 71 insertions(+), 28 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index cc0910d..d36e0ed 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -4,7 +4,7 @@ PODS: - iOSSnapshotTestCase/Core (4.0.1) - iOSSnapshotTestCase/SwiftSupport (4.0.1): - iOSSnapshotTestCase/Core - - WLEmptyState (2.0.0) + - WLEmptyState (3.0.0) DEPENDENCIES: - iOSSnapshotTestCase @@ -20,7 +20,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: iOSSnapshotTestCase: f3b2b7e606fe03fdbe49af84316bd235df32dc44 - WLEmptyState: 0573edb909655cd6e5e7a367b371a10525dcee5a + WLEmptyState: 5c7cae4cdc57641ff1193338ad601bf4fa2f05ad PODFILE CHECKSUM: 5fd6a2332b7cd50dfecaf0807164322168c50c78 diff --git a/Example/Pods/Local Podspecs/WLEmptyState.podspec.json b/Example/Pods/Local Podspecs/WLEmptyState.podspec.json index d121e44..d87bdf5 100644 --- a/Example/Pods/Local Podspecs/WLEmptyState.podspec.json +++ b/Example/Pods/Local Podspecs/WLEmptyState.podspec.json @@ -1,6 +1,6 @@ { "name": "WLEmptyState", - "version": "2.0.0", + "version": "3.0.0", "summary": "Custom view for Empty states on tables or collection entities", "description": "A control to display a place holder in case there's no data on a UITableView or UICollectionView", "homepage": "https://github.com/wizeline/WLEmptyState", @@ -13,7 +13,7 @@ }, "source": { "git": "https://github.com/wizeline/WLEmptyState.git", - "tag": "2.0.0" + "tag": "3.0.0" }, "platforms": { "ios": "9.0" diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index cc0910d..d36e0ed 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -4,7 +4,7 @@ PODS: - iOSSnapshotTestCase/Core (4.0.1) - iOSSnapshotTestCase/SwiftSupport (4.0.1): - iOSSnapshotTestCase/Core - - WLEmptyState (2.0.0) + - WLEmptyState (3.0.0) DEPENDENCIES: - iOSSnapshotTestCase @@ -20,7 +20,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: iOSSnapshotTestCase: f3b2b7e606fe03fdbe49af84316bd235df32dc44 - WLEmptyState: 0573edb909655cd6e5e7a367b371a10525dcee5a + WLEmptyState: 5c7cae4cdc57641ff1193338ad601bf4fa2f05ad PODFILE CHECKSUM: 5fd6a2332b7cd50dfecaf0807164322168c50c78 diff --git a/Example/Pods/Target Support Files/WLEmptyState/ResourceBundle-WLEmptyState-WLEmptyState-Info.plist b/Example/Pods/Target Support Files/WLEmptyState/ResourceBundle-WLEmptyState-WLEmptyState-Info.plist index 16a4ec9..492c4f3 100644 --- a/Example/Pods/Target Support Files/WLEmptyState/ResourceBundle-WLEmptyState-WLEmptyState-Info.plist +++ b/Example/Pods/Target Support Files/WLEmptyState/ResourceBundle-WLEmptyState-WLEmptyState-Info.plist @@ -13,7 +13,7 @@ CFBundlePackageType BNDL CFBundleShortVersionString - 2.0.0 + 3.0.0 CFBundleSignature ???? CFBundleVersion diff --git a/Example/Pods/Target Support Files/WLEmptyState/WLEmptyState-Info.plist b/Example/Pods/Target Support Files/WLEmptyState/WLEmptyState-Info.plist index 0a12077..4522675 100644 --- a/Example/Pods/Target Support Files/WLEmptyState/WLEmptyState-Info.plist +++ b/Example/Pods/Target Support Files/WLEmptyState/WLEmptyState-Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.0.0 + 3.0.0 CFBundleSignature ???? CFBundleVersion diff --git a/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift b/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift index 5f45a08..5b0572d 100644 --- a/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift +++ b/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift @@ -43,26 +43,44 @@ extension UICollectionView: WLEmptyStateProtocol { } } - @objc private dynamic func swizzledReload() { - guard emptyStateDataSource != nil else { return } + /// The original value before enable/disable scrolling. + var originalScrollingValue: Bool { + get { + return (objc_getAssociatedObject(self, &AssociatedKeys.originalScrollingValue) as? Bool) ?? isScrollEnabled + } + set { + objc_setAssociatedObject(self, &AssociatedKeys.originalScrollingValue, newValue, .OBJC_ASSOCIATION_COPY) + } + } + + @objc private dynamic func swizzledReload() { swizzledReload() + guard emptyStateDataSource != nil else { return } + if numberOfItems == 0 && self.subviews.count > 1 { + originalScrollingValue = isScrollEnabled + isScrollEnabled = emptyStateDelegate?.emptyStateShouldScroll() ?? true + backgroundView = emptyStateView if let emptyStateView = emptyStateView as? EmptyStateView { - emptyStateView.titleLabel.attributedText = self.emptyStateDataSource?.titleForEmptyDataSet() - emptyStateView.descriptionLabel.attributedText = self.emptyStateDataSource?.descriptionForEmptyDataSet() - emptyStateView.image.image = self.emptyStateDataSource?.imageForEmptyDataSet() + let datasource = self.emptyStateDataSource + emptyStateView.titleLabel.attributedText = datasource?.titleForEmptyDataSet() + emptyStateView.descriptionLabel.attributedText = datasource?.descriptionForEmptyDataSet() + emptyStateView.image.image = datasource?.imageForEmptyDataSet() } else { emptyStateView.translatesAutoresizingMaskIntoConstraints = false - emptyStateView.heightAnchor.constraint(equalTo: heightAnchor).isActive = true - emptyStateView.widthAnchor.constraint(equalTo: widthAnchor).isActive = true - emptyStateView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true - emptyStateView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true + NSLayoutConstraint.activate([ + emptyStateView.heightAnchor.constraint(equalTo: heightAnchor), + emptyStateView.widthAnchor.constraint(equalTo: widthAnchor), + emptyStateView.centerYAnchor.constraint(equalTo: centerYAnchor), + emptyStateView.centerXAnchor.constraint(equalTo: centerXAnchor) + ]) } } else { removeEmptyView() + isScrollEnabled = originalScrollingValue } } } diff --git a/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift b/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift index a62760e..7365ff3 100644 --- a/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift +++ b/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift @@ -44,26 +44,44 @@ extension UITableView: WLEmptyStateProtocol { } } + /// The original value before enable/disable scrolling. + var originalScrollingValue: Bool { + get { + return (objc_getAssociatedObject(self, &AssociatedKeys.originalScrollingValue) as? Bool) ?? isScrollEnabled + } + + set { + objc_setAssociatedObject(self, &AssociatedKeys.originalScrollingValue, newValue, .OBJC_ASSOCIATION_COPY) + } + } + @objc private dynamic func swizzledReload() { - guard emptyStateDataSource != nil else { return } - swizzledReload() + guard emptyStateDataSource != nil else { return } + if numberOfItems == 0 && self.subviews.count > 1 { + originalScrollingValue = isScrollEnabled + isScrollEnabled = emptyStateDelegate?.emptyStateShouldScroll() ?? true + addSubview(emptyStateView) if let emptyStateView = emptyStateView as? EmptyStateView { - emptyStateView.titleLabel.attributedText = self.emptyStateDataSource?.titleForEmptyDataSet() - emptyStateView.descriptionLabel.attributedText = self.emptyStateDataSource?.descriptionForEmptyDataSet() - emptyStateView.image.image = self.emptyStateDataSource?.imageForEmptyDataSet() + let datasource = self.emptyStateDataSource + emptyStateView.titleLabel.attributedText = datasource?.titleForEmptyDataSet() + emptyStateView.descriptionLabel.attributedText = datasource?.descriptionForEmptyDataSet() + emptyStateView.image.image = datasource?.imageForEmptyDataSet() } else { emptyStateView.translatesAutoresizingMaskIntoConstraints = false - emptyStateView.heightAnchor.constraint(equalTo: heightAnchor).isActive = true - emptyStateView.widthAnchor.constraint(equalTo: widthAnchor).isActive = true - emptyStateView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true - emptyStateView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true + NSLayoutConstraint.activate([ + emptyStateView.heightAnchor.constraint(equalTo: heightAnchor), + emptyStateView.widthAnchor.constraint(equalTo: widthAnchor), + emptyStateView.centerYAnchor.constraint(equalTo: centerYAnchor), + emptyStateView.centerXAnchor.constraint(equalTo: centerXAnchor) + ]) } } else { removeEmptyView() + isScrollEnabled = originalScrollingValue } } } diff --git a/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift b/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift index ae2ea68..8bbee08 100644 --- a/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift +++ b/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift @@ -9,7 +9,13 @@ import Foundation public protocol WLEmptyStateDelegate: class { - // TODO: Add delegate functions 😅 - //emptyDataSetShouldAllowTouch + func emptyStateShouldScroll() -> Bool } +extension WLEmptyStateDelegate { + + func emptyStateShouldScroll() -> Bool { + return true + } + +} diff --git a/WLEmptyState/Classes/Protocols/WLEmptyStateProtocol.swift b/WLEmptyState/Classes/Protocols/WLEmptyStateProtocol.swift index 762272a..797995f 100644 --- a/WLEmptyState/Classes/Protocols/WLEmptyStateProtocol.swift +++ b/WLEmptyState/Classes/Protocols/WLEmptyStateProtocol.swift @@ -12,6 +12,7 @@ struct AssociatedKeys { static var emptyStateDelegate = "emptyStateDelegate" static var emptyStateDataSource = "emptyStateDataSource" static var emptyStateView = "emptyStateView" + static var originalScrollingValue = "originalScrollingValue" } /// This protocol provides the basic needed to override emptyViewState on anyclass that supports it From 4f00ffce3d6cd765b59ff7e70c4b27d7512a4291 Mon Sep 17 00:00:00 2001 From: Jorge Ovalle Date: Thu, 1 Aug 2019 14:52:23 -0500 Subject: [PATCH 2/6] Add Unit tests for delegate function --- Example/Tests/DelegateTests.swift | 48 +++++++++++++++++++ Example/Tests/UICollectionViewMocks.swift | 10 +++- Example/Tests/UITableViewMocks.swift | 10 +++- .../WLEmptyState.xcodeproj/project.pbxproj | 7 ++- .../Protocols/WLEmptyStateDelegate.swift | 2 +- 5 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 Example/Tests/DelegateTests.swift diff --git a/Example/Tests/DelegateTests.swift b/Example/Tests/DelegateTests.swift new file mode 100644 index 0000000..1a614e2 --- /dev/null +++ b/Example/Tests/DelegateTests.swift @@ -0,0 +1,48 @@ +// +// DelegateTests.swift +// WLEmptyState_Example +// +// Created by Jorge Ovalle on 8/1/19. +// Copyright © 2019 CocoaPods. All rights reserved. +// + +import XCTest +import WLEmptyState + +class DelegateTests: XCTestCase { + + override func setUp() { + WLEmptyState.configure() + } + + // MARK: - UTableView + func testShouldScrollDelegatePropertyOnTableDefault() { + let defaultTableViewController = DefaultTableViewController() + + let shouldScrollTableView = defaultTableViewController.tableView.emptyStateDelegate?.emptyStateShouldScroll() + XCTAssertEqual(true, shouldScrollTableView) + } + + func testShouldScrollDelegatePropertyOnTableCustom() { + let customTableViewController = CustomEmptyStateTableViewController() + + let shouldScrollTableView = customTableViewController.tableView.emptyStateDelegate?.emptyStateShouldScroll() + XCTAssertEqual(false, shouldScrollTableView) + } + + // MARK: - UICollectionView + func testShouldScrollDelegatePropertyOnCollectionDefault() { + let defaultCollectionViewController = DefaultCollectionViewController(collectionViewLayout: UICollectionViewFlowLayout()) + + let shouldScrollTableView = defaultCollectionViewController.collectionView.emptyStateDelegate?.emptyStateShouldScroll() + XCTAssertEqual(true, shouldScrollTableView) + } + + func testShouldScrollDelegatePropertyOnCollectionCustom() { + let customCollectionViewController = CustomCollectionViewController(collectionViewLayout: UICollectionViewFlowLayout()) + + let shouldScrollTableView = customCollectionViewController.collectionView.emptyStateDelegate?.emptyStateShouldScroll() + XCTAssertEqual(false, shouldScrollTableView) + } + +} diff --git a/Example/Tests/UICollectionViewMocks.swift b/Example/Tests/UICollectionViewMocks.swift index ba4d0dc..f235f09 100644 --- a/Example/Tests/UICollectionViewMocks.swift +++ b/Example/Tests/UICollectionViewMocks.swift @@ -10,24 +10,26 @@ import WLEmptyState // MARK: Default Empty State on UICollectionView -final class DefaultCollectionViewController: UICollectionViewController, WLEmptyStateDataSource { +final class DefaultCollectionViewController: UICollectionViewController, WLEmptyStateDataSource, WLEmptyStateDelegate { override func viewDidLoad() { super.viewDidLoad() collectionView.emptyStateDataSource = self + collectionView.emptyStateDelegate = self } } // MARK: Customized default Empty State on UICollectionView -final class CustomCollectionViewController: UICollectionViewController, WLEmptyStateDataSource { +final class CustomCollectionViewController: UICollectionViewController, WLEmptyStateDataSource, WLEmptyStateDelegate { override func viewDidLoad() { super.viewDidLoad() collectionView.emptyStateDataSource = self + collectionView.emptyStateDelegate = self } func titleForEmptyDataSet() -> NSAttributedString { @@ -41,6 +43,10 @@ final class CustomCollectionViewController: UICollectionViewController, WLEmptyS func imageForEmptyDataSet() -> UIImage? { return nil } + + func emptyStateShouldScroll() -> Bool { + return false + } } // MARK: Custom Empty State on UICollectionView diff --git a/Example/Tests/UITableViewMocks.swift b/Example/Tests/UITableViewMocks.swift index 0c5a1e1..72eb478 100644 --- a/Example/Tests/UITableViewMocks.swift +++ b/Example/Tests/UITableViewMocks.swift @@ -10,12 +10,13 @@ import WLEmptyState // MARK: Default Empty State on UITableView -final class DefaultTableViewController: UITableViewController, WLEmptyStateDataSource { +final class DefaultTableViewController: UITableViewController, WLEmptyStateDataSource, WLEmptyStateDelegate { override func viewDidLoad() { super.viewDidLoad() tableView.emptyStateDataSource = self + tableView.emptyStateDelegate = self } } @@ -45,12 +46,13 @@ final class CustomTableViewController: UITableViewController, WLEmptyStateDataSo // MARK: Custom Empty State on UITableView -final class CustomEmptyStateTableViewController: UITableViewController, WLEmptyStateDataSource { +final class CustomEmptyStateTableViewController: UITableViewController, WLEmptyStateDataSource, WLEmptyStateDelegate { override func viewDidLoad() { super.viewDidLoad() tableView.emptyStateDataSource = self + tableView.emptyStateDelegate = self } func customViewForEmptyState() -> UIView? { @@ -59,6 +61,10 @@ final class CustomEmptyStateTableViewController: UITableViewController, WLEmptyS return view } + func emptyStateShouldScroll() -> Bool { + return false + } + } diff --git a/Example/WLEmptyState.xcodeproj/project.pbxproj b/Example/WLEmptyState.xcodeproj/project.pbxproj index 6fa5c68..177400c 100644 --- a/Example/WLEmptyState.xcodeproj/project.pbxproj +++ b/Example/WLEmptyState.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ 7A53B06A227F76C1007718E3 /* UIViewController+Storyboard.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A53B069227F76C1007718E3 /* UIViewController+Storyboard.swift */; }; 7A60354D2214DB2B000265EC /* DataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A60354C2214DB2B000265EC /* DataSourceTests.swift */; }; 7A6035502214DC7E000265EC /* UITableViewMocks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A60354E2214DBBF000265EC /* UITableViewMocks.swift */; }; + 7AC01BCA22F3717C003BBC41 /* DelegateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AC01BC822F37178003BBC41 /* DelegateTests.swift */; }; A2D832CF21F965BE00C39001 /* SnapshotTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2D832CE21F965BE00C39001 /* SnapshotTests.swift */; }; D1B6CC7AF3E1EC8EF12A6340 /* Pods_WLEmptyState_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0424AD21D7FF86F64DF8F8C3 /* Pods_WLEmptyState_Example.framework */; }; /* End PBXBuildFile section */ @@ -49,6 +50,7 @@ 7A53B069227F76C1007718E3 /* UIViewController+Storyboard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+Storyboard.swift"; sourceTree = ""; }; 7A60354C2214DB2B000265EC /* DataSourceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataSourceTests.swift; sourceTree = ""; }; 7A60354E2214DBBF000265EC /* UITableViewMocks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UITableViewMocks.swift; sourceTree = ""; }; + 7AC01BC822F37178003BBC41 /* DelegateTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DelegateTests.swift; sourceTree = ""; }; 84DAF8E07A8ECD21288C5213 /* WLEmptyState.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = WLEmptyState.podspec; path = ../WLEmptyState.podspec; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 8A840B888B6222D270FDB5AC /* Pods-WLEmptyState_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WLEmptyState_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-WLEmptyState_Example/Pods-WLEmptyState_Example.release.xcconfig"; sourceTree = ""; }; 8D01069E49EF92D29E2AF9A1 /* Pods-WLEmptyState_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WLEmptyState_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WLEmptyState_Example/Pods-WLEmptyState_Example.debug.xcconfig"; sourceTree = ""; }; @@ -105,7 +107,6 @@ 607FACF51AFB993E008FA782 /* Podspec Metadata */, 607FACD21AFB9204008FA782 /* Example for WLEmptyState */, 607FACE81AFB9204008FA782 /* Tests */, - 607FACD11AFB9204008FA782 /* Products */, 18D52A2518BD719291B9F3C8 /* Pods */, 435FD54265B62AA7A84C9701 /* Frameworks */, ); @@ -118,6 +119,7 @@ 607FACE51AFB9204008FA782 /* WLEmptyState_Tests.xctest */, ); name = Products; + path = ..; sourceTree = ""; }; 607FACD21AFB9204008FA782 /* Example for WLEmptyState */ = { @@ -148,6 +150,8 @@ children = ( 7A3CAFE222C592D200F6FD40 /* Mocks */, 7A60354C2214DB2B000265EC /* DataSourceTests.swift */, + 7AC01BC822F37178003BBC41 /* DelegateTests.swift */, + 607FACD11AFB9204008FA782 /* Products */, A2D832CE21F965BE00C39001 /* SnapshotTests.swift */, 607FACE91AFB9204008FA782 /* Supporting Files */, 7A53B069227F76C1007718E3 /* UIViewController+Storyboard.swift */, @@ -383,6 +387,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 7AC01BCA22F3717C003BBC41 /* DelegateTests.swift in Sources */, A2D832CF21F965BE00C39001 /* SnapshotTests.swift in Sources */, 7A60354D2214DB2B000265EC /* DataSourceTests.swift in Sources */, 7A05C45B22C6B65D001AAD97 /* UICollectionViewMocks.swift in Sources */, diff --git a/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift b/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift index 8bbee08..8624745 100644 --- a/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift +++ b/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift @@ -12,7 +12,7 @@ public protocol WLEmptyStateDelegate: class { func emptyStateShouldScroll() -> Bool } -extension WLEmptyStateDelegate { +public extension WLEmptyStateDelegate { func emptyStateShouldScroll() -> Bool { return true From b0c86dd0eccfa72f5130722e4dbb0a6db5f89806 Mon Sep 17 00:00:00 2001 From: Jorge Ovalle Date: Thu, 1 Aug 2019 16:00:04 -0500 Subject: [PATCH 3/6] Fix changes after peers reviews --- .../UICollectionView+WLEmptyState.swift | 2 +- .../Extensions/UITableView+WLEmptyState.swift | 2 +- .../Classes/Views/EmptyStateView.swift | 26 ++++++++++++------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift b/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift index 5b0572d..c86dcfe 100644 --- a/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift +++ b/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift @@ -68,7 +68,7 @@ extension UICollectionView: WLEmptyStateProtocol { let datasource = self.emptyStateDataSource emptyStateView.titleLabel.attributedText = datasource?.titleForEmptyDataSet() emptyStateView.descriptionLabel.attributedText = datasource?.descriptionForEmptyDataSet() - emptyStateView.image.image = datasource?.imageForEmptyDataSet() + emptyStateView.image = datasource?.imageForEmptyDataSet() } else { emptyStateView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ diff --git a/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift b/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift index 7365ff3..185f8de 100644 --- a/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift +++ b/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift @@ -69,7 +69,7 @@ extension UITableView: WLEmptyStateProtocol { let datasource = self.emptyStateDataSource emptyStateView.titleLabel.attributedText = datasource?.titleForEmptyDataSet() emptyStateView.descriptionLabel.attributedText = datasource?.descriptionForEmptyDataSet() - emptyStateView.image.image = datasource?.imageForEmptyDataSet() + emptyStateView.image = datasource?.imageForEmptyDataSet() } else { emptyStateView.translatesAutoresizingMaskIntoConstraints = false NSLayoutConstraint.activate([ diff --git a/WLEmptyState/Classes/Views/EmptyStateView.swift b/WLEmptyState/Classes/Views/EmptyStateView.swift index 62bcb61..6c39df0 100644 --- a/WLEmptyState/Classes/Views/EmptyStateView.swift +++ b/WLEmptyState/Classes/Views/EmptyStateView.swift @@ -23,21 +23,21 @@ final class EmptyStateView: UIView { private lazy var imageContainer: UIView = { let view = UIView() - view.addSubview(image) + view.addSubview(imageView) NSLayoutConstraint.activate([ - image.widthAnchor.constraint(equalToConstant: 80), - image.heightAnchor.constraint(equalToConstant: 80), - image.centerYAnchor.constraint(equalTo: view.centerYAnchor), - image.centerXAnchor.constraint(equalTo: view.centerXAnchor), - view.heightAnchor.constraint(equalTo: image.heightAnchor)]) + imageView.widthAnchor.constraint(equalToConstant: 80), + imageView.heightAnchor.constraint(equalToConstant: 80), + imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor), + imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor), + view.heightAnchor.constraint(equalTo: imageView.heightAnchor)]) return view }() - lazy var image: UIImageView = { - let image = UIImageView() - image.translatesAutoresizingMaskIntoConstraints = false - return image + private lazy var imageView: UIImageView = { + let imageView = UIImageView() + imageView.translatesAutoresizingMaskIntoConstraints = false + return imageView }() lazy var titleLabel: UILabel = { @@ -66,6 +66,12 @@ final class EmptyStateView: UIView { return containerView }() + var image: UIImage? { + didSet { + self.imageView.image = image + } + } + override public init(frame: CGRect) { super.init(frame: frame) From aa2e5371b9dc8f58c36e276c165cebf0ef95d9d1 Mon Sep 17 00:00:00 2001 From: Jorge Ovalle Date: Thu, 1 Aug 2019 16:04:48 -0500 Subject: [PATCH 4/6] Add type to handle default values --- Example/Pods/Pods.xcodeproj/project.pbxproj | 26 ++++++++++--------- .../UICollectionView+WLEmptyState.swift | 2 +- .../Extensions/UITableView+WLEmptyState.swift | 2 +- .../Classes/Misc/DefaultConstants.swift | 14 ++++++++++ .../Protocols/WLEmptyStateDelegate.swift | 2 +- 5 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 WLEmptyState/Classes/Misc/DefaultConstants.swift diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index 23dcf79..6862632 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ 6E0AEAF7C58394086477F02041E3116C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7BD4ED544B638D07C7D755AF1C27116A /* Foundation.framework */; }; 787A205220AB808614F5D13D132EA149 /* WLEmptyState-dummy.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DA2CECB345AD9A51DE26C290648DD9B /* WLEmptyState-dummy.m */; }; 796D4CB4F4AB8ECBBD931B099A74E833 /* FBSnapshotTestController.h in Headers */ = {isa = PBXBuildFile; fileRef = 0BFB7DE40547F6148458C28227213A42 /* FBSnapshotTestController.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 7AC01BCC22F38AEB003BBC41 /* DefaultConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7AC01BCB22F38AEB003BBC41 /* DefaultConstants.swift */; }; 82CE8E0DC98452F08E1A03D3CA91B763 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8CAA89EEF1039078430D7A886477E365 /* UIKit.framework */; }; 86BC25FD2CC085B17A374500C747062D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 716A9972B9D9103B54DB950893FAF104 /* QuartzCore.framework */; }; 883DF5A93C5836247391BA4F4084F472 /* WLEmptyStateDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 46001DFE9B8BA55912C9A071359DF952 /* WLEmptyStateDelegate.swift */; }; @@ -91,10 +92,10 @@ 23928FDC0ED7C820AD9E342887E20F56 /* WLEmptyStateProtocol.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = WLEmptyStateProtocol.swift; sourceTree = ""; }; 23B54D55C8DCD0F868DA457E72A3A336 /* Pods-WLEmptyState_Tests-frameworks.sh */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.script.sh; path = "Pods-WLEmptyState_Tests-frameworks.sh"; sourceTree = ""; }; 265CD8C75ABD553AA7BAE08110CA91EB /* Pods-WLEmptyState_Tests-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-WLEmptyState_Tests-dummy.m"; sourceTree = ""; }; - 2B507FEF91037E69863AD9913B0F33E2 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; path = README.md; sourceTree = ""; }; - 2D5FA71EC26145ADE2EF5523A89194E8 /* WLEmptyState.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = WLEmptyState.framework; path = WLEmptyState.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 2B507FEF91037E69863AD9913B0F33E2 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; + 2D5FA71EC26145ADE2EF5523A89194E8 /* WLEmptyState.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = WLEmptyState.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2EE0D8468132004B33C282270003A158 /* UIImage+Diff.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "UIImage+Diff.h"; path = "FBSnapshotTestCase/Categories/UIImage+Diff.h"; sourceTree = ""; }; - 382E0631A928F9F897E7456B47A65AE4 /* WLEmptyState.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; lastKnownFileType = text; path = WLEmptyState.podspec; sourceTree = ""; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 382E0631A928F9F897E7456B47A65AE4 /* WLEmptyState.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; path = WLEmptyState.podspec; sourceTree = ""; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 3B465D0AA1B75B79D8358A10B22219A8 /* Logger.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = ""; }; 3BF0D8E3529AAF9DD2F8B3378FD89216 /* FBSnapshotTestCase.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = FBSnapshotTestCase.h; path = FBSnapshotTestCase/FBSnapshotTestCase.h; sourceTree = ""; }; 432D328D5B1788520371534F0EC9AA67 /* SwiftSupport.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; name = SwiftSupport.swift; path = FBSnapshotTestCase/SwiftSupport.swift; sourceTree = ""; }; @@ -110,14 +111,15 @@ 5B1BBF81351D3BE2C4B6DB647665080C /* WLEmptyState-prefix.pch */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "WLEmptyState-prefix.pch"; sourceTree = ""; }; 5E601BD54DA9BF4071437E60125281FA /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/System/Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 5FA455F4C1848537B65373E52124BE30 /* Pods-WLEmptyState_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-WLEmptyState_Tests.release.xcconfig"; sourceTree = ""; }; - 601281EDE1A9776D1DF9E51300A5CA12 /* Pods_WLEmptyState_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_WLEmptyState_Tests.framework; path = "Pods-WLEmptyState_Tests.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; + 601281EDE1A9776D1DF9E51300A5CA12 /* Pods_WLEmptyState_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WLEmptyState_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 61DF90569F26A389D41A44E0EB950F81 /* ResourceBundle-WLEmptyState-WLEmptyState-Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "ResourceBundle-WLEmptyState-WLEmptyState-Info.plist"; sourceTree = ""; }; 64860ED4D1469506201CA2ECB2F54AF9 /* iOSSnapshotTestCase-Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "iOSSnapshotTestCase-Info.plist"; sourceTree = ""; }; 651ECCFB431F822BACAFD37B79B23930 /* Pods-WLEmptyState_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-WLEmptyState_Tests.debug.xcconfig"; sourceTree = ""; }; - 661E5C00E4D54F4B1EE720D6CB0E051D /* Pods_WLEmptyState_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_WLEmptyState_Example.framework; path = "Pods-WLEmptyState_Example.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; + 661E5C00E4D54F4B1EE720D6CB0E051D /* Pods_WLEmptyState_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_WLEmptyState_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6B445E473011D84E70AA46BDEA57247C /* EmptyStateView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = EmptyStateView.swift; sourceTree = ""; }; 716A9972B9D9103B54DB950893FAF104 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/System/Library/Frameworks/QuartzCore.framework; sourceTree = DEVELOPER_DIR; }; 796F28118D863DD7DDE14D1F6AC3DC9C /* iOSSnapshotTestCase-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "iOSSnapshotTestCase-dummy.m"; sourceTree = ""; }; + 7AC01BCB22F38AEB003BBC41 /* DefaultConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultConstants.swift; sourceTree = ""; }; 7BD4ED544B638D07C7D755AF1C27116A /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; 7FCBCF80903B45DA453AB5DDE8D7A6C3 /* UICollectionView+WLEmptyState.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = "UICollectionView+WLEmptyState.swift"; sourceTree = ""; }; 829DB7B5216ADA72ACE785A166929149 /* WLEmptyStateDataSource.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = WLEmptyStateDataSource.swift; sourceTree = ""; }; @@ -126,12 +128,12 @@ 900C95C1DE73EA90A623D23D95C912B0 /* iOSSnapshotTestCase.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.module; path = iOSSnapshotTestCase.modulemap; sourceTree = ""; }; 91DD58AC853E63C9E7A077824B07C059 /* Pods-WLEmptyState_Tests-Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-WLEmptyState_Tests-Info.plist"; sourceTree = ""; }; 9692458AA4CCE1DF8581A004A1E43CC1 /* Pods-WLEmptyState_Tests-acknowledgements.markdown */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = "Pods-WLEmptyState_Tests-acknowledgements.markdown"; sourceTree = ""; }; - 9B1461BA0DDB214CC99F1297D0A9ABFB /* WLEmptyState.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; name = WLEmptyState.bundle; path = "WLEmptyState-WLEmptyState.bundle"; sourceTree = BUILT_PRODUCTS_DIR; }; - 9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 9B1461BA0DDB214CC99F1297D0A9ABFB /* WLEmptyState.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WLEmptyState.bundle; sourceTree = BUILT_PRODUCTS_DIR; }; + 9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; ADF27F24B8BF110336D77D1AAA7CE468 /* Pods-WLEmptyState_Tests-umbrella.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; path = "Pods-WLEmptyState_Tests-umbrella.h"; sourceTree = ""; }; B2993DACA98C9F02D8A0CB71FED08A89 /* Pods-WLEmptyState_Example.modulemap */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.module; path = "Pods-WLEmptyState_Example.modulemap"; sourceTree = ""; }; B75A47899E602A5CA9E833F7D136622D /* iOSSnapshotTestCase.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = iOSSnapshotTestCase.xcconfig; sourceTree = ""; }; - B91B00F8BE943329D633234BD67AE0AC /* FBSnapshotTestCase.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = FBSnapshotTestCase.framework; path = iOSSnapshotTestCase.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + B91B00F8BE943329D633234BD67AE0AC /* FBSnapshotTestCase.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FBSnapshotTestCase.framework; sourceTree = BUILT_PRODUCTS_DIR; }; BD3E11CFF525A7BE0F5090E39A8A725C /* FBSnapshotTestCasePlatform.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = FBSnapshotTestCasePlatform.m; path = FBSnapshotTestCase/FBSnapshotTestCasePlatform.m; sourceTree = ""; }; C6719E811186D49205511976434B9370 /* Pods-WLEmptyState_Example-dummy.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; path = "Pods-WLEmptyState_Example-dummy.m"; sourceTree = ""; }; C7AC36E62B80086F28116AF2A338F0CC /* WLEmptyState.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = WLEmptyState.xcconfig; sourceTree = ""; }; @@ -141,7 +143,7 @@ DA6A57F8C023A7771ABC124B0DD3C765 /* Pods-WLEmptyState_Example-Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "Pods-WLEmptyState_Example-Info.plist"; sourceTree = ""; }; DC37D45B91EAA34C1B307819F4FBFA48 /* FBSnapshotTestCasePlatform.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = FBSnapshotTestCasePlatform.h; path = FBSnapshotTestCase/FBSnapshotTestCasePlatform.h; sourceTree = ""; }; E65DA46D3D6E37CAF98E12ACB8E01391 /* Pods-WLEmptyState_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-WLEmptyState_Example.release.xcconfig"; sourceTree = ""; }; - E729756D8AB1430F9072D9F98FCC175E /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; path = LICENSE; sourceTree = ""; }; + E729756D8AB1430F9072D9F98FCC175E /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; path = LICENSE; sourceTree = ""; }; EB07CC184E97597B5EF96293FD8D6775 /* UIImage+Compare.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "UIImage+Compare.m"; path = "FBSnapshotTestCase/Categories/UIImage+Compare.m"; sourceTree = ""; }; EBD54FBC707C522306409616608E03F7 /* UIImage+Snapshot.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "UIImage+Snapshot.h"; path = "FBSnapshotTestCase/Categories/UIImage+Snapshot.h"; sourceTree = ""; }; ED5A6D3FA1DF67296DBD945B79B922CB /* Pods-WLEmptyState_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; path = "Pods-WLEmptyState_Example.debug.xcconfig"; sourceTree = ""; }; @@ -281,6 +283,7 @@ 3B465D0AA1B75B79D8358A10B22219A8 /* Logger.swift */, 49D79B4D6AF9A39F6775048CB486FC51 /* Swizzler.swift */, 4A20E8DA676A3BA117B2A2FC28DB81D4 /* WLEmptyState.swift */, + 7AC01BCB22F38AEB003BBC41 /* DefaultConstants.swift */, ); name = Misc; path = WLEmptyState/Classes/Misc; @@ -434,7 +437,6 @@ E8F185C38F4D0FECED758E1073BF7128 /* Support Files */, A222A9C1427FEE47EF8DE5C03195EBC3 /* SwiftSupport */, ); - name = iOSSnapshotTestCase; path = iOSSnapshotTestCase; sourceTree = ""; }; @@ -672,6 +674,7 @@ 2474524F7C71BF56DD6703DBE2B03807 /* UITableView+WLEmptyState.swift in Sources */, 787A205220AB808614F5D13D132EA149 /* WLEmptyState-dummy.m in Sources */, 29092836581744A4869CF30E4C2182C0 /* WLEmptyState.swift in Sources */, + 7AC01BCC22F38AEB003BBC41 /* DefaultConstants.swift in Sources */, 936BFBC785EE65333A5B52AE964CBFF4 /* WLEmptyStateDataSource.swift in Sources */, 883DF5A93C5836247391BA4F4084F472 /* WLEmptyStateDelegate.swift in Sources */, 49B000C28653390705DC788F5C6052F1 /* WLEmptyStateProtocol.swift in Sources */, @@ -1011,8 +1014,7 @@ MTL_FAST_MATH = YES; PRODUCT_NAME = "$(TARGET_NAME)"; STRIP_INSTALLED_PRODUCT = NO; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 5.0; SYMROOT = "${SRCROOT}/../build"; }; diff --git a/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift b/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift index c86dcfe..18a9f94 100644 --- a/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift +++ b/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift @@ -61,7 +61,7 @@ extension UICollectionView: WLEmptyStateProtocol { if numberOfItems == 0 && self.subviews.count > 1 { originalScrollingValue = isScrollEnabled - isScrollEnabled = emptyStateDelegate?.emptyStateShouldScroll() ?? true + isScrollEnabled = emptyStateDelegate?.emptyStateShouldScroll() ?? DefaultConstants.shouldScrollOnEmptyState backgroundView = emptyStateView if let emptyStateView = emptyStateView as? EmptyStateView { diff --git a/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift b/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift index 185f8de..641eb91 100644 --- a/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift +++ b/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift @@ -62,7 +62,7 @@ extension UITableView: WLEmptyStateProtocol { if numberOfItems == 0 && self.subviews.count > 1 { originalScrollingValue = isScrollEnabled - isScrollEnabled = emptyStateDelegate?.emptyStateShouldScroll() ?? true + isScrollEnabled = emptyStateDelegate?.emptyStateShouldScroll() ?? DefaultConstants.shouldScrollOnEmptyState addSubview(emptyStateView) if let emptyStateView = emptyStateView as? EmptyStateView { diff --git a/WLEmptyState/Classes/Misc/DefaultConstants.swift b/WLEmptyState/Classes/Misc/DefaultConstants.swift new file mode 100644 index 0000000..14751cf --- /dev/null +++ b/WLEmptyState/Classes/Misc/DefaultConstants.swift @@ -0,0 +1,14 @@ +// +// DefaultConstants.swift +// WLEmptyState +// +// Created by Jorge Ovalle on 8/1/19. +// + +import Foundation + +enum DefaultConstants { + + static let shouldScrollOnEmptyState: Bool = true + +} diff --git a/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift b/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift index 8624745..26ac5a7 100644 --- a/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift +++ b/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift @@ -15,7 +15,7 @@ public protocol WLEmptyStateDelegate: class { public extension WLEmptyStateDelegate { func emptyStateShouldScroll() -> Bool { - return true + return DefaultConstants.shouldScrollOnEmptyState } } From c6714fa9092dc0f599d8e186f420968c9357501c Mon Sep 17 00:00:00 2001 From: Jorge Ovalle Date: Thu, 1 Aug 2019 16:10:52 -0500 Subject: [PATCH 5/6] rename delegate function --- Example/Tests/DelegateTests.swift | 16 ++++++++-------- .../UICollectionView+WLEmptyState.swift | 2 +- .../Extensions/UITableView+WLEmptyState.swift | 2 +- WLEmptyState/Classes/Misc/DefaultConstants.swift | 2 +- .../Classes/Protocols/WLEmptyStateDelegate.swift | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Example/Tests/DelegateTests.swift b/Example/Tests/DelegateTests.swift index 1a614e2..c4e9993 100644 --- a/Example/Tests/DelegateTests.swift +++ b/Example/Tests/DelegateTests.swift @@ -19,30 +19,30 @@ class DelegateTests: XCTestCase { func testShouldScrollDelegatePropertyOnTableDefault() { let defaultTableViewController = DefaultTableViewController() - let shouldScrollTableView = defaultTableViewController.tableView.emptyStateDelegate?.emptyStateShouldScroll() - XCTAssertEqual(true, shouldScrollTableView) + let enableScrollForEmptyState = defaultTableViewController.tableView.emptyStateDelegate?.enableScrollForEmptyState() + XCTAssertEqual(true, enableScrollForEmptyState) } func testShouldScrollDelegatePropertyOnTableCustom() { let customTableViewController = CustomEmptyStateTableViewController() - let shouldScrollTableView = customTableViewController.tableView.emptyStateDelegate?.emptyStateShouldScroll() - XCTAssertEqual(false, shouldScrollTableView) + let enableScrollForEmptyState = customTableViewController.tableView.emptyStateDelegate?.enableScrollForEmptyState() + XCTAssertEqual(false, enableScrollForEmptyState) } // MARK: - UICollectionView func testShouldScrollDelegatePropertyOnCollectionDefault() { let defaultCollectionViewController = DefaultCollectionViewController(collectionViewLayout: UICollectionViewFlowLayout()) - let shouldScrollTableView = defaultCollectionViewController.collectionView.emptyStateDelegate?.emptyStateShouldScroll() - XCTAssertEqual(true, shouldScrollTableView) + let enableScrollForEmptyState = defaultCollectionViewController.collectionView.emptyStateDelegate?.enableScrollForEmptyState() + XCTAssertEqual(true, enableScrollForEmptyState) } func testShouldScrollDelegatePropertyOnCollectionCustom() { let customCollectionViewController = CustomCollectionViewController(collectionViewLayout: UICollectionViewFlowLayout()) - let shouldScrollTableView = customCollectionViewController.collectionView.emptyStateDelegate?.emptyStateShouldScroll() - XCTAssertEqual(false, shouldScrollTableView) + let enableScrollForEmptyState = customCollectionViewController.collectionView.emptyStateDelegate?.enableScrollForEmptyState() + XCTAssertEqual(false, enableScrollForEmptyState) } } diff --git a/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift b/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift index 18a9f94..cbf903a 100644 --- a/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift +++ b/WLEmptyState/Classes/Extensions/UICollectionView+WLEmptyState.swift @@ -61,7 +61,7 @@ extension UICollectionView: WLEmptyStateProtocol { if numberOfItems == 0 && self.subviews.count > 1 { originalScrollingValue = isScrollEnabled - isScrollEnabled = emptyStateDelegate?.emptyStateShouldScroll() ?? DefaultConstants.shouldScrollOnEmptyState + isScrollEnabled = emptyStateDelegate?.enableScrollForEmptyState() ?? DefaultConstants.enableScrollForEmptyState backgroundView = emptyStateView if let emptyStateView = emptyStateView as? EmptyStateView { diff --git a/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift b/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift index 641eb91..665ddab 100644 --- a/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift +++ b/WLEmptyState/Classes/Extensions/UITableView+WLEmptyState.swift @@ -62,7 +62,7 @@ extension UITableView: WLEmptyStateProtocol { if numberOfItems == 0 && self.subviews.count > 1 { originalScrollingValue = isScrollEnabled - isScrollEnabled = emptyStateDelegate?.emptyStateShouldScroll() ?? DefaultConstants.shouldScrollOnEmptyState + isScrollEnabled = emptyStateDelegate?.enableScrollForEmptyState() ?? DefaultConstants.enableScrollForEmptyState addSubview(emptyStateView) if let emptyStateView = emptyStateView as? EmptyStateView { diff --git a/WLEmptyState/Classes/Misc/DefaultConstants.swift b/WLEmptyState/Classes/Misc/DefaultConstants.swift index 14751cf..f5ea743 100644 --- a/WLEmptyState/Classes/Misc/DefaultConstants.swift +++ b/WLEmptyState/Classes/Misc/DefaultConstants.swift @@ -9,6 +9,6 @@ import Foundation enum DefaultConstants { - static let shouldScrollOnEmptyState: Bool = true + static let enableScrollForEmptyState: Bool = true } diff --git a/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift b/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift index 26ac5a7..996a462 100644 --- a/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift +++ b/WLEmptyState/Classes/Protocols/WLEmptyStateDelegate.swift @@ -9,13 +9,13 @@ import Foundation public protocol WLEmptyStateDelegate: class { - func emptyStateShouldScroll() -> Bool + func enableScrollForEmptyState() -> Bool } public extension WLEmptyStateDelegate { - func emptyStateShouldScroll() -> Bool { - return DefaultConstants.shouldScrollOnEmptyState + func enableScrollForEmptyState() -> Bool { + return DefaultConstants.enableScrollForEmptyState } } From e47fad3d8d40121095ab8b6c06f63af4834b7a7c Mon Sep 17 00:00:00 2001 From: Jorge Ovalle Date: Thu, 1 Aug 2019 17:27:39 -0500 Subject: [PATCH 6/6] Updated tests --- Example/Tests/UICollectionViewMocks.swift | 2 +- Example/Tests/UITableViewMocks.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/Tests/UICollectionViewMocks.swift b/Example/Tests/UICollectionViewMocks.swift index f235f09..9cd2a99 100644 --- a/Example/Tests/UICollectionViewMocks.swift +++ b/Example/Tests/UICollectionViewMocks.swift @@ -44,7 +44,7 @@ final class CustomCollectionViewController: UICollectionViewController, WLEmptyS return nil } - func emptyStateShouldScroll() -> Bool { + func enableScrollForEmptyState() -> Bool { return false } } diff --git a/Example/Tests/UITableViewMocks.swift b/Example/Tests/UITableViewMocks.swift index 72eb478..b69a585 100644 --- a/Example/Tests/UITableViewMocks.swift +++ b/Example/Tests/UITableViewMocks.swift @@ -61,7 +61,7 @@ final class CustomEmptyStateTableViewController: UITableViewController, WLEmptyS return view } - func emptyStateShouldScroll() -> Bool { + func enableScrollForEmptyState() -> Bool { return false }