Skip to content

Commit

Permalink
Bugfix: SectionFooterView AutoDimension Support
Browse files Browse the repository at this point in the history
Problem:
1. I noticed our app was manually laying out subviews in our sectionFooters when I didn't see the need to.

2. After recent changes, Group tableView's which had nil section extremity defaulted to zero, which drops the standard spacing between sections. Note in attatchment.

Notable info:
Statics currently has deploy target of iOS8, which did not yet support automatic sectionFooterView dimensioning.

Solution:
- Offer autosizing option which uses UITableViewAutomaticDimension rather than view's original bounds height. Retain original .view(_) case in the event some clients were already sizing beforehand limiting integration breaks. This also offers automatic margin adherence.
- Bump deploy target to iOS9 for clean integration.
- Revert 2 previous PRs
- Default height for plain/grouped styles to play friendly with tableView's defaults.
  • Loading branch information
Dane Miluski committed Oct 4, 2017
1 parent 722e5bb commit 58fcb2f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Static.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -481,7 +481,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0.1;
Expand Down
13 changes: 11 additions & 2 deletions Static/DataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ extension DataSource: UITableViewDataSource {
}

public func tableView(_ tableView: UITableView, heightForHeaderInSection sectionIndex: Int) -> CGFloat {
return section(at: sectionIndex)?.header?.viewHeight ?? UITableViewAutomaticDimension
return section(at: sectionIndex)?.header?.viewHeight ?? tableView.style.defaultSectionExtremityHeight
}

public func tableView(_ tableView: UITableView, titleForFooterInSection sectionIndex: Int) -> String? {
Expand All @@ -216,7 +216,7 @@ extension DataSource: UITableViewDataSource {
}

public func tableView(_ tableView: UITableView, heightForFooterInSection sectionIndex: Int) -> CGFloat {
return section(at: sectionIndex)?.footer?.viewHeight ?? UITableViewAutomaticDimension
return section(at: sectionIndex)?.footer?.viewHeight ?? tableView.style.defaultSectionExtremityHeight
}

public func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
Expand Down Expand Up @@ -283,3 +283,12 @@ extension DataSource: UITableViewDelegate {
}
}
}

extension UITableViewStyle {
var defaultSectionExtremityHeight: CGFloat {
switch self {
case .plain: return 0
case .grouped: return UITableViewAutomaticDimension
}
}
}
12 changes: 10 additions & 2 deletions Static/Section.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public struct Section: Hashable, Equatable {
/// Custom view for the header or footer. The height will be the view's `bounds.height`.
case view(UIView)

// View Sized with autolayout
// If Pre iOS11: Requires tableview estimatedSectionHeader/FooterHeight to be > 0
case autoLayoutView(UIView)

var _title: String? {
switch self {
case .title(let extremityTitle): return extremityTitle
Expand All @@ -23,12 +27,16 @@ public struct Section: Hashable, Equatable {
var _view: UIView? {
switch self {
case .view(let extremityView): return extremityView
case .autoLayoutView(let extremityView): return extremityView
default: return nil
}
}

var viewHeight: CGFloat? {
return _view?.bounds.height
var viewHeight: CGFloat {
switch self {
case .title(_), .autoLayoutView(_): return UITableViewAutomaticDimension
case .view(let view): return view.bounds.height
}
}
}

Expand Down

0 comments on commit 58fcb2f

Please sign in to comment.