Skip to content

Commit

Permalink
fix the autoredirecting external browser
Browse files Browse the repository at this point in the history
  • Loading branch information
rwecho committed Apr 6, 2024
1 parent 948b995 commit 06bb799
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/V2ex.Blazor/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ContentPage.Behaviors>
<toolkit:StatusBarBehavior StatusBarColor="#f3f4f6" StatusBarStyle="DarkContent" />
</ContentPage.Behaviors>
<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html" UrlLoading="BlazorWebView_UrlLoading">
<BlazorWebView.RootComponents>
<RootComponent Selector="#app" ComponentType="{x:Type shared:Main}" />
</BlazorWebView.RootComponents>
Expand Down
15 changes: 12 additions & 3 deletions src/V2ex.Blazor/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
public MainPage()
{
InitializeComponent();


// The SoftInput in the MainActivity.cs is not working, so we have to do it here.
Expand All @@ -16,5 +16,14 @@ public MainPage()
window.SetSoftInputMode(Android.Views.SoftInput.AdjustResize);
#endif
});


}


private void BlazorWebView_UrlLoading(object sender, Microsoft.AspNetCore.Components.WebView.UrlLoadingEventArgs e)
{

}

}
3 changes: 2 additions & 1 deletion src/V2ex.Blazor/Pages/ReturnPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
<BlazorWebView x:Name="blazorWebView"
HostPage="wwwroot/index.html"
StartPath="{Binding TargetLocation}"
local:WebViewEvents.TitleChangeCommand="{Binding TitleChangeCommand}">
local:WebViewEvents.TitleChangeCommand="{Binding TitleChangeCommand}"
UrlLoading="BlazorWebView_UrlLoading">
<BlazorWebView.RootComponents>
<RootComponent x:Name="RootComponent" Selector="#app" ComponentType="{x:Type shared:Main}" />
</BlazorWebView.RootComponents>
Expand Down
5 changes: 5 additions & 0 deletions src/V2ex.Blazor/Pages/ReturnPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ public ReturnPage(string targetLocation)
{ "Url", targetLocation }
};
}

private void BlazorWebView_UrlLoading(object sender, Microsoft.AspNetCore.Components.WebView.UrlLoadingEventArgs e)
{
e.UrlLoadingStrategy = Microsoft.AspNetCore.Components.WebView.UrlLoadingStrategy.OpenInWebView;
}
}

0 comments on commit 06bb799

Please sign in to comment.