示例#1
0
        public virtual void AddChild(MC.Element child, int physicalSiblingIndex)
        {
            if (child is null)
            {
                throw new ArgumentNullException(nameof(child));
            }

            MC.ShellItem itemToAdd = child switch
            {
                MC.TemplatedPage childAsTemplatedPage => childAsTemplatedPage,       // Implicit conversion
                         MC.ShellContent childAsShellContent => childAsShellContent, // Implicit conversion
                         MC.ShellSection childAsShellSection => childAsShellSection, // Implicit conversion
                         MC.MenuItem childAsMenuItem => childAsMenuItem,             // Implicit conversion
                         MC.ShellItem childAsShellItem => childAsShellItem,
                         _ => throw new NotSupportedException($"Handler of type '{GetType().FullName}' representing element type '{TargetElement?.GetType().FullName ?? "<null>"}' doesn't support adding a child (child type is '{child.GetType().FullName}').")
            };

            if (ShellControl.Items.Count >= physicalSiblingIndex)
            {
                ShellControl.Items.Insert(physicalSiblingIndex, itemToAdd);
            }
            else
            {
                Debug.WriteLine($"WARNING: {nameof(AddChild)} called with {nameof(physicalSiblingIndex)}={physicalSiblingIndex}, but ShellControl.Items.Count={ShellControl.Items.Count}");
                ShellControl.Items.Add(itemToAdd);
            }
        }
示例#2
0
 private MC.ShellSection GetSectionForElement(MC.Element child)
 {
     return(child switch
     {
         MC.TemplatedPage childAsTemplatedPage => GetSectionForTemplatedPage(childAsTemplatedPage),
         MC.ShellContent childAsShellContent => GetSectionForContent(childAsShellContent),
         MC.ShellSection childAsShellSection => childAsShellSection,
         _ => null
     });
示例#3
0
 private MC.ShellItem GetItemForElement(MC.Element child)
 {
     return(child switch
     {
         MC.TemplatedPage childAsTemplatedPage => GetItemForTemplatedPage(childAsTemplatedPage),
         MC.ShellContent childAsShellContent => GetItemForContent(childAsShellContent),
         MC.ShellSection childAsShellSection => GetItemForSection(childAsShellSection),
         MC.MenuItem childAsMenuItem => GetItemForMenuItem(childAsMenuItem),
         MC.ShellItem childAsShellItem => childAsShellItem,
         _ => null
     });
 private static ElementHandler CreateHandler(MC.Element parent, MobileBlazorBindingsRenderer renderer)
 {
     return(parent switch
     {
         MC.ContentPage contentPage => new ContentPageHandler(renderer, contentPage),
         MC.ContentView contentView => new ContentViewHandler(renderer, contentView),
         MC.Label label => new LabelHandler(renderer, label),
         MC.FlyoutPage flyoutPage => new FlyoutPageHandler(renderer, flyoutPage),
         MC.ScrollView scrollView => new ScrollViewHandler(renderer, scrollView),
         MC.ShellContent shellContent => new ShellContentHandler(renderer, shellContent),
         MC.Shell shell => new ShellHandler(renderer, shell),
         MC.ShellItem shellItem => new ShellItemHandler(renderer, shellItem),
         MC.ShellSection shellSection => new ShellSectionHandler(renderer, shellSection),
         MC.TabbedPage tabbedPage => new TabbedPageHandler(renderer, tabbedPage),
         _ => new ElementHandler(renderer, parent),
     });
示例#5
0
        // This is used for cases where the user is navigating via native UI navigation i.e. clicking on Tabs
        // If the user defers this type of navigation we generate the equivalent GotoAsync call
        // so when the deferral is completed the same navigation can complete
        public bool ProposeNavigationOutsideGotoAsync(
            ShellNavigationSource source,
            ShellItem shellItem,
            ShellSection shellSection,
            ShellContent shellContent,
            IReadOnlyList <Page> stack,
            bool canCancel,
            bool isAnimated)
        {
            if (AccumulateNavigatedEvents)
            {
                return(true);
            }

            var proposedState = GetNavigationState(shellItem, shellSection, shellContent, stack, shellSection.Navigation.ModalStack);
            var navArgs       = ProposeNavigation(source, proposedState, canCancel, isAnimated);

            if (navArgs.DeferralCount > 0)
            {
                navArgs.RegisterDeferralCompletedCallBack(async() =>
                {
                    if (navArgs.Cancelled)
                    {
                        return;
                    }

                    Func <Task> navigationTask = () => GoToAsync(navArgs.Target, navArgs.Animate, false, navArgs);

                    if (Device.IsInvokeRequired)
                    {
                        await Device.InvokeOnMainThreadAsync(navigationTask);
                    }
                    else
                    {
                        await navigationTask();
                    }
                });
            }

            return(!navArgs.NavigationDelayedOrCancelled);
        }
示例#6
0
        bool IShellItemController.ProposeSection(ShellSection shellSection, bool setValue)
        {
            var controller = (IShellController)Parent;

            if (controller == null)
            {
                return(false);
            }

            bool accept = controller.ProposeNavigation(ShellNavigationSource.ShellSectionChanged,
                                                       this,
                                                       shellSection,
                                                       shellSection?.CurrentItem,
                                                       shellSection?.Stack,
                                                       true
                                                       );

            if (accept && setValue)
            {
                SetValueFromRenderer(CurrentItemProperty, shellSection);
            }

            return(accept);
        }
示例#7
0
        public static ShellNavigationParameters GetNavigationParameters(
            ShellItem shellItem,
            ShellSection shellSection,
            ShellContent shellContent,
            IReadOnlyList <Page> sectionStack,
            IReadOnlyList <Page> modalStack)
        {
            var state    = GetNavigationState(shellItem, shellSection, shellContent, sectionStack, modalStack);
            var navStack = shellSection.Navigation.NavigationStack;

            var topNavStackPage =
                (modalStack?.Count > 0 ? modalStack[modalStack.Count - 1] : null) ??
                (navStack?.Count > 0 ? navStack[navStack.Count - 1] : null);

            var queryParametersTarget =
                topNavStackPage as BindableObject ??
                (shellContent?.Content as BindableObject) ??
                shellContent;

            ShellRouteParameters routeParameters = null;

            if (queryParametersTarget?.GetValue(ShellContent.QueryAttributesProperty) is
                ShellRouteParameters shellRouteParameters)
            {
                routeParameters = shellRouteParameters;
            }

            return(new ShellNavigationParameters()
            {
                TargetState = state,
                Animated = false,
                EnableRelativeShellRoutes = false,
                DeferredArgs = null,
                Parameters = routeParameters
            });
        }
示例#8
0
        public ShellSectionHandler(NativeComponentRenderer renderer, MC.ShellSection shellSectionControl) : base(renderer, shellSectionControl)
        {
            ShellSectionControl = shellSectionControl ?? throw new ArgumentNullException(nameof(shellSectionControl));

            Initialize(renderer);
        }