MauiHybridWebView icon indicating copy to clipboard operation
MauiHybridWebView copied to clipboard

Manually adding / removing call backs

Open IeuanWalker opened this issue 3 years ago • 0 comments

Sorry same draft PR as before, when i tried syncing my main branch it auto deleted my commits #1

Hi, great work on this control.

Thought I'd just do a draft PR to show an implementation I prefer. I'm not a big fan JSInvokeTarget, think it could add some complexity to some simpler use cases.

So I propose adding 2 methods to Add/ Remove JS callback methods.

That way to don't need a completely separate class that contain all the call back methods, you could simply do this -

// Register in the constructor or anywhere else
myHybridWebView.AddLocalCallback(this, nameof(AddLocalCallBackTest));

private async void AddLocalCallBackTest(string message, int value)
{
    WriteToLog($"I'm a .NET method called from JavaScript with message='{message}' and value={value}, using a local registration");
}

IeuanWalker avatar Apr 18 '23 15:04 IeuanWalker