Skip to content

Commit

Permalink
Merge pull request #126 from edgiardina/appactions-usedispatcher
Browse files Browse the repository at this point in the history
Appactions usedispatcher
  • Loading branch information
edgiardina authored Mar 2, 2024
2 parents d260eec + b3dd928 commit 9eea9ef
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
28 changes: 23 additions & 5 deletions App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ protected override async void OnStart()
await NotificationManager.RequestAccess();
}

public static void HandleAppActions(AppAction appAction)
public static async void HandleAppActions(AppAction appAction)
{
App.Current.Dispatcher.Dispatch(async () =>
var route = $"//{appAction.Id}";

Current.Dispatcher.DispatchDelayed(TimeSpan.FromMilliseconds(500), async () =>
{
await Shell.Current.GoToAsync($"//{appAction.Id}");
await Shell.Current.GoToAsync(route);
});
await Task.Delay(500);
((AppShell)Shell.Current).ConfirmSelectedTabIsCorrect(route);
}

//Some places we can't Dependency Inject so we add this static helper
Expand All @@ -65,7 +69,14 @@ protected override async void OnAppLinkRequestReceived(Uri uri)

if (!string.IsNullOrEmpty(id))
{
await Shell.Current.GoToAsync($"//rankings/player-details?playerId={id}");
var route = $"//rankings/player-details?playerId={id}";

Current.Dispatcher.DispatchDelayed(TimeSpan.FromMilliseconds(500), async () =>
{
await Shell.Current.GoToAsync(route);
});
await Task.Delay(500);
((AppShell)Shell.Current).ConfirmSelectedTabIsCorrect(route);
}
}
//tournaments/view.php?t=46773
Expand All @@ -74,7 +85,14 @@ protected override async void OnAppLinkRequestReceived(Uri uri)
var id = HttpUtility.ParseQueryString(uri.Query)["t"];
if (!string.IsNullOrEmpty(id))
{
await Shell.Current.GoToAsync($"//rankings/tournament-results?tournamentId={id}");
var route = $"//rankings/tournament-results?tournamentId={id}";

Current.Dispatcher.DispatchDelayed(TimeSpan.FromMilliseconds(500), async () =>
{
await Shell.Current.GoToAsync(route);
});
await Task.Delay(500);
((AppShell)Shell.Current).ConfirmSelectedTabIsCorrect(route);
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion AppShell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,30 @@
xmlns:local="clr-namespace:Ifpa"
xmlns:views="clr-namespace:Ifpa.Views"
Shell.FlyoutBehavior="Disabled">
<TabBar>
<TabBar x:Name="MainTabBar">
<ShellContent Title="{x:Static local:Strings.AppShell_Rankings}"
x:Name="RankingsTab"
ContentTemplate="{DataTemplate views:RankingsPage}"
Icon="numbered_list.png"
Route="rankings" />
<ShellContent Title="{x:Static local:Strings.AppShell_ChampSeries}"
x:Name="ChampionshipSeriesTab"
ContentTemplate="{DataTemplate views:ChampionshipSeriesListPage}"
Icon="trophy.png"
Route="champ-series-list" />
<ShellContent Title="{x:Static local:Strings.AppShell_MyStats}"
x:Name="MyStatsTab"
ContentTemplate="{DataTemplate views:PlayerDetailPage}"
Icon="mystats.png"
Route="my-stats" />
<ShellContent Title="{x:Static local:Strings.AppShell_Calendar}"
x:Name="CalendarTab"
ContentTemplate="{DataTemplate views:CalendarPage}"
Icon="calendar.png"
Route="calendar" />
<!-- More Menu Items-->
<ShellContent Title="{x:Static local:Strings.AppShell_More}"
x:Name="MoreTab"
ContentTemplate="{DataTemplate views:MoreItemsPage}"
Icon="more.png"
Route="more" />
Expand Down
33 changes: 29 additions & 4 deletions AppShell.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ namespace Ifpa;

public partial class AppShell : Shell
{
public AppShell()
{
InitializeComponent();
public AppShell()
{
InitializeComponent();

Routing.RegisterRoute("rankings-filter", typeof(RankingsFilterModalPage));
Routing.RegisterRoute("player-search", typeof(PlayerSearchPage));
Routing.RegisterRoute("player-details", typeof(PlayerDetailPage));
Routing.RegisterRoute("player-results", typeof(PlayerResultsPage));
Routing.RegisterRoute("activity-feed", typeof(ActivityFeedPage));
Routing.RegisterRoute("pvp", typeof(PlayerVersusPlayerPage));
Routing.RegisterRoute("pvp-detail", typeof(PlayerVersusPlayerDetailPage));
Routing.RegisterRoute("pvp-detail", typeof(PlayerVersusPlayerDetailPage));
Routing.RegisterRoute("tournament-results", typeof(TournamentResultsPage));
Routing.RegisterRoute("player-champ-series", typeof(PlayerChampionshipSeriesPage));

Expand Down Expand Up @@ -66,4 +66,29 @@ protected override async void OnNavigating(ShellNavigatingEventArgs args)

token?.Complete();
}
// TODO: this is a hack to get the correct tab to show when navigating to a page
// https://github.com/dotnet/maui/issues/16568
public void ConfirmSelectedTabIsCorrect(string route)
{
if (route.Contains("rankings"))
{
MainTabBar.CurrentItem = RankingsTab;
}
else if (route.Contains("champ-series-list"))
{
MainTabBar.CurrentItem = ChampionshipSeriesTab;
}
else if (route.Contains("calendar"))
{
MainTabBar.CurrentItem = CalendarTab;
}
else if (route.Contains("my-stats"))
{
MainTabBar.CurrentItem = MyStatsTab;
}
else if (route.Contains("more"))
{
MainTabBar.CurrentItem = MoreTab;
}
}
}

0 comments on commit 9eea9ef

Please sign in to comment.