Tab bar issue

This commit is contained in:
Lumaa 2024-08-11 14:37:50 +02:00
parent c868b0cd2e
commit d4d3fe43d3
2 changed files with 20 additions and 2 deletions

View File

@ -5,13 +5,17 @@ import SwiftUI
struct TabsView: View {
@State var selectedTab: TabDestination = Navigator.shared.selectedTab
var canTap: Binding<Bool> = .constant(true)
var postButton: () -> Void = {}
var tapAction: () -> Void = {}
var retapAction: () -> Void = {}
var body: some View {
HStack(alignment: .center) {
Button {
guard canTap.wrappedValue else { return }
if selectedTab == .timeline {
retapAction()
} else {
@ -25,11 +29,14 @@ struct TabsView: View {
Tabs.timeline.image
}
}
.disabled(!canTap.wrappedValue)
.buttonStyle(NoTapAnimationStyle())
Spacer()
Button {
guard canTap.wrappedValue else { return }
if selectedTab == .search {
retapAction()
} else {
@ -43,20 +50,26 @@ struct TabsView: View {
Tabs.search.image
}
}
.disabled(!canTap.wrappedValue)
.buttonStyle(NoTapAnimationStyle())
Spacer()
Button {
guard canTap.wrappedValue else { return }
postButton()
} label: {
Tabs.post.image
}
.disabled(!canTap.wrappedValue)
.buttonStyle(NoTapAnimationStyle())
Spacer()
Button {
guard canTap.wrappedValue else { return }
if selectedTab == .activity {
retapAction()
} else {
@ -70,11 +83,14 @@ struct TabsView: View {
Tabs.activity.image
}
}
.disabled(!canTap.wrappedValue)
.buttonStyle(NoTapAnimationStyle())
Spacer()
Button {
guard canTap.wrappedValue else { return }
if selectedTab == .profile {
retapAction()
} else {
@ -88,6 +104,7 @@ struct TabsView: View {
Tabs.profile.image
}
}
.disabled(!canTap.wrappedValue)
.buttonStyle(NoTapAnimationStyle())
}
.padding(.horizontal, 30)

View File

@ -41,7 +41,7 @@ struct ContentView: View {
}
.frame(maxWidth: appDelegate.windowWidth)
.overlay(alignment: .bottom) {
TabsView(postButton: {
TabsView(canTap: $navigator.showTabbar, postButton: {
uniNavigator.presentedSheet = .post(content: "", replyId: nil, editId: nil)
}, retapAction: {
navigator.path = []
@ -53,6 +53,7 @@ struct ContentView: View {
y: navigator.showTabbar ? 0 : CGFloat
.getFontSize(from: .extraLargeTitle) * 7.5
)
.allowsHitTesting(navigator.showTabbar)
}
.withSheets(sheetDestination: $uniNavigator.presentedSheet)
.withCovers(sheetDestination: $uniNavigator.presentedCover)