RichEditorView icon indicating copy to clipboard operation
RichEditorView copied to clipboard

How to make RichEditorView become first responder ?

Open panychyk opened this issue 4 years ago • 7 comments

editorView.focus() not work on iOS 11

panychyk avatar May 14 '20 10:05 panychyk

this workaround worked for me.

editor.webView.becomeFirstResponder()
editor.focus(at: .zero)

caglayansever avatar Dec 17 '20 14:12 caglayansever

editor.webView.becomeFirstResponder()
editor.focus(at: .zero)

Not working for me iOS 14.

parth-simformsolutions avatar Jan 05 '21 12:01 parth-simformsolutions

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

danleom89 avatar Feb 03 '22 10:02 danleom89

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

rmi111 avatar May 14 '22 12:05 rmi111

Not working in iOS 15

vchaubey-ontic avatar Jan 25 '23 10:01 vchaubey-ontic

does any one found solution ?

vchaubey-ontic avatar Jan 25 '23 10:01 vchaubey-ontic

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

eebrian123tw93 avatar Feb 09 '23 06:02 eebrian123tw93