Last active
November 28, 2021 04:27
-
-
Save DaisukeNagata/1253ea3c6e999166a12f4abf45fb001d to your computer and use it in GitHub Desktop.
AutoOpenTextField.swift
This file contains 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 | |
@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() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
default.mov