diff --git a/Package.swift b/Package.swift index 148940d..e4536c9 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.1 +// swift-tools-version:5.3 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/ScrollStackController.podspec b/ScrollStackController.podspec index d8ba55a..894ddbe 100644 --- a/ScrollStackController.podspec +++ b/ScrollStackController.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "ScrollStackController" - s.version = "1.3.3" + s.version = "1.4.0" s.summary = "Create complex scrollable layout using UIViewController and simplify your code" s.homepage = "https://github.com/malcommac/ScrollStackController" s.license = { :type => "MIT", :file => "LICENSE" } @@ -10,5 +10,5 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/malcommac/ScrollStackController.git", :tag => s.version.to_s } s.frameworks = "Foundation", "UIKit" s.source_files = 'Sources/**/*.swift' - s.swift_versions = ['5.0', '5.1'] + s.swift_versions = ['5.0', '5.1', '5.3'] end diff --git a/ScrollStackController.xcodeproj/project.xcworkspace/xcuserdata/daniele.xcuserdatad/UserInterfaceState.xcuserstate b/ScrollStackController.xcodeproj/project.xcworkspace/xcuserdata/daniele.xcuserdatad/UserInterfaceState.xcuserstate index b47b9c8..1cc44b7 100644 Binary files a/ScrollStackController.xcodeproj/project.xcworkspace/xcuserdata/daniele.xcuserdatad/UserInterfaceState.xcuserstate and b/ScrollStackController.xcodeproj/project.xcworkspace/xcuserdata/daniele.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/ScrollStackControllerDemo/ViewController.swift b/ScrollStackControllerDemo/ViewController.swift index e547a54..879cd1f 100644 --- a/ScrollStackControllerDemo/ViewController.swift +++ b/ScrollStackControllerDemo/ViewController.swift @@ -50,6 +50,12 @@ class ViewController: UIViewController, ScrollStackControllerDelegate { pricingVC = PricingVC.create(delegate: self) notesVC = NotesVC.create(delegate: self) + /*stackView.isSeparatorHidden = false + stackView.separatorColor = .red + stackView.separatorThickness = 3 + stackView.autoHideLastRowSeparator = true + */ + /* Plain UIView example let plainView = UIView(frame: .zero) @@ -58,13 +64,16 @@ class ViewController: UIViewController, ScrollStackControllerDelegate { stackView.addRow(view: plainView) */ - stackView.addRows(controllers: [welcomeVC, notesVC, tagsVC, galleryVC, pricingVC], animated: false) + stackView.addRows(controllers: [welcomeVC, notesVC/*, tagsVC, galleryVC, pricingVC*/], animated: false) } @IBAction public func addNewRow() { - let galleryVC = GalleryVC.create() - stackView.scrollToTop() - stackView.addRow(controller: galleryVC, at: .top, animated: true) + stackView.addRows(controllers: [tagsVC, galleryVC, pricingVC], animated: false) + + +// let galleryVC = GalleryVC.create() +// stackView.scrollToTop() +// stackView.addRow(controller: galleryVC, at: .top, animated: true) } @IBAction public func hideOrShowRandomRow() { diff --git a/Sources/ScrollStackController/ScrollStack.swift b/Sources/ScrollStackController/ScrollStack.swift index 2cd0ed0..98a92f5 100644 --- a/Sources/ScrollStackController/ScrollStack.swift +++ b/Sources/ScrollStackController/ScrollStack.swift @@ -180,7 +180,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate { /// Hide automatically the last separator. open var autoHideLastRowSeparator = false { didSet { - updateRowSeparatorVisibility(lastRow) + updateRowsSeparatorVisibility() } } @@ -803,9 +803,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate { guard let row = row else { return nil } - - let previousRow = rowBeforeRow(row) - + // Animate visibility let removedController = row.controller animateCellVisibility(row, animated: animated, hide: true, completion: { [weak self] in @@ -817,7 +815,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate { // When removing a cell the cell above is the only cell whose separator visibility // will be affected, so we need to update its visibility. - self.updateRowSeparatorVisibility(previousRow) + self.updateRowsSeparatorVisibility() // Remove from the status self.prevVisibilityState.removeValue(forKey: row) @@ -883,31 +881,17 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate { } private func postInsertRow(_ row: ScrollStackRow, animated: Bool, completion: (() -> Void)? = nil) { - // Setup separator visibility for the new cell - updateRowSeparatorVisibility(row) - - // A cell can affect the visibility of the cell before it, e.g. if - // `automaticallyHidesLastSeparator` is true and a new cell is added as the last cell, so update - // the previous cell's separator visibility as well. - updateRowSeparatorVisibility(rowBeforeRow(row)) - - // Animate visibility - animateCellVisibility(row, animated: animated, hide: false, completion: completion) + updateRowsSeparatorVisibility() // update visibility of the separators + animateCellVisibility(row, animated: animated, hide: false, completion: completion) // Animate visibility of the cell } /// Update the separator visibility. /// /// - Parameter row: row target. - private func updateRowSeparatorVisibility(_ row: ScrollStackRow?) { - guard let row = row, row === stackView.arrangedSubviews.last else { - return - } - - row.isSeparatorHidden = hideSeparators - - let isLast = (row === rows.last) - if isLast && autoHideLastRowSeparator { - row.isSeparatorHidden = true + private func updateRowsSeparatorVisibility() { + let rows = stackView.arrangedSubviews as? [ScrollStackRow] ?? [] + for (idx, row) in rows.enumerated() { + row.separatorView.isHidden = (idx == rows.last?.index ? true : row.isSeparatorHidden) } } diff --git a/Sources/ScrollStackController/ScrollStackRow.swift b/Sources/ScrollStackController/ScrollStackRow.swift index 0504f3c..1a75687 100644 --- a/Sources/ScrollStackController/ScrollStackRow.swift +++ b/Sources/ScrollStackController/ScrollStackRow.swift @@ -127,12 +127,15 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate { } open var isSeparatorHidden: Bool { - get { - return separatorView.isHidden - } - set { - separatorView.isHidden = newValue + didSet { + separatorView.isHidden = isSeparatorHidden } +// get { +// return separatorView.isHidden +// } +// set { +// separatorView.isHidden = newValue +// } } // MARK: Private Properties @@ -179,6 +182,7 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate { self.controller = nil self.contentView = view self.rowPadding = stackView.rowPadding + self.isSeparatorHidden = stackView.isSeparatorHidden super.init(frame: .zero) @@ -190,6 +194,8 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate { self.controller = controller self.contentView = controller.view self.rowPadding = stackView.rowPadding + self.isSeparatorHidden = stackView.isSeparatorHidden + super.init(frame: .zero) setupPostInit() @@ -237,6 +243,8 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate { didUpdateSeparatorAxis() applyParentStackAttributes() + + separatorView.isHidden = isSeparatorHidden } private func applyParentStackAttributes() {