Skip to content

Commit

Permalink
Remove popToRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimillian committed Jul 9, 2024
1 parent 3ec5c8c commit 7c2e8d6
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 93 deletions.
2 changes: 1 addition & 1 deletion IceCubesApp/App/AppRegistry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ extension View {
StatusEditHistoryView(statusId: status)
.withEnvironments()
case .settings:
SettingsTabs(popToRootTab: .constant(.settings), isModal: true)
SettingsTabs(isModal: true)
.withEnvironments()
.preferredColorScheme(Theme.shared.selectedScheme == .dark ? .dark : .light)
case .accountPushNotficationsSettings:
Expand Down
19 changes: 5 additions & 14 deletions IceCubesApp/App/Main/AppView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ struct AppView: View {
@Binding var selectedTab: AppTab
@Binding var appRouterPath: RouterPath

@State var popToRootTab: AppTab = .other
@State var iosTabs = iOSTabs.shared
@State var sidebarTabs = SidebarTabs.shared

Expand Down Expand Up @@ -64,21 +63,14 @@ struct AppView: View {
#endif
return
}
if newTab == selectedTab {
/// Stupid hack to trigger onChange binding in tab views.
popToRootTab = .other
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
popToRootTab = selectedTab
}
}


HapticManager.shared.fireHaptic(.tabSelection)
SoundEffectManager.shared.playSound(.tabSelection)

selectedTab = newTab
})) {
ForEach(availableTabs) { tab in
tab.makeContentView(selectedTab: $selectedTab, popToRootTab: $popToRootTab)
tab.makeContentView(selectedTab: $selectedTab)
.tabItem {
if userPreferences.showiPhoneTabLabel {
tab.label
Expand Down Expand Up @@ -108,14 +100,13 @@ struct AppView: View {
#if !os(visionOS)
var sidebarView: some View {
SideBarView(selectedTab: $selectedTab,
popToRootTab: $popToRootTab,
tabs: availableTabs)
{
HStack(spacing: 0) {
TabView(selection: $selectedTab) {
ForEach(availableTabs) { tab in
Tab(value: tab) {
tab.makeContentView(selectedTab: $selectedTab, popToRootTab: $popToRootTab)
tab.makeContentView(selectedTab: $selectedTab)
} label: {
tab.label
}
Expand All @@ -142,8 +133,8 @@ struct AppView: View {
#endif

var notificationsSecondaryColumn: some View {
NotificationsTab(selectedTab: .constant(.notifications),
popToRootTab: $popToRootTab, lockedType: nil)
NotificationsTab(selectedTab: .constant(.notifications)
, lockedType: nil)
.environment(\.isSecondaryColumn, true)
.frame(maxWidth: .secondaryColumnWidth)
.id(appAccountsManager.currentAccount.id)
Expand Down
8 changes: 0 additions & 8 deletions IceCubesApp/App/SideBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ struct SideBarView<Content: View>: View {
@Environment(RouterPath.self) private var routerPath

@Binding var selectedTab: AppTab
@Binding var popToRootTab: AppTab
var tabs: [AppTab]
@ViewBuilder var content: () -> Content

Expand Down Expand Up @@ -143,13 +142,6 @@ struct SideBarView<Content: View>: View {
Button {
// ensure keyboard is always dismissed when selecting a tab
hideKeyboard()

if tab == selectedTab {
popToRootTab = .other
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
popToRootTab = tab
}
}
selectedTab = tab
SoundEffectManager.shared.playSound(.tabSelection)
if tab == .notifications {
Expand Down
10 changes: 0 additions & 10 deletions IceCubesApp/App/Tabs/ExploreTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct ExploreTab: View {
@Environment(Client.self) private var client
@State private var routerPath = RouterPath()
@State private var scrollToTopSignal: Int = 0
@Binding var popToRootTab: AppTab

var body: some View {
NavigationStack(path: $routerPath.path) {
Expand All @@ -28,15 +27,6 @@ struct ExploreTab: View {
}
.withSafariRouter()
.environment(routerPath)
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
if newValue == .explore {
if routerPath.path.isEmpty {
scrollToTopSignal += 1
} else {
routerPath.path = []
}
}
}
.onChange(of: client.id) {
routerPath.path = []
}
Expand Down
10 changes: 0 additions & 10 deletions IceCubesApp/App/Tabs/MessagesTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ struct MessagesTab: View {
@Environment(AppAccountsManager.self) private var appAccount
@State private var routerPath = RouterPath()
@State private var scrollToTopSignal: Int = 0
@Binding var popToRootTab: AppTab

var body: some View {
NavigationStack(path: $routerPath.path) {
Expand All @@ -29,15 +28,6 @@ struct MessagesTab: View {
.toolbarBackground(theme.primaryBackgroundColor.opacity(0.30), 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 = []
}
Expand Down
10 changes: 0 additions & 10 deletions IceCubesApp/App/Tabs/NotificationTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ struct NotificationsTab: View {
@State private var scrollToTopSignal: Int = 0

@Binding var selectedTab: AppTab
@Binding var popToRootTab: AppTab

let lockedType: Models.Notification.NotificationType?

Expand Down Expand Up @@ -51,15 +50,6 @@ struct NotificationsTab: View {
}
.withSafariRouter()
.environment(routerPath)
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
if newValue == .notifications {
if routerPath.path.isEmpty {
scrollToTopSignal += 1
} else {
routerPath.path = []
}
}
}
.onChange(of: selectedTab) { _, _ in
clearNotifications()
}
Expand Down
10 changes: 0 additions & 10 deletions IceCubesApp/App/Tabs/ProfileTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct ProfileTab: View {
@Environment(CurrentAccount.self) private var currentAccount
@State private var routerPath = RouterPath()
@State private var scrollToTopSignal: Int = 0
@Binding var popToRootTab: AppTab

var body: some View {
NavigationStack(path: $routerPath.path) {
Expand All @@ -31,15 +30,6 @@ struct ProfileTab: View {
.allowsHitTesting(false)
}
}
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
if newValue == .profile {
if routerPath.path.isEmpty {
scrollToTopSignal += 1
} else {
routerPath.path = []
}
}
}
.onChange(of: client.id) {
routerPath.path = []
}
Expand Down
7 changes: 0 additions & 7 deletions IceCubesApp/App/Tabs/Settings/SettingsTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ struct SettingsTabs: View {
@State private var cachedRemoved = false
@State private var timelineCache = TimelineCache()

@Binding var popToRootTab: AppTab

let isModal: Bool

@State private var startingPoint: SettingsStartingPoint? = nil
Expand Down Expand Up @@ -103,11 +101,6 @@ struct SettingsTabs: View {
}
.withSafariRouter()
.environment(routerPath)
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
if newValue == .notifications {
routerPath.path = []
}
}
}

private var accountsSection: some View {
Expand Down
22 changes: 11 additions & 11 deletions IceCubesApp/App/Tabs/Tabs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ enum AppTab: Int, Identifiable, Hashable, CaseIterable, Codable {
}

@ViewBuilder
func makeContentView(selectedTab: Binding<AppTab>, popToRootTab: Binding<AppTab>) -> some View {
func makeContentView(selectedTab: Binding<AppTab>) -> some View {
switch self {
case .timeline:
TimelineTab(popToRootTab: popToRootTab)
TimelineTab()
case .trending:
TimelineTab(popToRootTab: popToRootTab, timeline: .trending)
TimelineTab(timeline: .trending)
case .local:
TimelineTab(popToRootTab: popToRootTab, timeline: .local)
TimelineTab(timeline: .local)
case .federated:
TimelineTab(popToRootTab: popToRootTab, timeline: .federated)
TimelineTab(timeline: .federated)
case .notifications:
NotificationsTab(selectedTab: selectedTab, popToRootTab: popToRootTab, lockedType: nil)
NotificationsTab(selectedTab: selectedTab, lockedType: nil)
case .mentions:
NotificationsTab(selectedTab: selectedTab, popToRootTab: popToRootTab, lockedType: .mention)
NotificationsTab(selectedTab: selectedTab, lockedType: .mention)
case .explore:
ExploreTab(popToRootTab: popToRootTab)
ExploreTab()
case .messages:
MessagesTab(popToRootTab: popToRootTab)
MessagesTab()
case .settings:
SettingsTabs(popToRootTab: popToRootTab, isModal: false)
SettingsTabs(isModal: false)
case .profile:
ProfileTab(popToRootTab: popToRootTab)
ProfileTab()
case .bookmarks:
NavigationTab {
AccountStatusesListView(mode: .bookmarks)
Expand Down
13 changes: 1 addition & 12 deletions IceCubesApp/App/Tabs/Timeline/TimelineTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct TimelineTab: View {
@Environment(UserPreferences.self) private var preferences
@Environment(Client.self) private var client
@State private var routerPath = RouterPath()
@Binding var popToRootTab: AppTab

@State private var didAppear: Bool = false
@State private var timeline: TimelineFilter = .home
Expand All @@ -33,9 +32,8 @@ struct TimelineTab: View {

private let canFilterTimeline: Bool

init(popToRootTab: Binding<AppTab>, timeline: TimelineFilter? = nil) {
init(timeline: TimelineFilter? = nil) {
canFilterTimeline = timeline == nil
_popToRootTab = popToRootTab
_timeline = .init(initialValue: timeline ?? .home)
}

Expand Down Expand Up @@ -77,15 +75,6 @@ struct TimelineTab: View {
.onChange(of: currentAccount.account?.id) {
resetTimelineFilter()
}
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in
if newValue == .timeline {
if routerPath.path.isEmpty {
scrollToTopSignal += 1
} else {
routerPath.path = []
}
}
}
.onChange(of: client.id) {
routerPath.path = []
}
Expand Down

0 comments on commit 7c2e8d6

Please sign in to comment.