Merge pull request #96 from TouchInstinct/feature/appearance

Add appearance for view, cell etc.
This commit is contained in:
iON1k 2017-10-13 17:29:17 +03:00 committed by GitHub
commit 2c637702e4
12 changed files with 160 additions and 143 deletions

View File

@ -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 extension
- **Add**: `Appearance` to `EmptyCell`
- **Remove**: `SeparatorCellViewModel`.

View File

@ -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"

View File

@ -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,16 +386,14 @@
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 */; };
A6C9A4FB1F8BBCF2009311CC /* EmptyCellViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A6AF3B361F8B956E00CDB971 /* EmptyCellViewModel.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 */; };
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 */; };
@ -401,10 +401,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 */; };
@ -468,6 +466,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 = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
40F118481F8FF223004AADAF /* TableRow+AppearanceExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TableRow+AppearanceExtension.swift"; sourceTree = "<group>"; };
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 = "<group>"; };
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 = "<group>"; };
@ -600,13 +600,11 @@
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 = "<group>"; };
A658E54C1F8CD7790093527A /* TableRow+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TableRow+Extensions.swift"; sourceTree = "<group>"; };
A658E54C1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TableRow+SeparatorsExtensions.swift"; sourceTree = "<group>"; };
A658E54F1F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Array+SeparatorRowBoxExtensions.swift"; sourceTree = "<group>"; };
A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCellViewModel.swift; sourceTree = "<group>"; };
A66428A61F8A653600C6308D /* SeparatorCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorCell.swift; sourceTree = "<group>"; };
A66428A71F8A654600C6308D /* EmptyCellRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellRow.swift; sourceTree = "<group>"; };
A66428A81F8A655600C6308D /* SeparatorRowBox.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeparatorRowBox.swift; sourceTree = "<group>"; };
A6AF3B361F8B956E00CDB971 /* EmptyCellViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCellViewModel.swift; sourceTree = "<group>"; };
A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyCell.swift; sourceTree = "<group>"; };
A6D10EAA1F8A9278003E69DD /* Comparable+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Comparable+Extensions.swift"; sourceTree = "<group>"; };
A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellSeparatorType.swift; sourceTree = "<group>"; };
@ -945,7 +943,8 @@
isa = PBXGroup;
children = (
671462011EB3396E00EAB194 /* TableDirector+Extensions.swift */,
A658E54C1F8CD7790093527A /* TableRow+Extensions.swift */,
A658E54C1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift */,
40F118481F8FF223004AADAF /* TableRow+AppearanceExtension.swift */,
);
path = TableDirector;
sourceTree = "<group>";
@ -1072,6 +1071,7 @@
671462321EB3396E00EAB194 /* ViewHeightProtocol.swift */,
671462331EB3396E00EAB194 /* ViewModelProtocol.swift */,
671462341EB3396E00EAB194 /* XibNameProtocol.swift */,
40F118461F8FEF97004AADAF /* AppearanceProtocol.swift */,
);
path = Protocols;
sourceTree = "<group>";
@ -1266,7 +1266,6 @@
isa = PBXGroup;
children = (
A66428A61F8A653600C6308D /* SeparatorCell.swift */,
A66428A51F8A653500C6308D /* SeparatorCellViewModel.swift */,
A6E0DDEE1F8A6C57002CA74E /* CellSeparatorType.swift */,
A6E0DDF01F8A6C80002CA74E /* SeparatorConfiguration.swift */,
);
@ -1285,7 +1284,6 @@
isa = PBXGroup;
children = (
A6AF3B371F8B956F00CDB971 /* EmptyCell.swift */,
A6AF3B361F8B956E00CDB971 /* EmptyCellViewModel.swift */,
A66428A71F8A654600C6308D /* EmptyCellRow.swift */,
);
path = EmptyCell;
@ -2122,7 +2120,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 */,
@ -2150,9 +2148,9 @@
671462781EB3396E00EAB194 /* ResizeContentMode.swift in Sources */,
A6E0DDE11F8A696F002CA74E /* SeparatorRowBox.swift in Sources */,
A6E0DDDE1F8A696F002CA74E /* EmptyCellRow.swift in Sources */,
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 */,
@ -2178,7 +2176,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 */,
@ -2186,6 +2183,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 */,
@ -2212,14 +2210,12 @@
buildActionMask = 2147483647;
files = (
A6C9A5051F8BC78F009311CC /* SeparatorConfiguration.swift in Sources */,
A6C9A50D1F8BC799009311CC /* EmptyCellViewModel.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+Extensions.swift in Sources */,
A6E0DDE41F8A696F002CA74E /* SeparatorCellViewModel.swift in Sources */,
A658E54E1F8CD7790093527A /* TableRow+SeparatorsExtensions.swift in Sources */,
A658E5511F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */,
671463BB1EB34B1E00EAB194 /* CursorTests.swift in Sources */,
A6F32C101F6EBE9600AC08EE /* StringExtensionTests.swift in Sources */,

View File

@ -25,14 +25,33 @@ 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 struct Appearance {
let color: UIColor
public func configure(with viewModel: EmptyCellViewModel) {
backgroundColor = .clear
contentView.backgroundColor = viewModel.color
selectionStyle = .none
configureSeparator(with: viewModel)
public init(color: UIColor = .clear) {
self.color = color
}
}
public override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setup()
}
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
public func configure(appearance: Appearance) {
selectionStyle = .none
contentView.backgroundColor = appearance.color
}
public func configure(with _: Void) { }
private func setup() {
configure(appearance: Appearance())
}
}

View File

@ -26,17 +26,19 @@ import TableKit
/// - Simulates spacing with no-breaking constraints
/// - Can end editing on click
public final class EmptyCellRow: TableRow<EmptyCell> {
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<EmptyCell> {
/// Used for set custom height to each cell, not for each cell type
override public var defaultHeight: CGFloat? {
return item.height
return rowHeight
}
}

View File

@ -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)

View File

@ -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
}
}
}

View File

@ -25,17 +25,19 @@ import TableKit
/// Class that used to configure separators when multiply cells presented in one section
/// Holds TableRow<T> 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<T>(tableRow: TableRow<T>) where T: SeparatorCell, T.T: SeparatorCellViewModel {
row = tableRow
viewModel = tableRow.item
/// - parameter row: TableRow which `cell` conforms to SeparatorCell
public init<T>(row: TableRow<T>) where T: SeparatorCell {
self.row = row
setSeparatorHandler = row.set
}
}

View File

@ -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))
}
}

View File

@ -20,20 +20,26 @@
// THE SOFTWARE.
//
import UIKit
import TableKit
/// ViewModel for EmptyCell
public final class EmptyCellViewModel: SeparatorCellViewModel {
private let updateAppearanceActionId = "TableRowUpdateAppearanceActionId"
let color: UIColor
let height: CGFloat
public extension TableRow where CellType: AppearanceProtocol {
/// Returns configured ViewModel for cell
/// - parameter height: Height of cell
/// - parameter color: Fill color of cell
/// - returns: Configured ViewModel
public init(height: CGFloat, color: UIColor = .clear) {
self.color = color
self.height = height
func with(appearance: CellType.Appearance) -> Self {
set(appearance: appearance)
return self
}
func set(appearance: CellType.Appearance) {
removeAction(forActionId: updateAppearanceActionId)
let action = TableRowAction<CellType>(.configure) { options in
options.cell?.configure(appearance: appearance)
}
action.id = updateAppearanceActionId
on(action)
}
}

View File

@ -22,24 +22,33 @@
import TableKit
public extension TableRow where CellType.T: SeparatorCellViewModel {
private let configureSeparatorActionId = "TableRowConfigureSeparatorActionId"
public extension TableRow where CellType: SeparatorCell {
func with(separatorType: CellSeparatorType) -> Self {
item.set(separatorType: separatorType)
set(separatorType: separatorType)
return self
}
func set(separatorType: CellSeparatorType) {
item.set(separatorType: separatorType)
removeAction(forActionId: configureSeparatorActionId)
let action = TableRowAction<CellType>(.configure) { options in
options.cell?.configureSeparator(with: separatorType)
}
action.id = configureSeparatorActionId
on(action)
}
}
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)
}
}

View File

@ -0,0 +1,28 @@
//
// 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.
//
//Protocol which ensures that specific type can apply appearance to itself
public protocol AppearanceProtocol {
associatedtype Appearance
func configure(appearance: Appearance)
}