(SwiftUI) Can't Click Button on Sheet Modals Show View
when detection beacon present sheet model. in the sheet model there are 2 button. i want to click on more experience (button) to present another view. when i click on button more experience it doesn't present the view.
Hope you can help me, Thanks! Any help would be deeply appreciated!
I'm new in swiftui, Please forgive me if I make a few mistakes My English isn’t so great.
**Code: **
import Combine
import CoreLocation
import SwiftUI
struct ContentView: View {
@ObservedObject var detector = BeaconDetector()
@EnvironmentObject var popupManager: PopupManager
@EnvironmentObject var authViewModel: AuthViewModel
@State var isNavigationBarHidden: Bool = true
@State var isShowAlert = false
@State var showDetail = false
@State var isActive = false // added
@StateObject var artwork = ArtworkViewModel()
var body: some View {
VStack {
Group {
if let userSession = authViewModel.userSession {
// logged in user
if detector.lastDistance == .immediate {
if !detector.beaconFound {
Text("")
.onAppear {
// Show the alert (view appear)
isShowAlert = true
}
.alert(isPresented: $isShowAlert) {
Alert(
title: Text("Hi! Art Lovers"),
message: Text("We want to help you find your nearest Artwork 🖼️"),
dismissButton: .default(Text("OK")) {
showDetail = true
}
)
}
} else if let getArtwork = artwork.artworks.first(where: { $0.id == "1" }),
getArtwork.uuidbeacon == BeaconDetector.getBeaconID() {
NavigationLink(destination: ArtworkInfoBeacon(artwork: getArtwork), isActive: $isActive) {
ArtworkInfoBeacon(artwork: getArtwork)
}
.hidden() // hide the navigation link
.onAppear {
isActive = true
}
.onDisappear {
isActive = false
}
.simultaneousGesture(TapGesture().onEnded {
showDetail = true
})
}
} else {
mainInterfaceView
}
} else {
// no logged in user
LoginView()
}
}
}
.sheet(isPresented: $showDetail) {
// present the ArtworkInfoBeacon view as a sheet
if let getArtwork = artwork.artworks.first(where: { $0.id == "1" }),
getArtwork.uuidbeacon == BeaconDetector.getBeaconID() {
ArtworkInfoBeacon(artwork: getArtwork)
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView(artworkinfo: Artworkinfo(
id: 0,
atwName: "Anthropocene",
atwArtist: "Sirawich",
ateCate: "Painting",
atwDesc: "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal",
atwSound: "mp4",
atwImg: "AnthropoceneCover",
idExhbt: 0), exhibition: Exhibition(id: "", exhbtstate: "", exhbtname: "", exhbtstr: "", exhbtend: "", exhbtdesc: "", timestr: "", timeend: "", exhbtorgnz: "", loctname: "", loctdetail: "", ticket: "", imgcover: ""), artwork: ArtworkViewModel())
}
}
extension ContentView {
var mainInterfaceView: some View {
VStack {
MainTabView()
}
}
}
code ArtworkinfoBeacon:
Button {
print("Button Play")
} label: {
NavigationLink(destination:ArtworkPlayBeacon(artwork: artwork)){
HStack {
Spacer()
Text(" \(Image(systemName: "play.fill")) More Experience")
.foregroundColor(.white)
.padding(.vertical, 10)
.font(.semiSub)
Spacer()
}.background(Color.primaryColor1)
}.cornerRadius(24)
.padding()
}
} // section play sound