Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Sources/Classes/Sort Functions/Operations/ViewOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,23 @@ public extension Spruce {
/// - Note: This method will return an array of `View`. These are used so that when we adjust for coordinate space differences, it does not affect the way your screen renders. A `View` is a simple struct with `view: UIView` and `referencePoint: CGPoint` variables.
/// - Precondition: `recursiveDepth` is an Int >= 0 (0...Int.max).
public func subviews(withRecursiveDepth recursiveDepth: Int) -> [View] {
let subviews: [UIView]
var subviews: [UIView]

// Handle special cases for UITableView and UICollectionView
switch self.view {
case let tableView as UITableView:
subviews = tableView.visibleCells
if Spruce.includeTableViewSectionHeaders, let indexPaths = tableView.indexPathsForVisibleRows {
let sections = Set(indexPaths.map({$0.section}))
let sectionHeaders = sections.map({tableView.headerView(forSection: $0)}).filter({$0 != nil}).map({$0!})
subviews.append(contentsOf: sectionHeaders as [UIView])
}
case let collectionView as UICollectionView:
subviews = collectionView.visibleCells
if Spruce.includeCollectionViewSectionHeaders {
let sectionHeaders = collectionView.visibleSupplementaryViews(ofKind: UICollectionElementKindSectionHeader)
subviews.append(contentsOf: sectionHeaders as [UIView])
}
default:
subviews = self.view.subviews
}
Expand Down
3 changes: 3 additions & 0 deletions Sources/Classes/Spruce.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public struct Spruce {
internal init(view: UIView) {
self.view = view
}

public static var includeTableViewSectionHeaders = false
public static var includeCollectionViewSectionHeaders = false
}

/// Used to keep track of the `UIView` object and a changing reference point. Since Spruce allows for
Expand Down