IceCubes/IceCubesApp/App/Tabs/MessagesTab.swift
Bosco Ho 1bf4d9e398
Feature: Tab bar scroll to top (#1598)
* - *WIP* Explore tab: Tap on tab to scroll to top.

* - Explore tab: Tap tab to scroll to top.

* - Explore: Tap tab again to focus on search bar.
- Explore: Set `.defaultMinListRowHeight` so scroll to view doesn't occupy more than 1pt height in grouped style list.
- Explore: Add padding to get Explore list view to look the same.

* - Explore: Minor adjust to padding.

* - Messages: Add tap tab to scroll to top.

* - Notifications: Add tap tab to scroll to top.

* - Profile: Add tap tab to scroll to top.

* Add `ScrollToView` that can be used across all views.

* Move scroll-to-top constants to ScrollToView.

* Format

---------

Co-authored-by: Thomas Ricouard <ricouard77@gmail.com>
2023-10-05 08:22:45 +02:00

56 lines
1.6 KiB
Swift

import Account
import AppAccount
import Conversations
import DesignSystem
import Env
import Models
import Network
import Shimmer
import SwiftUI
@MainActor
struct MessagesTab: View {
@Environment(Theme.self) private var theme
@Environment(StreamWatcher.self) private var watcher
@Environment(Client.self) private var client
@Environment(CurrentAccount.self) private var currentAccount
@Environment(AppAccountsManager.self) private var appAccount
@State private var routerPath = RouterPath()
@State private var scrollToTopSignal: Int = 0
@Binding var popToRootTab: Tab
var body: some View {
NavigationStack(path: $routerPath.path) {
ConversationsListView(scrollToTopSignal: $scrollToTopSignal)
.withAppRouter()
.withSheetDestinations(sheetDestinations: $routerPath.presentedSheet)
.toolbar {
if UIDevice.current.userInterfaceIdiom != .pad {
ToolbarItem(placement: .navigationBarLeading) {
AppAccountsSelectorView(routerPath: routerPath)
}
}
}
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar)
.id(client.id)
}
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
if newValue == .messages {
if routerPath.path.isEmpty {
scrollToTopSignal += 1
} else {
routerPath.path = []
}
}
}
.onChange(of: client.id) {
routerPath.path = []
}
.onAppear {
routerPath.client = client
}
.withSafariRouter()
.environment(routerPath)
}
}