From 8f71f6649a80a985e7a1f688ce9665a41ace6176 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sun, 15 Sep 2024 08:06:10 +0200 Subject: [PATCH] Fixes --- IceCubesApp/App/Main/AppView.swift | 8 +- .../Sources/Timeline/View/TimelineView.swift | 76 ++++++++++--------- 2 files changed, 46 insertions(+), 38 deletions(-) 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 {