Skip to content

Commit d06ee80

Browse files
authored
fix: discord login (#450)
* prevent popup crash * AuthPopUp| code cleanup * tweak the discord portal UI and navigation
1 parent 2d913da commit d06ee80

3 files changed

Lines changed: 48 additions & 20 deletions

File tree

App/Views/PopUps/AuthPopUp.xaml.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ public AuthPopUp(Action<AuthResponse> callBack)
2121
public App CurrentApp { get; private set; }
2222
private async void Discord_Clicked(object sender, System.EventArgs e)
2323
{
24-
CurrentApp.ShowLoadingIndicator();
25-
DiscordAuthPortal discordAuthPortal = new(CallBack);
24+
// Close this popup
25+
await this.CloseAsync();
2626

27+
CurrentApp.ShowLoadingIndicator();
2728

28-
await App.Current.Windows[0].Page.Navigation.PushAsync(discordAuthPortal);
29+
await Shell.Current.Navigation.PushAsync(new DiscordAuthPortal(CallBack));
2930

30-
// Close this popup
31-
await this.CloseAsync();
3231
}
3332
}

App/Views/Portals/DiscordAuthPortal.xaml

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,37 @@
55
xmlns:Core="GamHubApp.Core"
66
xmlns:local="clr-namespace:GamHubApp.Views.Portals"
77
BackgroundColor="{StaticResource BgBannerColor}"
8-
x:DataType="local:DiscordAuthPortal">
8+
x:DataType="local:DiscordAuthPortal"
9+
Shell.NavBarIsVisible="True">
910
<ContentPage.Content>
10-
<WebView Source="{Binding Url}"
11-
VerticalOptions="Fill"
12-
HorizontalOptions="Fill"
13-
Navigated="DiscordPortal_Navigated"
14-
Navigating="DiscordPortal_Navigating"
15-
x:Name="DiscordPortal"
16-
BackgroundColor="{StaticResource BgBannerColor}"
17-
/>
11+
<Grid RowDefinitions="50,*" >
12+
<Grid ColumnDefinitions="*,20"
13+
BackgroundColor="{DynamicResource LightDark}">
14+
<Button Text="&#xf00d;"
15+
FontFamily="FaSolid"
16+
FontSize="27"
17+
CornerRadius="20"
18+
WidthRequest="80"
19+
TextColor="{DynamicResource FontColor}"
20+
BackgroundColor="{DynamicResource LightDark}"
21+
VerticalOptions="Center"
22+
HorizontalOptions="End"
23+
Clicked="Close_Clicked"
24+
Grid.Column="1"/>
25+
</Grid>
26+
<WebView Source="{Binding Url}"
27+
VerticalOptions="Fill"
28+
HorizontalOptions="Fill"
29+
Navigated="DiscordPortal_Navigated"
30+
Navigating="DiscordPortal_Navigating"
31+
x:Name="DiscordPortal"
32+
BackgroundColor="{StaticResource BgBannerColor}"
33+
Grid.Row="1"
34+
/>
35+
36+
</Grid>
37+
38+
1839
</ContentPage.Content>
1940
</ContentPage>
2041

App/Views/Portals/DiscordAuthPortal.xaml.cs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ protected override void OnAppearing()
3131
private async void DiscordPortal_Navigated(object sender, WebNavigatedEventArgs e)
3232
{
3333

34-
35-
3634
// Remove loding indicator
3735
if (e.Url.Contains("discord.com/oauth2/authorize"))
3836
{
@@ -54,14 +52,19 @@ private async void DiscordPortal_Navigated(object sender, WebNavigatedEventArgs
5452
Result = true;
5553
CallBack(res);
5654

57-
// Navigate back
58-
CurrentApp.Windows[0].Page.Navigation.RemovePage(this);
59-
60-
CurrentApp.RemoveLoadingIndicator();
55+
await NavigateBack();
6156
return;
6257
}
6358
}
6459

60+
private static async Task NavigateBack()
61+
{
62+
await Shell.Current.Navigation.PopModalAsync();
63+
await CurrentApp.Windows[0].Navigation.PopModalAsync();
64+
65+
CurrentApp.RemoveLoadingIndicator();
66+
}
67+
6568
private void DiscordPortal_Navigating(object sender, WebNavigatingEventArgs e)
6669
{
6770
// Catch the navigation to the api
@@ -73,4 +76,9 @@ private void DiscordPortal_Navigating(object sender, WebNavigatingEventArgs e)
7376
DiscordPortal.IsVisible = false;
7477
}
7578
}
79+
80+
private void Close_Clicked(object sender, EventArgs e)
81+
{
82+
NavigateBack().GetAwaiter();
83+
}
7684
}

0 commit comments

Comments
 (0)