diff --git a/src/components/GameManagePopup/index.tsx b/src/components/GameManagePopup/index.tsx index bf7abcb..bb64427 100644 --- a/src/components/GameManagePopup/index.tsx +++ b/src/components/GameManagePopup/index.tsx @@ -16,8 +16,8 @@ const CancelPopup = forwardRef((props, ref) => { const { detail } = props; const [visible, setVisible] = useState(false); const [cancelReason, setCancelReason] = useState(""); + const [inputFocus, setInputFocus] = useState(false); const onFinish = useRef(null); - const inputRef = useRef(null); const { current_players, participants = [], publisher_id } = detail; const realParticipants = participants @@ -32,16 +32,15 @@ const CancelPopup = forwardRef((props, ref) => { show: (onAct) => { onFinish.current = onAct; setVisible(true); - // 使用 requestAnimationFrame 替代 setTimeout(0),性能更好 - requestAnimationFrame(() => { - requestAnimationFrame(() => { - inputRef.current && inputRef.current.focus(); - }); + // 使用 Taro.nextTick 确保在下一个渲染周期后聚焦 + Taro.nextTick(() => { + setInputFocus(true); }); }, })); function onClose() { + setInputFocus(false); setVisible(false); setCancelReason(""); } @@ -85,13 +84,13 @@ const CancelPopup = forwardRef((props, ref) => { {hasOtherJoin && ( setCancelReason(e.detail.value)} maxlength={100} + onBlur={() => setInputFocus(false)} /> )}