cjwirth / RichEditorView

RichEditorView is a simple, modular, drop-in UIView subclass for Rich Text Editing.
BSD 3-Clause "New" or "Revised" License
1.89k stars 445 forks source link

How to make RichEditorView become first responder ? #238

Open panychyk opened 4 years ago

panychyk commented 4 years ago

editorView.focus() not work on iOS 11

caglayansever commented 3 years ago

this workaround worked for me.

editor.webView.becomeFirstResponder()
editor.focus(at: .zero)
parth-simformsolutions commented 3 years ago
editor.webView.becomeFirstResponder()
editor.focus(at: .zero)

Not working for me iOS 14.

danleom89 commented 2 years ago

I need to open the keyboard when the view appears. Is there any update about the issue?

rmi111 commented 2 years ago

I am facing similar issue, any solutions to this, note: I am calling RichEditor inside SwiftUI view.

vchaubey-ontic commented 1 year ago

Not working in iOS 15

vchaubey-ontic commented 1 year ago

does any one found solution ?

eebrian123tw93 commented 1 year ago

try this

extension WKWebView {

    func setKeyboardRequiresUserInteraction( _ value: Bool) {

        guard let WKContentViewClass = NSClassFromString("WKContentView") else { return }

        typealias OlderClosureType =  @convention(c) (Any, Selector, UnsafeRawPointer, Bool, Bool, Any?) -> Void
        typealias NewerClosureType =  @convention(c) (Any, Selector, UnsafeRawPointer, Bool, Bool, Bool, Any?) -> Void

        let olderSelector = sel_getUid("_startAssistingNode:userIsInteracting:blurPreviousNode:userObject:")
        let iOS12_2Selector = sel_getUid("_elementDidFocus:userIsInteracting:blurPreviousNode:changingActivityState:userObject:")
        let iOS13Selector = sel_getUid("_elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:")
        if let method = class_getInstanceMethod(WKContentViewClass, iOS13Selector) {

            let originalImp: IMP = method_getImplementation(method)
            let original: NewerClosureType = unsafeBitCast(originalImp, to: NewerClosureType.self)
            let block : @convention(block) (Any, UnsafeRawPointer, Bool, Bool, Bool, Any?) -> Void = { (me, arg0, arg1, arg2, arg3, arg4) in
                original(me, iOS13Selector, arg0, !value, arg2, arg3, arg4)
            }
            let imp: IMP = imp_implementationWithBlock(block)
            method_setImplementation(method, imp)
        } else if let method = class_getInstanceMethod(WKContentViewClass, iOS12_2Selector) {

            let originalImp: IMP = method_getImplementation(method)
            let original: NewerClosureType = unsafeBitCast(originalImp, to: NewerClosureType.self)
            let block : @convention(block) (Any, UnsafeRawPointer, Bool, Bool, Bool, Any?) -> Void = { (me, arg0, arg1, arg2, arg3, arg4) in
                original(me, iOS12_2Selector, arg0, !value, arg2, arg3, arg4)
            }
            let imp: IMP = imp_implementationWithBlock(block)
            method_setImplementation(method, imp)
        } else  if let method = class_getInstanceMethod(WKContentViewClass, olderSelector) {
            let originalImp: IMP = method_getImplementation(method)
            let original: OlderClosureType = unsafeBitCast(originalImp, to: OlderClosureType.self)
            let block : @convention(block) (Any, UnsafeRawPointer, Bool, Bool, Any?) -> Void = { (me, arg0, arg1, arg2, arg3) in
                original(me, olderSelector, arg0, !value, arg2, arg3)
            }
            let imp: IMP = imp_implementationWithBlock(block)
            method_setImplementation(method, imp)
        }

    }

}

stackoverflow juejin