0

I probably worked too much today..

In this tiny app when the button is clicked a new view must appear after 3 seconds hVideoURL variable is assigned a value (which is not NIL). So a new view (sheet) should appear with the text "IS NOT NIL"..

But for some reason when it's shown i see "wow, it's nil", which means variable still has no value.

Why i that? What am i missing?

struct ContentView: View {
    @State var hVideoURL: URL? = nil
    @State var isPaused: Bool = false

    var body: some View {
        Button("Let's Go!") {
            DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
                print("settings isPaused to TRUE")
                self.hVideoURL = URL(string: "https://firebasestorage.googleapis.com/v0/b/fitma-e3043.appspot.com/o/flamelink%2Fmedia%2F1-horizontal.mov?alt=media&token=8f7dfc0f-0261-4a78-9eb0-6154ce1d9dfe")
                
                print("[debug] hVideoURL = \(hVideoURL)")
                
                self.isPaused = true
            }
        }
        .sheet(isPresented: self.$isPaused, onDismiss: {
            self.isPaused = false
            print("resume playing main video")
            
        }) {
           detailedVideoView
        }
    }
    
    @ViewBuilder
    var detailedVideoView: some View {
        if self.hVideoURL != nil {
            VStack {
                Text("IS NOT NIL")
            }
        } else {
            Text("wow, it's nil")
        }
    }
}
eugene_prg
  • 948
  • 2
  • 12
  • 25
  • 1
    Does this answer your question? [SwiftUI: Sheet cannot show correct values in first time](https://stackoverflow.com/questions/64798211/swiftui-sheet-cannot-show-correct-values-in-first-time) – lorem ipsum Apr 11 '21 at 19:17
  • thank you but the problem is with "hVideoURL". it gets a value but when sheet is opened hVideoURL is stil nill.. "isPaused" is handled correctly in my case, so i don't think your link is relevant to me issue. – eugene_prg Apr 11 '21 at 19:31
  • oh, it seems like you are right. will give it a shot tomorrow. thank you – eugene_prg Apr 11 '21 at 20:11

0 Answers0