view sheet on first launch

Hi


I'm trying to display a sheet when the app first launches, similiar to when you upraded iOS to 13 and tapped say reminders.


But I'm struggling to get with working with SwiftUI, here is a snippet of the code. It essentially crashes the app.

import SwiftUI

struct ContentView: View {
    @State private var showingSheet = false

    var body: some View {
       return self.sheet(isPresented: $showingSheet) {
            RegisterHome()
        }
    }
}

struct RegisterHome: View {
    var body: some View {
        NavigationView {
            Text("Register")
                .navigationBarTitle("Register")
        }
    }
}


Any thoughts would be very much appreciated.


Thanks, Craig

Answered by craigaps in 400004022

Hi Claude31


I re-jigged a bit of code around to the following:


struct ContentView: View {
    @State private var showingSheet = true

    var body: some View {
        RequestHome().sheet(isPresented: $showingSheet) {
            RegisterHome()
        }
    }
}


This gives me the effect I was trying to achieve - a sheet display on launch which I'll conditionalize later on.


Craig

Where does it crash exactly ? What message ?

Accepted Answer

Hi Claude31


I re-jigged a bit of code around to the following:


struct ContentView: View {
    @State private var showingSheet = true

    var body: some View {
        RequestHome().sheet(isPresented: $showingSheet) {
            RegisterHome()
        }
    }
}


This gives me the effect I was trying to achieve - a sheet display on launch which I'll conditionalize later on.


Craig

Thanks for feedback. You can close the thread on your correct answer.


And if possible move the thread to SwiftUI.

view sheet on first launch
 
 
Q