Reputation: 1
I want the SearchandFilterBar to toggle the ShowDestinationSeachView filter, however when I click on the search button nothing happens.
I have tried to remove the SearchandFilterBar from the toolbar too see whether the functionality was flawed because it was in the toolbar however that did not do anything, just changed the appearance.
import SwiftUI
import Kingfisher
struct ContentView: View {
@State private var showMenu = false
@State private var showDestinationSearchView = false
@StateObject var exploreViewModel = ExploreViewModel(service: ExploreService())
@EnvironmentObject var viewModel: AuthViewModel
@State private var location: String = "" // Example location binding
var body: some View {
NavigationView {
ZStack(alignment: .topLeading) {
Group {
// No user logged in
if viewModel.userSession == nil {
LoginView()
} else {
if showDestinationSearchView {
DestinationSearchView(show: $showDestinationSearchView, viewModel: exploreViewModel)
} else {
mainInterfaceView
}
}
}
if showMenu {
ZStack {
Color(.black)
.opacity(showMenu ? 0.25 : 0.0)
}
.onTapGesture {
withAnimation(.easeInOut) {
showMenu = false
}
}
.ignoresSafeArea()
SideMenuView()
.frame(width: 300)
.offset(x: showMenu ? 0 : -300, y: 100)
.transition(.move(edge: .leading))
}
}
// .navigationTitle("Home") // Removed to hide default title
// .navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
HStack {
if let user = viewModel.currentUser {
Button(action: {
withAnimation {
showMenu.toggle()
}
}) {
KFImage(URL(string: user.profileImageUrl))
.resizable()
.scaledToFit()
.frame(width: 32, height: 32)
.clipShape(Circle())
}
}
// Custom Search and Filter Bar
SearchAndFilterBar(location: $exploreViewModel.searchLocation)
.frame(width: 200) // Adjust width as needed
.onTapGesture {
withAnimation(.snappy) {
showDestinationSearchView.toggle()
}
}
}
}
}
.onAppear {
showMenu = false
}
}
}
var mainInterfaceView: some View {
MainTabView()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.environmentObject(AuthViewModel())
}
}
Upvotes: 0
Views: 65