like having .disabled without graying it out?
That would be confusing for the user. It is very important to have a consistent.
I tried something. Let me know if that's what you are looking for:
struct ContentView: View {
@State private var theField: String = ""
@State private var disabledField = true
@State private var prompt: String = "disabled"
@FocusState private var focusedField: Int?
var body: some View {
TextField(prompt, text: $theField)
.frame(width: 200, height: 30)
.disabled(disabledField)
.focused($focusedField, equals: 1)
.overlay( // so the doubletap will be handled, even though textFied is disabled
RoundedRectangle(cornerRadius: 4)
.stroke(Color.gray, lineWidth: 1) // just to see, color can be set to bg or white
.offset(x: -5, y: 0)
.onTapGesture(count: 2) {
prompt = "Enter"
disabledField = false
focusedField = 2 // any value ≠ 1: to get the cursor appear when set to 1
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) { // delay to sequence focus changes and get cursor appear
focusedField = 1
}
}
)
}
}
You can set the color of the prompt so that it does not appear dimmed
TextField(prompt, text: $theField, prompt: Text(prompt).foregroundColor(.blue))