private async void Accept(object sender, RoutedEventArgs e) { if (!Creatable) return; Favorite favorite = new Favorite() { Name = name, Address = address, Description = description, Symbol = symbol, Location = Location.Location, Timestamp = DateTime.Now }; await favorite.SaveToFile(collection); State favState = new State() { Sheet = typeof(LocationSheet), MapCenter = favorite.Location, MapZoomLevel = 14 }; NavigationManager.Current.NavigateTo(favState, favorite); }
private void SearchBox_GotFocus(object sender, RoutedEventArgs e) { if (SheetsFrame.CurrentSourcePageType == typeof(LibrarySheet)) { NavigationManager.Current.NavigateTo(NavigationManager.Current.VisibilityFull, null); } else { State SearchState = new State() { Sheet = typeof(LibrarySheet), SheetVisibility = UI.Navigation.Visibility.Full }; NavigationManager.Current.NavigateTo(SearchState, null); } }
public void EditSavedRoute(IRoute route) { if (SheetFrame.CurrentSourcePageType == typeof(RouteSheet)) { (SheetFrame.Content as RouteSheet).AddEditFavorite(this, new RoutedEventArgs()); State cancelAddEditFavoriteState = new State() { OnBackAction = new Action((SheetFrame.Content as RouteSheet).CancelAddEditFavorite) }; NavigateTo(cancelAddEditFavoriteState, null); } else { throw new NotImplementedException(); /* editFavoriteState = new State() { Sheet = typeof(EditFavoriteSheet), SheetVisibility = Visibility.Full, IsModal = true }; NavigateTo(editFavoriteState, location);*/ } }
/// <summary> /// The default constructor to instantiate this class with reference to a Frame, a StateWrapper and the ScrollViewer on the MainPage /// </summary> /// <param name="frame"></param> /// <param name="sharedState"></param> /// <param name="scrollViewer"></param> public NavigationManager(ref Frame frame, ref ScrollViewer scrollViewer) { // Check is the instance doesnt already exist. if (Current != null) { //if there is an instance in the app already present then simply throw an error. throw new Exception("Only one navigation manager can exist in a App."); } // Setting the instance to the static instance field. Current = this; // Setting the frame / scrollViewer reference. this.SheetFrame = frame; this.scrollViewer = scrollViewer; // Handle the StatusBar on Mobile if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar")) { statusBar = StatusBar.GetForCurrentView(); } //initializing the stack. this.StateStack = new Stack<State>(); // Create the initial State this.SharedState = new State(); this.SharedState.Sheet = typeof(LibrarySheet); this.SharedState.SheetVisibility = Visibility.Hidden; // Add the initial State to the Stack NavigateTo(this.SharedState, null); // Hooking up the events for BackRequest. SystemNavigationManager.GetForCurrentView().BackRequested += NavigationManager_BackRequested; // Also listen to the InputPane (SIP aka Onscreen Keyboard) InputPane.GetForCurrentView().Hiding += InputPane_Hiding; InputPane.GetForCurrentView().Showing += InputPane_Showing; // Listen to the ScrollViewer scrollViewer.ViewChanging += ScrollViewer_ViewChanging; scrollViewer.ViewChanged += ScrollViewer_ViewChanged; ScrollViewerPreviousOffset = scrollViewer.VerticalOffset; }
public void AddFavorite(ILocation location) { if (SheetFrame.CurrentSourcePageType == typeof(LocationSheet)) { (SheetFrame.Content as LocationSheet).AddEditFavorite(this, new RoutedEventArgs()); State cancelAddEditFavoriteState = new State() { OnBackAction = new Action((SheetFrame.Content as LocationSheet).CancelAddEditFavorite) }; NavigateTo(cancelAddEditFavoriteState, null); } else { State addFavoriteState = new State() { Sheet = typeof(AddFavoriteSheet), SheetVisibility = Visibility.Full, IsModal = true }; NavigateTo(addFavoriteState, location); } }
public void SaveRoute(IRoute route) { if (SheetFrame.CurrentSourcePageType == typeof(RouteSheet)) { (SheetFrame.Content as RouteSheet).AddEditFavorite(this, new RoutedEventArgs()); State cancelAddEditFavoriteState = new State() { OnBackAction = new Action((SheetFrame.Content as RouteSheet).CancelAddEditFavorite) }; NavigateTo(cancelAddEditFavoriteState, null); } else { State addFavoriteState = new State() { Sheet = typeof(AddFavoriteSheet), // TODO: This seems totally wrong SheetVisibility = Visibility.Full, IsModal = true }; NavigateTo(addFavoriteState, route); } }
public void RouteFrom(ILocation start) { State routeToState = new State() { SheetVisibility = Visibility.Full, Sheet = typeof(RouteRequestSheet) }; KomootRouteRequest request = new KomootRouteRequest(new BasicLocation(), start); NavigateTo(routeToState, request); }
public void ShowRoute(IRoute route) { State routeToState = new State() { SheetVisibility = Visibility.Half, Sheet = typeof(RouteSheet) }; NavigateTo(routeToState, route); }
public void ShowOnMap(IRoute route) { State showOnMapState = new State() { MapHeading = 90, //MapElements = new List<MapElement>() { route }; // TODO: BLALBLAB SheetVisibility = Visibility.Hidden }; NavigateTo(showOnMapState, null); }
public void RouteTo(ILocation destination) { State routeToState = new State() { SheetVisibility = Visibility.Full, Sheet = typeof(RouteRequestSheet) }; KomootRouteRequest request = new KomootRouteRequest(destination); NavigateTo(routeToState, request); }
public void ShowOnMap(ILocation location) { State showOnMapState = new State() { MapCenter = location.Location, MapZoomLevel = 16, MapHeading = 90, SheetVisibility = Visibility.Hidden }; NavigateTo(showOnMapState, null); }
public void ShowLocation(ILocation location) { State locationState = new State() { //MapCenter = location.Location, Sheet = typeof(LocationSheet), SheetVisibility = Visibility.Half }; NavigateTo(locationState, location); }
private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e) { // Kill the rubberband effect (bounce back) if ((scrollViewer.VerticalOffset == 0 && scrollViewer.VerticalOffset < ScrollViewerPreviousOffset) || (scrollViewer.VerticalOffset == scrollViewer.ScrollableHeight && scrollViewer.VerticalOffset > ScrollViewerPreviousOffset)) { scrollViewer.CancelDirectManipulations(); } ScrollViewerPreviousOffset = scrollViewer.VerticalOffset; // Make it large again SheetFrame.Height = scrollViewer.VerticalOffset; //if (SheetFrame.Height != scrollViewer.ScrollableHeight) SheetFrame.Height = scrollViewer.ScrollableHeight; SLOWER, RESOURCE ARM VARIANT if (e.IsIntermediate) return; // Swipe up is s significant State change, so it should be Backbuttonable :D if (SharedState.SheetVisibility != Visibility.Full && SharedState.SheetVisibility != Visibility.Half && Math.Abs(scrollViewer.VerticalOffset - scrollViewer.ScrollableHeight) < 0.001) { // Add this to the Stack NavigateTo(VisibilityFull, null); } Debug.WriteLine("SCROLL:" + scrollViewer.VerticalOffset); Debug.WriteLine(scrollViewer.ScrollableHeight + " / " + MainPage.SheetHalfFactor + " = " + scrollViewer.ScrollableHeight / MainPage.SheetHalfFactor); // Swipe up is s significant State change, so it should be Backbuttonable :D if (Math.Abs(scrollViewer.VerticalOffset - scrollViewer.ScrollableHeight / MainPage.SheetHalfFactor) < 10) { // Add this to the Stack if (SharedState.SheetVisibility != Visibility.Half && SharedState.SheetVisibility != Visibility.Full) NavigateTo(VisibilityHalf, null); //SheetFrame.Height = scrollViewer.ScrollableHeight / MainPage.SheetHalfFactor; SLOWER, RESOURCE ARM VARIANT } // Swipe down, directly after a Swipe up should remove the Swipe up from the Stack (UP->DOWN, now Back is the same State) if ((SharedState == VisibilityFull || SharedState == VisibilityHalf) && scrollViewer.VerticalOffset <= MainPage.HiddenSheetPeekSize) { // Manipulate Stack State previousState = StateStack.Pop(); // The currently shown State State nextState = StateStack.Peek(); // Older State // Pop through dem States til we get the one we're searching for while (nextState == VisibilityFull || nextState == VisibilityHalf) { previousState = StateStack.Pop(); // Take the modal away nextState = StateStack.Peek(); // Take a look at the next one } SharedState = nextState; OnPropertyChanged("SharedState"); if (SharedState.HasSheetVisibility) SetVisibility(SharedState.SheetVisibility); // Check if we still can go back UpdateBackButtonVisibility(); } }
/// <summary> /// Go back one State /// </summary> public void NavigateBack() { // If we can't go back return immediately if (!CanGoBack) return; // Manipulate Stack State previousState = StateStack.Pop(); // The currently shown State State nextState = StateStack.Peek(); // Older State // Check if we can go back to this State or if it was a modal one /////// THIS SHOULD NORMALLY NOT HAPPEN, IT'S JUST TO BE SURE while (nextState.IsModal) { StateStack.Pop(); // Take the modal away nextState = StateStack.Peek(); // Take a look at the next one } // Check if the next State (in History the older one) had a Sheet --> Navigate there if (SheetFrame.CanGoBack && previousState.Sheet != null) SheetFrame.GoBack(); SharedState = nextState; OnPropertyChanged("SharedState"); if (SharedState.HasSheetVisibility) SetVisibility(SharedState.SheetVisibility); // Invoke the GoBackAction! if (previousState.HasOnBackAction) previousState.OnBackAction.Invoke(); // Check if we still can go back UpdateBackButtonVisibility(); }
/// <summary> /// Navigate to a State /// </summary> /// <param name="nextState"></param> /// <param name="parameter"></param> public void NavigateTo(State nextState, object parameter) { State previousState = null; // We don't know yet if there is a State if (StateStack.Count > 0) // Actually there should always be a State except for the very first call { previousState = StateStack.Peek(); // The currently visible State will be the previous State if (previousState == nextState) // It's the same State --> senseless return; // If the current State is a Modal, delete it from the Stack so you can't go back here if (previousState.IsModal && nextState.HasSheet) { StateStack.Pop(); } } // Add it to the Stack StateStack.Push(nextState); // Change the Sheet if there is one (otherwise it just stays the same) Type sheet = nextState.Sheet; if (nextState.Sheet != null) SheetFrame.Navigate(nextState.Sheet, parameter); // If the current State is modal and the next one has a sheet, remove the modal one from the frames backstack if (previousState != null && previousState.IsModal && nextState.HasSheet) { if (previousState.HasSheet) SheetFrame.BackStack.RemoveAt(SheetFrame.BackStack.Count - 1); } // Change the shared State and notify about it SharedState = nextState; OnPropertyChanged("SharedState"); if (SharedState.HasSheetVisibility) SetVisibility(SharedState.SheetVisibility); // Check if we still can go back UpdateBackButtonVisibility(); }