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.