Skip to content

Commit 0fb86d4

Browse files
committed
Merge branch 'fix/dock-safe-area-on-anchor' into fix/dock-safe-area-px
2 parents 49466c8 + a184fdf commit 0fb86d4

2 files changed

Lines changed: 32 additions & 18 deletions

File tree

‎packages/hub-ui/src/client/components/dock/Dock.vue‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { docksSplitGroupsWithCapacity, getEntryGroup, resolveNextRecentDockIds,
1010
import { setDocksOverflowPanel, useDocksGroupPanel } from '../../state/floating-tooltip'
1111
import { useSettings } from '../../state/settings-defaults'
1212
import { useIsRpcTrusted } from '../../utils/useIsRpcTrusted'
13+
import { useSafeArea } from '../../utils/useSafeArea'
1314
import BrandMark from '../icons/BrandMark.vue'
1415
import {
1516
dockLayoutCssVars,
@@ -41,22 +42,7 @@ const isSafari = navigator.userAgent.includes('Safari') && !navigator.userAgent.
4142
4243
const anchorEl = useTemplateRef<HTMLDivElement>('anchorEl')
4344
44-
const safeArea = {
45-
top: ref(''),
46-
right: ref(''),
47-
bottom: ref(''),
48-
left: ref(''),
49-
}
50-
51-
function updateSafeArea() {
52-
if (!anchorEl.value)
53-
return
54-
const style = getComputedStyle(anchorEl.value)
55-
safeArea.top.value = style.getPropertyValue('--devframes-safe-area-top')
56-
safeArea.right.value = style.getPropertyValue('--devframes-safe-area-right')
57-
safeArea.bottom.value = style.getPropertyValue('--devframes-safe-area-bottom')
58-
safeArea.left.value = style.getPropertyValue('--devframes-safe-area-left')
59-
}
45+
const safeArea = useSafeArea(anchorEl)
6046
6147
function toNumber(value: string) {
6248
const num = Number.parseFloat(value)
@@ -169,12 +155,10 @@ watch(selectedEntry, (entry) => {
169155
onMounted(async () => {
170156
windowSize.width = window.innerWidth
171157
windowSize.height = window.innerHeight
172-
updateSafeArea()
173158
174159
useEventListener(window, 'resize', () => {
175160
windowSize.width = window.innerWidth
176161
windowSize.height = window.innerHeight
177-
updateSafeArea()
178162
})
179163
180164
useEventListener(window, 'pointermove', (e: PointerEvent) => {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { MaybeElementRef } from '@vueuse/core'
2+
import { tryOnMounted, unrefElement, useDebounceFn, useEventListener } from '@vueuse/core'
3+
import { shallowRef } from 'vue'
4+
5+
/**
6+
* Ported from VueUse's `useScreenSafeArea` for now: it always sets its CSS variables on
7+
* `<html>` and has no option for a custom element, which breaks hydration on SSR hosts.
8+
*/
9+
export function useSafeArea(target: MaybeElementRef) {
10+
const top = shallowRef('')
11+
const right = shallowRef('')
12+
const bottom = shallowRef('')
13+
const left = shallowRef('')
14+
15+
function update() {
16+
const element = unrefElement(target)
17+
if (!element)
18+
return
19+
const style = getComputedStyle(element)
20+
top.value = style.getPropertyValue('--devframes-safe-area-top')
21+
right.value = style.getPropertyValue('--devframes-safe-area-right')
22+
bottom.value = style.getPropertyValue('--devframes-safe-area-bottom')
23+
left.value = style.getPropertyValue('--devframes-safe-area-left')
24+
}
25+
26+
tryOnMounted(update)
27+
useEventListener('resize', useDebounceFn(update), { passive: true })
28+
29+
return { top, right, bottom, left, update }
30+
}

0 commit comments

Comments
 (0)