fix(top-bar): top bar cannot auto-hide on the home page

This commit is contained in:
Hakadao
2024-07-23 00:51:17 +08:00
parent 6c3e72eb86
commit f30a6a711f
3 changed files with 19 additions and 4 deletions

View File

@@ -5,7 +5,7 @@ import type { Ref, UnwrapNestedRefs } from 'vue'
import { useApiClient } from '~/composables/api'
import { useBewlyApp } from '~/composables/useAppProvider'
import { useDelayedHover } from '~/composables/useDelayedHover'
import { TOP_BAR_VISIBILITY_CHANGE } from '~/constants/globalEvents'
import { OVERLAY_SCROLL_BAR_SCROLL, TOP_BAR_VISIBILITY_CHANGE } from '~/constants/globalEvents'
import { AppPage } from '~/enums/appEnums'
import { settings } from '~/logic'
import { getUserID, isHomePage } from '~/utils/main'
@@ -292,11 +292,21 @@ onMounted(async () => {
initData()
await nextTick()
toggleTopBarVisible(true)
window.addEventListener('scroll', handleScroll)
emitter.off(OVERLAY_SCROLL_BAR_SCROLL)
if (isHomePage() && !settings.value.useOriginalBilibiliHomepage) {
emitter.on(OVERLAY_SCROLL_BAR_SCROLL, () => {
handleScroll()
})
}
else {
window.addEventListener('scroll', handleScroll)
}
})
onBeforeMount(() => {
onUnmounted(() => {
window.removeEventListener('scroll', handleScroll)
emitter.off(OVERLAY_SCROLL_BAR_SCROLL)
})
async function initData() {
@@ -310,7 +320,7 @@ async function initData() {
}
function handleScroll() {
if (isHomePage()) {
if (isHomePage() && !settings.value.useOriginalBilibiliHomepage) {
const osInstance = scrollbarRef.value?.osInstance()
scrollTop.value = osInstance.elements().viewport.scrollTop as number
}

View File

@@ -1 +1,2 @@
export const TOP_BAR_VISIBILITY_CHANGE = 'topBarVisibilityChange'
export const OVERLAY_SCROLL_BAR_SCROLL = 'overlayScrollBarScroll'

View File

@@ -13,9 +13,11 @@ import Settings from '~/components/Settings/Settings.vue'
import TopBar from '~/components/TopBar/TopBar.vue'
import type { BewlyAppProvider } from '~/composables/useAppProvider'
import { useDark } from '~/composables/useDark'
import { OVERLAY_SCROLL_BAR_SCROLL } from '~/constants/globalEvents'
import { AppPage, LanguageType } from '~/enums/appEnums'
import { accessKey, settings } from '~/logic'
import { getUserID, hexToRGBA, isHomePage, scrollToTop } from '~/utils/main'
import emitter from '~/utils/mitt'
const { isDark } = useDark()
const activatedPage = ref<AppPage>(settings.value.dockItemVisibilityList.find(e => e.visible === true)?.page ?? AppPage.Home)
@@ -177,6 +179,8 @@ function handleAdaptToOtherPageStylesChange() {
}
function handleOsScroll() {
emitter.emit(OVERLAY_SCROLL_BAR_SCROLL)
const osInstance = scrollbarRef.value?.osInstance()
const { viewport } = osInstance.elements()
const { scrollTop, scrollHeight, clientHeight } = viewport // get scroll offset