Created
January 8, 2022 09:53
-
-
Save bbenetskyy/d3d03db020542a002579d761507374b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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