Skip to content

Commit

Permalink
fix: Properly update WebView history properties
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinZikmund committed Jul 5, 2023
1 parent 2e0ac4e commit 96999a8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/Uno.UI/UI/Xaml/Controls/WebView/Core/CoreWebView2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ internal void RaiseNavigationCompleted(Uri? uri, bool isSuccess, int httpStatusC

internal void RaiseHistoryChanged() => HistoryChanged?.Invoke(this, null);

internal void SetHistoryProperties(bool canGoBack, bool canGoForward)
{
CanGoBack = canGoBack;
CanGoForward = canGoForward;
}

internal void RaiseWebMessageReceived(string message) => WebMessageReceived?.Invoke(this, new(message));

internal void RaiseUnsupportedUriSchemeIdentified(Uri targetUri, out bool handled)
Expand All @@ -173,13 +179,6 @@ internal void RaiseUnsupportedUriSchemeIdentified(Uri targetUri, out bool handle
handled = args.Handled;
}

internal void SetHistoryProperties(bool canGoBack, bool canGoForward)
{
CanGoBack = canGoBack;
CanGoForward = canGoForward;
RaiseHistoryChanged();
}

internal static bool GetIsHistoryEntryValid(string url) =>
!url.IsNullOrWhiteSpace() &&
!url.Equals(BlankUrl, StringComparison.OrdinalIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public override void OnPageFinished(Android.Webkit.WebView view, string url)
{
_coreWebView.DocumentTitle = view.Title;

_nativeWebViewWrapper.RefreshHistoryProperties();
_coreWebView.RaiseHistoryChanged();

var uri = !_nativeWebViewWrapper._wasLoadedFromString && !string.IsNullOrEmpty(url) ? new Uri(url) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ async Task<string> INativeWebView.InvokeScriptAsync(string script, string[] argu
// Because Android doesn't let you modify the navigation history,
// we need CanGoBack, CanGoForward, GoBack and GoForward to take the above condition into consideration.

internal void OnNavigationHistoryChanged()
internal void RefreshHistoryProperties()
{
// A non-zero number of steps to the nearest valid history entry means that navigation in the given direction is allowed
var canGoBack = GetStepsToNearestValidHistoryEntry(direction: -1 /* backward */) != 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ private void RaiseNavigationStarting(object navigationData, out bool cancel)
private void RaiseNavigationCompleted(Uri uri, bool isSuccess, int httpStatusCode, CoreWebView2WebErrorStatus errorStatus)
{
_coreWebView.SetHistoryProperties(CanGoBack, CanGoForward);
_coreWebView.RaiseHistoryChanged();
_coreWebView.RaiseNavigationCompleted(uri, isSuccess, httpStatusCode, errorStatus);
}

Expand Down

0 comments on commit 96999a8

Please sign in to comment.