Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
malcommac committed Sep 25, 2020
2 parents 0dea6e1 + 22ec633 commit 4263d85
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions ScrollStackController.podspec
Original file line number Diff line number Diff line change
@@ -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" }
Expand All @@ -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
Binary file not shown.
17 changes: 13 additions & 4 deletions ScrollStackControllerDemo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down
34 changes: 9 additions & 25 deletions Sources/ScrollStackController/ScrollStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ open class ScrollStack: UIScrollView, UIScrollViewDelegate {
/// Hide automatically the last separator.
open var autoHideLastRowSeparator = false {
didSet {
updateRowSeparatorVisibility(lastRow)
updateRowsSeparatorVisibility()
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
}

Expand Down
18 changes: 13 additions & 5 deletions Sources/ScrollStackController/ScrollStackRow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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()
Expand Down Expand Up @@ -237,6 +243,8 @@ open class ScrollStackRow: UIView, UIGestureRecognizerDelegate {
didUpdateSeparatorAxis()

applyParentStackAttributes()

separatorView.isHidden = isSeparatorHidden
}

private func applyParentStackAttributes() {
Expand Down

0 comments on commit 4263d85

Please sign in to comment.