Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save takoikatakotako/bebbe1a96fe42973ee4a79462ec5da71 to your computer and use it in GitHub Desktop.
SwiftUIでモーダルを表示する時に値を渡す
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()
}
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