Skip to content

Commit

Permalink
fix: update Popup's ref when Masking re-renderers
Browse files Browse the repository at this point in the history
  • Loading branch information
ziqisia committed Dec 2, 2024
1 parent 4a5c0f8 commit 458d6c8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/arcodesign/components/popup/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef, forwardRef, Ref, useImperativeHandle } from 'react';
import React, { useRef, forwardRef, Ref, useImperativeHandle, useState } from 'react';
import { cls, componentWrapper } from '@arco-design/mobile-utils';
import { ContextLayout, CompWithGlobalContext } from '../context-provider';
import Masking, { MaskingCommonProps, MaskingRef, OpenBaseProps } from '../masking';
Expand Down Expand Up @@ -62,11 +62,14 @@ const Popup = forwardRef((props: PopupProps, ref: Ref<PopupRef>) => {
translateZ = false,
maskTransitionTimeout = { enter: 450, exit: 240 },
contentTransitionTimeout = { enter: 450, exit: 240 },
onOpen,
onClose,
...restProps
} = props;
const maskingRef = useRef<MaskingRef>(null);
const [trueVisible, setTrueVisible] = useState(props.visible);

useImperativeHandle(ref, () => maskingRef.current!);
useImperativeHandle(ref, () => maskingRef.current!, [props, trueVisible]);

function renderPopup({ prefixCls }) {
const prefix = `${prefixCls}-popup`;
Expand All @@ -87,6 +90,14 @@ const Popup = forwardRef((props: PopupProps, ref: Ref<PopupRef>) => {
)}
maskTransitionTimeout={maskTransitionTimeout}
contentTransitionTimeout={contentTransitionTimeout}
onOpen={() => {
setTrueVisible(true);
onOpen?.();
}}
onClose={() => {
setTrueVisible(false);
onClose?.();
}}
{...restProps}
>
{children}
Expand Down

0 comments on commit 458d6c8

Please sign in to comment.