How to manually show/dismiss the keyboard?

#19 · closed · 2 comments

View on GitHub ↗

SeRG1k17

I found a way to hide the keyboard through the window hierarchy: ```swift extension View { func endEditing(_ force: Bool) { UIApplication.shared.windows.forEach { $0.endEditing(force)} } } ``` But this is clearly not the best solution. I have not looked at all the code, but it will be sufficient to make this initializer public: ```swift //Keyboard.swift public init(animationDuration: TimeInterval, height: CGFloat) { self.animationDuration = animationDuration self.height = height } ``` ```swift var body: some View { KeyboardObservingView { NavigationView { } .onTapGesture { self.keyboard.state = Keyboard.State(animationDuration: 0,25, height: 0) } } } ```

Comments

github-actions[bot]

Thanks for creating an issue!

nickffox

@SeRG1k17 - this framework doesn’t actually show or hide the keyboard, it adjusts your views so that the keyboard doesn’t cover them. If I’m understanding your question correctly it’s out of scope for this library. I think instead of using this library to show/hide the keyboard, you’ll want to do something like what you posted where you call beginEditng/endEditing manually.