Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

GoBack() on a custom HybridWebView?

$
0
0

Hello Xamarin Community,
I built myself a Xamarin App with the HybridWebView as described on the official

Microsoft docs page

The problem is, everytime i press the back button of the OS, the app closes. This is not the behaviour I want, as I want the back button to affect the content inside the HybridWebview and go back one page on the website.
Just overriding OnBackButtonPressed() does not do the job, as the custom Hybridwebview has no GoBack() function like the native Webview and derrives just from View.

Is there any possibility to use the back button of the OS to navigate inside the HybridWebview?

The HybridWebview

.
.
    public class HybridWebView : View
    {
        Action<string> action;

        public static readonly BindableProperty UriProperty = BindableProperty.Create(
          propertyName: "Uri",
          returnType: typeof(string),
          declaringType: typeof(HybridWebView),
          defaultValue: default(string));

        public string Uri
        {
            get { return (string)GetValue(UriProperty); }
            set { SetValue(UriProperty, value); }
        }

        public void RegisterAction(Action<string> callback)
        {
            action = callback;
        }

        public void Cleanup()
        {
            action = null;

        }

        public void InvokeAction(string data)
        {
            if (action == null || data == null)
            {
                return;
            }
            action.Invoke(data);
        }
    }

inside the page

 <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
            <local:HybridWebView 
            x:Name="hybridWebView" 
            BackgroundColor="Black"
            Margin="0"
            HorizontalOptions="FillAndExpand"
            VerticalOptions="FillAndExpand"
            IsVisible="{Binding IsLoading, Converter={Helpers:InverseBoolConverter}}"
            />

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>