Skip to content

Instantly share code, notes, and snippets.

@SlappyAUS
Created December 2, 2020 06:08
Show Gist options
  • Save SlappyAUS/de8623a2bfe7ef6f47357a674a8b8ce7 to your computer and use it in GitHub Desktop.
Save SlappyAUS/de8623a2bfe7ef6f47357a674a8b8ce7 to your computer and use it in GitHub Desktop.
ConfirmationTextField #swift #swiftui #io
struct ConfirmationTextField: View {
@State private var showtextFieldToolbar = false
let keyboardType: UIKeyboardType
@Binding var text: String
var body: some View {
TextField("", text: $text)
{ isChanged in
if isChanged {
showtextFieldToolbar = true
}
} onCommit: {
showtextFieldToolbar = false
}
.overlay(
VStack {
if showtextFieldToolbar {
HStack {
Spacer()
Button {
showtextFieldToolbar = false
UIApplication.shared
.sendAction(#selector(UIResponder.resignFirstResponder),
to: nil, from: nil, for: nil)
} label: {
HStack {
Image(systemName: "checkmark.circle.fill")
Text("done".localized())
}
.foregroundColor(ColorManager.interactive_0)
}
}
.frame(idealWidth: .infinity, maxWidth: .infinity, alignment: .center)
}
}
)
.keyboardType(keyboardType)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment