Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: SectionFooterView AutoDimension Support #110

Merged

Conversation

dmiluski
Copy link
Contributor

@dmiluski dmiluski commented Aug 29, 2017

Problem:

  1. I noticed our app was manually laying out subviews in our sectionFooters when I didn't see the need to. (Given auto-layout/intrinsic size support)

eg.. (Unnecessarily maintaining and calculation including insets/frame)

    override func layoutSubviews() {
        super.layoutSubviews()
        var frame = self.frame
        frame.size = CGSize(width: frame.size.width, height: signUpInstructionsLabel.systemLayoutSizeFitting(UILayoutFittingCompressedSize).height + textInsets.top + textInsets.bottom)
        self.frame = frame
    }
  1. After recent changes, Group tableView's which had nil section extremity defaulted to zero, which drops the standard spacing between sections. (Using current master)

screen shot 2017-08-28 at 9 39 07 pm

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.
  • Bump deploy target to iOS9 for clean integration.
  • Revert 2 previous PRs focused on same issue

Testing:
Tested with simulators

  • iOS11 beta5 on iPhone 7 (Friendly)
  • iOS 10.3 on iPhone 6. (Requires owner to set estimatedSectionHeader/FooterHeights to > 0

Did not test on iOS 9

Dane Miluski added 2 commits August 28, 2017 20:56
…ension if the view returns as 0 (venmo#109)"

This reverts commit 319a8b8.
…fix"

This reverts commit 2071110, reversing
changes made to e002d86.
@dmiluski
Copy link
Contributor Author

Hi Neal, is this change friendly to your issue you saw? Care to test with this branch?

@dmiluski
Copy link
Contributor Author

@hyperspacemark @eliperkins @rhaining for further review

@@ -13,6 +13,9 @@ 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
case autoLayoutView(UIView)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely not tied to this naming since in my current case name, but wanted to convey this would handle automatic dimensioning rather than use the views set bounds.height. Only added a new case to prevent previous integration breaks.

My current use case adds stackViews without constraints, but ended up using this to not break existing .view(_) sizing.

@dmiluski
Copy link
Contributor Author

dmiluski commented Oct 4, 2017

@rhaining @hyperspacemark Finally found my error.

This PR works in supporting Autolayout FooterViews in iOS10/11.

BUT:
in order for it to function in iOS 10, estimatedHeights must be set > 0. I unfortunately was setting to UITableViewAutomaticDimension == -1 🤦‍♂️

Example Working:
tableView.estimatedSectionFooterHeight = 20
tableView.estimatedSectionHeaderHeight = 20

@@ -13,6 +13,9 @@ 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
case autoLayoutView(UIView)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If using this view, must set estimated header/footer height to > 0, if using tableView's before iOS11

@dmiluski dmiluski force-pushed the bugfix/headerFooterAutoLayoutSupport branch from 2d8c055 to 285bcf2 Compare October 4, 2017 01:31
headerHeight = UITableViewAutomaticDimension
}
return headerHeight
return section(at: sectionIndex)?.header?.viewHeight ?? UITableViewAutomaticDimension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the thing we lose here is that if there's no header defined for this section, we're returning 'automatic dimension' now, versus in the previous code, we're returning 0 in that case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this returns 0 if the table style is 'plain', and auto dimension if the table style is 'grouped' ??

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double checking plain vs grouped once more

footerHeight = UITableViewAutomaticDimension
}
return footerHeight
return section(at: sectionIndex)?.footer?.viewHeight ?? UITableViewAutomaticDimension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar question here

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.
@dmiluski dmiluski force-pushed the bugfix/headerFooterAutoLayoutSupport branch from 285bcf2 to 58fcb2f Compare October 4, 2017 16:45
@dmiluski
Copy link
Contributor Author

dmiluski commented Oct 4, 2017

Followed up with a change for default heights.

By returning autodimension height by default, plain tableViews were taking non-standard heights with nil extremities. Update to use a default height between styles which performs equivalent to default handling if nil vs filled extremities

Also updated Example code with example of how to create an autosized extremity

@rhaining rhaining merged commit 8ae55ef into venmo:master Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants