diff --git a/packages/taro-components-rn/src/components/Input/index.tsx b/packages/taro-components-rn/src/components/Input/index.tsx index e66fb5a3c872..3df930ac5e5c 100644 --- a/packages/taro-components-rn/src/components/Input/index.tsx +++ b/packages/taro-components-rn/src/components/Input/index.tsx @@ -121,7 +121,7 @@ const _Input = (props: InputProps) => { if (typeof result === 'string') { tmpValue.current = result setReturnValue(result) - } else if (returnValue) { + } else if (returnValue !== undefined) { // 为了处理输入不合法,setState 相同值时,状态不更新,UI 也得不到更新,重置状态进而更新 setReturnValue(undefined) } diff --git a/packages/taro-rn/src/lib/keyboard.ts b/packages/taro-rn/src/lib/keyboard.ts index 42a4253a222c..b35da35b303b 100644 --- a/packages/taro-rn/src/lib/keyboard.ts +++ b/packages/taro-rn/src/lib/keyboard.ts @@ -17,8 +17,8 @@ const hideKeyboard = (opts: Taro.hideKeyboard.Option = {}): Promise { - _cbManager.trigger({ height: e.endCoordinates.height }) +const keyboardHeightListener = (height: number) => { + _cbManager.trigger({ height }) } /** @@ -28,8 +28,12 @@ const keyboardHeightListener = (e) => { const onKeyboardHeightChange = (callback: Taro.onKeyboardHeightChange.Callback): void => { _cbManager.add(callback) if (!_hasListener) { - Keyboard.addListener('keyboardDidShow', keyboardHeightListener) - Keyboard.addListener('keyboardDidHide', keyboardHeightListener) + Keyboard.addListener('keyboardDidShow', (e) => { + keyboardHeightListener(e.endCoordinates.height) + }) + Keyboard.addListener('keyboardDidHide', () => { + keyboardHeightListener(0) + }) _hasListener = true } } @@ -53,8 +57,4 @@ const offKeyboardHeightChange = (callback?: Taro.onKeyboardHeightChange.Callback } } -export { - hideKeyboard, - offKeyboardHeightChange, - onKeyboardHeightChange -} +export { hideKeyboard, offKeyboardHeightChange, onKeyboardHeightChange }