mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-23 15:42:27 +03:00
fix(core): sidebar shakes unexpectedly during init on mobile (#8506)
https://github.com/user-attachments/assets/4b2791fb-073b-4653-bf2b-d04653bde3c8
This commit is contained in:
parent
3ca052c55f
commit
90ef12eaca
@ -49,6 +49,22 @@ export function AppSidebar({ children }: PropsWithChildren) {
|
||||
const hovering = useLiveData(appSidebarService.hovering$) && open !== true;
|
||||
const resizing = useLiveData(appSidebarService.resizing$);
|
||||
const [deferredHovering, setDeferredHovering] = useState(false);
|
||||
const [initialized, setInitialized] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (BUILD_CONFIG.isElectron) {
|
||||
setInitialized(true);
|
||||
return;
|
||||
}
|
||||
const shouldFloating = window.matchMedia(
|
||||
`(max-width: ${floatingMaxWidth}px)`
|
||||
).matches;
|
||||
|
||||
appSidebarService.setSmallScreenMode(shouldFloating);
|
||||
setInitialized(true);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (open) {
|
||||
// if open, we don't need to show the floating sidebar
|
||||
@ -90,7 +106,6 @@ export function AppSidebar({ children }: PropsWithChildren) {
|
||||
}
|
||||
|
||||
const dOnResize = debounce(onResize, 50);
|
||||
onResize();
|
||||
window.addEventListener('resize', dOnResize);
|
||||
return () => {
|
||||
window.removeEventListener('resize', dOnResize);
|
||||
@ -147,6 +162,10 @@ export function AppSidebar({ children }: PropsWithChildren) {
|
||||
};
|
||||
}, [appSidebarService, resizing, sidebarState, width]);
|
||||
|
||||
if (!initialized) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<ResizePanel
|
||||
|
Loading…
Reference in New Issue
Block a user