mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-06-07 14:28:50 +00:00
Tab timeline tab top scroll to top
This commit is contained in:
parent
07a4ef856d
commit
315a57b447
4 changed files with 26 additions and 5 deletions
|
@ -16,7 +16,7 @@ extension View {
|
||||||
case let .statusDetail(id):
|
case let .statusDetail(id):
|
||||||
StatusDetailView(statusId: id)
|
StatusDetailView(statusId: id)
|
||||||
case let .hashTag(tag, accountId):
|
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):
|
case let .following(id):
|
||||||
AccountsListView(mode: .following(accountId: id))
|
AccountsListView(mode: .following(accountId: id))
|
||||||
case let .followers(id):
|
case let .followers(id):
|
||||||
|
|
|
@ -10,10 +10,11 @@ struct TimelineTab: View {
|
||||||
@StateObject private var routeurPath = RouterPath()
|
@StateObject private var routeurPath = RouterPath()
|
||||||
@Binding var popToRootTab: Tab
|
@Binding var popToRootTab: Tab
|
||||||
@State private var timeline: TimelineFilter = .home
|
@State private var timeline: TimelineFilter = .home
|
||||||
|
@State private var scrollToTopSignal: Int = 0
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
NavigationStack(path: $routeurPath.path) {
|
NavigationStack(path: $routeurPath.path) {
|
||||||
TimelineView(timeline: $timeline)
|
TimelineView(timeline: $timeline, scrollToTopSignal: $scrollToTopSignal)
|
||||||
.withAppRouteur()
|
.withAppRouteur()
|
||||||
.withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet)
|
.withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet)
|
||||||
.toolbar {
|
.toolbar {
|
||||||
|
@ -33,7 +34,11 @@ struct TimelineTab: View {
|
||||||
.environmentObject(routeurPath)
|
.environmentObject(routeurPath)
|
||||||
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in
|
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in
|
||||||
if popToRootTab == .timeline {
|
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)
|
.background(theme.primaryBackgroundColor)
|
||||||
}
|
}
|
||||||
.onAppear {
|
.onAppear {
|
||||||
|
|
|
@ -16,13 +16,18 @@ public struct TimelineView: View {
|
||||||
@EnvironmentObject private var account: CurrentAccount
|
@EnvironmentObject private var account: CurrentAccount
|
||||||
@EnvironmentObject private var watcher: StreamWatcher
|
@EnvironmentObject private var watcher: StreamWatcher
|
||||||
@EnvironmentObject private var client: Client
|
@EnvironmentObject private var client: Client
|
||||||
|
|
||||||
@StateObject private var viewModel = TimelineViewModel()
|
@StateObject private var viewModel = TimelineViewModel()
|
||||||
|
|
||||||
|
@State private var scrollProxy: ScrollViewProxy?
|
||||||
@Binding var timeline: TimelineFilter
|
@Binding var timeline: TimelineFilter
|
||||||
|
@Binding var scrollToTopSignal: Int
|
||||||
|
|
||||||
private let feedbackGenerator = UIImpactFeedbackGenerator()
|
private let feedbackGenerator = UIImpactFeedbackGenerator()
|
||||||
|
|
||||||
public init(timeline: Binding<TimelineFilter>) {
|
public init(timeline: Binding<TimelineFilter>, scrollToTopSignal: Binding<Int>) {
|
||||||
_timeline = timeline
|
_timeline = timeline
|
||||||
|
_scrollToTopSignal = scrollToTopSignal
|
||||||
}
|
}
|
||||||
|
|
||||||
public var body: some View {
|
public var body: some View {
|
||||||
|
@ -30,9 +35,11 @@ public struct TimelineView: View {
|
||||||
ZStack(alignment: .top) {
|
ZStack(alignment: .top) {
|
||||||
ScrollView {
|
ScrollView {
|
||||||
LazyVStack {
|
LazyVStack {
|
||||||
|
Rectangle()
|
||||||
|
.frame(height: 0)
|
||||||
|
.id(Constants.scrollToTop)
|
||||||
tagHeaderView
|
tagHeaderView
|
||||||
.padding(.bottom, 16)
|
.padding(.bottom, 16)
|
||||||
.id(Constants.scrollToTop)
|
|
||||||
StatusesListView(fetcher: viewModel)
|
StatusesListView(fetcher: viewModel)
|
||||||
}
|
}
|
||||||
.padding(.top, DS.Constants.layoutPadding)
|
.padding(.top, DS.Constants.layoutPadding)
|
||||||
|
@ -42,6 +49,9 @@ public struct TimelineView: View {
|
||||||
makePendingNewPostsView(proxy: proxy)
|
makePendingNewPostsView(proxy: proxy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onAppear {
|
||||||
|
scrollProxy = proxy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.navigationTitle(timeline.title())
|
.navigationTitle(timeline.title())
|
||||||
.navigationBarTitleDisplayMode(.inline)
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
|
@ -59,6 +69,11 @@ public struct TimelineView: View {
|
||||||
viewModel.handleEvent(event: latestEvent, currentAccount: account)
|
viewModel.handleEvent(event: latestEvent, currentAccount: account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.onChange(of: scrollToTopSignal, perform: { _ in
|
||||||
|
withAnimation {
|
||||||
|
scrollProxy?.scrollTo(Constants.scrollToTop, anchor: .top)
|
||||||
|
}
|
||||||
|
})
|
||||||
.onChange(of: timeline) { newTimeline in
|
.onChange(of: timeline) { newTimeline in
|
||||||
viewModel.timeline = timeline
|
viewModel.timeline = timeline
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue