fix: catalog form meta data update
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import React from 'react';
|
||||
|
||||
export default function useBodyScroll() {
|
||||
const scrollHeight = React.useRef(0);
|
||||
const scrollerState = React.useRef<any>({});
|
||||
|
||||
const bodyScroller = React.useRef<any>(null);
|
||||
|
||||
const instanceRef = React.useRef<any>(null);
|
||||
|
||||
const int = () => {
|
||||
bodyScroller.current =
|
||||
window.__GPUSTACK_BODY_SCROLLER__?.elements()?.scrollEventElement;
|
||||
|
||||
instanceRef.current = window.__GPUSTACK_BODY_SCROLLER__;
|
||||
};
|
||||
|
||||
const saveScrollHeight = React.useCallback(() => {
|
||||
scrollerState.current = instanceRef.current?.state();
|
||||
|
||||
console.log('saveScrollHeight', scrollerState.current?.overflowAmount?.y);
|
||||
|
||||
const scrollTop = scrollerState.current?.overflowAmount?.y;
|
||||
scrollHeight.current = scrollTop;
|
||||
instanceRef.current?.options?.({
|
||||
overflow: {
|
||||
x: 'hidden',
|
||||
y: 'visible'
|
||||
}
|
||||
});
|
||||
}, []);
|
||||
|
||||
const restoreScrollHeight = React.useCallback(() => {
|
||||
console.log('saveScrollHeight++++++++++', scrollHeight.current);
|
||||
|
||||
bodyScroller.current?.scrollTo?.({
|
||||
top: scrollHeight.current,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
|
||||
instanceRef.current?.options?.({
|
||||
overflow: {
|
||||
x: 'hidden',
|
||||
y: 'scroll'
|
||||
}
|
||||
});
|
||||
|
||||
instanceRef.current?.update?.();
|
||||
}, []);
|
||||
|
||||
React.useEffect(() => {
|
||||
int();
|
||||
return () => {
|
||||
bodyScroller.current = null;
|
||||
instanceRef.current = null;
|
||||
};
|
||||
}, []);
|
||||
|
||||
return { saveScrollHeight, restoreScrollHeight };
|
||||
}
|
||||
@@ -23,7 +23,12 @@ export const overlaySollerOptions: UseOverlayScrollbarsParams = {
|
||||
defer: true
|
||||
};
|
||||
|
||||
export default function useOverlayScroller(options?: any) {
|
||||
export default function useOverlayScroller(data?: {
|
||||
options?: any;
|
||||
events?: any;
|
||||
defer?: boolean;
|
||||
}) {
|
||||
const { options, events, defer = true } = data || {};
|
||||
const scrollEventElement = React.useRef<any>(null);
|
||||
const instanceRef = React.useRef<any>(null);
|
||||
const initialized = React.useRef(false);
|
||||
@@ -42,8 +47,10 @@ export default function useOverlayScroller(options?: any) {
|
||||
clickScroll: 'instant'
|
||||
}
|
||||
},
|
||||
|
||||
defer: true
|
||||
events: {
|
||||
...events
|
||||
},
|
||||
defer: defer
|
||||
});
|
||||
|
||||
instanceRef.current = instance?.();
|
||||
@@ -99,7 +106,7 @@ export default function useOverlayScroller(options?: any) {
|
||||
const createInstance = React.useCallback(
|
||||
(el: any) => {
|
||||
if (instanceRef.current) {
|
||||
return;
|
||||
return instanceRef.current;
|
||||
}
|
||||
if (el) {
|
||||
initialize(el);
|
||||
@@ -108,6 +115,7 @@ export default function useOverlayScroller(options?: any) {
|
||||
scrollEventElement.current =
|
||||
instanceRef.current?.elements()?.scrollEventElement;
|
||||
}
|
||||
return instanceRef.current;
|
||||
},
|
||||
[initialize, instance]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user