Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

How to make RichEditorView become first responder ? #238

Open
panychyk opened this issue May 14, 2020 · 7 comments
Open

How to make RichEditorView become first responder ? #238

panychyk opened this issue May 14, 2020 · 7 comments

Comments

@panychyk
Copy link

editorView.focus() not work on iOS 11

@caglayansever
Copy link

this workaround worked for me.

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

@parth-simformsolutions
Copy link

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

Not working for me iOS 14.

@danleom89
Copy link

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

@rmi111
Copy link

rmi111 commented May 14, 2022

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

@vchaubey-ontic
Copy link

Not working in iOS 15

@vchaubey-ontic
Copy link

does any one found solution ?

@eebrian123tw93
Copy link

eebrian123tw93 commented Feb 9, 2023

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants