public async Task ShowAsync(bool immediate = false) { //If we're currently appeared or appearing we're already doing the thing we wanna be doing so just return if (state == PanelViewControllerState.Appeared || state == PanelViewControllerState.Appearing) { return; } //If we're in the middle of disappearing we need to cancel the disappearing action if (state == PanelViewControllerState.Disappearing) { //Cancel Current Transition cancellationTokenSource.Cancel(); cancellationTokenSource = null; } state = PanelViewControllerState.Appearing; if (cancellationTokenSource == null) { cancellationTokenSource = new CancellationTokenSource(); } var currentToken = cancellationTokenSource.Token; if (!IsViewLoaded) { await LoadViewAsync().ConfigureAwait(true); if (currentToken.IsCancellationRequested) { return; } } willAppear?.Invoke(); if (immediate) { panelView.ShowImmediate(); } else { await panelView.ShowAsync(currentToken); } if (cancellationTokenSource.IsCancellationRequested) { return; } state = PanelViewControllerState.Appeared; didAppear?.Invoke(); }
public async Task HideAsync(bool immediate = false) { //If we're already disappeared or disappearing we're already doing the right thing so just return if (state == PanelViewControllerState.Disappeared || state == PanelViewControllerState.Disappearing) { return; } //If we're currently appearing we should cancel the appear using our cancellation token if (state == PanelViewControllerState.Appearing && cancellationTokenSource != null) { //Cancel Current Transition cancellationTokenSource.Cancel(); cancellationTokenSource = null; } state = PanelViewControllerState.Disappearing; if (cancellationTokenSource == null) { cancellationTokenSource = new CancellationTokenSource(); } var currentToken = cancellationTokenSource.Token; willDisappear?.Invoke(); if (immediate) { panelView.HideImmediate(); } else { await panelView.HideAsync(currentToken); } if (currentToken.IsCancellationRequested) { return; } didDisappear?.Invoke(); state = PanelViewControllerState.Disappeared; }