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

Support tappable headers #193

Merged
merged 5 commits into from
Aug 13, 2020
Merged

Support tappable headers #193

merged 5 commits into from
Aug 13, 2020

Conversation

kyleve
Copy link
Collaborator

@kyleve kyleve commented Aug 11, 2020

This PR introduces support for tappable headers and footers, by adding an onTap handler to HeaderFooter. When provided, the header becomes tappable, and you can provide a pressedBackgroundView to appear, similar to the selectedBackgroundView of cells.

There's some unrelated changes to how zIndexing is done to improve determinism in layout, and there are also some fixes to bugs I found alongside this work.

@kyleve kyleve force-pushed the kve/zindex-ordered-by-global-index branch from fc59087 to 69ccbe1 Compare August 11, 2020 02:17
@kyleve
Copy link
Collaborator Author

kyleve commented Aug 11, 2020

We should allow pinning items, so these headers can be pinned

@kyleve kyleve changed the title Order ZIndex by global index [DRAFT] Support tappable headers Aug 12, 2020
@kyleve kyleve marked this pull request as draft August 12, 2020 01:37
@@ -10,12 +10,12 @@ import Foundation

extension ListView
{
struct VisibleContent
final class VisibleContent
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is needed to fix an unrelated bug that I found working on this; needs to be a class to avoid exclusive access crashes.

@kyleve kyleve force-pushed the kve/zindex-ordered-by-global-index branch from 1e27376 to 316af9a Compare August 13, 2020 20:55
…-global-index

* origin/main:
  Add demo for manual selection management
@kyleve kyleve changed the title [DRAFT] Support tappable headers Support tappable headers Aug 13, 2020
@kyleve
Copy link
Collaborator Author

kyleve commented Aug 13, 2020

Alright, this should be good to go now

@kyleve kyleve marked this pull request as ready for review August 13, 2020 21:06
CHANGELOG.md Outdated Show resolved Hide resolved

switch state {

case .possible, .began, .changed:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it right to include possible here? The docs say that's the "default" state, but maybe that's not true for concrete subclasses?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh yeah, doh. I wonder how this works at all...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed!

case .ended, .cancelled, .failed:
let didEnd = state == .ended

UIView.animate(withDuration: didEnd ? 0.1 : 0.0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

UITableView doesn't animate deselection except when specified, and it's more like 0.3s - not sure we shouldn't do this, but seems rather arbitrary

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted this animated, since it's basically like a button press, and it looks nicer when the press ends with an animation, IMO.

}


fileprivate final class PressGestureRecognizer : UILongPressGestureRecognizer {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm curious why you're using a long press gesture for this? Does it recognize a quick tap?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I needed a continuous gesture recognizer, a tap recognizer is discrete (it calls you on tap and then is done), which isnt how row selection works in list views; eg how you can press down, hold, and then release to trigger a row selection.

Or put another way, this mimics the row selection behavior UICollectionView provides.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(And it does recognize a tap, since I set the min duration to 0:)

        self.pressRecognizer = PressGestureRecognizer()
        self.pressRecognizer.minimumPressDuration = 0.0
        self.pressRecognizer.allowableMovementAfterBegin = 5.0

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah gotcha, just noticed the minimumPressDuration set to 0 above - missed that before

{
let view = self.collectionView!

self.layout.positionStickySectionHeadersIfNeeded(in: view)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious why you moved this out of updateLayout - is there a case where you'd update the layout with positioning the headers?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since this was getting called in multiple layouts, I figured it made sense to centralize it here; which seemed to make sense.

}

let kind : SupplementaryKind
let layout : HeaderFooterLayout
let measurer : (Sizing.MeasureInfo) -> CGSize

let isPopulated : Bool

Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't actually matter ofc, but there's a checkbox in Xcode to strip whitespace from empty lines to prevent this in diffs :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Huh, TIL!

@@ -95,16 +95,24 @@ extension PresentationState
cache.push(view, with: self.model.reuseIdentifier)
}

func createReusableHeaderFooterView(frame : CGRect) -> UIView
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unused

@kyleve kyleve merged commit 53b9c51 into main Aug 13, 2020
@kyleve kyleve deleted the kve/zindex-ordered-by-global-index branch August 13, 2020 23:17
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.

3 participants