KeyboardObserving icon indicating copy to clipboard operation
KeyboardObserving copied to clipboard

Added sample project and return Keyboard from the KeyboardObservingView

Open SeRG1k17 opened this issue 4 years ago • 2 comments

  • Added empty Example to the library.
  • It will be useful if KeyboardObservingView will return Keyboard object as a parameter to ViewBuilder:
KeyboardObservingView { keyboard in 
//
}

I found the issue, when you adding @EnvironmentObject var keyboard: Keyboard to the View. This leads to the fact that the field values are cleared after changing the field on this view or on the next in the nav stack.

  • @nickffox What do you think, about using Environment?:
struct KeyboardKey: EnvironmentKey {
    static let defaultValue: Keyboard = Keyboard()
}

extension EnvironmentValues {
    var keyboard: Keyboard {
        get {
            return self[KeyboardKey.self]
        }
        set {
            self[KeyboardKey.self] = newValue
        }
    }
}

SeRG1k17 avatar May 30 '20 12:05 SeRG1k17

Thanks! I’ll take a look at this over the weekend

nickffox avatar Jun 06 '20 07:06 nickffox

@SeRG1k17 I took a look at this PR, and I’m a bit confused by the use case. Can you help me understand why a client might need access to the keyboard object?

Thanks for adding an empty project!

nickffox avatar Jun 08 '20 18:06 nickffox