Closed amoshsueh closed 1 year ago
Hi @amoshsueh! I think i understand what you mean! let me check if i can add something meaningful :) Good idea!, I'll give it a go.
Question: What do you need in particular: A callback when keybords dismiss in general? or when your particular custom keyboard dismisses? Like, imagine you have multiple ones, would you want that all of those have separate callbacks?
@paescebu Thanks for your quickly reply.
I want the particular custom keyboard which is in editing mode to have this dismiss callback. After all, only one text field can be edited at a time.
Perfect, very clear! Let's get to work then.
@paescebu By the way, is there any way to manually dismiss the custom keyboard?
@amoshsueh could you check out the branchfeature/add-editing-ended-callback
and tell me if this is what you imagined?
it's used like:
SwiftUI: using a new modifier called: onEditingEndedCustomKeyboard(action:)
UIKit: assigning the CustomKeyboard the onEditingEnded
closure
About:
@paescebu By the way, is there any way to manually dismiss the custom keyboard?
No there is nothing yet, but I'll tell you how you can solve this otherwise :)
But i'm having second thoughts about this feature, i'll give you more insights after i got your feedback :)
@paescebu It doesn't seem to be working. I don't know if I'm missing something.
Code example:
let numberPad = CustomKeyboard.numberPad
numberPad.onEditingEnded = {
print("onEditingEnded") // Nothing happened here
}
textField.inputView = numberPad.keyboardInputView
static var numberPad: CustomKeyboard {
CustomKeyboardBuilder { textDocumentProxy, submit, playSystemFeedback in
return VStack {
// custom keyboard codes
}
.onEditingEndedCustomKeyboard {
print("onEditingEnded") // Nothing happened here
}
}
}
And I found textFieldDidEndEditing
is not called when I switch to other text field.
@amoshsueh,
make sure you use the onEditingEndedCustomKeyboard
modifer the same way as the onSubmitCustomKeyboard
modifier in the README.md. When in SwiftUI (from outside the Keyboard) and after the use of the customKeyboard
modifier.
For UIKit i actually haven't tested it, yet and i guess to make it work there i have to change it up a bit :D
But ANYWAY, about my second thoughts:
I like to be inspired by the default keyboards and APIs from Apple (on iOS), like in Messages, Contacts etc.
FocusState
property wrappers in SwiftUI or the UITextFieldDelegate
in UIKit for example and observe it's changes. I think that would be the best way also for CustomKeyboard and that should work out of the box for you. endEditing(true)
or resignFirstResponder()
on the textField in UIKit, or call UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
from anywhere.But I think FocusState is the way to go for both of your issues actually!
What do you think? Does it make sense what I'm saying or do you think this should actually be covered by the Keyboard, let me know! 😄
@paescebu
I use my own custom text field created by UIViewRepresentable and apply onEditingEnded
but it's not working. Then I use SwiftUI's TextField and it's working perfectly. Maybe something wrong with my codes but it's fine.
I've been doing some thinking on my own, I should use this library in a different way. The below API of TextField already meets my needs:
public init<S>(_ title: S, text: Binding<String>, onEditingChanged: @escaping (Bool) -> Void) where S : StringProtocol
So I think maybe there is no need for onEditingEndedCustomKeyboard
. You can think about whether it is necessary to add this feature to the main branch.
I'm glad the discussion with you gave me some inspiration and thank you for being willing to share your thoughts with me.
Best wish.
@amoshsueh True! Completely forgot that TextField also has a closure for that already!
Awesome to hear that my thoughts inspired to think the need through :)
Have a great one!
Thanks for your hard work on this library, it's really useful!
I wonder if you can add an
onDismiss
callback when custom keyboard dismissed?When I click on other text fields (with default keyboard) while typing with custom keyboard, I need to handle something before dismissal and change the text.
Let me know if you need more details, thanks.