Eilon / MauiHybridWebView

MIT License
203 stars 41 forks source link

Manually adding / removing call backs #15

Open IeuanWalker opened 1 year ago

IeuanWalker commented 1 year ago

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");
}