forked from RSSNext/Follow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent overscroll bounce in some scene
Signed-off-by: Innei <tukon479@gmail.com>
- Loading branch information
Showing
9 changed files
with
156 additions
and
96 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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export * from "./useBizQuery" | ||
export * from "./useContextMenu" | ||
export * from "./useI18n" | ||
export * from "./usePreventOverscrollBounce" | ||
export * from "./useSwitchHotkeyScope" | ||
export * from "./useSyncTheme" |
37 changes: 37 additions & 0 deletions
37
apps/renderer/src/hooks/common/usePreventOverscrollBounce.ts
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,37 @@ | ||
import { useEffect } from "react" | ||
|
||
const PREVENT_SPRING_CLASS = "prevent-spring" | ||
|
||
/** | ||
* Prevent overscroll bounce | ||
* @param enabled - Whether to enable the prevention of overscroll bounce, default is true | ||
*/ | ||
export const usePreventOverscrollBounce = (enabled = true) => { | ||
useEffect(() => { | ||
if (!enabled) return | ||
|
||
// If has style element, skip | ||
if (document.querySelector(`#${PREVENT_SPRING_CLASS}`)) { | ||
return | ||
} | ||
|
||
const styleElement = document.createElement("style") | ||
styleElement.id = PREVENT_SPRING_CLASS | ||
styleElement.textContent = ` | ||
[data-${PREVENT_SPRING_CLASS}] { | ||
overscroll-behavior: none !important; | ||
} | ||
` | ||
|
||
document.head.append(styleElement) | ||
|
||
document.documentElement.dataset.preventSpring = "true" | ||
document.body.dataset.preventSpring = "true" | ||
|
||
return () => { | ||
delete document.documentElement.dataset.preventSpring | ||
delete document.body.dataset.preventSpring | ||
styleElement.remove() | ||
} | ||
}, [enabled]) | ||
} |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.