SwiftUIで閉じることができないモーダルを表示する
SwiftUIで閉じることができないモーダルを表示する方法です。

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
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() | |
} |
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
import SwiftUI | |
struct ModalView: View { | |
@Environment(\.dismiss) var dismiss | |
var body: some View { | |
Button(action: { | |
dismiss() | |
}, label: { | |
Text("Close") | |
}) | |
.interactiveDismissDisabled(true) | |
} | |
} |