Пример #1
0
        public async Task UpdateNavigation(NavigationOperation <TViewModel> navigationOperation, INavigationInProgress navigationInProgress)
        {
            if (navigationOperation.Pushes.Count == 0 && navigationOperation.Pops.Count == 0)
            {
                return;
            }

            var controllersToPush = navigationOperation.Pushes.Select(x => new PushInformation <TViewModel>(_factoryAssociation[x.Screen], x.Instance)).ToList();

            foreach (var push in navigationOperation.Pushes)
            {
                await push.Instance.GetViewModel("");                 //TODO: add route here
            }

            if (navigationInProgress.IsCancelled)
            {
                Task.Run(async() =>
                {
                    // we wait 10s just in case, shouldn't put too much memory pressure on GC
                    await Task.Delay(10_000);

                    foreach (var push in navigationOperation.Pushes)
                    {
                        push.Instance.ViewModelInstance?.SafeDispose();
                    }
                }).ConfigureAwait(false);
                return;
            }

            navigationInProgress.Commit();

            CrossCurrentActivity.Current.Activity.RunOnUiThread(() => _navigationStack.ApplyActions(navigationOperation.Pops.Count, controllersToPush));
        }
Пример #2
0
        public Task UpdateNavigation(NavigationOperation <SampleViewModel> navigationOperation, INavigationInProgress navigationInProgress)
        {
            Console.WriteLine($"\tOperations to apply: Pops={navigationOperation.Pops.Count}, Pushes={navigationOperation.Pushes.Count}");
            Console.WriteLine("");

            navigationInProgress.Commit();
            return(Task.CompletedTask);
        }
        public async Task UpdateNavigation(NavigationOperation <TViewModel> navigationOperation, INavigationInProgress navigationInProgress)
        {
            if (navigationOperation.Pushes.Count == 0 && navigationOperation.Pops.Count == 0)
            {
                return;
            }

            var controllersToPush = navigationOperation.Pushes.Select(x => new PushInformation <TViewModel>(_factoryAssociation[x.Screen], x.Instance));

            foreach (var push in navigationOperation.Pushes)
            {
                await push.Instance.GetViewModel("");                 //TODO: add route here
            }

            if (navigationInProgress.IsCancelled)
            {
                Task.Run(async() =>
                {
                    // we wait 10s just in case, shouldn't put too much memory pressure on GC
                    await Task.Delay(10_000);

                    foreach (var push in navigationOperation.Pushes)
                    {
                        push.Instance.ViewModelInstance?.SafeDispose();
                    }
                }).ConfigureAwait(false);
                return;
            }

            navigationInProgress.Commit();
            UIApplication.SharedApplication.InvokeOnMainThread(() =>
            {
                var callbackActionWaiter = new CallbackActionWaiter();
                callbackActionWaiter.WaitOne();
                _navigationStack.EnsureInitialized(_navigationController);

                _navigationStack.ApplyActions(navigationOperation.Pops.Count, controllersToPush, callbackActionWaiter);

                // lines below could be commented if we encounter issues with viewmodel disposing
                callbackActionWaiter.Add(() =>
                {
                    foreach (PopAction <TViewModel> pop in navigationOperation.Pops)
                    {
                        pop.Instance.ViewModelInstance?.DispatchSafeDispose();
                    }
                });

                Task.Run(async() =>
                {
                    // we wait 10s to let the time for navigation controller animations before disposing content
                    await Task.Delay(10_000);
                    UIApplication.SharedApplication.InvokeOnMainThread(callbackActionWaiter.ReleaseOne);
                });
            });
        }