diff --git a/IceCubesApp/App/Main/AppView.swift b/IceCubesApp/App/Main/AppView.swift index 01e35488..f798de8e 100644 --- a/IceCubesApp/App/Main/AppView.swift +++ b/IceCubesApp/App/Main/AppView.swift @@ -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 diff --git a/Packages/Timeline/Sources/Timeline/View/TimelineView.swift b/Packages/Timeline/Sources/Timeline/View/TimelineView.swift index 40303980..b4c412b8 100644 --- a/Packages/Timeline/Sources/Timeline/View/TimelineView.swift +++ b/Packages/Timeline/Sources/Timeline/View/TimelineView.swift @@ -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 {