Giter Site home page Giter Site logo

Comments (8)

gmckenzi avatar gmckenzi commented on June 27, 2024

I see there is a bunch of swizzling code for focus in MarkupWKWebView that was commented out on Sep 5. If I restore that code and call showKeyboard() from makeUIView in the UI representable class, the editor gets focus and the keyboard appears.

I expect there was a good reason for commenting out this code and losing the functionality, but I'd love to know why or what the risks are of restoring this code.

from markupeditor.

stevengharris avatar stevengharris commented on June 27, 2024

I did a lot of work on this issue that is still in main right now. Basically you can tell the MarkupEditor which view should be the firstResponder by its id:

MarkupEditor.firstResponder = <The String id of the MarkupWKWebView>

In the demos, the id is set to "Document" when the MarkupEditorView is created:

MarkupEditorView(markupDelegate: self, html: $demoHtml, resourcesUrl: resourcesUrl, id: "Document")

In the app I'm using MarkupEditor with, I have a unique id for the model-type object that holds onto the HTML I feed to the MarkupEditor.

Behind the scenes, the MarkupWKWebView observes the ObservedFirstResponder and responds:

/// Monitor the setting for MarkupEditor.observedFirstResponder, and set this MarkupWKWebView to be the first responder
/// when the id matches.
///
/// Becoming the first reponder also means that focus and selection state are set properly.
private func observeFirstResponder() {
    firstResponder = MarkupEditor.observedFirstResponder.$id.sink { [weak self] selectedId in
        guard let selectedId, let self, self.id == selectedId else {
            return
        }
        self.becomeFirstResponderIfReady()
    }
}

Main should be stable and I hope (but tbh not absolutely certain) compatible with the Beta release.

from markupeditor.

gmckenzi avatar gmckenzi commented on June 27, 2024

Awesome -- I'll point my package ref to main and give this a go. Thank you for such a prompt and detailed reply!

from markupeditor.

stevengharris avatar stevengharris commented on June 27, 2024

Sorry, I think I sent you on a wild goose chase with main as opposed to the swizzling methods you found earlier. The work I did on firstResponder was useful and dealt with the case of it not working right because a view was not yet ready. In my usage, I have a List of MarkupWebViews, and I need to scroll to a particular one and make sure the insertion-point caret is showing properly, which is not the issue you're having. I even removed the swizzling methods for keyboard interaction from main because I figured they were not needed!!!

I think the reason I commented that code out was because, as you said, Apple mostly doesn't want you to be bringing up the keyboard without the user selecting something. Plus, in my own case, I want the view to open without the keyboard when on iOS, because I want it to be readable and scrollable without the keyboard covering the screen. I still think that will be the default case, but I can see adding a setting to make it optional, and then calling showKeyboard() at the right place when the option is set. That work would amount to adding a new static to MarkupEditor (so, for example, it could be set in your AppDelegate or someplace handy), and then gating the call to showKeyboard with a test on that setting. I'm not completely certain that makeUIView is the right place, but maybe. I might prefer it on a MarkupDelegate callback.

If you want to do that as a PR, I'd love to put it in. (FWIW, it would be easiest for me on main.) Otherwise, we can leave this open and I will try to deal with it at some point relatively soon.

I appreciate your raising the issue and can see how this can be very important. If you don't file a PR, please add any additional info about how you dealt with it if you think it will be useful to me and others.

Also, please note #89, which you will need to work around for now.

from markupeditor.

gmckenzi avatar gmckenzi commented on June 27, 2024

Thank you for all this info, and apologies for my delay in responding. I've been heads-down for the last little while.

Over the next week I'll focus on implementing this and reach out for feedback and/or submit a PR.

from markupeditor.

anishjain123 avatar anishjain123 commented on June 27, 2024

Has this been resolved? @gmckenzi @stevengharris

from markupeditor.

stevengharris avatar stevengharris commented on June 27, 2024

I haven't been able to spend any time on it. Have you tried what @gmckenzi suggested in #88 (comment)?

from markupeditor.

JohnKuan avatar JohnKuan commented on June 27, 2024

Hi @stevengharris, not sure if this is related.

In my use case, I have other UITextFields above the MarkupEditor. The MarkupEditor is the entire space below. When I try to tap on the space except the topmost line, it does not respond to being a first responder. However when I tap on the top most line, it becomes the first responder. This only happens for the first time, and after that it works properly.

RPReplay_Final1692860986.mov

from markupeditor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.