public void ChangeCurrentActivity(ActivityModel newActivity, int nextIndex) { if (_activities.Count <= nextIndex) { _activities.Add(newActivity); } CurrentIndex = nextIndex; BackStackChanged?.Invoke(); }
private Task <bool> NavigateWithMode(ActivityModel newActivity, NavigationMode navigationMode) { return(RunNavigationWithCheck(async() => { var currentActivity = CurrentActivityModel; _activityStackManager.ClearForwardStack(); await NavigateImplAsync(navigationMode, currentActivity, newActivity, _activityStackManager.CurrentIndex + 1); return true; })); }
private async Task UpdateContent(NavigationMode navigationMode, ActivityModel currentActivity, ActivityModel nextActivity) { var animation = ActualActivityTransition; var current = currentActivity?.GetActivity(this); var next = nextActivity?.GetActivity(this); if (animation != null) { AddActivityToContentRoot(navigationMode, animation.InsertionMode, next); switch (navigationMode) { case NavigationMode.New: await animation.OnStart(next, current); break; case NavigationMode.Back: await animation.OnClose(current, next); break; default: throw new ArgumentOutOfRangeException(nameof(navigationMode), navigationMode, null); } Children.Remove(current); } else { if (Children.Any()) { Children[0] = next; } else { Children.Add(next); } } }
private async Task NavigateImplAsync(NavigationMode navigationMode, ActivityModel currentActivity, ActivityModel nextActivity, int nextIndex) { IsHitTestVisible = false; InvokeLifecycleBeforeContentChanged(navigationMode, currentActivity, nextActivity); _activityStackManager.ChangeCurrentActivity(nextActivity, nextIndex); OnCurrentActivityChanged(currentActivity?.Activity, nextActivity?.Activity); Navigating?.Invoke(this, EventArgs.Empty); await UpdateContent(navigationMode, currentActivity, nextActivity); InvokeLifecycleAfterContentChanged(navigationMode, currentActivity, nextActivity); IsHitTestVisible = true; ReleaseActivity(currentActivity); Navigated?.Invoke(this, EventArgs.Empty); }
public Task <bool> Navigate(Type activityType, object parameter) { var newActivity = new ActivityModel(activityType, parameter); return(NavigateWithMode(newActivity, NavigationMode.New)); }
private void InvokeLifecycleAfterContentChanged(NavigationMode navigationMode, ActivityModel currentActivity, ActivityModel nextActivity) { switch (navigationMode) { case NavigationMode.New: currentActivity?.GetActivity(this)?.OnStop(); nextActivity?.GetActivity(this)?.OnResume(); break; case NavigationMode.Back: currentActivity?.GetActivity(this)?.OnDestroy(); nextActivity?.GetActivity(this).OnResume(); break; case NavigationMode.Forward: break; case NavigationMode.Refresh: break; default: throw new ArgumentOutOfRangeException(nameof(navigationMode), navigationMode, null); } }