I want to navigate to ChatScreen() based on conditions, when click on right group, print statement is showing "group found" but its not navigating:
List(viewModel.danceGroups) { group in
Button(action: {
if authViewModel.authenticationState == .authenticated {
check(groupId: group.id, userId: authViewModel.uid){ performed in
if performed{
goToChatScreen = true
}else {
showPopup = true
}
}
} else {
showSignInSheet = true
}
}) {
VStack(alignment: .leading) {
Text(group.groupName)
.bold()
.font(.title2)
Text(hoursAgo(from: TimeInterval(group.timestamp), from: group.isPermanent))
.font(.footnote)
.italic()
}
}
.navigationDestination(isPresented: $goToChatScreen){
ChatScreen(groupId: group.id)
}
}
func check(groupId: String, userId: String, completion: @escaping (Bool) -> Void) {
let database = Database.database().reference()
let GroupsRef = //path
GroupsRef.observeSingleEvent(of: .value) { snapshot in
if snapshot.exists() {
if let joinedDanceGroups = snapshot.value as? [String: Bool], joinedDanceGroups[groupId] == true {
print("group found")
completion(true)
} else {
print("group not found")
completion(false)
}
} else {
completion(false)
}
}
}
I tried to first assign the a bool according to check() and then checking conditions for navigation or popup but then it shows popup even when clicking right group