Created
September 29, 2024 16:19
-
-
Save katsuyoshi/8175488d81210d51c11aa9dd7779f4c1 to your computer and use it in GitHub Desktop.
If the alert isn’t shown, set the show flag later. I guess the alert view hides behind some view when the view creates complexity.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@State var isPresented = false | |
var body: some View { | |
VStack { | |
Image(systemName: "globe") | |
.imageScale(.large) | |
.foregroundStyle(.tint) | |
Text("Hello, world!") | |
} | |
.padding() | |
.onAppear() { | |
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1) { | |
isPresented.toggle() | |
} | |
} | |
.alert("Alert", isPresented: $isPresented) { | |
Button("OK") { | |
isPresented = false | |
} | |
} message: { | |
Text("Alert message.") | |
} | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The point is: