Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Last active November 28, 2021 04:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save DaisukeNagata/1253ea3c6e999166a12f4abf45fb001d to your computer and use it in GitHub Desktop.
AutoOpenTextField.swift
import SwiftUI
@available(iOS 15.0, *)
struct AutoOpenTextField: View {
@State private var name = ""
@FocusState var isFocused: Bool {
didSet {
DispatchQueue.main.async {
isFocused = true
}
}
}
var body: some View {
TextField("Name", text: $name)
.focused($isFocused)
.onAppear {
isFocused = false
}
}
}
@available(iOS 15.0, *)
struct AutoOpenTextField_Previews: PreviewProvider {
static var previews: some View {
AutoOpenTextField()
}
}
@DaisukeNagata
Copy link
Author

default.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment