diff --git a/src/components/Comments/index.tsx b/src/components/Comments/index.tsx index e8eebb1..b470461 100644 --- a/src/components/Comments/index.tsx +++ b/src/components/Comments/index.tsx @@ -34,7 +34,7 @@ function toast(msg) { interface CommentInputProps { onConfirm?: ( - value: { content: string } & Partial + value: { content: string } & Partial, ) => void; } @@ -49,119 +49,118 @@ interface CommentInputReplyParamsType { nickname: string; } -const CommentInput = forwardRef(function ( - props, - ref -) { - const { onConfirm } = props; - const [visible, setVisible] = useState(false); - const [value, setValue] = useState(""); - const [params, setParams] = useState< - CommentInputReplyParamsType | undefined - >(); +const CommentInput = forwardRef( + function (props, ref) { + const { onConfirm } = props; + const [visible, setVisible] = useState(false); + const [value, setValue] = useState(""); + const [params, setParams] = useState< + CommentInputReplyParamsType | undefined + >(); - const { - keyboardHeight, - isKeyboardVisible, - addListener, - initializeKeyboardListener, - } = useKeyboardHeight(); + const { + keyboardHeight, + isKeyboardVisible, + addListener, + initializeKeyboardListener, + } = useKeyboardHeight(); - // 使用全局键盘状态监听 - useEffect(() => { - // 初始化全局键盘监听器 - initializeKeyboardListener(); + // 使用全局键盘状态监听 + useEffect(() => { + // 初始化全局键盘监听器 + initializeKeyboardListener(); - // 添加本地监听器 - const removeListener = addListener((height, visible) => { - console.log("PublishBall 收到键盘变化:", height, visible); - // 这里只记录或用于其他逻辑,布局是否响应交由 shouldReactToKeyboard 决定 - }); + // 添加本地监听器 + const removeListener = addListener(() => { + // 布局是否响应交由 shouldReactToKeyboard 决定 + }); - return () => { - removeListener(); - }; - }, [initializeKeyboardListener, addListener]); + return () => { + removeListener(); + }; + }, [initializeKeyboardListener, addListener]); - const inputDomRef = useRef(null); + const inputDomRef = useRef(null); - useImperativeHandle(ref, () => ({ - show: (_params: CommentInputReplyParamsType | undefined) => { - setVisible(true); - setTimeout(() => { - inputDomRef.current && inputDomRef.current?.focus(); - }, 100); - setParams(_params); - }, - })); + useImperativeHandle(ref, () => ({ + show: (_params: CommentInputReplyParamsType | undefined) => { + setVisible(true); + setTimeout(() => { + inputDomRef.current && inputDomRef.current?.focus(); + }, 100); + setParams(_params); + }, + })); - function handleSend() { - if (!value) { - toast("评论内容不得为空"); - return; + function handleSend() { + if (!value) { + toast("评论内容不得为空"); + return; + } + if (value.length > 200) { + return; + } + onConfirm?.({ content: value, ...params }); + onClose(); } - if (value.length > 200) { - return; - } - onConfirm?.({ content: value, ...params }); - onClose(); - } - function onClose() { - setVisible(false); - setValue(""); - inputDomRef.current && inputDomRef.current?.blur(); - } - console.log(keyboardHeight, "keyboardHeight"); - return ( - 0 ? `${keyboardHeight}px` : "0", - }} - enableDragToClose={false} - > - - -