Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How I can get selection value with WKWebView before CanPerform calling?

$
0
0

My problem is this: Before returning true or false from CanPerform, I need to check some value from js (getSelection), and only after that I can return.
This is my code:

public class CustomWKWebView : WKWebView
    {
        private const string SelectorOne = "One:";

        private const string SelectorTwo = "Two:";

        public CustomWKWebView(CGRect frame, WKWebViewConfiguration configuration) : base(frame, configuration)
        {
            _menu = UIMenuController.SharedMenuController;

            _menu.MenuItems = new[]
            {
            new UIMenuItem("One", new ObjCRuntime.Selector(SelectorOne)),
            new UIMenuItem("Two", new ObjCRuntime.Selector(SelectorTwo))
        }

        public override bool CanPerform(ObjCRuntime.Selector action, NSObject withSender)
        {
            /*this is a deadlock*/
            var checkValue = EvaluateJavaScriptAsync($"window.getSelection();").Result;
            if (checkValue)
                return true;
            return false;
        }
    }

But so solution is wrong.
I thank all in advance. And waiting for your proposal.


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>