LinkedInAttic / LayoutKit

LayoutKit is a fast view layout library for iOS, macOS, and tvOS.
http://layoutkit.org
Apache License 2.0
3.16k stars 267 forks source link

Weird top scrollViewOffset on ReloadableViewLayoutAdapter with UITableView #128

Closed Rep2 closed 7 years ago

Rep2 commented 7 years ago

I found a weird behaviour when using ReloadableViewLayoutAdapter with UITableView.

I am unable to remove tableView.topInset = 35. I think I have tried everything. Setting automaticallyAdjustsScrollViewInsets = false on all VCs in hierarchy and setting tableView.sectionHeaderHeight = 0, tableView.sectionFooterHeight = 0.

It is possible to set tableView.contentInset = UIEdgeInsets(top: -35, left: 0, bottom: 0, right: 0) but it seems too hacky.

The only thing that fixes this is changing

public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return currentArrangement[section].header?.frame.height ?? 0
}

to

public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return currentArrangement[section].header?.frame.height ?? CGFloat.leastNonzeroMagnitude
}

in extension ReloadableViewLayoutAdapter: UITableViewDelegate.

Setting header height to 0 results in it using default headerHeight value. Even though I have set tableView.sectionHeaderHeight = 0 it still adds topInset. Am I missing something?

I do not think default implementation should be CGFloat.leastNonzeroMagnitude. Better solution IMO would be to make method open.

staguer commented 7 years ago

Does this StackOverflow post explain this issue that you're seeing? http://stackoverflow.com/a/23664755

Rep2 commented 7 years ago

It describes the problem and uses (IMO hacky) solution tableView.contentInset = UIEdgeInsets(top: -35, left: 0, bottom: 0, right: 0).

I followed this post http://stackoverflow.com/questions/21069258/automaticallyadjustsscrollviewinsets-not-working and tried all solutions. Non except tableView.contentInset = UIEdgeInsets(top: -35, left: 0, bottom: 0, right: 0) work.

dgattey commented 7 years ago

Is your table view inside a view controller like that post described? If so, can you try following the steps they outlined for that situation?

Rep2 commented 7 years ago

Yes. I have tried setting it both as base view and adding it as a subview to the base view. Same behaviour on both cases.

I am not sure that LayoutKit is causing the problem, but it seems weird to me that manually setting the header view height to CGFloat.leastNonzeroMagnitude fixes the issue.