Exemplo n.º 1
0
 public Task Navigate(string key, object args, IStackOptions options)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 2
0
 public StackResult Navigate(IStackOptions options)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 3
0
        public async Task Navigate(string viewKey, object args, IStackOptions options)
        {
            Navigate(options);

            await Navigate(viewKey, args);
        }
Exemplo n.º 4
0
        public StackResult Navigate(IStackOptions options)
        {
            lock (_lock)
            {
                StackResult stackResult = StackResult.StackStarted;

                if (options.StackChoice == null)
                {
                    throw new NullReferenceException($"{nameof(NavigationService)}.{nameof(Navigate)} can not accept a null {nameof(options.StackChoice)}");
                }

                // Don't change to the same stack
                if (_currentStack != null &&
                    _currentStack.Equals(options.StackChoice))
                {
                    return(StackResult.None);
                }

                if (!_stacks.ContainsKey(options.StackChoice))
                {
                    throw new NullReferenceException($"{nameof(NavigationService)} does not contain a stack named {options.StackChoice.ToString()}");
                }

                // Current / Previous Stack
                IStack oldStack = null;
                if (_currentStack != null)
                {
                    oldStack = _stacks[_currentStack];
                    oldStack.StateChange(StackStatus.Background); // Schedules NoHistoryRemoval
                }

                var stack = _stacks[options.StackChoice];

                _currentStack = options.StackChoice;

                // Set new status
                stack.Proxy.ViewStatus = VisualStatus.Visible;

                // Switch over services
                _displayService.Init(stack.Proxy);

                ThreadHelper.RunOnUIThread(async() =>
                {
                    if (stack.Status == StackStatus.Stopped)
                    {
                        object args = null;

                        // If ArgsKey present only pass args along if the StartKey is the same
                        if ((!string.IsNullOrEmpty(options?.ArgsKey) && stack.NavigationStartKey == options?.ArgsKey) || string.IsNullOrEmpty(options?.ArgsKey))
                        {
                            stackResult = stackResult | StackResult.ArgsPassed;
                            args        = options?.Args;
                        }

                        var loadStartKey = options?.PredefinedStack == null;

                        if (loadStartKey)
                        {
                            stackResult = stackResult | StackResult.NavigationStarted;
                        }

                        await stack.StartNavigation(args: args, loadStartKey: loadStartKey);
                    }

                    //  Preload Stack
                    if (options?.PredefinedStack != null)
                    {
                        foreach (var page in options.PredefinedStack)
                        {
                            await Navigate(page.Key, page.Value);
                        }
                    }

                    // Find mainview from ViewHierarchy
                    var viewContainer = _viewContainers[_stackViewContainers[options.StackChoice]];

                    if (viewContainer is IMasterDetailContainer)
                    {
                        var masterDetailContainer = viewContainer as IMasterDetailContainer;
                        if (masterDetailContainer.DetailStack != null)
                        {
                            // Setup Detail Stack
                            var detailStack = _stacks[masterDetailContainer.DetailStack.StackIdentifier];

                            if (detailStack.Status == StackStatus.Stopped)
                            {
                                await detailStack.StartNavigation();
                            }

                            masterDetailContainer.Proxy.DetailNativeView = detailStack.Proxy.NativeView;

                            // Setup Master Stack
                            var masterStack = _stacks[masterDetailContainer.MasterStack.StackIdentifier];

                            if (masterStack.Status == StackStatus.Stopped)
                            {
                                await masterStack.StartNavigation();
                            }

                            masterDetailContainer.Proxy.MasterNativeView = masterStack.Proxy.NativeView;
                        }
                    }

                    _currentViewContainer = viewContainer;

                    if (!string.IsNullOrEmpty(options.ViewKey))
                    {
                        await Navigate(options.ViewKey, options.Args, options.NewInstance);
                    }

                    _setRoot?.Invoke(viewContainer.NativeView);

                    if (oldStack != null)
                    {
                        await oldStack.StackChanged();
                    }
                });

                return(stackResult);
            }
        }
Exemplo n.º 5
0
        public async Task Navigate(object containerId, object regionId, string viewKey, object args, IStackOptions options)
        {
            Navigate(containerId, regionId, options);

            await Navigate(viewKey, args);
        }
Exemplo n.º 6
0
        public StackResult Navigate(object containerId, object regionId, IStackOptions options)
        {
            lock (_lock)
            {
                StackResult stackResult = StackResult.StackStarted;

                if (options.StackChoice == null)
                {
                    throw new NullReferenceException($"{nameof(NavigationService)}.{nameof(Navigate)} can not accept a null {nameof(options.StackChoice)}");
                }

                // Don't change to the same stack
                if (_currentStack != null &&
                    _currentStack.Equals(options.StackChoice))
                {
                    if (_getRoot != null)
                    {
                        if (_getRoot() == null)
                        {
                            // Set Root Page
                            ThreadHelper.RunOnUIThread(() =>
                            {
                                var viewContainer = _viewContainers[_stackViewContainers[options.StackChoice]];
                                _setRoot?.Invoke(viewContainer?.NativeView);
                            });
                        }
                    }

                    return(StackResult.None);
                }

                if (!_stacks.ContainsKey(options.StackChoice) && regionId == null)
                {
                    throw new NullReferenceException($"{nameof(NavigationService)} does not contain a stack named {options.StackChoice.ToString()}");
                }

                // Current / Previous Stack
                IStack oldStack = null;
                if (_currentStack != null)
                {
                    oldStack = _stacks[_currentStack];
                    oldStack.StateChange(StackStatus.Background);                     // Schedules NoHistoryRemoval
                }

                var stack = _stacks[options.StackChoice];

                _currentStack = options.StackChoice;

                // Set new status
                stack.Proxy.ViewStatus = VisualStatus.Visible;

                // Switch over services
                _displayService.Init(stack.Proxy);

                ThreadHelper.RunOnUIThread(async() =>
                {
                    if (stack.Status == StackStatus.Stopped)
                    {
                        object args = null;

                        // If ArgsKey present only pass args along if the StartKey is the same
                        if ((!string.IsNullOrEmpty(options?.ArgsKey) && stack.NavigationStartKey == options?.ArgsKey) || string.IsNullOrEmpty(options?.ArgsKey))
                        {
                            stackResult = stackResult | StackResult.ArgsPassed;
                            args        = options?.Args;
                        }

                        var loadStartKey = options?.PredefinedStack == null;

                        if (loadStartKey)
                        {
                            stackResult = stackResult | StackResult.NavigationStarted;
                        }

                        await stack.StartNavigation(args: args, loadStartKey: loadStartKey);
                    }

                    //  Preload Stack
                    if (options?.PredefinedStack != null)
                    {
                        foreach (var page in options.PredefinedStack)
                        {
                            await Navigate(page.Key, page.Value);
                        }
                    }

                    IViewContainer viewContainer = null;

                    // Find mainview from ViewHierarchy
                    object viewContainerKey = regionId;
                    if (containerId != null && regionId != null)
                    {
                        var container = _viewContainers[containerId.ToString()];
                        if (container.RegionMapping.Any(x => x.Key.ToString() == regionId.ToString()))
                        {
                            viewContainer = container;
                        }
                    }
                    else if (containerId != null && regionId == null)
                    {
                        var container = _viewContainers[containerId.ToString()];
                        viewContainer = container;
                    }
                    else
                    {
                        if (_stackViewContainers.ContainsKey(stack.StackIdentifier))
                        {
                            viewContainer = _viewContainers[_stackViewContainers[stack.StackIdentifier]];
                        }
                        else
                        {
                            // Create single container
                            viewContainer = new SingleViewContainer(Guid.NewGuid().ToString(), stack);

                            // Add to list
                            _viewContainers.Add(viewContainer.Identifier, viewContainer);
                        }
                    }


                    // Tabbed View
                    if (viewContainer is ITabbedContainer tabbedView)
                    {
                        await InitializeTabbedView(tabbedView);
                    }

                    var containerSwitch = viewContainer.RegionMapping.Any(x => x.Key.ToString() == Convert.ToString(regionId));
                    KeyValuePair <object, ContainerType>?containerType = viewContainer.RegionMapping.FirstOrDefault(x => x.Key.ToString() == Convert.ToString(regionId));

                    // MasterDetail View load
                    if (viewContainer is IMasterDetailContainer)
                    {
                        var masterDetailContainer = viewContainer as IMasterDetailContainer;

                        if (masterDetailContainer.DetailStack != null)
                        {
                            if (masterDetailContainer.DetailStack is IStack detailStackDefinition)
                            {
                                // Setup Detail Stack
                                var detailStack = _stacks[detailStackDefinition.StackIdentifier];

                                if (detailStack.Status == StackStatus.Stopped)
                                {
                                    await detailStack.StartNavigation(options?.Args);
                                }

                                masterDetailContainer.Proxy.DetailNativeView = detailStack.Proxy.NativeView;
                            }
                            else if (masterDetailContainer.DetailStack is ITabbedContainer detailTabbedDefinition)
                            {
                                await InitializeTabbedView(detailTabbedDefinition);

                                masterDetailContainer.Proxy.DetailNativeView = detailTabbedDefinition.NativeView;
                            }

                            if (masterDetailContainer.MasterStack is IStack masterStackDefinition)
                            {
                                // Setup Master Stack
                                var masterStack = _stacks[masterStackDefinition.StackIdentifier];

                                if (masterStack.Status == StackStatus.Stopped)
                                {
                                    await masterStack.StartNavigation(options?.Args);
                                }

                                masterDetailContainer.Proxy.MasterNativeView = masterStack.Proxy.NativeView;
                            }
                            else if (masterDetailContainer.MasterStack is ITabbedContainer masterTabbedDefinition)
                            {
                                await InitializeTabbedView(masterTabbedDefinition);

                                masterDetailContainer.Proxy.MasterNativeView = masterTabbedDefinition.NativeView;
                            }
                        }
                    }

                    if (viewContainer is ITabbedContainer tabbedContainer)
                    {
                        // switch current page
                        tabbedContainer.SetCurrentPage(stack);
                    }

                    // If parent, then move switch container
                    if (viewContainer.ParentContainer != null)
                    {
                        viewContainer = viewContainer.ParentContainer;
                    }

                    _currentViewContainer = viewContainer;

                    if (!string.IsNullOrEmpty(options.ViewKey))
                    {
                        await Navigate(options.ViewKey, options.Args, options.NewInstance);
                    }

                    if (!containerSwitch)
                    {
                        _setRoot?.Invoke(viewContainer?.NativeView);
                    }
                    else if (viewContainer is IMasterDetailContainer container)
                    {
                        container.SetStack(containerType.Value.Value, stack.Proxy.NativeView);
                    }

                    if (oldStack != null)
                    {
                        await oldStack.StackChanged();
                    }
                });

                return(stackResult);
            }


            async Task InitializeTabbedView(ITabbedContainer tabbedView)
            {
                // Must start all stacks on the first tabbed view load
                // because when the tab changes, I can't block while I load an individual tab
                // I can only block moving to an entire page
                foreach (var item in tabbedView.Children)
                {
                    if (item.Status == StackStatus.Stopped)
                    {
                        await item.StartNavigation(options?.Args);
                    }
                }
            }
        }
Exemplo n.º 7
0
 public StackResult Navigate(IStackOptions options)
 {
     return(Navigate(containerId: null, regionId: null, options: options));
 }