Esempio n. 1
0
        public void NavigateDelegatesToIRegionNavigationService()
        {
            try
            {
                // Prepare
                IRegion region = new Region();

                var view = new ContentView();
                region.Add(view);

                var uri = new Uri(view.GetType().Name, UriKind.Relative);
                Action <IRegionNavigationResult> navigationCallback = nr => { };
                var navigationParameters = new NavigationParameters();

                var mockRegionNavigationService = new Mock <IRegionNavigationService>();
                mockRegionNavigationService.Setup(x => x.RequestNavigate(uri, navigationCallback, navigationParameters)).Verifiable();

                var containerMock = new Mock <IContainerExtension>();
                containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationService))).Returns(mockRegionNavigationService.Object);
                ContainerLocator.ResetContainer();
                ContainerLocator.SetContainerExtension(() => containerMock.Object);

                // Act
                region.NavigationService.RequestNavigate(uri, navigationCallback, navigationParameters);

                // Verify
                mockRegionNavigationService.VerifyAll();
            }
            finally
            {
                ContainerLocator.ResetContainer();
            }
        }
        public static void AddView(ContentView view)
        {
            if (view == null)
            {
                throw new ArgumentNullException();
            }

            views[view.GetType().Name] = view;
        }
        public void WhenNavigationSucceeds_NavigatedIsRaised()
        {
            // Prepare
            var view    = new ContentView();
            var viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string regionName    = "RegionName";
            var    regionManager = new RegionManager();

            regionManager.Regions.Add(regionName, region);

            var containerMock = new Mock <IContainerExtension>();

            containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(new RegionNavigationJournalEntry());

            IContainerExtension container    = containerMock.Object;
            var contentLoader                = new RegionNavigationContentLoader(container);
            IRegionNavigationJournal journal = Mock.Of <IRegionNavigationJournal>();

            var target = new RegionNavigationService(container, contentLoader, journal)
            {
                Region = region
            };

            bool isNavigatedRaised = false;

            target.Navigated += delegate(object sender, RegionNavigationEventArgs e)
            {
                if (sender == target)
                {
                    isNavigatedRaised = true;
                }
            };

            // Act
            bool isNavigationSuccessful = false;

            target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true);

            // Verify
            Assert.True(isNavigationSuccessful);
            Assert.True(isNavigatedRaised);
        }
        /// <summary>
        /// Invalidates the size of this ContentView
        /// </summary>
        /// <param name="page">The ContentView object to which this method will be extented to</param>
        public static void InvalidateSize(this ContentView view)
        {
            var method = view.GetType().GetTypeInfo().DeclaredMethods.FirstOrDefault(m => m.Name == "InvalidateMeasure");

            if (method != null)
            {
                method.Invoke(view, null);
            }
            else
            {
                var layout = view.Content as Layout;
                if (layout != null)
                {
                    layout.ForceLayout();
                }
            }
        }
        public void WhenNavigatingAndViewCannotBeAcquired_ThenNavigationResultHasError()
        {
            // Prepare
            var view    = new ContentView();
            var viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string otherType = "OtherType";

            var containerMock = new Mock <IContainerExtension>();

            containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(new RegionNavigationJournalEntry());
            IContainerExtension container = containerMock.Object;

            var targetHandlerMock = new Mock <IRegionNavigationContentLoader>();

            targetHandlerMock.Setup(th => th.LoadContent(It.IsAny <IRegion>(), It.IsAny <INavigationContext>())).Throws <ArgumentException>();

            IRegionNavigationJournal journal = Mock.Of <IRegionNavigationJournal>();

            var target = new RegionNavigationService(container, targetHandlerMock.Object, journal)
            {
                Region = region
            };

            // Act
            Exception error = null;

            target.RequestNavigate(
                new Uri(otherType.GetType().Name, UriKind.Relative),
                nr =>
            {
                error = nr.Error;
            });

            // Verify
            bool isViewActive = region.ActiveViews.Contains(view);

            Assert.False(isViewActive);
            Assert.IsType <ArgumentException>(error);
        }
        public void WhenNavigating_NavigationIsRecordedInJournal()
        {
            // Prepare
            var view    = new ContentView();
            var viewUri = new Uri(view.GetType().Name, UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string regionName    = "RegionName";
            var    regionManager = new RegionManager();

            regionManager.Regions.Add(regionName, region);

            IRegionNavigationJournalEntry journalEntry = new RegionNavigationJournalEntry();

            var containerMock = new Mock <IContainerExtension>();

            containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(journalEntry);

            IContainerExtension container = containerMock.Object;
            var contentLoader             = new RegionNavigationContentLoader(container);

            var journalMock = new Mock <IRegionNavigationJournal>();

            journalMock.Setup(x => x.RecordNavigation(journalEntry, true)).Verifiable();

            IRegionNavigationJournal journal = journalMock.Object;


            var target = new RegionNavigationService(container, contentLoader, journal)
            {
                Region = region
            };

            // Act
            target.RequestNavigate(viewUri, nr => { });

            // Verify
            Assert.NotNull(journalEntry);
            Assert.Equal(viewUri, journalEntry.Uri);
            journalMock.VerifyAll();
        }
        public void WhenNavigatingWithQueryString_ViewIsActivated()
        {
            // Prepare
            var view    = new ContentView();
            var viewUri = new Uri(view.GetType().Name + "?MyQuery=true", UriKind.Relative);

            IRegion region = new Region();

            region.Add(view);

            string regionName    = "RegionName";
            var    regionManager = new RegionManager();

            regionManager.Regions.Add(regionName, region);

            var containerMock = new Mock <IContainerExtension>();

            containerMock.Setup(x => x.Resolve(typeof(IRegionNavigationJournalEntry))).Returns(new RegionNavigationJournalEntry());

            var container     = containerMock.Object;
            var contentLoader = new RegionNavigationContentLoader(container);
            var journal       = Mock.Of <IRegionNavigationJournal>();

            var target = new RegionNavigationService(container, contentLoader, journal)
            {
                Region = region
            };

            // Act
            bool isNavigationSuccessful = false;

            target.RequestNavigate(viewUri, nr => isNavigationSuccessful = nr.Result == true);

            // Verify
            Assert.True(isNavigationSuccessful);
            bool isViewActive = region.ActiveViews.Contains(view);

            Assert.True(isViewActive);
        }
 private void ChangePage(ContentView view, bool showFooter = true)
 {
     MessagingCenter.Send <INavigationService, ContentView>(this, Helpers.MessageConstant.PageChanged, view);
     MessagingCenter.Send <INavigationService, Type>(this, Helpers.MessageConstant.PageChanged, view.GetType());
     MessagingCenter.Send <INavigationService, bool>(this, Helpers.MessageConstant.ShowFooter, showFooter);
     navigationStack.Add(view);
     footerStack.Add(showFooter);
     if (navigationStack.Count > 10)
     {
         navigationStack.RemoveAt(0);
         footerStack.RemoveAt(0);
     }
 }
        public bool OnTouch(View view, MotionEvent motionEvent)
        {
            if (view.GetType() == ContentView?.GetType())
            {
                if (!_gestureDetector.OnTouchEvent(motionEvent))
                {
                    if (motionEvent.Action == MotionEventActions.Up || motionEvent.Action == MotionEventActions.Cancel)
                    {
                        bool swipingRight = ContentView.TranslationX > 0;
                        bool swipingLeft  = ContentView.TranslationX < 0;
                        if (swipingLeft && ContentView.TranslationX > RightActionButtonLeftX())
                        {
                            float centerXPos = RightActionButtonLeftX() / 2;
                            if (ContentView.TranslationX > centerXPos)
                            {
                                ResetView();
                            }
                            else
                            {
                                SwipeToUncoverRightActionButton();
                            }
                        }
                        else if (swipingRight && ContentView.TranslationX < LeftActionButtonRightX())
                        {
                            float centerXPos = LeftActionButtonRightX() / 2;
                            if (ContentView.TranslationX > centerXPos)
                            {
                                SwipeToUncoverLeftActionButton();
                            }
                            else
                            {
                                ResetView();
                            }
                        }
                        else if (ContentView.TranslationX < RightActionButtonLeftX())
                        {
                            if (SwipeToActionEnabled && CheckFullSwipeLeftThresholdMet(ContentView.TranslationX))
                            {
                                SwipeFullLeft();
                            }
                            else
                            {
                                SwipeToUncoverRightActionButton();
                            }
                        }
                        else if (ContentView.TranslationX > LeftActionButtonRightX())
                        {
                            if (SwipeToActionEnabled && CheckFullSwipeRightThresholdMet(ContentView.TranslationX))
                            {
                                SwipeFullRight();
                            }
                            else
                            {
                                SwipeToUncoverLeftActionButton();
                            }
                        }
                        else if (swipingRight && LeftActionButton == null)
                        {
                            ResetView();
                        }
                        else if (swipingLeft && RightActionButton == null)
                        {
                            ResetView();
                        }
                    }
                }
                return(true);
            }

            return(false);
        }