Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Tap tab button again to scroll to top #1070

Merged
merged 6 commits into from
Jan 16, 2024
Merged

Conversation

bfollington
Copy link
Collaborator

@bfollington bfollington commented Jan 15, 2024

Fixes #991

Pretty simple, using ScrollReaderView for iOS 16 support but we could clean this up a little using the newer iOS 17 APIs down the line.

  • Tap tab button again to scroll to top of lists
  • Move away from .enumerated()
Screen.Recording.2024-01-15.at.4.34.17.pm.mov
Screen.Recording.2024-01-15.at.6.31.00.pm.mov

@bfollington bfollington force-pushed the 2024-01-15-scroll-to-top branch from a536e4f to dd33b38 Compare January 15, 2024 05:25
Comment on lines +286 to +288
ForEach(deck.indices, id: \.self) { index in
let card = deck[index]

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apparently there are problems with using enumerated() this way that can result in BAD_ACCESS errors, see: https://stackoverflow.com/a/63145650

Using indices is apparently safer and seems equally readable.

@bfollington bfollington marked this pull request as ready for review January 15, 2024 05:44
Copy link
Collaborator

@gordonbrander gordonbrander left a comment

Choose a reason for hiding this comment

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

One note, otherwise LGTM

@@ -35,6 +37,7 @@ struct EntryListView: View {
onLink: onLink
)
}
.id(idx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is likely to cause issues, as ids are meant to be stable identifiers tied to records. If the record changed but had same index, or if the same record changed index, we might see view invalidation bugs.

Should replace with a stable record ID of some sort.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good note, I've ditched this approach and inserted an EmptyView with a stable .id() at the top instead. This is easier to read as well imo, so win-win.

Copy link
Collaborator

@gordonbrander gordonbrander left a comment

Choose a reason for hiding this comment

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

LGTM

@bfollington bfollington merged commit 86b3c91 into main Jan 16, 2024
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tapping tab while on tab should scroll to top
2 participants