Revert "Switch to using LazyVStack for the Timeline"

This reverts commit 9878ca4b17.
This commit is contained in:
Maurice Parker 2020-07-27 10:24:32 -05:00
parent 9878ca4b17
commit 6b08b1e48b
2 changed files with 51 additions and 62 deletions

View File

@ -17,6 +17,13 @@ struct TimelineItemView: View {
var width: CGFloat
var timelineItem: TimelineItem
#if os(macOS)
var verticalPadding: CGFloat = 10
#endif
#if os(iOS)
var verticalPadding: CGFloat = 0
#endif
var body: some View {
HStack(alignment: .top) {
TimelineItemStatusView(selected: selected, status: timelineItem.status)
@ -58,8 +65,7 @@ struct TimelineItemView: View {
}
}
}
.padding(.vertical, 10)
.padding(.horizontal)
.padding(.vertical, verticalPadding)
.onAppear {
articleIconImageLoader.loadImage(for: timelineItem.article)
}

View File

@ -15,7 +15,6 @@ struct TimelineView: View {
@EnvironmentObject private var timelineModel: TimelineModel
@State private var navigate = false
@State private var timelineItemFrames = [String: CGRect]()
@ViewBuilder var body: some View {
@ -41,16 +40,11 @@ struct TimelineView: View {
.buttonStyle(PlainButtonStyle())
.help(isReadFiltered ?? false ? "Show Read Articles" : "Filter Read Articles")
}
ScrollView {
ScrollViewReader { scrollViewProxy in
LazyVStack {
ForEach(timelineItems.items) { timelineItem in
List(timelineItems.items, selection: $timelineModel.selectedTimelineItemIDs) { timelineItem in
let selected = timelineModel.selectedTimelineItemIDs.contains(timelineItem.article.articleID)
TimelineItemView(selected: selected, width: geometryReaderProxy.size.width, timelineItem: timelineItem)
.background(TimelineItemBackgroundView(selected: selected, timelineItem: timelineItem))
.onTapGesture {
timelineModel.selectedTimelineItemIDs = Set([timelineItem.id])
}
.background(TimelineItemFramePreferenceView(timelineItem: timelineItem))
}
.onPreferenceChange(TimelineItemFramePreferenceKey.self) { preferences in
for pref in preferences {
@ -71,25 +65,19 @@ struct TimelineView: View {
}
}
}
}
}
.navigationTitle(Text(verbatim: timelineModel.nameForDisplay))
#else
ZStack {
NavigationLink(destination: ArticleView(), isActive: $navigate) {
EmptyView()
}
ScrollView {
ScrollViewReader { scrollViewProxy in
LazyVStack {
ForEach(timelineItems.items) { timelineItem in
List(timelineItems.items) { timelineItem in
ZStack {
let selected = timelineModel.selectedTimelineItemID == timelineItem.article.articleID
TimelineItemView(selected: selected, width: geometryReaderProxy.size.width, timelineItem: timelineItem)
.background(TimelineItemBackgroundView(selected: selected, timelineItem: timelineItem))
.onTapGesture {
timelineModel.selectedTimelineItemIDs = Set([timelineItem.id])
navigate = true
}
.background(TimelineItemFramePreferenceView(timelineItem: timelineItem))
NavigationLink(destination: ArticleContainerView(),
tag: timelineItem.article.articleID,
selection: $timelineModel.selectedTimelineItemID) {
EmptyView()
}.buttonStyle(PlainButtonStyle())
}
}
.onPreferenceChange(TimelineItemFramePreferenceKey.self) { preferences in
@ -108,8 +96,6 @@ struct TimelineView: View {
}
}
}
}
}
.navigationBarTitle(Text(verbatim: timelineModel.nameForDisplay), displayMode: .inline)
#endif
}
@ -132,16 +118,13 @@ struct TimelineItemFramePreference: Equatable {
let frame: CGRect
}
struct TimelineItemBackgroundView: View {
let selected: Bool
struct TimelineItemFramePreferenceView: View {
let timelineItem: TimelineItem
var body: some View {
GeometryReader { proxy in
Rectangle()
.fill(selected ? Color.accentColor : Color.clear)
.cornerRadius(6)
.fill(Color.clear)
.preference(key: TimelineItemFramePreferenceKey.self,
value: [TimelineItemFramePreference(articleID: timelineItem.article.articleID, frame: proxy.frame(in: .global))])
}