Baconit.PanelManager.GoBack_Internal C# (CSharp) Method

GoBack_Internal() private method

Navigates back to the previous page
private GoBack_Internal ( ) : bool?
return bool?
        private bool? GoBack_Internal()
        {
            StackItem leavingStackItem = null;
            bool isPanelStillInStack = false;
            lock(m_panelStack)
            {
                if(m_state != State.Idle)
                {
                    // We can't do anything if we are already animating.
                    return null;
                }

                if(m_panelStack.Count <= 2)
                {
                    // We can't go back, there is nothing to go back to.
                    return false;
                }

                // Get the panel we are removing.
                leavingStackItem = m_panelStack.Last();

                // Remove the panel, use the index or we will remove the wrong one!
                m_panelStack.RemoveAt(m_panelStack.Count - 1);

                // Due to the pull forward logic this panel can be in the stack many times.
                // We need to check for it.
                foreach(StackItem item in m_panelStack)
                {
                    if(item.Id.Equals(leavingStackItem.Id) && item.Panel.GetType().Equals(leavingStackItem.Panel.GetType()))
                    {
                        isPanelStillInStack = true;
                        break;
                    }
                }

                // Report the new panel being shown.
                App.BaconMan.TelemetryMan.ReportPageView(m_panelStack.Last().Panel.GetType().Name);

                // Get the type of the leaving panel
                PanelType leavingPanelType = GetPanelType(leavingStackItem.Panel);

                // Start to fade out the current panel.
                PlayFadeAnimation(leavingPanelType, leavingPanelType, State.FadingOut);
            }

            // While not under lock inform the panel it is leaving.
            FireOnNavigateFrom(leavingStackItem.Panel);

            // If the panel isn't anywhere else in the stack kill it
            if(!isPanelStillInStack)
            {
                FireOnCleanupPanel(leavingStackItem.Panel);
            }

            return true;
        }