Spaces:
Running
Running
axeronis commited on
Commit ·
8b99b67
1
Parent(s): 5e92ba2
fix: Robust mobile scroll lock and swipe-bounce prevention (position fixed + preventDefault)
Browse files
frontend/app/chats/page.tsx
CHANGED
|
@@ -192,13 +192,20 @@ function ChatsContent() {
|
|
| 192 |
|
| 193 |
// Lock background scroll when mobile summary is open
|
| 194 |
useEffect(() => {
|
|
|
|
| 195 |
if (isMobileSummaryOpen) {
|
| 196 |
document.body.style.overflow = 'hidden'
|
|
|
|
|
|
|
| 197 |
} else {
|
| 198 |
document.body.style.overflow = ''
|
|
|
|
|
|
|
| 199 |
}
|
| 200 |
return () => {
|
| 201 |
-
document.body.style.overflow =
|
|
|
|
|
|
|
| 202 |
}
|
| 203 |
}, [isMobileSummaryOpen])
|
| 204 |
|
|
|
|
| 192 |
|
| 193 |
// Lock background scroll when mobile summary is open
|
| 194 |
useEffect(() => {
|
| 195 |
+
const originalStyle = window.getComputedStyle(document.body).overflow
|
| 196 |
if (isMobileSummaryOpen) {
|
| 197 |
document.body.style.overflow = 'hidden'
|
| 198 |
+
document.body.style.position = 'fixed'
|
| 199 |
+
document.body.style.width = '100%'
|
| 200 |
} else {
|
| 201 |
document.body.style.overflow = ''
|
| 202 |
+
document.body.style.position = ''
|
| 203 |
+
document.body.style.width = ''
|
| 204 |
}
|
| 205 |
return () => {
|
| 206 |
+
document.body.style.overflow = originalStyle
|
| 207 |
+
document.body.style.position = ''
|
| 208 |
+
document.body.style.width = ''
|
| 209 |
}
|
| 210 |
}, [isMobileSummaryOpen])
|
| 211 |
|
frontend/components/ChatWindow.tsx
CHANGED
|
@@ -162,12 +162,21 @@ export function ChatWindow({
|
|
| 162 |
|
| 163 |
// Lock scroll when mobile drawer is open
|
| 164 |
useEffect(() => {
|
|
|
|
| 165 |
if (isMobileDrawerOpen) {
|
| 166 |
document.body.style.overflow = 'hidden'
|
|
|
|
|
|
|
| 167 |
} else {
|
| 168 |
document.body.style.overflow = ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
}
|
| 170 |
-
return () => { document.body.style.overflow = '' }
|
| 171 |
}, [isMobileDrawerOpen])
|
| 172 |
|
| 173 |
// ============================================================================
|
|
@@ -358,6 +367,10 @@ export function ChatWindow({
|
|
| 358 |
// Prioritize horizontal movement (multiply X diff for tolerance)
|
| 359 |
// This allows diagonal swipes to count as horizontal if they have enough momentum
|
| 360 |
if (Math.abs(diffX) > diffY * 0.8) {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
if (diffX > 40) { // Swipe left (open)
|
| 362 |
setIsMobileDrawerOpen(true)
|
| 363 |
document.removeEventListener('touchmove', handleTouchMove)
|
|
|
|
| 162 |
|
| 163 |
// Lock scroll when mobile drawer is open
|
| 164 |
useEffect(() => {
|
| 165 |
+
const originalStyle = window.getComputedStyle(document.body).overflow
|
| 166 |
if (isMobileDrawerOpen) {
|
| 167 |
document.body.style.overflow = 'hidden'
|
| 168 |
+
document.body.style.position = 'fixed'
|
| 169 |
+
document.body.style.width = '100%'
|
| 170 |
} else {
|
| 171 |
document.body.style.overflow = ''
|
| 172 |
+
document.body.style.position = ''
|
| 173 |
+
document.body.style.width = ''
|
| 174 |
+
}
|
| 175 |
+
return () => {
|
| 176 |
+
document.body.style.overflow = originalStyle
|
| 177 |
+
document.body.style.position = ''
|
| 178 |
+
document.body.style.width = ''
|
| 179 |
}
|
|
|
|
| 180 |
}, [isMobileDrawerOpen])
|
| 181 |
|
| 182 |
// ============================================================================
|
|
|
|
| 367 |
// Prioritize horizontal movement (multiply X diff for tolerance)
|
| 368 |
// This allows diagonal swipes to count as horizontal if they have enough momentum
|
| 369 |
if (Math.abs(diffX) > diffY * 0.8) {
|
| 370 |
+
if (Math.abs(diffX) > 10) { // If horizontal movement is detected, stop page bounce
|
| 371 |
+
if (moveEvent.cancelable) moveEvent.preventDefault()
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
if (diffX > 40) { // Swipe left (open)
|
| 375 |
setIsMobileDrawerOpen(true)
|
| 376 |
document.removeEventListener('touchmove', handleTouchMove)
|