I’m working on an app where I have one or more featured, full screen views presented before the rest of the “explore” content (think home page on Spotify).
I have the following structure at the moment:
GeometryReader { proxy in
let h = proxy.size.height
ScrollView {
if data == nil {
Recommended(event: nil)
.padding(.vertical, 8)
.frame(height: h)
.frame(maxWidth: .infinity)
} else {
LazyVStack(spacing: proxy.safeAreaInsets.bottom / 2) {
ForEach(data?.recommended ?? []) { _ in
Recommended(event: events[0])
.padding(.vertical, 8)
.frame(height: h)
.frame(maxWidth: .infinity)
.padding(.bottom, proxy.safeAreaInsets.bottom / 2)
}
}
.scrollTargetLayout()
}
if let sections = data?.sections {
LazyVStack(spacing: 32) {
ForEach(Array(sections.enumerated()), id: .offset) { e in
let section = e.element
EventRow(title: section.title, events: section.events)
}
}
.scrollTargetLayout()
}
Spacer()
}
// .scrollPosition(id: $scrollID) this was an attempt
// .scrollTargetBehavior(.custom) this was another attempt
.scrollDisabled(data == nil)
.scrollIndicators(.hidden)
.ignoresSafeArea(.container)
.refreshable {
print("refresh")
}
.onChange(of: scrollID) { _, newValue in
print(newValue ?? "")
}
}
I attempted to switch the paging style based off the scrollID
but got the following after writing a ternary
.scrollTargetBehavior(true ? .paging : .viewAligned)
// Member 'viewAligned' in 'PagingScrollTargetBehavior' produces result of type 'ViewAlignedScrollTargetBehavior', but context expects 'PagingScrollTargetBehavior'
I was also looking into a custom implementation of scroll target behavior but my experimentation yielded few results.