From 245b776205e18900f6ac4625e48101bc4c078ed2 Mon Sep 17 00:00:00 2001 From: Pavan Kataria Date: Sat, 11 Mar 2017 10:15:50 +0000 Subject: [PATCH 1/7] Trims row columns to the header count specified --- SwiftDataTables/Classes/DataStructureModel.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SwiftDataTables/Classes/DataStructureModel.swift b/SwiftDataTables/Classes/DataStructureModel.swift index a20be28..c9ed688 100644 --- a/SwiftDataTables/Classes/DataStructureModel.swift +++ b/SwiftDataTables/Classes/DataStructureModel.swift @@ -43,8 +43,11 @@ public struct DataStructureModel { self.headerTitles = headerTitles let unfilteredData = data let sanitisedData = unfilteredData.filter({ currentRowData in - return currentRowData.count == self.columnCount + //Trim column count for current row to the number of headers present + let rowWithPreferredColumnCount = Array(currentRowData.prefix(upTo: self.columnCount)) + return rowWithPreferredColumnCount.count == self.columnCount }) + self.data = sanitisedData//sanitisedData self.shouldFitTitles = shouldMakeTitlesFitInColumn self.columnAverageContentLength = self.processColumnDataAverages(data: self.data) From 38e5bd4e6ac23c6bbc38fd72d79b52bbe48f2b9e Mon Sep 17 00:00:00 2001 From: Pavan Kataria Date: Sat, 11 Mar 2017 10:16:35 +0000 Subject: [PATCH 2/7] Refactors the way content width is calculated. --- CHANGELOG.md | 2 +- Example/SwiftDataTables/ViewController.swift | 6 +++--- SwiftDataTables/Classes/SwiftDataTable.swift | 6 ++++++ SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4e498d..d8ba84b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ ## [0.2](https://github.com/pavankataria/SwiftDataTables/tree/0.2) (2017-03-10) [Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.1.1...0.2) -**Merged pull requests:** +**Implemented enhancements:** - Image bundle [\#1](https://github.com/pavankataria/SwiftDataTables/pull/1) ([pavankataria](https://github.com/pavankataria)) diff --git a/Example/SwiftDataTables/ViewController.swift b/Example/SwiftDataTables/ViewController.swift index 04993e9..f33a003 100644 --- a/Example/SwiftDataTables/ViewController.swift +++ b/Example/SwiftDataTables/ViewController.swift @@ -51,9 +51,9 @@ extension ViewController { "Id", "Name", "Email", - "Number", - "City", - "Balance" + "Number" +// "City", +// "Balance" ] } diff --git a/SwiftDataTables/Classes/SwiftDataTable.swift b/SwiftDataTables/Classes/SwiftDataTable.swift index 2f8eca6..a53e0dc 100644 --- a/SwiftDataTables/Classes/SwiftDataTable.swift +++ b/SwiftDataTables/Classes/SwiftDataTable.swift @@ -389,6 +389,11 @@ extension SwiftDataTable { return max(averageDataColumnWidth, max(self.minimumColumnWidth(), self.minimumHeaderColumnWidth(index: index))) } + + func calculateContentWidth() -> CGFloat { + return Array(0.. CGFloat { return 44 } @@ -400,6 +405,7 @@ extension SwiftDataTable { func minimumColumnWidth() -> CGFloat { return 70 } + func minimumHeaderColumnWidth(index: Int) -> CGFloat { return CGFloat(self.pixelsPerCharacter() * CGFloat(self.dataStructure.headerTitles[index].characters.count)) } diff --git a/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift b/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift index a0bf7a1..8a8f071 100644 --- a/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift +++ b/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift @@ -91,7 +91,7 @@ class SwiftDataTableFlowLayout: UICollectionViewFlowLayout { } override var collectionViewContentSize: CGSize { - let width = Array(0.. Date: Sat, 11 Mar 2017 10:18:18 +0000 Subject: [PATCH 3/7] Fixes bug where Data Grid would crash if the content width was smaller than the width of the frame --- SwiftDataTables/Classes/SwiftDataTable.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftDataTables/Classes/SwiftDataTable.swift b/SwiftDataTables/Classes/SwiftDataTable.swift index a53e0dc..9a0f7d2 100644 --- a/SwiftDataTables/Classes/SwiftDataTable.swift +++ b/SwiftDataTables/Classes/SwiftDataTable.swift @@ -268,7 +268,7 @@ extension SwiftDataTable: UIScrollViewDelegate { if self.disableScrollViewRightBounce(){ let maxX = self.collectionView.contentSize.width-self.collectionView.frame.width if (self.collectionView.contentOffset.x >= maxX){ - self.collectionView.contentOffset.x = maxX-1 + self.collectionView.contentOffset.x = max(maxX-1, 0) } } if self.disableScrollViewBottomBounce(){ From 55ed88a51c1135d17bbaf760fbd81f6a842b2e5c Mon Sep 17 00:00:00 2001 From: Pavan Kataria Date: Sat, 11 Mar 2017 14:01:25 +0000 Subject: [PATCH 4/7] Checkpoint --- SwiftDataTables/Classes/SwiftDataTable.swift | 80 ++++++++++++++++++-- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/SwiftDataTables/Classes/SwiftDataTable.swift b/SwiftDataTables/Classes/SwiftDataTable.swift index 9a0f7d2..797a84e 100644 --- a/SwiftDataTables/Classes/SwiftDataTable.swift +++ b/SwiftDataTables/Classes/SwiftDataTable.swift @@ -79,16 +79,18 @@ public class SwiftDataTable: UIView { fileprivate var rowViewModels = [[DataCellViewModel]]() fileprivate var paginationViewModel: PaginationHeaderViewModel! fileprivate var menuLengthViewModel: MenuLengthHeaderViewModel! - + fileprivate var columnWidths = [CGFloat]() + //MARK: - Lifecycle public init(data: [[String]], headerTitles: [String], frame: CGRect = .zero) { - self.dataStructure = DataStructureModel(data: data, headerTitles: headerTitles) +// self.dataStructure = DataStructureModel(data: data, headerTitles: headerTitles) super.init(frame: frame) - self.createDataCellViewModels(with: self.dataStructure) - self.layout = SwiftDataTableFlowLayout(dataTable: self) + + self.set(data: data, headerTitles: headerTitles) + self.registerObservers() self.collectionView.reloadData() } @@ -127,9 +129,51 @@ public class SwiftDataTable: UIView { collectionView.register(UINib(nibName: menuLengthIdentifier, bundle: podBundle), forSupplementaryViewOfKind: SupplementaryViewType.menuLengthHeader.rawValue, withReuseIdentifier: menuLengthIdentifier) } + public override var frame: CGRect { + get { + return super.frame + } + set { + super.frame = frame + self.calculateColumnWidths() + } + } func set(data: [[String]], headerTitles: [String]){ - let dataStructure = DataStructureModel(data: data, headerTitles: headerTitles) - self.createDataModels(with:dataStructure) + self.dataStructure = DataStructureModel(data: data, headerTitles: headerTitles) + self.createDataCellViewModels(with: self.dataStructure) + self.layout = SwiftDataTableFlowLayout(dataTable: self) + self.calculateColumnWidths() + } + + private func calculateColumnWidths(){ + //calculate the automatic widths for each column + self.columnWidths.removeAll() + for columnIndex in Array(0.. CGFloat { - let dataStructure = self.dataStructure + + /// Automatically calcualtes the width the column should be based on the content + /// in the rows under the column. + /// + /// - Parameter index: The column index + /// - Returns: The automatic width of the column irrespective of the Data Grid frame width + func automaticWidthForColumn(index: Int) -> CGFloat { let columnAverage: CGFloat = CGFloat(dataStructure.averageDataLengthForColumn(index: index)) let sortingArrowVisualElementWidth: CGFloat = 20 // This is ugly let averageDataColumnWidth: CGFloat = columnAverage * self.pixelsPerCharacter() + sortingArrowVisualElementWidth return max(averageDataColumnWidth, max(self.minimumColumnWidth(), self.minimumHeaderColumnWidth(index: index))) } +// func automaticWidthForAllColumns(){ +// let automaticCalculatedWidth: CGFloat = Array(0.. CGFloat { + return self.columnWidths[index] + } func calculateContentWidth() -> CGFloat { return Array(0.. Date: Sat, 11 Mar 2017 15:42:04 +0000 Subject: [PATCH 5/7] Creates new delegate method and resizes columns with weighted distribgution across entire width of data table frame if the content is smaller --- Example/SwiftDataTables/ViewController.swift | 3 - SwiftDataTables/Classes/SwiftDataTable.swift | 67 ++++++++++--------- .../Classes/SwiftDataTableFlowLayout.swift | 2 +- 3 files changed, 37 insertions(+), 35 deletions(-) diff --git a/Example/SwiftDataTables/ViewController.swift b/Example/SwiftDataTables/ViewController.swift index f33a003..40bf2f8 100644 --- a/Example/SwiftDataTables/ViewController.swift +++ b/Example/SwiftDataTables/ViewController.swift @@ -37,11 +37,8 @@ class ViewController: UIViewController { self.dataTable.backgroundColor = UIColor.init(red: 235/255, green: 235/255, blue: 235/255, alpha: 1) //25/255, green: 33/255, blue: 39/255, alpha: 1) - self.dataTable.autoresizingMask = [.flexibleWidth, .flexibleHeight] - self.dataTable.frame = self.view.bounds - self.view.addSubview(self.dataTable); } } diff --git a/SwiftDataTables/Classes/SwiftDataTable.swift b/SwiftDataTables/Classes/SwiftDataTable.swift index 797a84e..2ff110a 100644 --- a/SwiftDataTables/Classes/SwiftDataTable.swift +++ b/SwiftDataTables/Classes/SwiftDataTable.swift @@ -92,7 +92,6 @@ public class SwiftDataTable: UIView { self.set(data: data, headerTitles: headerTitles) self.registerObservers() - self.collectionView.reloadData() } required public init?(coder aDecoder: NSCoder) { @@ -129,15 +128,17 @@ public class SwiftDataTable: UIView { collectionView.register(UINib(nibName: menuLengthIdentifier, bundle: podBundle), forSupplementaryViewOfKind: SupplementaryViewType.menuLengthHeader.rawValue, withReuseIdentifier: menuLengthIdentifier) } - public override var frame: CGRect { - get { - return super.frame - } - set { - super.frame = frame - self.calculateColumnWidths() - } - } +// public override var frame: CGRect { +// get { +// return super.frame +// } +// set { +// super.frame = frame +//// if frame != .zero { +//// self.calculateColumnWidths() +//// } +// } +// } func set(data: [[String]], headerTitles: [String]){ self.dataStructure = DataStructureModel(data: data, headerTitles: headerTitles) self.createDataCellViewModels(with: self.dataStructure) @@ -145,37 +146,36 @@ public class SwiftDataTable: UIView { self.calculateColumnWidths() } - private func calculateColumnWidths(){ + func calculateColumnWidths(){ //calculate the automatic widths for each column self.columnWidths.removeAll() for columnIndex in Array(0.. Bool{ + return true + } func shouldSectionHeadersFloat() -> Bool { return true } @@ -432,6 +436,7 @@ extension SwiftDataTable { /// - Parameter index: The column index /// - Returns: The automatic width of the column irrespective of the Data Grid frame width func automaticWidthForColumn(index: Int) -> CGFloat { + print(self.frame.width) let columnAverage: CGFloat = CGFloat(dataStructure.averageDataLengthForColumn(index: index)) let sortingArrowVisualElementWidth: CGFloat = 20 // This is ugly let averageDataColumnWidth: CGFloat = columnAverage * self.pixelsPerCharacter() + sortingArrowVisualElementWidth diff --git a/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift b/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift index 8a8f071..75a3392 100644 --- a/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift +++ b/SwiftDataTables/Classes/SwiftDataTableFlowLayout.swift @@ -37,7 +37,7 @@ class SwiftDataTableFlowLayout: UICollectionViewFlowLayout { guard self.cache.isEmpty else { return } - + self.dataTable.calculateColumnWidths() let methodStart = Date() var xOffsets = [CGFloat]() From 34b4177ca67356603870f4bb7973da7f8d62c726 Mon Sep 17 00:00:00 2001 From: Pavan Kataria Date: Sat, 11 Mar 2017 16:07:36 +0000 Subject: [PATCH 6/7] Updates example project to cater for multi rotation and makes example project a universal app --- Example/Podfile.lock | 4 ++-- Example/Pods/Local Podspecs/SwiftDataTables.podspec.json | 4 ++-- Example/Pods/Manifest.lock | 4 ++-- .../Pods/Target Support Files/SwiftDataTables/Info.plist | 2 +- Example/SwiftDataTables.xcodeproj/project.pbxproj | 4 ++-- Example/SwiftDataTables/Info.plist | 9 +++++++++ 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index d012858..43402e2 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -12,7 +12,7 @@ PODS: - Nimble - Quick - Quick (1.0.0) - - SwiftDataTables (0.2.4) + - SwiftDataTables (0.2.5) DEPENDENCIES: - FBSnapshotTestCase @@ -30,7 +30,7 @@ SPEC CHECKSUMS: Nimble: 415e3aa3267e7bc2c96b05fa814ddea7bb686a29 Nimble-Snapshots: e743439f26c2fa99d8f7e0d7c01c99bcb40aa6f2 Quick: 8024e4a47e6cc03a9d5245ef0948264fc6d27cff - SwiftDataTables: 3c87142d2539a9cd554e9567eb91689cfd9d6c39 + SwiftDataTables: 05cf3879c95cb0dceb421bd7233e8f56602b1a18 PODFILE CHECKSUM: 9948d9c085c4f798f028aaa1e7597151e452280e diff --git a/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json b/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json index a0ac80b..2248f05 100644 --- a/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json +++ b/Example/Pods/Local Podspecs/SwiftDataTables.podspec.json @@ -1,6 +1,6 @@ { "name": "SwiftDataTables", - "version": "0.2.4", + "version": "0.2.5", "summary": "A Swift Data Table package that allows ordering, searching, and paging with extensible options.", "description": "SwiftDataTables allows you to display grid-like data sets in a nicely formatted table for iOS. The main goal for the end-user are to be able to obtain useful information from the table as quickly as possible with the following features: ordering, searching, and paging; where as for the developer is to allow for easy implementation with extensible options. This package was inspired by Javascript's DataTables package.", "homepage": "https://github.com/pavankataria/SwiftDataTables", @@ -13,7 +13,7 @@ }, "source": { "git": "https://github.com/pavankataria/SwiftDataTables.git", - "tag": "0.2.4" + "tag": "0.2.5" }, "platforms": { "ios": "9.0" diff --git a/Example/Pods/Manifest.lock b/Example/Pods/Manifest.lock index d012858..43402e2 100644 --- a/Example/Pods/Manifest.lock +++ b/Example/Pods/Manifest.lock @@ -12,7 +12,7 @@ PODS: - Nimble - Quick - Quick (1.0.0) - - SwiftDataTables (0.2.4) + - SwiftDataTables (0.2.5) DEPENDENCIES: - FBSnapshotTestCase @@ -30,7 +30,7 @@ SPEC CHECKSUMS: Nimble: 415e3aa3267e7bc2c96b05fa814ddea7bb686a29 Nimble-Snapshots: e743439f26c2fa99d8f7e0d7c01c99bcb40aa6f2 Quick: 8024e4a47e6cc03a9d5245ef0948264fc6d27cff - SwiftDataTables: 3c87142d2539a9cd554e9567eb91689cfd9d6c39 + SwiftDataTables: 05cf3879c95cb0dceb421bd7233e8f56602b1a18 PODFILE CHECKSUM: 9948d9c085c4f798f028aaa1e7597151e452280e diff --git a/Example/Pods/Target Support Files/SwiftDataTables/Info.plist b/Example/Pods/Target Support Files/SwiftDataTables/Info.plist index f7c6cd4..c83163f 100644 --- a/Example/Pods/Target Support Files/SwiftDataTables/Info.plist +++ b/Example/Pods/Target Support Files/SwiftDataTables/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.2.4 + 0.2.5 CFBundleSignature ???? CFBundleVersion diff --git a/Example/SwiftDataTables.xcodeproj/project.pbxproj b/Example/SwiftDataTables.xcodeproj/project.pbxproj index 3c56e7f..34e4eb8 100644 --- a/Example/SwiftDataTables.xcodeproj/project.pbxproj +++ b/Example/SwiftDataTables.xcodeproj/project.pbxproj @@ -510,7 +510,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; - TARGETED_DEVICE_FAMILY = 2; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; }; @@ -527,7 +527,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 3.0; - TARGETED_DEVICE_FAMILY = 2; + TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; }; diff --git a/Example/SwiftDataTables/Info.plist b/Example/SwiftDataTables/Info.plist index eb18faa..81187dd 100644 --- a/Example/SwiftDataTables/Info.plist +++ b/Example/SwiftDataTables/Info.plist @@ -34,6 +34,15 @@ UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeRight From f200da3eee951ebfd39312eb5c6be1873befa4d8 Mon Sep 17 00:00:00 2001 From: Pavan Kataria Date: Sat, 11 Mar 2017 16:11:03 +0000 Subject: [PATCH 7/7] Changes log --- Example/CHANGELOG.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Example/CHANGELOG.md diff --git a/Example/CHANGELOG.md b/Example/CHANGELOG.md new file mode 100644 index 0000000..1560569 --- /dev/null +++ b/Example/CHANGELOG.md @@ -0,0 +1,34 @@ +# Change Log + +## [0.2.6](https://github.com/pavankataria/SwiftDataTables/tree/0.2.6) (2017-03-11) +[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.5...0.2.6) + +## [0.2.5](https://github.com/pavankataria/SwiftDataTables/tree/0.2.5) (2017-03-10) +[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.4...0.2.5) + +## [0.2.4](https://github.com/pavankataria/SwiftDataTables/tree/0.2.4) (2017-03-10) +[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.3...0.2.4) + +## [0.2.3](https://github.com/pavankataria/SwiftDataTables/tree/0.2.3) (2017-03-10) +[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.2...0.2.3) + +## [0.2.2](https://github.com/pavankataria/SwiftDataTables/tree/0.2.2) (2017-03-10) +[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2.1...0.2.2) + +## [0.2.1](https://github.com/pavankataria/SwiftDataTables/tree/0.2.1) (2017-03-10) +[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.2...0.2.1) + +## [0.2](https://github.com/pavankataria/SwiftDataTables/tree/0.2) (2017-03-10) +[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.1.1...0.2) + +**Implemented enhancements:** + +- Image bundle [\#1](https://github.com/pavankataria/SwiftDataTables/pull/1) ([pavankataria](https://github.com/pavankataria)) + +## [0.1.1](https://github.com/pavankataria/SwiftDataTables/tree/0.1.1) (2017-03-09) +[Full Changelog](https://github.com/pavankataria/SwiftDataTables/compare/0.1.0...0.1.1) + +## [0.1.0](https://github.com/pavankataria/SwiftDataTables/tree/0.1.0) (2017-03-09) + + +\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* \ No newline at end of file