Properly handles onBeforeShow and onShow.