public override async Task <bool> ShowMasterDetailPage(Type view, MvvmCross.Forms.Presenters.Attributes.MvxMasterDetailPagePresentationAttribute attribute, MvxViewModelRequest request)
        {
            var page = await CloseAndCreatePage(view, request, attribute);

            if (attribute.Position == MasterDetailPosition.Root)
            {
                if (page is FlyoutPage masterDetailRoot)
                {
                    if (masterDetailRoot.Flyout == null)
                    {
                        masterDetailRoot.Flyout = CreateContentPage().Build(cp => cp.Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage));
                    }
                    if (masterDetailRoot.Detail == null)
                    {
                        masterDetailRoot.Detail = CreateContentPage().Build(cp => cp.Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage));
                    }

                    await PushOrReplacePage(FormsApplication.MainPage, page, attribute);
                }
                else
                {
                    throw new MvxException($"A root page should be of type {nameof(FlyoutPage)}");
                }
            }
            else
            {
                FlyoutPage masterDetailHost = null;
                if (attribute is MvxCustomMasterDetailPagePresentationAttribute attr && attr.MasterHostViewType != null)
                {
                    masterDetailHost = GetPageOfTypeByType(attr.MasterHostViewType) as FlyoutPage;
                }
                if (masterDetailHost == null)
                {
                    masterDetailHost = GetPageOfType <FlyoutPage>();
                }

                if (masterDetailHost == null)
                {
                    //Assume we have to create the host
                    masterDetailHost = CreateMasterDetailPage();

                    if (!string.IsNullOrWhiteSpace(attribute.Icon))
                    {
                        masterDetailHost.IconImageSource = attribute.Icon;
                    }

                    masterDetailHost.Flyout = CreateContentPage().Build(cp => cp.Title = !string.IsNullOrWhiteSpace(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage));
                    masterDetailHost.Detail = CreateContentPage();

                    var masterDetailRootAttribute = new MvxMasterDetailPagePresentationAttribute {
                        Position = MasterDetailPosition.Root, WrapInNavigationPage = attribute.WrapInNavigationPage, NoHistory = attribute.NoHistory
                    };

                    await PushOrReplacePage(FormsApplication.MainPage, masterDetailHost, masterDetailRootAttribute);
                }

                if (attribute.Position == MasterDetailPosition.Master)
                {
                    await PushOrReplacePage(masterDetailHost.Flyout, page, attribute);
                }
                else
                {
                    await PushOrReplacePage(masterDetailHost.Detail, page, attribute);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public virtual void ShowMasterDetailPage(
            Type view,
            MvxMasterDetailPagePresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            CloseAllModals();

            var page = CreatePage(view, request);

            if (attribute.Position == MasterDetailPosition.Root)
            {
                if (page is MasterDetailPage masterDetailRoot)
                {
                    if (masterDetailRoot.Master == null)
                    {
                        masterDetailRoot.Master = new MvxContentPage()
                        {
                            Title = "MvvmCross"
                        }
                    }
                    ;
                    if (masterDetailRoot.Detail == null)
                    {
                        masterDetailRoot.Detail = new MvxContentPage()
                        {
                            Title = "MvvmCross"
                        }
                    }
                    ;

                    if (attribute.WrapInNavigationPage && FormsApplication.MainPage is MvxNavigationPage currentPage)
                    {
                        currentPage.PushAsync(page);
                    }
                    else if (attribute.WrapInNavigationPage)
                    {
                        FormsApplication.MainPage = new MvxNavigationPage(page);
                    }
                    else
                    {
                        FormsApplication.MainPage = page;
                    }
                }
                else
                {
                    throw new MvxException($"A root page should be of type {nameof(MasterDetailPage)}");
                }
            }
            else
            {
                var masterDetailHost = FormsApplication.MainPage as MasterDetailPage;
                if (masterDetailHost == null && FormsApplication.MainPage is MvxNavigationPage navigationPage)
                {
                    masterDetailHost = navigationPage.CurrentPage as MasterDetailPage;
                    if (masterDetailHost == null)
                    {
                        masterDetailHost        = new MasterDetailPage();
                        masterDetailHost.Master = new MvxContentPage()
                        {
                            Title = "MvvmCross"
                        };
                        masterDetailHost.Detail = new MvxContentPage()
                        {
                            Title = "MvvmCross"
                        };
                        navigationPage.PushAsync(masterDetailHost);
                    }
                }
                else if (masterDetailHost == null)
                {
                    //Assume we have to create the host
                    masterDetailHost        = new MasterDetailPage();
                    masterDetailHost.Master = new MvxContentPage()
                    {
                        Title = "MvvmCross"
                    };
                    masterDetailHost.Detail = new MvxContentPage()
                    {
                        Title = "MvvmCross"
                    };
                    FormsApplication.MainPage = masterDetailHost;
                }
                if (attribute.Position == MasterDetailPosition.Master)
                {
                    if (attribute.WrapInNavigationPage && masterDetailHost.Master is MvxNavigationPage navigationMasterPage)
                    {
                        navigationMasterPage.PushAsync(page);
                    }
                    else if (attribute.WrapInNavigationPage)
                    {
                        masterDetailHost.Master = new MvxNavigationPage(page);
                    }
                    else
                    {
                        masterDetailHost.Master = page;
                    }
                }
                else
                {
                    if (attribute.WrapInNavigationPage && masterDetailHost.Detail is MvxNavigationPage navigationDetailPage)
                    {
                        navigationDetailPage.PushAsync(page);
                    }
                    else if (attribute.WrapInNavigationPage)
                    {
                        masterDetailHost.Detail = new MvxNavigationPage(page);
                    }
                    else
                    {
                        masterDetailHost.Detail = page;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public virtual void ShowMasterDetailPage(
            Type view,
            MvxMasterDetailPagePresentationAttribute attribute,
            MvxViewModelRequest request)
        {
            var page = CloseAndCreatePage(view, request, attribute);

            if (attribute.Position == MasterDetailPosition.Root)
            {
                if (page is MasterDetailPage masterDetailRoot)
                {
                    if (masterDetailRoot.Master == null)
                    {
                        masterDetailRoot.Master = new MvxContentPage()
                        {
                            Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                        }
                    }
                    ;
                    if (masterDetailRoot.Detail == null)
                    {
                        masterDetailRoot.Detail = new MvxContentPage()
                        {
                            Title = !string.IsNullOrEmpty(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                        }
                    }
                    ;

                    PushOrReplacePage(FormsApplication.MainPage, page, attribute);
                }
                else
                {
                    throw new MvxException($"A root page should be of type {nameof(MasterDetailPage)}");
                }
            }
            else
            {
                var masterDetailHost = GetHostPageOfType <MvxMasterDetailPage>();
                if (masterDetailHost == null)
                {
                    //Assume we have to create the host
                    masterDetailHost = new MvxMasterDetailPage();

                    if (!string.IsNullOrWhiteSpace(attribute.Icon))
                    {
                        masterDetailHost.Icon = attribute.Icon;
                    }

                    masterDetailHost.Master = new MvxContentPage()
                    {
                        Title = !string.IsNullOrWhiteSpace(attribute.Title) ? attribute.Title : nameof(MvxMasterDetailPage)
                    };
                    masterDetailHost.Detail = new MvxContentPage();

                    var masterDetailRootAttribute = new MvxMasterDetailPagePresentationAttribute {
                        Position = MasterDetailPosition.Root, WrapInNavigationPage = attribute.WrapInNavigationPage, NoHistory = attribute.NoHistory
                    };

                    PushOrReplacePage(FormsApplication.MainPage, masterDetailHost, masterDetailRootAttribute);
                }

                if (attribute.Position == MasterDetailPosition.Master)
                {
                    PushOrReplacePage(masterDetailHost.Master, page, attribute);
                }
                else
                {
                    PushOrReplacePage(masterDetailHost.Detail, page, attribute);
                }
            }
        }
Exemplo n.º 4
0
 private MvxMasterDetailPagePresentationAttribute CreateMasterDetailRootAttribute(MvxMasterDetailPagePresentationAttribute attribute)
 {
     return(new MvxMasterDetailPagePresentationAttribute
     {
         Position = MasterDetailPosition.Root,
         WrapInNavigationPage = attribute.WrapInNavigationPage,
         // MK This is a workaround for the issue on iOS, where setting FormsApplication.MainPage with a new NavigationPage (or other Page for that matter)
         //    is not working. By setting NoHistory flag to false we avoid replacing the current MainPage with a brand new one. Instead, we navigate to the MasterDetail page
         //    leaving the already existing NavigationPage intact.
         //
         //    This issue is being tracked in here: https://yambay.atlassian.net/browse/PRODEV-4896
         NoHistory = false
     });
 }