Tab timeline tab top scroll to top
This commit is contained in:
parent
07a4ef856d
commit
315a57b447
|
@ -16,7 +16,7 @@ extension View {
|
|||
case let .statusDetail(id):
|
||||
StatusDetailView(statusId: id)
|
||||
case let .hashTag(tag, accountId):
|
||||
TimelineView(timeline: .constant(.hashtag(tag: tag, accountId: accountId)))
|
||||
TimelineView(timeline: .constant(.hashtag(tag: tag, accountId: accountId)), scrollToTopSignal: .constant(0))
|
||||
case let .following(id):
|
||||
AccountsListView(mode: .following(accountId: id))
|
||||
case let .followers(id):
|
||||
|
|
|
@ -10,10 +10,11 @@ struct TimelineTab: View {
|
|||
@StateObject private var routeurPath = RouterPath()
|
||||
@Binding var popToRootTab: Tab
|
||||
@State private var timeline: TimelineFilter = .home
|
||||
@State private var scrollToTopSignal: Int = 0
|
||||
|
||||
var body: some View {
|
||||
NavigationStack(path: $routeurPath.path) {
|
||||
TimelineView(timeline: $timeline)
|
||||
TimelineView(timeline: $timeline, scrollToTopSignal: $scrollToTopSignal)
|
||||
.withAppRouteur()
|
||||
.withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet)
|
||||
.toolbar {
|
||||
|
@ -33,7 +34,11 @@ struct TimelineTab: View {
|
|||
.environmentObject(routeurPath)
|
||||
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in
|
||||
if popToRootTab == .timeline {
|
||||
routeurPath.path = []
|
||||
if routeurPath.path.isEmpty {
|
||||
scrollToTopSignal += 1
|
||||
} else {
|
||||
routeurPath.path = []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ public struct AccountDetailView: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(theme.primaryBackgroundColor)
|
||||
}
|
||||
.onAppear {
|
||||
|
|
|
@ -16,13 +16,18 @@ public struct TimelineView: View {
|
|||
@EnvironmentObject private var account: CurrentAccount
|
||||
@EnvironmentObject private var watcher: StreamWatcher
|
||||
@EnvironmentObject private var client: Client
|
||||
|
||||
@StateObject private var viewModel = TimelineViewModel()
|
||||
|
||||
@State private var scrollProxy: ScrollViewProxy?
|
||||
@Binding var timeline: TimelineFilter
|
||||
@Binding var scrollToTopSignal: Int
|
||||
|
||||
private let feedbackGenerator = UIImpactFeedbackGenerator()
|
||||
|
||||
public init(timeline: Binding<TimelineFilter>) {
|
||||
public init(timeline: Binding<TimelineFilter>, scrollToTopSignal: Binding<Int>) {
|
||||
_timeline = timeline
|
||||
_scrollToTopSignal = scrollToTopSignal
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
|
@ -30,9 +35,11 @@ public struct TimelineView: View {
|
|||
ZStack(alignment: .top) {
|
||||
ScrollView {
|
||||
LazyVStack {
|
||||
Rectangle()
|
||||
.frame(height: 0)
|
||||
.id(Constants.scrollToTop)
|
||||
tagHeaderView
|
||||
.padding(.bottom, 16)
|
||||
.id(Constants.scrollToTop)
|
||||
StatusesListView(fetcher: viewModel)
|
||||
}
|
||||
.padding(.top, DS.Constants.layoutPadding)
|
||||
|
@ -42,6 +49,9 @@ public struct TimelineView: View {
|
|||
makePendingNewPostsView(proxy: proxy)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
scrollProxy = proxy
|
||||
}
|
||||
}
|
||||
.navigationTitle(timeline.title())
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
|
@ -59,6 +69,11 @@ public struct TimelineView: View {
|
|||
viewModel.handleEvent(event: latestEvent, currentAccount: account)
|
||||
}
|
||||
}
|
||||
.onChange(of: scrollToTopSignal, perform: { _ in
|
||||
withAnimation {
|
||||
scrollProxy?.scrollTo(Constants.scrollToTop, anchor: .top)
|
||||
}
|
||||
})
|
||||
.onChange(of: timeline) { newTimeline in
|
||||
viewModel.timeline = timeline
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue