Skip to content

Instantly share code, notes, and snippets.

@takoikatakotako
Created October 24, 2024 01:00
Show Gist options
  • Select an option

  • Save takoikatakotako/1fbf2df8914e9375febda007e3fac5e7 to your computer and use it in GitHub Desktop.

Select an option

Save takoikatakotako/1fbf2df8914e9375febda007e3fac5e7 to your computer and use it in GitHub Desktop.
SwiftUIで閉じることができないモーダルを表示する
import SwiftUI
struct ContentView: View {
@State var showingSheet = false
var body: some View {
Button(action: {
showingSheet = true
}, label: {
Text("Show Modal!")
})
.sheet(isPresented: $showingSheet) {
ModalView()
}
}
}
#Preview {
ContentView()
}
import SwiftUI
struct ModalView: View {
@Environment(\.dismiss) var dismiss
var body: some View {
Button(action: {
dismiss()
}, label: {
Text("Close")
})
.interactiveDismissDisabled(true)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment