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

View File

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