mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-28 17:43:47 +00:00
Update ConnectionModal.tsx
This commit is contained in:
@@ -139,6 +139,9 @@ export default function ConnectionModal({ onClose }: ConnectionModalProps) {
|
|||||||
const isMobile = isMobileScreen
|
const isMobile = isMobileScreen
|
||||||
const scrollContainerRef = useRef<HTMLDivElement>(null)
|
const scrollContainerRef = useRef<HTMLDivElement>(null)
|
||||||
|
|
||||||
|
// Ref для хранения актуального обработчика BackButton (фикс мигания)
|
||||||
|
const backButtonHandlerRef = useRef<() => void>(() => {})
|
||||||
|
|
||||||
// Prevent scroll events from bubbling to parent/Telegram
|
// Prevent scroll events from bubbling to parent/Telegram
|
||||||
const handleScrollContainerWheel = useCallback((e: React.WheelEvent) => {
|
const handleScrollContainerWheel = useCallback((e: React.WheelEvent) => {
|
||||||
const container = e.currentTarget
|
const container = e.currentTarget
|
||||||
@@ -200,16 +203,28 @@ export default function ConnectionModal({ onClose }: ConnectionModalProps) {
|
|||||||
return () => document.removeEventListener('keydown', handleKeyDown)
|
return () => document.removeEventListener('keydown', handleKeyDown)
|
||||||
}, [handleClose, handleBack, showAppSelector])
|
}, [handleClose, handleBack, showAppSelector])
|
||||||
|
|
||||||
|
// Обновляем ref при изменении логики (без перезапуска эффекта BackButton)
|
||||||
|
useEffect(() => {
|
||||||
|
backButtonHandlerRef.current = showAppSelector ? handleBack : handleClose
|
||||||
|
}, [showAppSelector, handleBack, handleClose])
|
||||||
|
|
||||||
|
// Управление BackButton — эффект запускается только при mount/unmount
|
||||||
|
// Используем стабильный обработчик через ref, чтобы избежать мигания
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!webApp?.BackButton) return
|
if (!webApp?.BackButton) return
|
||||||
const handler = showAppSelector ? handleBack : handleClose
|
|
||||||
|
const stableHandler = () => {
|
||||||
|
backButtonHandlerRef.current()
|
||||||
|
}
|
||||||
|
|
||||||
webApp.BackButton.show()
|
webApp.BackButton.show()
|
||||||
webApp.BackButton.onClick(handler)
|
webApp.BackButton.onClick(stableHandler)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
webApp.BackButton.offClick(handler)
|
webApp.BackButton.offClick(stableHandler)
|
||||||
webApp.BackButton.hide()
|
webApp.BackButton.hide()
|
||||||
}
|
}
|
||||||
}, [webApp, handleClose, handleBack, showAppSelector])
|
}, [webApp]) // Только webApp в зависимостях!
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
document.body.style.overflow = 'hidden'
|
document.body.style.overflow = 'hidden'
|
||||||
|
|||||||
Reference in New Issue
Block a user