adenearnshaw / AppShortcutsPlugin

AppShortcuts plugin for Xamarin and Windows
MIT License
33 stars 8 forks source link

[Question] How does it works with MasterDetail Template? #27

Closed mhrastegari closed 4 years ago

mhrastegari commented 4 years ago

Description

it opens the DetailPage inside the DetailPage even if i select another shortcut(like the About page in the GIF) it show that page with a back button and when i press that back button result is the same :( i think i'm doing something wrong or missing but i don't know what.

The Code

using Plugin.AppShortcuts;
using Plugin.AppShortcuts.Icons;
using System;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using XamNote.Views;

namespace XamNote
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class App : Application
    {
        public const string AppShortcutUriBase = "mhr://XamNote/";
        public const string ShortcutOption1 = "Note";
        public const string ShortcutOption2 = "About";

        [Obsolete]
        public App()
        {
            AddShortcuts();
            InitializeComponent();
            MainPage = new MainPage();
        }

        public async void AddShortcuts()
        {
            if (CrossAppShortcuts.IsSupported)
            {
                var shortCurts = await CrossAppShortcuts.Current.GetShortcuts();
                if (shortCurts.FirstOrDefault(prop => prop.Label == "Note") == null)
                {
                    var shortcut = new Shortcut()
                    {
                        Label = "Note",
                        Description = "Go to Home",
                        Icon = new HomeIcon(),
                        Uri = $"{AppShortcutUriBase}{ShortcutOption1}"
                    };
                    await CrossAppShortcuts.Current.AddShortcut(shortcut);
                }

                if (shortCurts.FirstOrDefault(prop => prop.Label == "About") == null)
                {
                    var shortcut = new Shortcut()
                    {
                        Label = "About",
                        Description = "Go to About",
                        Icon = new ContactIcon(),
                        Uri = $"{AppShortcutUriBase}{ShortcutOption2}"
                    };
                    await CrossAppShortcuts.Current.AddShortcut(shortcut);
                }
            }
        }

        protected override void OnAppLinkRequestReceived(Uri uri)
        {
            var option = uri.ToString().Replace(AppShortcutUriBase, "");
            if (!string.IsNullOrEmpty(option))
            {
                MainPage = new NavigationPage(new MainPage());
                switch (option)
                {
                    case ShortcutOption1:
                        MainPage.Navigation.PushAsync(new ItemsPage());
                        break;

                    case ShortcutOption2:
                        MainPage.Navigation.PushAsync(new AboutPage());
                        break;
                }
            }
            else
                base.OnAppLinkRequestReceived(uri);
        }

    }
}

ScreenShot

5875307526244796268

adenearnshaw commented 4 years ago

Here's a sample https://github.com/adenearnshaw/AppShortcutsPluginSamples/tree/master/MasterDetailPage