Skip to content

Commit 36747e6

Browse files
committed
add screen edges debug component (#edges in url)
fix: provide possible fix for rare issue when mobile control elements were going outside of the screen on ios
1 parent 9dad509 commit 36747e6

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

prismarine-viewer/viewer/lib/ui/newStats.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const stats = {}
66
let lastY = 20
77
export const addNewStat = (id: string, width = 80, x = rightOffset, y = lastY) => {
88
const pane = document.createElement('div')
9-
pane.id = 'fps-counter'
109
pane.style.position = 'fixed'
1110
pane.style.top = `${y}px`
1211
pane.style.right = `${x}px`
@@ -27,6 +26,7 @@ export const addNewStat = (id: string, width = 80, x = rightOffset, y = lastY) =
2726

2827
return {
2928
updateText (text: string) {
29+
if (pane.innerText === text) return
3030
pane.innerText = text
3131
},
3232
setVisibility (visible: boolean) {

src/react/DebugEdges.tsx

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { useState } from 'react'
2+
import { useIsHashActive } from './simpleHooks'
3+
4+
export default () => {
5+
const MODES_COUNT = 4
6+
const [mode, setMode] = useState(0)
7+
const isHashActive = useIsHashActive('#edges')
8+
9+
if (!isHashActive) return null
10+
11+
const styles: React.CSSProperties = {
12+
display: 'flex',
13+
fontSize: 18,
14+
zIndex: 10_000,
15+
background: 'rgba(0, 0, 255, 0.5)',
16+
border: '2px solid red',
17+
whiteSpace: 'pre',
18+
}
19+
let text = ''
20+
if (mode === 0) {
21+
styles.position = 'fixed'
22+
styles.inset = 0
23+
styles.height = '100%'
24+
text = 'inset 0 fixed 100% height'
25+
}
26+
if (mode === 1) {
27+
styles.position = 'fixed'
28+
styles.inset = 0
29+
text = 'inset 0 fixed'
30+
}
31+
if (mode === 2) {
32+
styles.position = 'absolute'
33+
styles.inset = 0
34+
text = 'inset 0 absolute'
35+
}
36+
if (mode === 3) {
37+
styles.position = 'fixed'
38+
styles.top = 0
39+
styles.left = 0
40+
styles.right = 0
41+
styles.height = '100dvh'
42+
text = 'top 0 fixed 100dvh'
43+
}
44+
45+
return <div
46+
style={styles}
47+
onClick={() => {
48+
setMode((mode + 1) % MODES_COUNT)
49+
}}
50+
>
51+
{mode}: {text}{'\n'}
52+
inner: {window.innerWidth}x{window.innerHeight}{'\n'}
53+
outer: {window.outerWidth}x{window.outerHeight}{'\n'}
54+
</div>
55+
}

src/react/TouchControls.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ export default () => {
5757
style={{ zIndex: modals.length ? 7 : 8 }}
5858
className={css`
5959
position: fixed;
60-
inset: 0;
61-
height: 100%;
60+
bottom: 0;
61+
/* height: 100%; */
6262
display: flex;
6363
width: 100%;
6464
justify-content: space-between;

src/react/simpleHooks.ts

+17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { useUtilsEffect } from '@zardoy/react-util'
2+
import { useEffect, useState } from 'react'
23
import { useMedia } from 'react-use'
34

45
const SMALL_SCREEN_MEDIA = '@media (max-width: 440px)'
@@ -25,3 +26,19 @@ export const useCopyKeybinding = (getCopyText: () => string | undefined) => {
2526
}, { signal })
2627
}, [getCopyText])
2728
}
29+
30+
export const useIsHashActive = (hash: `#${string}`) => {
31+
const [isActive, setIsActive] = useState(false)
32+
33+
useEffect(() => {
34+
const checkHash = () => {
35+
setIsActive(location.hash === hash)
36+
}
37+
checkHash()
38+
addEventListener('hashchange', checkHash)
39+
return () => {
40+
removeEventListener('hashchange', checkHash)
41+
}
42+
}, [])
43+
return isActive
44+
}

src/reactUi.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import SignInMessageProvider from './react/SignInMessageProvider'
4545
import BookProvider from './react/BookProvider'
4646
import { options } from './optionsStorage'
4747
import BossBarOverlayProvider from './react/BossBarOverlayProvider'
48+
import DebugEdges from './react/DebugEdges'
4849

4950
const RobustPortal = ({ children, to }) => {
5051
return createPortal(<PerComponentErrorBoundary>{children}</PerComponentErrorBoundary>, to)
@@ -198,6 +199,7 @@ const App = () => {
198199
<GamepadUiCursor />
199200
</div>
200201
<div />
202+
<DebugEdges />
201203
</RobustPortal>
202204
</ButtonAppProvider>
203205
</div>

0 commit comments

Comments
 (0)