forked from Ajaxy/telegram-tt
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from ulu-telegram/master
deploy
- Loading branch information
Showing
4 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { ipcRenderer } from 'electron'; | ||
|
||
const useMultitouchBackSwipe = (callback: () => void, threshold = 100) => { | ||
const [scrollPosition, setScrollPosition] = useState(0); | ||
|
||
useEffect(() => { | ||
const handleScrollTouchBegin = () => { | ||
setScrollPosition(0); // Сброс позиции прокрутки при начале жеста | ||
}; | ||
|
||
const handleScrollTouchEnd = () => { | ||
if (scrollPosition > threshold) { | ||
callback(); // Вызов callback, если прокрутка превысила порог | ||
} | ||
}; | ||
|
||
const handleWheel = (e: { deltaX: number }) => { | ||
setScrollPosition((prev) => prev + e.deltaX); // Обновление позиции прокрутки | ||
}; | ||
|
||
document.addEventListener('wheel', handleWheel); | ||
ipcRenderer.on('scroll-touch-begin', handleScrollTouchBegin); | ||
ipcRenderer.on('scroll-touch-end', handleScrollTouchEnd); | ||
|
||
return () => { | ||
document.removeEventListener('wheel', handleWheel); | ||
ipcRenderer.removeListener('scroll-touch-begin', handleScrollTouchBegin); | ||
ipcRenderer.removeListener('scroll-touch-end', handleScrollTouchEnd); | ||
}; | ||
}, [callback, scrollPosition, threshold]); | ||
|
||
return scrollPosition; | ||
}; | ||
|
||
export default useMultitouchBackSwipe; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters