Done callback from WebView - xamarin

in my XF application I have the possibility to open a web page.
For do this I use the Xamarin.Essential: await Browser.OpenAsync(url, opts);.
I need to have a callback when the user tap on Done button (on iOS) or the back button (on Andorid).
How can I do this?
There is another way other than use Xamarin.Essential?
Thank you!
EDIT
I need to execute some C# code when the user tap on the "done button" in iOS or the back button on Android when the WebView is open.
I'm not trying to execute some JavaScript code, or execute C# code from Javascript.
Android video.
Sample here.

Yeah if you don't want to use Essentials for opening pages, you could use
Device.OpenUri(new Uri("www.example.com"));
And if you want it to be in a async fucntion
await Device.OpenUri(new Uri("www.example.com"));
And if you are looking into adding callback functionality from the webview, you would need to create a HybridWebView and custom renderers for iOS & Android, as shown here.

Related

Open certain links in external browser using Nativescript

I am working on a simple app written in Nativescript.
The app has a login form that authenticates against an API, and on success loads a webview. So not that complicated.
But I would like to be able to open certain links in the default browser on the phone, and not in webview, like links to external sites.
Is it possible to "capture" all link clicks, and if the link has the target attribute set to blank, we make the link open in a external browser?
I need a solution that works both on iOS and Android.
Is this possible to do in Nativescript?
Yes, it's possible to do that in NativeScript but not with the default WebView component. I was exactly in this situation, what I did is writing a plugin that customizes default WebView in NativeScript to override the default WKUIDelegate in iOS webview & idem for Android.
For iOS, the WKUIDelegate allow to detect if any attempt to open link with target _blank with method webViewCreateWebViewWithConfigurationForNavigationActionWindowFeatures, hence, when implementing your custom webview with this delegate allow to open link in external browser / application as you wish.
Take a look at this plugin: https://github.com/Notalib/nativescript-webview-ext to have an idea how to customize default webview.
You may use the nativescript-webview-ext plugin and use the shouldOverrideUrlLoading event to check the URL and cancel the process as needed then use the open url method in utility module to open the given url in default browser.
You can import this
import * as utils from "#nativescript/core/utils";
and then do
utils.openUrl("https://www.youtube.com/");
whenever you want to open a link (in this case youtube) in a default browser.

Open Xamarin.Forms Page from Xamarin.Android

I am receiving Firebase Pushnotifications in Xamarin.Android.
While receving I want to open a specific content page of my Xamarin.Forms App.
I use
Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new ShowAlert(null));
"ShowAlert" is the page I want to open.
The constructor of "ShowAlert" is beeing called an executed, but the page is not beeing opened. What's missing?
Thanks for you help!
Are you calling PushAsync from the UI thread? Device.BeginInvokeOnUIThread .

NativeScript open action extensions

Is there way to open the iOS Action extensions from the NativeScript library?
https://developer.apple.com/ios/human-interface-guidelines/extensions/sharing-and-actions/
Basically I'm trying to open a Text file, so I can upload it to iCloud, Dropbox or send it via Email. Basically like the "intent" on Android.
NativeScript implements a function called utils.ios.openFile(this.documents.path + this.fileName) but this is opening a new Windows with a share Button. When I press this button the action extension popup opens. Is it possible to open that popup straightaway?
A TypeScript/Angular solution would be great.
I wrote this plugin. It will open the sharing-and-actions for iOS and on Android an intent.
https://github.com/braune-digital/nativescript-share-file

Is there anyway to switch off the switch application warning from inside a uwp webview

I have an app that opens other part of the app inside the webview, but I need to turn off the warning of switching apps. The idea is to the user to just open another part of the app when he clicks the page inside the webview. Anyone has any thoughts?
Thanks in advance.

How to call a c# method from javascript in window phone 7?

I want to detect swipe in web browser control in C# using JavaScript. I want to add some JavaScript to my web content and then if swipe occurs, call a method that loads another web content in the same web browser control.
I would like some sample code or any other suggestion to do this.
Thanks in advance
You'll need to use something to detect the swipe in javascript. I've been recommended to use touch.js but haven't had a chance to try this yet.
When you detect the swipe you can call out to native code using window.external.notify().
Be sure to set IsScriptEnabled="True" on the WebBrowser control and register an handler for the ScriptNotify event.
It's this event handler which would load the new content.
First of all, consider that gestures for a webbrowser control have it's own handlers. Now, if you don't need to pan/zoom or the like in the webbrowser control, it's not a problem.
Then you simply set the IsHitTestEnabled attribute to false, so that the web-browser no longer receives input. Then you can simply use the GestureService from the Silverlight Toolkit to handle the swipe/flick inputs.
I wrote some code on how to handle this, in another question: wp7 horizontal swipe selection

Resources