This commit is contained in:
Thomas Ricouard 2024-09-15 08:06:10 +02:00
parent 122e57d8ac
commit 8f71f6649a
2 changed files with 46 additions and 38 deletions

View file

@ -115,8 +115,11 @@ struct AppView: View {
#if !os(visionOS)
var sidebarView: some View {
SideBarView(selectedTab: $selectedTab,
tabs: availableTabs)
SideBarView(selectedTab: .init(get: {
selectedTab
}, set: { newTab in
updateTab(with: newTab)
}), tabs: availableTabs)
{
HStack(spacing: 0) {
if #available(iOS 18.0, *) {
@ -142,6 +145,7 @@ struct AppView: View {
}
}
.environment(appRouterPath)
.environment(\.selectedTabScrollToTop, selectedTabScrollToTop)
}
#endif

View file

@ -47,42 +47,7 @@ public struct TimelineView: View {
public var body: some View {
ZStack(alignment: .top) {
ScrollViewReader { proxy in
List {
scrollToTopView
TimelineTagGroupheaderView(group: $selectedTagGroup, timeline: $timeline)
TimelineTagHeaderView(tag: $viewModel.tag)
switch viewModel.timeline {
case .remoteLocal:
StatusesListView(fetcher: viewModel, client: client, routerPath: routerPath, isRemote: true)
default:
StatusesListView(fetcher: viewModel, client: client, routerPath: routerPath)
.environment(\.isHomeTimeline, timeline == .home)
}
}
.id(client.id)
.environment(\.defaultMinListRowHeight, 1)
.listStyle(.plain)
.onChange(of: selectedTabScrollToTop) { _, newValue in
if newValue == 0, routerPath.path.isEmpty {
withAnimation {
proxy.scrollTo(ScrollToView.Constants.scrollToTop, anchor: .top)
}
}
}
#if !os(visionOS)
.scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor)
#endif
.introspect(.list, on: .iOS(.v17, .v18)) { (collectionView: UICollectionView) in
DispatchQueue.main.async {
self.collectionView = collectionView
}
prefetcher.viewModel = viewModel
collectionView.isPrefetchingEnabled = true
collectionView.prefetchDataSource = prefetcher
}
}
listView
if viewModel.timeline.supportNewestPagination {
TimelineUnreadStatusesView(observer: viewModel.pendingStatusesObserver)
}
@ -210,6 +175,45 @@ public struct TimelineView: View {
}
}
}
private var listView: some View {
ScrollViewReader { proxy in
List {
scrollToTopView
TimelineTagGroupheaderView(group: $selectedTagGroup, timeline: $timeline)
TimelineTagHeaderView(tag: $viewModel.tag)
switch viewModel.timeline {
case .remoteLocal:
StatusesListView(fetcher: viewModel, client: client, routerPath: routerPath, isRemote: true)
default:
StatusesListView(fetcher: viewModel, client: client, routerPath: routerPath)
.environment(\.isHomeTimeline, timeline == .home)
}
}
.id(client.id)
.environment(\.defaultMinListRowHeight, 1)
.listStyle(.plain)
#if !os(visionOS)
.scrollContentBackground(.hidden)
.background(theme.primaryBackgroundColor)
#endif
.introspect(.list, on: .iOS(.v17, .v18)) { (collectionView: UICollectionView) in
DispatchQueue.main.async {
self.collectionView = collectionView
}
prefetcher.viewModel = viewModel
collectionView.isPrefetchingEnabled = true
collectionView.prefetchDataSource = prefetcher
}
.onChange(of: selectedTabScrollToTop) { _, newValue in
if newValue == 0, routerPath.path.isEmpty {
withAnimation {
proxy.scrollTo(ScrollToView.Constants.scrollToTop, anchor: .top)
}
}
}
}
}
@ToolbarContentBuilder
private var toolbarTitleView: some ToolbarContent {