IceCubes/IceCubesApp/App/Tabs/ExploreTab.swift

48 lines
1.3 KiB
Swift
Raw Normal View History

2023-01-17 11:36:01 +01:00
import AppAccount
import DesignSystem
import Env
import Explore
2023-01-17 11:36:01 +01:00
import Models
import Network
2023-01-17 11:36:01 +01:00
import SwiftUI
2023-09-19 09:18:20 +02:00
@MainActor
struct ExploreTab: View {
2023-09-18 21:03:52 +02:00
@Environment(Theme.self) private var theme
2023-09-19 09:18:20 +02:00
@Environment(UserPreferences.self) private var preferences
@Environment(CurrentAccount.self) private var currentAccount
@Environment(Client.self) private var client
@State private var routerPath = RouterPath()
@State private var scrollToTopSignal: Int = 0
2022-12-27 09:25:26 +01:00
@Binding var popToRootTab: Tab
2023-01-17 11:36:01 +01:00
var body: some View {
NavigationStack(path: $routerPath.path) {
ExploreView(scrollToTopSignal: $scrollToTopSignal)
.withAppRouter()
.withSheetDestinations(sheetDestinations: $routerPath.presentedSheet)
2024-01-23 08:51:58 +01:00
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.30), for: .navigationBar)
2022-12-29 17:22:07 +01:00
.toolbar {
ToolbarTab(routerPath: $routerPath)
2022-12-29 17:22:07 +01:00
}
}
.withSafariRouter()
.environment(routerPath)
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
if newValue == .explore {
if routerPath.path.isEmpty {
scrollToTopSignal += 1
} else {
routerPath.path = []
}
2022-12-24 11:50:05 +01:00
}
}
.onChange(of: client.id) {
routerPath.path = []
}
.onAppear {
routerPath.client = client
}
}
}