Please implement this logic in `onBeforeShow` and `onBeforeHide`.