Beispiel #1
0
        public void Should_InvokeViewShellPopPage_When_PageIsPopped()
        {
            // Arrange
            var sut = new ViewStackService(_viewShell, new[] { _page, _page });

            // Act
            sut.PopPages().Subscribe();

            // Assert
            _viewShell.Received(1).PopPage(true);
        }
Beispiel #2
0
        public HomeViewModel(IViewStackService viewStackService)
            : base(viewStackService)
        {
            PushPage = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PushPage(new HomeViewModel(ViewStackService)));
            });

            PushModalWithNav = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PushModal(new NavigationPageViewModel(new HomeViewModel(ViewStackService))));
            });

            PushModalWithoutNav = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PushModal(new HomeViewModel(ViewStackService)));
            });

            PopModal = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService.PopModal());
            });

            var canPop = this.WhenAnyValue(
                vm => vm.PopCount,
                vm => vm.PageCount,
                (popCount, pageCount) => popCount > 0 && popCount < pageCount);

            PopPages = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(ViewStackService
                       .PopPages(_popCount ?? 0, true));
            },
                canPop);

            var canPopToNewPage = this.WhenAnyValue(
                vm => vm.PageIndex,
                pageIndex => pageIndex >= 0 && pageIndex < PageCount);

            PopToNewPage = ReactiveCommand.CreateFromObservable(
                () =>
            {
                return(Observable
                       .Start(() => ViewStackService.InsertPage(PageIndex ?? 0, new LoginViewModel(ViewStackService)), RxApp.MainThreadScheduler)
                       .SelectMany(_ => ViewStackService.PopToPage(PageIndex ?? 0)));
            },
                canPopToNewPage);

            this.WhenActivated(
                disposables =>
            {
                _pageCount = ViewStackService
                             .PageStack
                             .Select(
                    x =>
                {
                    return(x != null ? x.Count : 0);
                })
                             .ToProperty(this, vm => vm.PageCount, default(int), false, RxApp.MainThreadScheduler)
                             .DisposeWith(disposables);
            });
        }