mirror of
https://github.com/koodo-reader/koodo-reader.git
synced 2026-04-24 08:57:26 -04:00
Add debounce functionality to resize event in Background component
- Implemented a debounce mechanism for the window resize event to optimize performance. - The state is updated with the new page width after a delay of 300ms following the last resize event.
This commit is contained in:
2
src/assets/lib/kookit.min.js
vendored
2
src/assets/lib/kookit.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -24,6 +24,21 @@ class Background extends React.Component<BackgroundProps, BackgroundState> {
|
||||
this.props.isSettingLocked
|
||||
)
|
||||
);
|
||||
let resizeTimer: NodeJS.Timeout;
|
||||
window.addEventListener("resize", (event) => {
|
||||
clearTimeout(resizeTimer);
|
||||
resizeTimer = setTimeout(() => {
|
||||
this.setState(
|
||||
getPageWidth(
|
||||
this.props.readerMode,
|
||||
this.props.scale,
|
||||
parseInt(this.props.margin),
|
||||
this.props.isNavLocked,
|
||||
this.props.isSettingLocked
|
||||
)
|
||||
);
|
||||
}, 300); // 300ms 防抖
|
||||
});
|
||||
}
|
||||
async UNSAFE_componentWillReceiveProps(nextProps: BackgroundProps) {
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user