Created
October 24, 2024 00:14
-
-
Save takoikatakotako/bebbe1a96fe42973ee4a79462ec5da71 to your computer and use it in GitHub Desktop.
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 name = "" | |
| @State var showingSheet = false | |
| var body: some View { | |
| VStack(spacing: 16) { | |
| TextField("Input Name", text: $name) | |
| .textFieldStyle(RoundedBorderTextFieldStyle()) | |
| .padding() | |
| Text("Name: \(name)") | |
| Button { | |
| showingSheet = true | |
| } label: { | |
| Text("Show Modal") | |
| .font(Font.system(size: 20)) | |
| .foregroundColor(Color.white) | |
| .padding(16) | |
| .background(Color.gray) | |
| .cornerRadius(16) | |
| } | |
| .sheet(isPresented: $showingSheet) { | |
| PokemonView(pokemonName: name) | |
| } | |
| } | |
| } | |
| } | |
| #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 PokemonView: View { | |
| let pokemonName: String | |
| var body: some View { | |
| Text("Name: \(pokemonName)") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment