From 7ad1d3e8e0a29dc2a95292d436f1a14a14880472 Mon Sep 17 00:00:00 2001 From: Reinier Melian Date: Wed, 30 Nov 2022 15:08:14 +0100 Subject: [PATCH 1/7] Centralise Z positioning logic of headers and footers --- TableViewKit/TableViewKitDelegate.swift | 16 ++++++++++++++-- TableViewKit/TableViewManager.swift | 9 +++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/TableViewKit/TableViewKitDelegate.swift b/TableViewKit/TableViewKitDelegate.swift index 1f4ec8c..4d03e82 100644 --- a/TableViewKit/TableViewKitDelegate.swift +++ b/TableViewKit/TableViewKitDelegate.swift @@ -48,12 +48,24 @@ open class TableViewKitDelegate: NSObject, UITableViewDelegate { /// Implementation of UITableViewDelegate open func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { - return view(for: { $0.header }, inSection: section) + let view = view(for: { $0.header }, inSection: section) + + if let zPosition = manager.zPositionForHeader(in: section) { + view?.layer.zPosition = zPosition + } + + return view } /// Implementation of UITableViewDelegate open func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { - return view(for: { $0.footer }, inSection: section) + let view = view(for: { $0.footer }, inSection: section) + + if let zPosition = manager.zPositionForFooter(in: section) { + view?.layer.zPosition = zPosition + } + + return views } /// Implementation of UITableViewDelegate diff --git a/TableViewKit/TableViewManager.swift b/TableViewKit/TableViewManager.swift index 4689922..67c45a4 100644 --- a/TableViewKit/TableViewManager.swift +++ b/TableViewKit/TableViewManager.swift @@ -100,6 +100,15 @@ open class TableViewManager { open func zPositionForCell(at indexPath: IndexPath) -> CGFloat? { nil } + + open func zPositionForHeader(in section: Int) -> CGFloat? { + nil + } + + open func zPositionForFooter(in section: Int) -> CGFloat? { + nil + } + } extension TableViewManager { From d0042a91e0b5242c56280dbe598b72952967e1c3 Mon Sep 17 00:00:00 2001 From: Reinier Melian Date: Wed, 30 Nov 2022 15:18:40 +0100 Subject: [PATCH 2/7] fixing small typo --- TableViewKit/TableViewKitDelegate.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TableViewKit/TableViewKitDelegate.swift b/TableViewKit/TableViewKitDelegate.swift index 4d03e82..2197273 100644 --- a/TableViewKit/TableViewKitDelegate.swift +++ b/TableViewKit/TableViewKitDelegate.swift @@ -65,7 +65,7 @@ open class TableViewKitDelegate: NSObject, UITableViewDelegate { view?.layer.zPosition = zPosition } - return views + return view } /// Implementation of UITableViewDelegate From a46dfc4344bb3ae6b4c6d95e5660e7a8f9de9d48 Mon Sep 17 00:00:00 2001 From: Reinier Melian Date: Thu, 1 Dec 2022 10:45:22 +0100 Subject: [PATCH 3/7] Added new tests for Z position in header and footer --- .../TableViewDelegateTests.swift | 30 +++++++++++++++ TableViewKitTests/TableViewManagerMock.swift | 19 ++++++++++ TableViewKitTests/TableViewManagerTests.swift | 38 +++++++++++++++++++ 3 files changed, 87 insertions(+) diff --git a/TableViewKitTests/TableViewDelegateTests.swift b/TableViewKitTests/TableViewDelegateTests.swift index 9273553..7d4a675 100644 --- a/TableViewKitTests/TableViewDelegateTests.swift +++ b/TableViewKitTests/TableViewDelegateTests.swift @@ -23,6 +23,23 @@ class CustomHeaderFooterView: UITableViewHeaderFooterView { } } +class TestRegisterHeaderFooterViewItem: HeaderFooter { + static var drawer = AnyHeaderFooterDrawer(TestRegisterHeaderFooterDrawer.self) + var height: Height? = .static(60) +} + +// MARK: - AncillariesBundleInTheAppHeaderDrawer + +class TestRegisterHeaderFooterDrawer: HeaderFooterDrawer { + static let bundle = Bundle(for: TestRegisterHeaderFooterViewItem.self) + static let nib = UINib(nibName: String(describing: TestRegisterHeaderFooterView.self), bundle: bundle) + static var type = HeaderFooterType.nib(TestRegisterHeaderFooterDrawer.nib, TestRegisterHeaderFooterView.self) + + static func draw(_ view: TestRegisterHeaderFooterView, with item: TestRegisterHeaderFooterViewItem) { + } +} + + class CustomHeaderDrawer: HeaderFooterDrawer { static public var type = HeaderFooterType.class(CustomHeaderFooterView.self) @@ -58,6 +75,18 @@ class ViewHeaderFooterSection: TableSection { } } +class ViewHeaderFooterSectionInstaciated: TableSection { + var items: ObservableArray = [] + + internal var header: HeaderFooterView = .view(TestRegisterHeaderFooterViewItem()) + internal var footer: HeaderFooterView = .view(TestRegisterHeaderFooterViewItem()) + + convenience init(items: [TableItem]) { + self.init() + self.items.insert(contentsOf: items, at: 0) + } +} + class NoHeigthItem: TableItem { static internal var drawer = AnyCellDrawer(TestDrawer.self) @@ -318,4 +347,5 @@ class TableViewDelegateTests: XCTestCase { withSender: nil) expect(actionableItem.check) == 1 } + } diff --git a/TableViewKitTests/TableViewManagerMock.swift b/TableViewKitTests/TableViewManagerMock.swift index c7aff14..de4beb5 100644 --- a/TableViewKitTests/TableViewManagerMock.swift +++ b/TableViewKitTests/TableViewManagerMock.swift @@ -4,11 +4,30 @@ final class TableViewManagerMock: TableViewManager { private(set) var zPositionForCellCallsCount = 0 private(set) var zPositionForCellReceivedIndexPath: IndexPath? + private(set) var zPositionForHeaderCallsCount = 0 + private(set) var zPositionForHeaderReceivedSection: Int? + private(set) var zPositionForFooterCallsCount = 0 + private(set) var zPositionForFooterReceivedSection: Int? var zPositionForCellReturnValue: CGFloat? + var zPositionForHeaderReturnValue: CGFloat? + var zPositionForFooterReturnValue: CGFloat? override func zPositionForCell(at indexPath: IndexPath) -> CGFloat? { zPositionForCellCallsCount += 1 zPositionForCellReceivedIndexPath = indexPath return zPositionForCellReturnValue } + + override func zPositionForHeader(in section: Int) -> CGFloat? { + zPositionForHeaderCallsCount += 1 + zPositionForHeaderReceivedSection = section + return zPositionForHeaderReturnValue + } + + override func zPositionForFooter(in section: Int) -> CGFloat? { + zPositionForFooterCallsCount += 1 + zPositionForFooterReceivedSection = section + return zPositionForFooterReturnValue + } + } diff --git a/TableViewKitTests/TableViewManagerTests.swift b/TableViewKitTests/TableViewManagerTests.swift index dc5956c..808906f 100644 --- a/TableViewKitTests/TableViewManagerTests.swift +++ b/TableViewKitTests/TableViewManagerTests.swift @@ -213,4 +213,42 @@ class TableViewManagerTests: XCTestCase { XCTAssertEqual(tableManager.zPositionForCellCallsCount, 1) XCTAssertEqual(cell.layer.zPosition, zPosition) } + + func testZPositionForHeader() throws { + // Given + let zPosition: CGFloat = 4 + let tableManager = tableManagerForInstanciatedSections(itemsBySection: 3, numberOfSections: 2) + tableManager.zPositionForHeaderReturnValue = zPosition + let delegate = try XCTUnwrap(tableManager.delegate) + // When + let headerSection0 = try XCTUnwrap(delegate.tableView(tableManager.tableView, viewForHeaderInSection: 0)) + let headerSection1 = try XCTUnwrap(delegate.tableView(tableManager.tableView, viewForHeaderInSection: 1)) + // Then + XCTAssertEqual(tableManager.zPositionForHeaderCallsCount, 2) + XCTAssertEqual(headerSection0.layer.zPosition, zPosition) + XCTAssertEqual(headerSection1.layer.zPosition, zPosition) + } + + func testZPositionForFooter() throws { + // Given + let zPosition: CGFloat = 4 + let tableManager = tableManagerForInstanciatedSections(itemsBySection: 3, numberOfSections: 2) + tableManager.zPositionForFooterReturnValue = zPosition + let delegate = try XCTUnwrap(tableManager.delegate) + // When + let footerSection0 = try XCTUnwrap(delegate.tableView(tableManager.tableView, viewForFooterInSection: 0)) + let footerSection1 = try XCTUnwrap(delegate.tableView(tableManager.tableView, viewForFooterInSection: 1)) + // Then + XCTAssertEqual(tableManager.zPositionForFooterCallsCount, 2) + XCTAssertEqual(footerSection0.layer.zPosition, zPosition) + XCTAssertEqual(footerSection1.layer.zPosition, zPosition) + } + + private func tableManagerForInstanciatedSections(itemsBySection: Int, numberOfSections: Int) -> TableViewManagerMock { + let sections = Array( + repeating: ViewHeaderFooterSectionInstaciated(items: .init(repeating: TestItem(), count: itemsBySection)), + count: numberOfSections + ) + return TableViewManagerMock(tableView: UITableView(), sections: sections) + } } From 049157042e9887a44af142a147120f4f1ca6d0f1 Mon Sep 17 00:00:00 2001 From: Reinier Melian Date: Thu, 28 Sep 2023 16:04:09 +0200 Subject: [PATCH 4/7] opening trailingSwipe and leadingSwipe TableViewKitDelegate --- TableViewKit/TableViewKitDelegate.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TableViewKit/TableViewKitDelegate.swift b/TableViewKit/TableViewKitDelegate.swift index 2197273..cf781b3 100644 --- a/TableViewKit/TableViewKitDelegate.swift +++ b/TableViewKit/TableViewKitDelegate.swift @@ -76,14 +76,14 @@ open class TableViewKitDelegate: NSObject, UITableViewDelegate { /// Implementation of UITableViewDelegate // swiftlint:disable:next line_length - public func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + open func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { guard let item = manager.item(at: indexPath) as? Editable else { return nil } return item.trailingConfiguration } /// Implementation of UITableViewDelegate // swiftlint:disable:next line_length - public func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { + open func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { guard let item = manager.item(at: indexPath) as? Editable else { return nil } return item.leadingConfiguration } From e24227c606a6ac92ac5efd22cadecd9b6206e40f Mon Sep 17 00:00:00 2001 From: Reinier Melian Date: Mon, 22 Jan 2024 15:23:08 +0100 Subject: [PATCH 5/7] first attempt to create a SPM package --- .../contents.xcworkspacedata | 7 ++++ Package.resolved | 32 +++++++++++++++++++ Package.swift | 28 ++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata create mode 100644 Package.resolved create mode 100644 Package.swift diff --git a/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..8195362 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,32 @@ +{ + "pins" : [ + { + "identity" : "cwlcatchexception", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mattgallagher/CwlCatchException.git", + "state" : { + "revision" : "3b123999de19bf04905bc1dfdb76f817b0f2cc00", + "version" : "2.1.2" + } + }, + { + "identity" : "cwlpreconditiontesting", + "kind" : "remoteSourceControl", + "location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", + "state" : { + "revision" : "dc9af4781f2afdd1e68e90f80b8603be73ea7abc", + "version" : "2.2.0" + } + }, + { + "identity" : "nimble", + "kind" : "remoteSourceControl", + "location" : "https://github.com/Quick/Nimble.git", + "state" : { + "revision" : "c1f3dd66222d5e7a1a20afc237f7e7bc432c564f", + "version" : "13.2.0" + } + } + ], + "version" : 2 +} diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..d27d349 --- /dev/null +++ b/Package.swift @@ -0,0 +1,28 @@ +// swift-tools-version:5.8 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "TableViewKit", + platforms: [.iOS(.v15)], + products: [ + .library( + name: "TableViewKit", targets: ["TableViewKit"]), + ], + dependencies: [ + .package( + url: "https://github.com/Quick/Nimble.git", .upToNextMajor(from: "13.2.0") + ), + ], + targets: [ + .target( + name: "TableViewKit", + dependencies: [], + path: "./TableViewKit"), + .testTarget( + name: "TableViewKitTests", + dependencies: ["TableViewKit", "Nimble"], + path: "./TableViewKitTests") + ] +) From 7f831076f2148d000ad7836d76920d6433f4c20a Mon Sep 17 00:00:00 2001 From: Reinier Melian Date: Mon, 22 Jan 2024 15:52:28 +0100 Subject: [PATCH 6/7] Removed submodule --- .gitmodules | 4 +--- External/Nimble | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 160000 External/Nimble diff --git a/.gitmodules b/.gitmodules index c25a7ad..8b13789 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1 @@ -[submodule "External/Nimble"] - path = External/Nimble - url = git://github.com/Quick/Nimble.git + diff --git a/External/Nimble b/External/Nimble deleted file mode 160000 index 38c9ab0..0000000 --- a/External/Nimble +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 38c9ab0846a3fbec308eb2aa9ef68b10a7434eb4 From 0c093144e07550319efe20f4ce64c202c33931e1 Mon Sep 17 00:00:00 2001 From: Reinier Melian Date: Mon, 22 Jan 2024 16:26:48 +0100 Subject: [PATCH 7/7] adding UIKit import --- TableViewKit/ActionPerformable.swift | 2 +- TableViewKit/Height.swift | 1 + TableViewKit/NibClassType.swift | 1 + TableViewKit/Protocols/Editable.swift | 1 + TableViewKit/Protocols/Selectable.swift | 1 + TableViewKit/Protocols/TableItem.swift | 1 + 6 files changed, 6 insertions(+), 1 deletion(-) diff --git a/TableViewKit/ActionPerformable.swift b/TableViewKit/ActionPerformable.swift index 56ba79f..c152520 100644 --- a/TableViewKit/ActionPerformable.swift +++ b/TableViewKit/ActionPerformable.swift @@ -1,5 +1,5 @@ import Foundation - +import UIKit /// A type that represent the kind of action an item should perform. /// I.e.: copy or paste public enum ItemAction { diff --git a/TableViewKit/Height.swift b/TableViewKit/Height.swift index 5b995d6..91cd9e6 100644 --- a/TableViewKit/Height.swift +++ b/TableViewKit/Height.swift @@ -1,4 +1,5 @@ import Foundation +import UIKit /// Defines either a dynamic or static height public enum Height { diff --git a/TableViewKit/NibClassType.swift b/TableViewKit/NibClassType.swift index 6ab2645..a486404 100644 --- a/TableViewKit/NibClassType.swift +++ b/TableViewKit/NibClassType.swift @@ -1,4 +1,5 @@ import Foundation +import UIKit /// A Nib/Class loadable type public enum NibClassType { diff --git a/TableViewKit/Protocols/Editable.swift b/TableViewKit/Protocols/Editable.swift index ee77f9b..4afaa6c 100644 --- a/TableViewKit/Protocols/Editable.swift +++ b/TableViewKit/Protocols/Editable.swift @@ -1,4 +1,5 @@ import Foundation +import UIKit /// A type that represent an item that can be edited public protocol Editable: TableItem { diff --git a/TableViewKit/Protocols/Selectable.swift b/TableViewKit/Protocols/Selectable.swift index d3d389d..b528bd6 100644 --- a/TableViewKit/Protocols/Selectable.swift +++ b/TableViewKit/Protocols/Selectable.swift @@ -1,4 +1,5 @@ import Foundation +import UIKit /// A type that represent an item that can be selected public protocol Selectable: TableItem { diff --git a/TableViewKit/Protocols/TableItem.swift b/TableViewKit/Protocols/TableItem.swift index c126651..8fd916a 100644 --- a/TableViewKit/Protocols/TableItem.swift +++ b/TableViewKit/Protocols/TableItem.swift @@ -1,4 +1,5 @@ import Foundation +import UIKit @available(*, deprecated, renamed: "TableItem") public typealias Item = TableItem