Last active
December 2, 2025 10:03
-
-
Save simonbs/3ef87ba29e6eca34b919cbdc5f346aae to your computer and use it in GitHub Desktop.
Is there a reliable way in SwiftUI to show a sheet without animation so it is visible immediately when the parent view appears?
This file contains hidden or 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
| struct ContentView: View { | |
| @State private var isModalPresented = false | |
| var body: some View { | |
| VStack { | |
| Button { | |
| isModalPresented = true | |
| } label: { | |
| Text("Present Modal") | |
| } | |
| } | |
| .padding() | |
| .sheet(isPresented: $isModalPresented) { | |
| ModalView() | |
| } | |
| } | |
| } | |
| struct ModalView: View { | |
| @Environment(\.dismiss) private var dismiss | |
| @State private var isSheetPresented = true | |
| var body: some View { | |
| NavigationView { | |
| VStack { | |
| Text("I'm presented modally.") | |
| Spacer() | |
| } | |
| .padding() | |
| .frame(maxWidth: .infinity, maxHeight: .infinity) | |
| .background(Color(uiColor: .systemGroupedBackground)) | |
| .navigationTitle("Modal") | |
| .navigationBarTitleDisplayMode(.inline) | |
| .toolbar { | |
| ToolbarItem(placement: .topBarLeading) { | |
| Button { | |
| dismiss() | |
| } label: { | |
| Label("Close", systemImage: "xmark") | |
| } | |
| } | |
| } | |
| // How can the sheet be shown without animation, so it's already visible when the modal opens? ππ€ | |
| .sheet(isPresented: $isSheetPresented) { | |
| Text("I am a sheet. How can I be shown without animation, so I am already visible when the modal opens?") | |
| .padding() | |
| .presentationDetents([.medium]) | |
| .presentationBackgroundInteraction(.enabled) | |
| .presentationDragIndicator(.hidden) | |
| .interactiveDismissDisabled(true) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Combine two sheets: a main modal sheet with animation, and a second (secondary) sheet without animation. However, it needs a delay for the transition to finish; apparently,
onAppearexecutes when the transition of the parent sheet ends.Only one sheet