Giter VIP home page Giter VIP logo

Comments (10)

amoshsueh avatar amoshsueh commented on May 24, 2024 1

@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.

from customkeyboardkit.

paescebu avatar paescebu commented on May 24, 2024 1

Perfect, very clear! Let's get to work then.

from customkeyboardkit.

amoshsueh avatar amoshsueh commented on May 24, 2024 1

@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.

from customkeyboardkit.

paescebu avatar paescebu commented on May 24, 2024 1

@amoshsueh,
make sure you use the onEditingEndedCustomKeyboardmodifer the same way as the onSubmitCustomKeyboard modifier in the README.md. When in SwiftUI (from outside the Keyboard) and after the use of the customKeyboardmodifier.

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.

  • There we also don't have a dismiss button and therefore a programmatic dismiss API directly.
  • Also for native keyboards we also don't have callbacks when the keyboard dismisses, but in order to achieve what you want, we'd use the 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.
  • To dismiss the keyboard programmatically, theres also no native API for it for the keyboards explicitly, but as well, we can set the focus State i assume, or call: 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! 😄

from customkeyboardkit.

amoshsueh avatar amoshsueh commented on May 24, 2024 1

@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.

from customkeyboardkit.

paescebu avatar paescebu commented on May 24, 2024

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.

from customkeyboardkit.

paescebu avatar paescebu commented on May 24, 2024

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?

from customkeyboardkit.

amoshsueh avatar amoshsueh commented on May 24, 2024

@paescebu By the way, is there any way to manually dismiss the custom keyboard?

from customkeyboardkit.

paescebu avatar paescebu commented on May 24, 2024

@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 :)

from customkeyboardkit.

paescebu avatar paescebu commented on May 24, 2024

@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!

from customkeyboardkit.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.