From 68733e0d68e76efd3cc58b2e68a269aced0e5668 Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Thu, 12 Oct 2017 22:11:27 +0300 Subject: [PATCH 01/14] Add appearance protocol --- LeadKit.xcodeproj/project.pbxproj | 20 ++++++--- .../TableRow+AppearanceExtension.swift | 42 +++++++++++++++++++ ...ft => TableRow+SeparatorsExtensions.swift} | 0 Sources/Protocols/AppearanceProtocol.swift | 27 ++++++++++++ 4 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift rename Sources/Extensions/TableDirector/{TableRow+Extensions.swift => TableRow+SeparatorsExtensions.swift} (100%) create mode 100644 Sources/Protocols/AppearanceProtocol.swift diff --git a/LeadKit.xcodeproj/project.pbxproj b/LeadKit.xcodeproj/project.pbxproj index 214db442..4bd8ce12 100644 --- a/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit.xcodeproj/project.pbxproj @@ -10,6 +10,8 @@ 2D6A0E6105F4A9BF22BF4BB1 /* Pods_LeadKit_iOS_ExtensionsTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3C88ED8C9373F85C06697849 /* Pods_LeadKit_iOS_ExtensionsTests.framework */; }; 2D96F18874B9519F5AD74003 /* Pods_LeadKit_LeadKit_tvOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D0F8D0002B21A4F31981F1ED /* Pods_LeadKit_LeadKit_tvOS.framework */; }; 3614FEACB9E8313C87F7C393 /* Pods_LeadKit_tvOSTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4DB1CCAB1EAAACD3AC42C795 /* Pods_LeadKit_tvOSTests.framework */; }; + 40F118471F8FEF97004AADAF /* AppearanceProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F118461F8FEF97004AADAF /* AppearanceProtocol.swift */; }; + 40F118491F8FF223004AADAF /* TableRow+AppearanceExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40F118481F8FF223004AADAF /* TableRow+AppearanceExtension.swift */; }; 67051ADB1EBC7C36008EADC0 /* SpinnerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67051ADA1EBC7C36008EADC0 /* SpinnerView.swift */; }; 67051ADC1EBC7C36008EADC0 /* SpinnerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67051ADA1EBC7C36008EADC0 /* SpinnerView.swift */; }; 67051ADD1EBC7C36008EADC0 /* SpinnerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67051ADA1EBC7C36008EADC0 /* SpinnerView.swift */; }; @@ -384,8 +386,8 @@ 67E6C2371EBB32F5007842A6 /* SingleLoadCursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */; }; 67E6C2381EBB32F5007842A6 /* SingleLoadCursor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67E6C2341EBB32F5007842A6 /* SingleLoadCursor.swift */; }; 82F8BB181F5DDED100C1061B /* Single+DeferredJust.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F8BB171F5DDED100C1061B /* Single+DeferredJust.swift */; }; - A658E54D1F8CD7790093527A /* TableRow+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54C1F8CD7790093527A /* TableRow+Extensions.swift */; }; - A658E54E1F8CD7790093527A /* TableRow+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54C1F8CD7790093527A /* TableRow+Extensions.swift */; }; + A658E54D1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54C1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift */; }; + A658E54E1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54C1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift */; }; A658E5501F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54F1F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift */; }; A658E5511F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54F1F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift */; }; A6C9A4FA1F8BBCF2009311CC /* EmptyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */; }; @@ -468,6 +470,8 @@ 2BD6FE790236CFF8D2CD505E /* Pods-LeadKit-LeadKit iOS Extensions.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit-LeadKit iOS Extensions.release.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit-LeadKit iOS Extensions/Pods-LeadKit-LeadKit iOS Extensions.release.xcconfig"; sourceTree = ""; }; 381DF859FC4E26D499123014 /* Pods-LeadKit iOS ExtensionsTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit iOS ExtensionsTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit iOS ExtensionsTests/Pods-LeadKit iOS ExtensionsTests.release.xcconfig"; sourceTree = ""; }; 3C88ED8C9373F85C06697849 /* Pods_LeadKit_iOS_ExtensionsTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_iOS_ExtensionsTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 40F118461F8FEF97004AADAF /* AppearanceProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppearanceProtocol.swift; sourceTree = ""; }; + 40F118481F8FF223004AADAF /* TableRow+AppearanceExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TableRow+AppearanceExtension.swift"; sourceTree = ""; }; 4B8CD4D99A5B9CDB08308679 /* Pods-LeadKit-LeadKit iOS Extensions.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit-LeadKit iOS Extensions.debug.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit-LeadKit iOS Extensions/Pods-LeadKit-LeadKit iOS Extensions.debug.xcconfig"; sourceTree = ""; }; 4DB1CCAB1EAAACD3AC42C795 /* Pods_LeadKit_tvOSTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_tvOSTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 53B12E773F945234CCA9A7E9 /* Pods-LeadKit iOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit iOSTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit iOSTests/Pods-LeadKit iOSTests.release.xcconfig"; sourceTree = ""; }; @@ -600,7 +604,7 @@ 887F99C5326BD220C2811BD6 /* Pods_LeadKit_LeadKit_iOS_Extensions.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_LeadKit_iOS_Extensions.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 95E457F1241D136396FC2420 /* Pods_LeadKitTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKitTests.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9966FB938D114F79F71AE037 /* Pods-LeadKit-LeadKit iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit-LeadKit iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit-LeadKit iOS/Pods-LeadKit-LeadKit iOS.release.xcconfig"; sourceTree = ""; }; - A658E54C1F8CD7790093527A /* TableRow+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TableRow+Extensions.swift"; sourceTree = ""; }; + A658E54C1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TableRow+SeparatorsExtensions.swift"; sourceTree = ""; }; A658E54F1F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+SeparatorRowBoxExtensions.swift"; sourceTree = ""; }; A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCellViewModel.swift; sourceTree = ""; }; A66428A61F8A653600C6308D /* SeparatorCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCell.swift; sourceTree = ""; }; @@ -945,7 +949,8 @@ isa = PBXGroup; children = ( 671462011EB3396E00EAB194 /* TableDirector+Extensions.swift */, - A658E54C1F8CD7790093527A /* TableRow+Extensions.swift */, + A658E54C1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift */, + 40F118481F8FF223004AADAF /* TableRow+AppearanceExtension.swift */, ); path = TableDirector; sourceTree = ""; @@ -1072,6 +1077,7 @@ 671462321EB3396E00EAB194 /* ViewHeightProtocol.swift */, 671462331EB3396E00EAB194 /* ViewModelProtocol.swift */, 671462341EB3396E00EAB194 /* XibNameProtocol.swift */, + 40F118461F8FEF97004AADAF /* AppearanceProtocol.swift */, ); path = Protocols; sourceTree = ""; @@ -2122,7 +2128,7 @@ 671462D01EB3396E00EAB194 /* UIScrollView+Support.swift in Sources */, 671463901EB3396E00EAB194 /* TemplateDrawingOperation.swift in Sources */, 6714630C1EB3396E00EAB194 /* UIViewController+DefaultStoryboardIdentifier.swift in Sources */, - A658E54D1F8CD7790093527A /* TableRow+Extensions.swift in Sources */, + A658E54D1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift in Sources */, 671462981EB3396E00EAB194 /* CGSize+Resize.swift in Sources */, 671462F81EB3396E00EAB194 /* UIView+DefaultReuseIdentifier.swift in Sources */, 67051ADB1EBC7C36008EADC0 /* SpinnerView.swift in Sources */, @@ -2153,6 +2159,7 @@ A6C9A4FB1F8BBCF2009311CC /* EmptyCellViewModel.swift in Sources */, 671463041EB3396E00EAB194 /* UIView+LoadingIndicator.swift in Sources */, EFBE57D61EC3603E0040E00A /* UIAlertController+Extensions.swift in Sources */, + 40F118491F8FF223004AADAF /* TableRow+AppearanceExtension.swift in Sources */, 671463701EB3396E00EAB194 /* ApiRequestParameters.swift in Sources */, A658E5501F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */, 671462EC1EB3396E00EAB194 /* UIImage+Extensions.swift in Sources */, @@ -2186,6 +2193,7 @@ 671463741EB3396E00EAB194 /* BorderDrawingOperation.swift in Sources */, 6714633C1EB3396E00EAB194 /* LoadingIndicator.swift in Sources */, 67E6C2351EBB32F5007842A6 /* SingleLoadCursor.swift in Sources */, + 40F118471F8FEF97004AADAF /* AppearanceProtocol.swift in Sources */, 671463181EB3396E00EAB194 /* UIWindow+Extensions.swift in Sources */, 671462541EB3396E00EAB194 /* App.swift in Sources */, 6714635C1EB3396E00EAB194 /* StoryboardProtocol.swift in Sources */, @@ -2218,7 +2226,7 @@ A6C9A50E1F8BC799009311CC /* EmptyCellRow.swift in Sources */, A6C9A50C1F8BC799009311CC /* EmptyCell.swift in Sources */, 671463B81EB34B1E00EAB194 /* StubCursor.swift in Sources */, - A658E54E1F8CD7790093527A /* TableRow+Extensions.swift in Sources */, + A658E54E1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift in Sources */, A6E0DDE41F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */, A658E5511F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */, 671463BB1EB34B1E00EAB194 /* CursorTests.swift in Sources */, diff --git a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift new file mode 100644 index 00000000..61da42e3 --- /dev/null +++ b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift @@ -0,0 +1,42 @@ +// +// Copyright (c) 2017 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the Software), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +import TableKit + +fileprivate let updateAppearanceActionId = "TableRowUpdateAppearanceActionId" + +public extension TableRow where CellType: AppearanceProtocol { + + func with(appearance: CellType.Appearance) -> Self { + removeAction(forActionId: updateAppearanceActionId) + + let action = TableRowAction(.configure) { options in + options.cell?.update(appearance: appearance) + } + + action.id = updateAppearanceActionId + on(action) + + return self + } + +} diff --git a/Sources/Extensions/TableDirector/TableRow+Extensions.swift b/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift similarity index 100% rename from Sources/Extensions/TableDirector/TableRow+Extensions.swift rename to Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift diff --git a/Sources/Protocols/AppearanceProtocol.swift b/Sources/Protocols/AppearanceProtocol.swift new file mode 100644 index 00000000..a9f1542c --- /dev/null +++ b/Sources/Protocols/AppearanceProtocol.swift @@ -0,0 +1,27 @@ +// +// Copyright (c) 2017 Touch Instinct +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// + +public protocol AppearanceProtocol { + associatedtype Appearance + + func update(appearance: Appearance) +} From 26ebaa48e958017225bcb2838f2f5197bd1fa54f Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Thu, 12 Oct 2017 23:12:09 +0300 Subject: [PATCH 02/14] Separator cell refactoring --- LeadKit.xcodeproj/project.pbxproj | 18 ++--- .../Classes/Views/EmptyCell/EmptyCell.swift | 25 +++++-- ...wModel.swift => EmptyCellAppearance.swift} | 13 ++-- .../Views/EmptyCell/EmptyCellRow.swift | 12 ++-- .../Views/SeparatorCell/SeparatorCell.swift | 48 ++++++++----- .../SeparatorCellViewModel.swift | 68 ------------------- .../SeparatorRowBox/SeparatorRowBox.swift | 16 +++-- .../Array+SeparatorRowBoxExtensions.swift | 8 +-- .../TableRow+SeparatorsExtensions.swift | 20 ++++-- 9 files changed, 96 insertions(+), 132 deletions(-) rename Sources/Classes/Views/EmptyCell/{EmptyCellViewModel.swift => EmptyCellAppearance.swift} (78%) delete mode 100644 Sources/Classes/Views/SeparatorCell/SeparatorCellViewModel.swift diff --git a/LeadKit.xcodeproj/project.pbxproj b/LeadKit.xcodeproj/project.pbxproj index 4bd8ce12..845f5e82 100644 --- a/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit.xcodeproj/project.pbxproj @@ -391,11 +391,11 @@ A658E5501F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54F1F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift */; }; A658E5511F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54F1F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift */; }; A6C9A4FA1F8BBCF2009311CC /* EmptyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */; }; - A6C9A4FB1F8BBCF2009311CC /* EmptyCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B361F8B956E00CDB971 /* EmptyCellViewModel.swift */; }; + A6C9A4FB1F8BBCF2009311CC /* EmptyCellAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B361F8B956E00CDB971 /* EmptyCellAppearance.swift */; }; A6C9A5041F8BC78F009311CC /* CellSeparatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */; }; A6C9A5051F8BC78F009311CC /* SeparatorConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDF01F8A6C80002CA74E /* SeparatorConfiguration.swift */; }; A6C9A50C1F8BC799009311CC /* EmptyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */; }; - A6C9A50D1F8BC799009311CC /* EmptyCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B361F8B956E00CDB971 /* EmptyCellViewModel.swift */; }; + A6C9A50D1F8BC799009311CC /* EmptyCellAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B361F8B956E00CDB971 /* EmptyCellAppearance.swift */; }; A6C9A50E1F8BC799009311CC /* EmptyCellRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A71F8A654600C6308D /* EmptyCellRow.swift */; }; A6C9A50F1F8BC79D009311CC /* Comparable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */; }; A6C9A5101F8BC79D009311CC /* Comparable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */; }; @@ -403,10 +403,8 @@ A6D10EAB1F8A9278003E69DD /* Comparable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */; }; A6E0DDDE1F8A696F002CA74E /* EmptyCellRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A71F8A654600C6308D /* EmptyCellRow.swift */; }; A6E0DDDF1F8A696F002CA74E /* SeparatorCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A61F8A653600C6308D /* SeparatorCell.swift */; }; - A6E0DDE01F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */; }; A6E0DDE11F8A696F002CA74E /* SeparatorRowBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* SeparatorRowBox.swift */; }; A6E0DDE31F8A696F002CA74E /* SeparatorCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A61F8A653600C6308D /* SeparatorCell.swift */; }; - A6E0DDE41F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */; }; A6E0DDE51F8A696F002CA74E /* SeparatorRowBox.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A81F8A655600C6308D /* SeparatorRowBox.swift */; }; A6E0DDEF1F8A6C57002CA74E /* CellSeparatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */; }; A6E0DDF11F8A6C80002CA74E /* SeparatorConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDF01F8A6C80002CA74E /* SeparatorConfiguration.swift */; }; @@ -606,11 +604,10 @@ 9966FB938D114F79F71AE037 /* Pods-LeadKit-LeadKit iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-LeadKit-LeadKit iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-LeadKit-LeadKit iOS/Pods-LeadKit-LeadKit iOS.release.xcconfig"; sourceTree = ""; }; A658E54C1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TableRow+SeparatorsExtensions.swift"; sourceTree = ""; }; A658E54F1F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+SeparatorRowBoxExtensions.swift"; sourceTree = ""; }; - A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCellViewModel.swift; sourceTree = ""; }; A66428A61F8A653600C6308D /* SeparatorCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCell.swift; sourceTree = ""; }; A66428A71F8A654600C6308D /* EmptyCellRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellRow.swift; sourceTree = ""; }; A66428A81F8A655600C6308D /* SeparatorRowBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorRowBox.swift; sourceTree = ""; }; - A6AF3B361F8B956E00CDB971 /* EmptyCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellViewModel.swift; sourceTree = ""; }; + A6AF3B361F8B956E00CDB971 /* EmptyCellAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellAppearance.swift; sourceTree = ""; }; A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCell.swift; sourceTree = ""; }; A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Comparable+Extensions.swift"; sourceTree = ""; }; A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellSeparatorType.swift; sourceTree = ""; }; @@ -1272,7 +1269,6 @@ isa = PBXGroup; children = ( A66428A61F8A653600C6308D /* SeparatorCell.swift */, - A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */, A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */, A6E0DDF01F8A6C80002CA74E /* SeparatorConfiguration.swift */, ); @@ -1291,7 +1287,7 @@ isa = PBXGroup; children = ( A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */, - A6AF3B361F8B956E00CDB971 /* EmptyCellViewModel.swift */, + A6AF3B361F8B956E00CDB971 /* EmptyCellAppearance.swift */, A66428A71F8A654600C6308D /* EmptyCellRow.swift */, ); path = EmptyCell; @@ -2156,7 +2152,7 @@ 671462781EB3396E00EAB194 /* ResizeContentMode.swift in Sources */, A6E0DDE11F8A696F002CA74E /* SeparatorRowBox.swift in Sources */, A6E0DDDE1F8A696F002CA74E /* EmptyCellRow.swift in Sources */, - A6C9A4FB1F8BBCF2009311CC /* EmptyCellViewModel.swift in Sources */, + A6C9A4FB1F8BBCF2009311CC /* EmptyCellAppearance.swift in Sources */, 671463041EB3396E00EAB194 /* UIView+LoadingIndicator.swift in Sources */, EFBE57D61EC3603E0040E00A /* UIAlertController+Extensions.swift in Sources */, 40F118491F8FF223004AADAF /* TableRow+AppearanceExtension.swift in Sources */, @@ -2185,7 +2181,6 @@ A6F32C081F6EBDAA00AC08EE /* String+LocalizedComponent.swift in Sources */, 671462881EB3396E00EAB194 /* CGFloat+Pixels.swift in Sources */, 671462941EB3396E00EAB194 /* CGSize+CGContextSize.swift in Sources */, - A6E0DDE01F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */, 671463641EB3396E00EAB194 /* ViewHeightProtocol.swift in Sources */, 671462481EB3396E00EAB194 /* FixedPageCursor.swift in Sources */, 671462C81EB3396E00EAB194 /* String+Localization.swift in Sources */, @@ -2220,14 +2215,13 @@ buildActionMask = 2147483647; files = ( A6C9A5051F8BC78F009311CC /* SeparatorConfiguration.swift in Sources */, - A6C9A50D1F8BC799009311CC /* EmptyCellViewModel.swift in Sources */, + A6C9A50D1F8BC799009311CC /* EmptyCellAppearance.swift in Sources */, 671463CA1EB34B1E00EAB194 /* TestView.swift in Sources */, 671463C71EB34B1E00EAB194 /* PaginationViewModelTests.swift in Sources */, A6C9A50E1F8BC799009311CC /* EmptyCellRow.swift in Sources */, A6C9A50C1F8BC799009311CC /* EmptyCell.swift in Sources */, 671463B81EB34B1E00EAB194 /* StubCursor.swift in Sources */, A658E54E1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift in Sources */, - A6E0DDE41F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */, A658E5511F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */, 671463BB1EB34B1E00EAB194 /* CursorTests.swift in Sources */, A6F32C101F6EBE9600AC08EE /* StringExtensionTests.swift in Sources */, diff --git a/Sources/Classes/Views/EmptyCell/EmptyCell.swift b/Sources/Classes/Views/EmptyCell/EmptyCell.swift index b140c792..337ca829 100644 --- a/Sources/Classes/Views/EmptyCell/EmptyCell.swift +++ b/Sources/Classes/Views/EmptyCell/EmptyCell.swift @@ -25,14 +25,25 @@ import TableKit /// Empty cell class. Do not use it directly. /// - see: `EmptyCellRow` -public final class EmptyCell: SeparatorCell, ConfigurableCell { +public final class EmptyCell: SeparatorCell, AppearanceProtocol, ConfigurableCell { + public override init(style: UITableViewCellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) - public func configure(with viewModel: EmptyCellViewModel) { - backgroundColor = .clear - contentView.backgroundColor = viewModel.color - selectionStyle = .none - - configureSeparator(with: viewModel) + setup() } + public required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + public func update(appearance: EmptyCellAppearance) { + contentView.backgroundColor = appearance.color + } + + public func configure(with _: Void) { } + + private func setup() { + backgroundColor = .clear + selectionStyle = .none + } } diff --git a/Sources/Classes/Views/EmptyCell/EmptyCellViewModel.swift b/Sources/Classes/Views/EmptyCell/EmptyCellAppearance.swift similarity index 78% rename from Sources/Classes/Views/EmptyCell/EmptyCellViewModel.swift rename to Sources/Classes/Views/EmptyCell/EmptyCellAppearance.swift index 1c7d7281..0c432aa6 100644 --- a/Sources/Classes/Views/EmptyCell/EmptyCellViewModel.swift +++ b/Sources/Classes/Views/EmptyCell/EmptyCellAppearance.swift @@ -22,18 +22,15 @@ import UIKit -/// ViewModel for EmptyCell -public final class EmptyCellViewModel: SeparatorCellViewModel { +/// Appearance for EmptyCell +public final class EmptyCellAppearance { let color: UIColor - let height: CGFloat - /// Returns configured ViewModel for cell - /// - parameter height: Height of cell + /// Returns configured appearance for cell /// - parameter color: Fill color of cell - /// - returns: Configured ViewModel - public init(height: CGFloat, color: UIColor = .clear) { + /// - returns: Configured appearance + public init(color: UIColor = .clear) { self.color = color - self.height = height } } diff --git a/Sources/Classes/Views/EmptyCell/EmptyCellRow.swift b/Sources/Classes/Views/EmptyCell/EmptyCellRow.swift index d306bfee..f7393849 100644 --- a/Sources/Classes/Views/EmptyCell/EmptyCellRow.swift +++ b/Sources/Classes/Views/EmptyCell/EmptyCellRow.swift @@ -26,17 +26,19 @@ import TableKit /// - Simulates spacing with no-breaking constraints /// - Can end editing on click public final class EmptyCellRow: TableRow { + private let rowHeight: CGFloat /// Provide height with color to create row /// - parameter height: Height of row /// - parameter color: Color of row /// - parameter endEditingOnClick: Will cell end editing for neighbour currently active UIControl subclasses /// - returns: Fully configured EmptyCellRow - public convenience init(height: CGFloat, - color: UIColor = .clear, - endEditingOnClick: Bool = false) { + public init(height: CGFloat, + color: UIColor = .clear, + endEditingOnClick: Bool = false) { + rowHeight = height - self.init(item: EmptyCellViewModel(height: height, color: color)) + super.init(item: ()) if endEditingOnClick { self.on(.click) { options in @@ -47,7 +49,7 @@ public final class EmptyCellRow: TableRow { /// Used for set custom height to each cell, not for each cell type override public var defaultHeight: CGFloat? { - return item.height + return rowHeight } } diff --git a/Sources/Classes/Views/SeparatorCell/SeparatorCell.swift b/Sources/Classes/Views/SeparatorCell/SeparatorCell.swift index 918713e1..faf4f647 100644 --- a/Sources/Classes/Views/SeparatorCell/SeparatorCell.swift +++ b/Sources/Classes/Views/SeparatorCell/SeparatorCell.swift @@ -37,9 +37,26 @@ open class SeparatorCell: UITableViewCell { // MARK: - Public /// Configure separator with viewModel - /// - parameter viewModel: ViewModel of cell, that inherits from BaseCellViewModel - public func configureSeparator(with viewModel: SeparatorCellViewModel) { - configureInterface(with: viewModel) + /// - parameter separatorType: type of separators + public func configureSeparator(with separatorType: CellSeparatorType) { + switch separatorType { + case .none: + topView.isHidden = true + bottomView.isHidden = true + case .bottom(let configuration): + topView.isHidden = true + bottomView.isHidden = false + updateBottomSeparator(with: configuration) + case .top(let configuration): + topView.isHidden = false + bottomView.isHidden = true + updateTopSeparator(with: configuration) + case .full(let topConfiguration, let bottomConfiguration): + topView.isHidden = false + bottomView.isHidden = false + updateTopSeparator(with: topConfiguration) + updateBottomSeparator(with: bottomConfiguration) + } } /// Move separator upward in hierarchy @@ -107,19 +124,6 @@ open class SeparatorCell: UITableViewCell { // MARK: - Private - private func configureInterface(with viewModel: SeparatorCellViewModel) { - topView.isHidden = viewModel.separatorType.topIsHidden - bottomView.isHidden = viewModel.separatorType.bottomIsHidden - - topView.backgroundColor = viewModel.topSeparatorConfiguration?.color - topSeparatorHeight = viewModel.topSeparatorConfiguration?.height ?? Constants.defaultSeparatorHeight - topSeparatorInsets = viewModel.topSeparatorConfiguration?.insets ?? .zero - - bottomView.backgroundColor = viewModel.bottomSeparatorConfiguration?.color - bottomSeparatorHeight = viewModel.bottomSeparatorConfiguration?.height ?? Constants.defaultSeparatorHeight - bottomSeparatorInsets = viewModel.bottomSeparatorConfiguration?.insets ?? .zero - } - private func configureLineViews() { topView = createSeparatorView() bottomView = createSeparatorView() @@ -136,6 +140,18 @@ open class SeparatorCell: UITableViewCell { return view } + private func updateTopSeparator(with configuration: SeparatorConfiguration) { + topView.backgroundColor = configuration.color + topSeparatorHeight = configuration.height + topSeparatorInsets = configuration.insets ?? .zero + } + + private func updateBottomSeparator(with configuration: SeparatorConfiguration) { + bottomView.backgroundColor = configuration.color + bottomSeparatorHeight = configuration.height + bottomSeparatorInsets = configuration.insets ?? .zero + } + private func createConstraints() { // height topViewHeightConstraint = topView.heightAnchor.constraint(equalToConstant: topSeparatorHeight) diff --git a/Sources/Classes/Views/SeparatorCell/SeparatorCellViewModel.swift b/Sources/Classes/Views/SeparatorCell/SeparatorCellViewModel.swift deleted file mode 100644 index 1fac48ec..00000000 --- a/Sources/Classes/Views/SeparatorCell/SeparatorCellViewModel.swift +++ /dev/null @@ -1,68 +0,0 @@ -// -// Copyright (c) 2017 Touch Instinct -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the Software), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -import UIKit - -/// By default this class does not provide any separators -open class SeparatorCellViewModel { - - internal var separatorType = CellSeparatorType.none - - /// Configuration for topSeparator - /// - Important: Bottom dimension is ignored - internal var topSeparatorConfiguration: SeparatorConfiguration? - - /// Configuration for topSeparator - /// - Important: Top dimension is ignored - internal var bottomSeparatorConfiguration: SeparatorConfiguration? - - public init() {} - -} - -public extension SeparatorCellViewModel { - - func with(separatorType: CellSeparatorType) -> Self { - set(separatorType: separatorType) - return self - } - - func set(separatorType: CellSeparatorType) { - self.separatorType = separatorType - - switch separatorType { - case .top(let configuration): - topSeparatorConfiguration = configuration - bottomSeparatorConfiguration = nil - case .bottom(let configuration): - topSeparatorConfiguration = nil - bottomSeparatorConfiguration = configuration - case .full(let top, let bottom): - topSeparatorConfiguration = top - bottomSeparatorConfiguration = bottom - case .none: - topSeparatorConfiguration = nil - bottomSeparatorConfiguration = nil - } - } - -} diff --git a/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift b/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift index 06133398..f87ca389 100644 --- a/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift +++ b/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift @@ -25,17 +25,19 @@ import TableKit /// Class that used to configure separators when multiply cells presented in one section /// Holds TableRow with any model inherited from BaseCellViewModel public final class SeparatorRowBox { - /// Row `item`, that typed as BaseCellViewModel - public let viewModel: SeparatorCellViewModel + private let setSeparatorHandler: (CellSeparatorType) -> Void + + public func set(separatorType: CellSeparatorType) { + setSeparatorHandler(separatorType) + } - /// TableRow that typed to generic Row public let row: Row /// Initialize AnyBaseTableRow with tableRow - /// - parameter tableRow: TableRow which `item` conforms to BaseCellViewModel - public init(tableRow: TableRow) where T: SeparatorCell, T.T: SeparatorCellViewModel { - row = tableRow - viewModel = tableRow.item + /// - parameter row: TableRow which `cell` conforms to SeparatorCell + public init(row: TableRow) where T: SeparatorCell { + self.row = row + setSeparatorHandler = row.set } } diff --git a/Sources/Extensions/Array/Array+SeparatorRowBoxExtensions.swift b/Sources/Extensions/Array/Array+SeparatorRowBoxExtensions.swift index 94be5eea..b87c2402 100644 --- a/Sources/Extensions/Array/Array+SeparatorRowBoxExtensions.swift +++ b/Sources/Extensions/Array/Array+SeparatorRowBoxExtensions.swift @@ -41,11 +41,11 @@ public extension Array where Element == SeparatorRowBox { switch count { case 1: - first?.viewModel.set(separatorType: .full(extremeSeparatorConfiguration, extremeSeparatorConfiguration)) + first?.set(separatorType: .full(extremeSeparatorConfiguration, extremeSeparatorConfiguration)) default: - forEach { $0.viewModel.set(separatorType: .full(middleSeparatorConfiguration, middleSeparatorConfiguration))} - first?.viewModel.set(separatorType: .top(extremeSeparatorConfiguration)) - last?.viewModel.set(separatorType: .bottom(extremeSeparatorConfiguration)) + forEach { $0.set(separatorType: .full(middleSeparatorConfiguration, middleSeparatorConfiguration))} + first?.set(separatorType: .top(extremeSeparatorConfiguration)) + last?.set(separatorType: .bottom(extremeSeparatorConfiguration)) } } diff --git a/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift b/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift index 9b8db3d5..4108b165 100644 --- a/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift +++ b/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift @@ -22,24 +22,34 @@ import TableKit -public extension TableRow where CellType.T: SeparatorCellViewModel { +fileprivate let configureSeparatorActionId = "TableRowConfigureSeparatorActionId" + +public extension TableRow where CellType: SeparatorCell { func with(separatorType: CellSeparatorType) -> Self { - item.set(separatorType: separatorType) + removeAction(forActionId: configureSeparatorActionId) + + let action = TableRowAction(.configure) { options in + options.cell?.configureSeparator(with: separatorType) + } + + action.id = configureSeparatorActionId + on(action) + return self } func set(separatorType: CellSeparatorType) { - item.set(separatorType: separatorType) + _ = with(separatorType: separatorType) } } -public extension TableRow where CellType: SeparatorCell, CellType.T: SeparatorCellViewModel { +public extension TableRow where CellType: SeparatorCell { /// TableRow typed as SeparatorRowBox var separatorRowBox: SeparatorRowBox { - return SeparatorRowBox(tableRow: self) + return SeparatorRowBox(row: self) } } From fa2838bb9cab5adb22fb3ac2d8dd4a6befcc8cb8 Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Thu, 12 Oct 2017 23:18:51 +0300 Subject: [PATCH 03/14] Add set(appearance:) method to TableRow --- .../TableDirector/TableRow+AppearanceExtension.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift index 61da42e3..60a05177 100644 --- a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift +++ b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift @@ -39,4 +39,8 @@ public extension TableRow where CellType: AppearanceProtocol { return self } + func set(appearance: CellType.Appearance) { + _ = with(appearance: appearance) + } + } From 1ba179028e721d4566cd15944e15eb1043f19b47 Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 13:51:51 +0300 Subject: [PATCH 04/14] Rename AppearanceProtocol update(appearance:) method to configure(appearance:) --- Sources/Classes/Views/EmptyCell/EmptyCell.swift | 2 +- .../Extensions/TableDirector/TableRow+AppearanceExtension.swift | 2 +- Sources/Protocols/AppearanceProtocol.swift | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/Classes/Views/EmptyCell/EmptyCell.swift b/Sources/Classes/Views/EmptyCell/EmptyCell.swift index 337ca829..ade58937 100644 --- a/Sources/Classes/Views/EmptyCell/EmptyCell.swift +++ b/Sources/Classes/Views/EmptyCell/EmptyCell.swift @@ -36,7 +36,7 @@ public final class EmptyCell: SeparatorCell, AppearanceProtocol, ConfigurableCel fatalError("init(coder:) has not been implemented") } - public func update(appearance: EmptyCellAppearance) { + public func configure(appearance: EmptyCellAppearance) { contentView.backgroundColor = appearance.color } diff --git a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift index 60a05177..715c34de 100644 --- a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift +++ b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift @@ -30,7 +30,7 @@ public extension TableRow where CellType: AppearanceProtocol { removeAction(forActionId: updateAppearanceActionId) let action = TableRowAction(.configure) { options in - options.cell?.update(appearance: appearance) + options.cell?.configure(appearance: appearance) } action.id = updateAppearanceActionId diff --git a/Sources/Protocols/AppearanceProtocol.swift b/Sources/Protocols/AppearanceProtocol.swift index a9f1542c..a974f5c0 100644 --- a/Sources/Protocols/AppearanceProtocol.swift +++ b/Sources/Protocols/AppearanceProtocol.swift @@ -23,5 +23,5 @@ public protocol AppearanceProtocol { associatedtype Appearance - func update(appearance: Appearance) + func configure(appearance: Appearance) } From f7868ad827ad61b81ea133dd15c8fe7d76e877fd Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 13:56:36 +0300 Subject: [PATCH 05/14] Move EmptyCellAppearance to EmptyCell --- LeadKit.xcodeproj/project.pbxproj | 6 ---- .../Classes/Views/EmptyCell/EmptyCell.swift | 10 +++++- .../Views/EmptyCell/EmptyCellAppearance.swift | 36 ------------------- 3 files changed, 9 insertions(+), 43 deletions(-) delete mode 100644 Sources/Classes/Views/EmptyCell/EmptyCellAppearance.swift diff --git a/LeadKit.xcodeproj/project.pbxproj b/LeadKit.xcodeproj/project.pbxproj index 845f5e82..e1cf4873 100644 --- a/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit.xcodeproj/project.pbxproj @@ -391,11 +391,9 @@ A658E5501F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54F1F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift */; }; A658E5511F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A658E54F1F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift */; }; A6C9A4FA1F8BBCF2009311CC /* EmptyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */; }; - A6C9A4FB1F8BBCF2009311CC /* EmptyCellAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B361F8B956E00CDB971 /* EmptyCellAppearance.swift */; }; A6C9A5041F8BC78F009311CC /* CellSeparatorType.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */; }; A6C9A5051F8BC78F009311CC /* SeparatorConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6E0DDF01F8A6C80002CA74E /* SeparatorConfiguration.swift */; }; A6C9A50C1F8BC799009311CC /* EmptyCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */; }; - A6C9A50D1F8BC799009311CC /* EmptyCellAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B361F8B956E00CDB971 /* EmptyCellAppearance.swift */; }; A6C9A50E1F8BC799009311CC /* EmptyCellRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A66428A71F8A654600C6308D /* EmptyCellRow.swift */; }; A6C9A50F1F8BC79D009311CC /* Comparable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */; }; A6C9A5101F8BC79D009311CC /* Comparable+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */; }; @@ -607,7 +605,6 @@ A66428A61F8A653600C6308D /* SeparatorCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCell.swift; sourceTree = ""; }; A66428A71F8A654600C6308D /* EmptyCellRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellRow.swift; sourceTree = ""; }; A66428A81F8A655600C6308D /* SeparatorRowBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorRowBox.swift; sourceTree = ""; }; - A6AF3B361F8B956E00CDB971 /* EmptyCellAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellAppearance.swift; sourceTree = ""; }; A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCell.swift; sourceTree = ""; }; A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Comparable+Extensions.swift"; sourceTree = ""; }; A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellSeparatorType.swift; sourceTree = ""; }; @@ -1287,7 +1284,6 @@ isa = PBXGroup; children = ( A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */, - A6AF3B361F8B956E00CDB971 /* EmptyCellAppearance.swift */, A66428A71F8A654600C6308D /* EmptyCellRow.swift */, ); path = EmptyCell; @@ -2152,7 +2148,6 @@ 671462781EB3396E00EAB194 /* ResizeContentMode.swift in Sources */, A6E0DDE11F8A696F002CA74E /* SeparatorRowBox.swift in Sources */, A6E0DDDE1F8A696F002CA74E /* EmptyCellRow.swift in Sources */, - A6C9A4FB1F8BBCF2009311CC /* EmptyCellAppearance.swift in Sources */, 671463041EB3396E00EAB194 /* UIView+LoadingIndicator.swift in Sources */, EFBE57D61EC3603E0040E00A /* UIAlertController+Extensions.swift in Sources */, 40F118491F8FF223004AADAF /* TableRow+AppearanceExtension.swift in Sources */, @@ -2215,7 +2210,6 @@ buildActionMask = 2147483647; files = ( A6C9A5051F8BC78F009311CC /* SeparatorConfiguration.swift in Sources */, - A6C9A50D1F8BC799009311CC /* EmptyCellAppearance.swift in Sources */, 671463CA1EB34B1E00EAB194 /* TestView.swift in Sources */, 671463C71EB34B1E00EAB194 /* PaginationViewModelTests.swift in Sources */, A6C9A50E1F8BC799009311CC /* EmptyCellRow.swift in Sources */, diff --git a/Sources/Classes/Views/EmptyCell/EmptyCell.swift b/Sources/Classes/Views/EmptyCell/EmptyCell.swift index ade58937..1d6bae33 100644 --- a/Sources/Classes/Views/EmptyCell/EmptyCell.swift +++ b/Sources/Classes/Views/EmptyCell/EmptyCell.swift @@ -26,6 +26,14 @@ import TableKit /// Empty cell class. Do not use it directly. /// - see: `EmptyCellRow` public final class EmptyCell: SeparatorCell, AppearanceProtocol, ConfigurableCell { + public struct Appearance { + let color: UIColor + + public init(color: UIColor = .clear) { + self.color = color + } + } + public override init(style: UITableViewCellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) @@ -36,7 +44,7 @@ public final class EmptyCell: SeparatorCell, AppearanceProtocol, ConfigurableCel fatalError("init(coder:) has not been implemented") } - public func configure(appearance: EmptyCellAppearance) { + public func configure(appearance: Appearance) { contentView.backgroundColor = appearance.color } diff --git a/Sources/Classes/Views/EmptyCell/EmptyCellAppearance.swift b/Sources/Classes/Views/EmptyCell/EmptyCellAppearance.swift deleted file mode 100644 index 0c432aa6..00000000 --- a/Sources/Classes/Views/EmptyCell/EmptyCellAppearance.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// Copyright (c) 2017 Touch Instinct -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the Software), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -import UIKit - -/// Appearance for EmptyCell -public final class EmptyCellAppearance { - - let color: UIColor - - /// Returns configured appearance for cell - /// - parameter color: Fill color of cell - /// - returns: Configured appearance - public init(color: UIColor = .clear) { - self.color = color - } -} From 5c85bf2e5d21a432910a2fa20e92327602c60be3 Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 15:01:20 +0300 Subject: [PATCH 06/14] EmptyCell default appearance fix --- Sources/Classes/Views/EmptyCell/EmptyCell.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/Classes/Views/EmptyCell/EmptyCell.swift b/Sources/Classes/Views/EmptyCell/EmptyCell.swift index 1d6bae33..c0cca1b8 100644 --- a/Sources/Classes/Views/EmptyCell/EmptyCell.swift +++ b/Sources/Classes/Views/EmptyCell/EmptyCell.swift @@ -53,5 +53,7 @@ public final class EmptyCell: SeparatorCell, AppearanceProtocol, ConfigurableCel private func setup() { backgroundColor = .clear selectionStyle = .none + + configure(appearance: Appearance()) } } From 06a208bb7680dd35efcbb412a2ca53431ddb82c0 Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 16:02:05 +0300 Subject: [PATCH 07/14] Code review inspections fix --- .../Classes/Views/SeparatorRowBox/SeparatorRowBox.swift | 4 +++- .../TableDirector/TableRow+AppearanceExtension.swift | 6 +----- .../TableDirector/TableRow+SeparatorsExtensions.swift | 8 ++------ 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift b/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift index f87ca389..cf8674f8 100644 --- a/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift +++ b/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift @@ -37,7 +37,9 @@ public final class SeparatorRowBox { /// - parameter row: TableRow which `cell` conforms to SeparatorCell public init(row: TableRow) where T: SeparatorCell { self.row = row - setSeparatorHandler = row.set + setSeparatorHandler = { separatorType in + row.set(separatorType: separatorType) + } } } diff --git a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift index 715c34de..5060f6fe 100644 --- a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift +++ b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift @@ -26,7 +26,7 @@ fileprivate let updateAppearanceActionId = "TableRowUpdateAppearanceActionId" public extension TableRow where CellType: AppearanceProtocol { - func with(appearance: CellType.Appearance) -> Self { + @discardableResult func set(appearance: CellType.Appearance) -> Self { removeAction(forActionId: updateAppearanceActionId) let action = TableRowAction(.configure) { options in @@ -39,8 +39,4 @@ public extension TableRow where CellType: AppearanceProtocol { return self } - func set(appearance: CellType.Appearance) { - _ = with(appearance: appearance) - } - } diff --git a/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift b/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift index 4108b165..d69ad3cf 100644 --- a/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift +++ b/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift @@ -22,11 +22,11 @@ import TableKit -fileprivate let configureSeparatorActionId = "TableRowConfigureSeparatorActionId" +private let configureSeparatorActionId = "TableRowConfigureSeparatorActionId" public extension TableRow where CellType: SeparatorCell { - func with(separatorType: CellSeparatorType) -> Self { + @discardableResult func set(separatorType: CellSeparatorType) -> Self { removeAction(forActionId: configureSeparatorActionId) let action = TableRowAction(.configure) { options in @@ -39,10 +39,6 @@ public extension TableRow where CellType: SeparatorCell { return self } - func set(separatorType: CellSeparatorType) { - _ = with(separatorType: separatorType) - } - } public extension TableRow where CellType: SeparatorCell { From 6c29696367684bf7cae47a0d4717fe02a1bdfbed Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 16:08:22 +0300 Subject: [PATCH 08/14] Code review inspections fix vol. 2 --- Sources/Classes/Views/EmptyCell/EmptyCell.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Sources/Classes/Views/EmptyCell/EmptyCell.swift b/Sources/Classes/Views/EmptyCell/EmptyCell.swift index c0cca1b8..718b348b 100644 --- a/Sources/Classes/Views/EmptyCell/EmptyCell.swift +++ b/Sources/Classes/Views/EmptyCell/EmptyCell.swift @@ -45,15 +45,13 @@ public final class EmptyCell: SeparatorCell, AppearanceProtocol, ConfigurableCel } public func configure(appearance: Appearance) { + selectionStyle = .none contentView.backgroundColor = appearance.color } public func configure(with _: Void) { } private func setup() { - backgroundColor = .clear - selectionStyle = .none - configure(appearance: Appearance()) } } From 9ab7dc8f52f9e9b40e6cde3228deaf4a7233c01d Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 16:17:39 +0300 Subject: [PATCH 09/14] Code review inspections fix vol. 3 --- Sources/Protocols/AppearanceProtocol.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/Protocols/AppearanceProtocol.swift b/Sources/Protocols/AppearanceProtocol.swift index a974f5c0..26c89c4e 100644 --- a/Sources/Protocols/AppearanceProtocol.swift +++ b/Sources/Protocols/AppearanceProtocol.swift @@ -20,6 +20,7 @@ // THE SOFTWARE. // + //Protocol which ensures that specific type can apply appearance to itself public protocol AppearanceProtocol { associatedtype Appearance From cc26bdbd6845b21d3a052896dd151c8ea5223a50 Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 16:47:28 +0300 Subject: [PATCH 10/14] Code review inspections fix vol. 4 --- .../Views/SeparatorRowBox/SeparatorRowBox.swift | 4 +--- .../TableDirector/TableRow+AppearanceExtension.swift | 9 ++++++--- .../TableDirector/TableRow+SeparatorsExtensions.swift | 11 +++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift b/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift index cf8674f8..f87ca389 100644 --- a/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift +++ b/Sources/Classes/Views/SeparatorRowBox/SeparatorRowBox.swift @@ -37,9 +37,7 @@ public final class SeparatorRowBox { /// - parameter row: TableRow which `cell` conforms to SeparatorCell public init(row: TableRow) where T: SeparatorCell { self.row = row - setSeparatorHandler = { separatorType in - row.set(separatorType: separatorType) - } + setSeparatorHandler = row.set } } diff --git a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift index 5060f6fe..24ed16e1 100644 --- a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift +++ b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift @@ -26,7 +26,12 @@ fileprivate let updateAppearanceActionId = "TableRowUpdateAppearanceActionId" public extension TableRow where CellType: AppearanceProtocol { - @discardableResult func set(appearance: CellType.Appearance) -> Self { + func with(appearance: CellType.Appearance) -> Self { + set(appearance: appearance) + return self + } + + func set(appearance: CellType.Appearance) { removeAction(forActionId: updateAppearanceActionId) let action = TableRowAction(.configure) { options in @@ -35,8 +40,6 @@ public extension TableRow where CellType: AppearanceProtocol { action.id = updateAppearanceActionId on(action) - - return self } } diff --git a/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift b/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift index d69ad3cf..9076505c 100644 --- a/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift +++ b/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift @@ -22,11 +22,16 @@ import TableKit -private let configureSeparatorActionId = "TableRowConfigureSeparatorActionId" +fileprivate let configureSeparatorActionId = "TableRowConfigureSeparatorActionId" public extension TableRow where CellType: SeparatorCell { - @discardableResult func set(separatorType: CellSeparatorType) -> Self { + func with(separatorType: CellSeparatorType) -> Self { + set(separatorType: separatorType) + return self + } + + func set(separatorType: CellSeparatorType) { removeAction(forActionId: configureSeparatorActionId) let action = TableRowAction(.configure) { options in @@ -35,8 +40,6 @@ public extension TableRow where CellType: SeparatorCell { action.id = configureSeparatorActionId on(action) - - return self } } From 5e9a20d81ae15078e64a7afc093dc2d3f2a72ba2 Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 16:48:09 +0300 Subject: [PATCH 11/14] Minor change --- .../Extensions/TableDirector/TableRow+AppearanceExtension.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift index 24ed16e1..700afc27 100644 --- a/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift +++ b/Sources/Extensions/TableDirector/TableRow+AppearanceExtension.swift @@ -22,7 +22,7 @@ import TableKit -fileprivate let updateAppearanceActionId = "TableRowUpdateAppearanceActionId" +private let updateAppearanceActionId = "TableRowUpdateAppearanceActionId" public extension TableRow where CellType: AppearanceProtocol { From ee2fb6d7965798eb23c4cbdf10575f1b3659d5fe Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 16:49:01 +0300 Subject: [PATCH 12/14] One more minor change --- .../TableDirector/TableRow+SeparatorsExtensions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift b/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift index 9076505c..959816f3 100644 --- a/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift +++ b/Sources/Extensions/TableDirector/TableRow+SeparatorsExtensions.swift @@ -22,7 +22,7 @@ import TableKit -fileprivate let configureSeparatorActionId = "TableRowConfigureSeparatorActionId" +private let configureSeparatorActionId = "TableRowConfigureSeparatorActionId" public extension TableRow where CellType: SeparatorCell { From 81e87efb3c13d21d270c7b31764dafa6904fec0c Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 17:10:19 +0300 Subject: [PATCH 13/14] Update podspec and changelog --- CHANGELOG.md | 7 +++++++ LeadKit.podspec | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30505e72..b73a2be1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,3 +37,10 @@ - **Change**: Rename `AnyBaseTableRow` class to `SeparatorRowBox` - **Change**: Move `anyRow` property from `EmptyCellRow` to `TableRow` extension and rename it to `separatorRowBox`. - **Change**: Move `configure(extreme: middle:)` method from `TableDirector` extension to `Array` extension and rename it to `configureSeparators(extreme: middle:)` + +## 0.5.15 + +- **Add**: `AppearanceProtocol` which ensures that specific type can apply appearance to itself +- **Add**: `with(appearance:)`, `set(appearance:)` methods to TableRow extansion +- **Add**: `Appearance` to `EmptyCell` +- **Remove**: `SeparatorCellViewModel`. diff --git a/LeadKit.podspec b/LeadKit.podspec index 2cba232c..59f1479d 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKit" - s.version = "0.5.14" + s.version = "0.5.15" s.summary = "iOS framework with a bunch of tools for rapid development" s.homepage = "https://github.com/TouchInstinct/LeadKit" s.license = "Apache License, Version 2.0" From 56136eee4ba3bbcd04af14dbd802c06021359594 Mon Sep 17 00:00:00 2001 From: Anton Popkov Date: Fri, 13 Oct 2017 17:25:45 +0300 Subject: [PATCH 14/14] Changelog minor fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b73a2be1..ea349a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,6 @@ ## 0.5.15 - **Add**: `AppearanceProtocol` which ensures that specific type can apply appearance to itself -- **Add**: `with(appearance:)`, `set(appearance:)` methods to TableRow extansion +- **Add**: `with(appearance:)`, `set(appearance:)` methods to TableRow extension - **Add**: `Appearance` to `EmptyCell` - **Remove**: `SeparatorCellViewModel`.