Skip to content

Instantly share code, notes, and snippets.

@bbenetskyy
Created January 8, 2022 09:53
Show Gist options
  • Save bbenetskyy/d3d03db020542a002579d761507374b1 to your computer and use it in GitHub Desktop.
Save bbenetskyy/d3d03db020542a002579d761507374b1 to your computer and use it in GitHub Desktop.
ChatWebView.Source = new HtmlWebViewSource
{
Html = "<html><head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"></head><body>" +
"<script type=\"text/javascript\">" +
" function Run(text) { try { InvokeDisplayJSText(link); } catch(err) { alert(err); }} " +
" function DisplayXFText(text) { alert('DisplayXFText ' + text); } " +
"</script >" +
"<p><a href=\"#\" onclick=\"Run('Hello');\">Send 'Hello' to Xamarin.Forms</a></p>" +
"<p><a href=\"#\" onclick=\"Run2('From JS');\">Send 'From JS' to Xamarin.Forms</a></p>" +
"</body ></html >"
};
ChatWebView.RegisterDisplayJSTextAction(DisplayJSTextAction);
protected override void OnAppearing()
{
_ = Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromSeconds(3));
ChatWebView.SetXFAppText("Text from Xamarin.Forms Application");
});
}
private void DisplayJSTextAction(string text)
{
Device.InvokeOnMainThreadAsync(async () => await Application.Current.MainPage.DisplayAlert(text, string.Empty, "Great"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment