refactor(client): add delay API for scenarios without delay (#6681)

This commit is contained in:
Junyi 2025-04-17 14:30:32 +08:00 committed by GitHub
parent 18447848ca
commit 9add517d75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -67,21 +67,24 @@ const ActionModalContent: FC<{ footerNodeName: string; field: any; schema: any }
);
export function useDelayedVisible(visible: boolean, delay = 200) {
const [ready, setReady] = useState(false);
const [ready, setReady] = useState(delay === 0);
useEffect(() => {
if (ready) {
return;
}
if (visible) {
const timer = setTimeout(() => setReady(true), delay);
return () => clearTimeout(timer);
} else {
setReady(false);
}
}, [visible]);
}, [delay, ready, visible]);
return ready;
}
export const InternalActionModal: React.FC<ActionDrawerProps<ModalProps>> = observer(
(props) => {
const { footerNodeName = 'Action.Modal.Footer', width, zIndex: _zIndex, ...others } = props;
const { footerNodeName = 'Action.Modal.Footer', width, zIndex: _zIndex, delay = 200, ...others } = props;
const { visible, setVisible, openSize = 'middle', modalProps } = useActionContext();
const actualWidth = width ?? openSizeWidthMap.get(openSize);
const schema = useFieldSchema();
@ -102,7 +105,7 @@ export const InternalActionModal: React.FC<ActionDrawerProps<ModalProps>> = obse
}
const zIndex = getZIndex('modal', _zIndex || parentZIndex, props.level || 0);
const ready = useDelayedVisible(visible, 200); // 200ms 与 Modal 动画时间一致
const ready = useDelayedVisible(visible, delay); // 200ms 与 Modal 动画时间一致
return (
<ActionContextNoRerender>

View File

@ -92,6 +92,7 @@ export type ActionDrawerProps<T = DrawerProps> = T & {
footerNodeName?: string;
/** 当前弹窗嵌套的层级 */
level?: number;
delay?: number;
};
export type ComposedActionDrawer<T = DrawerProps> = React.FC<ActionDrawerProps<T>> & {