This amazing question got closed due to "lack of technical details", so I'm sure to put a plenty of here.
Setup:
- Create an iOS SwiftUI app
- Add files as follows
- Observe the problem
AppleApp.swift
import SwiftUI
@main
struct AppleApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
ContentView.swift
import SwiftUI
struct ContentView: View {
@State var isLocked = true
var body: some View {
VStack {
Text("Unlocked view")
.padding()
}.fullScreenCover(isPresented: $isLocked) {
} content: {
LockScreen($isLocked)
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
LockScreen.swift
import SwiftUI
struct LockScreen: View {
@Binding var isLocked: Bool
init(_ isLocked: Binding<Bool>) {
self._isLocked = isLocked
}
var body: some View {
ZStack {
Color.gray
VStack {
Text("Locked")
Button("Unlock") {
print("unlock button pressed")
isLocked = false
}
}
}
}
}
struct LockScreen_Previews: PreviewProvider {
@State static var isLocked: Bool = true
static var previews: some View {
LockScreen($isLocked)
}
}
The problem:
Take a look at the video: after the app launches the "unlocked view" is visible and "LockScreen" appears after a short delay with animation.
Desired outcome:
The app shows "LockScreen" just after the launch, but it's possible to dismiss it by pressing the "unlock" button.