fix: 修复沉浸底栏宽度动画持续收缩问题

This commit is contained in:
JSR
2026-03-27 21:54:03 +08:00
parent 6bcec4838c
commit 41f05c134e
+12 -4
View File
@@ -120,6 +120,8 @@ export const Home: React.FC<HomeProps> = ({
const immersiveToolbarRef = useRef<HTMLDivElement>(null)
const immersiveToolbarContentRef = useRef<HTMLDivElement>(null)
const [immersiveToolbarWidth, setImmersiveToolbarWidth] = useState<number | null>(null)
const immersiveToolbarHorizontalPadding = 20
const immersiveToolbarMinWidth = 320
const [selectedStudent, setSelectedStudent] = useState<student | null>(null)
const [batchMode, setBatchMode] = useState(false)
@@ -324,7 +326,10 @@ export const Home: React.FC<HomeProps> = ({
}, [])
useEffect(() => {
if (!immersiveMode) return
if (!immersiveMode) {
setImmersiveToolbarWidth(null)
return
}
const contentEl = immersiveToolbarContentRef.current
if (!contentEl) return
@@ -332,8 +337,11 @@ export const Home: React.FC<HomeProps> = ({
const updateToolbarWidth = () => {
if (frameId !== null) cancelAnimationFrame(frameId)
frameId = requestAnimationFrame(() => {
const contentWidth = Math.ceil(contentEl.getBoundingClientRect().width)
const nextWidth = contentWidth + 20
const contentWidth = Math.ceil(contentEl.scrollWidth)
const nextWidth = Math.max(
immersiveToolbarMinWidth,
contentWidth + immersiveToolbarHorizontalPadding
)
setImmersiveToolbarWidth((prev) => (prev === nextWidth ? prev : nextWidth))
})
}
@@ -348,7 +356,7 @@ export const Home: React.FC<HomeProps> = ({
window.removeEventListener("resize", updateToolbarWidth)
if (frameId !== null) cancelAnimationFrame(frameId)
}
}, [immersiveMode])
}, [immersiveMode, immersiveToolbarHorizontalPadding, immersiveToolbarMinWidth])
useEffect(() => {
return () => {