Skip to content

Commit a061ef3

Browse files
authored
Merge pull request #2301 from didi/feat-input-hold-keyboard
feat(rn): support `hold-keyboard` in mpx-input
2 parents 8563775 + 3ac2ba1 commit a061ef3

3 files changed

Lines changed: 8 additions & 2 deletions

File tree

packages/webpack-plugin/lib/runtime/components/react/context.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export type KeyboardAvoidContextValue = MutableRefObject<{
1010
cursorSpacing: number
1111
ref: MutableRefObject<any>
1212
adjustPosition: boolean
13+
holdKeyboard?: boolean
1314
keyboardHeight?: number
1415
onKeyboardShow?: () => void
1516
} | null>

packages/webpack-plugin/lib/runtime/components/react/mpx-input.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* ✔ selection-start
1919
* ✔ selection-end
2020
* ✔ adjust-position
21-
* hold-keyboard
21+
* hold-keyboard
2222
* ✘ safe-password-cert-path
2323
* ✘ safe-password-length
2424
* ✘ safe-password-time-stamp
@@ -102,6 +102,7 @@ export interface InputProps {
102102
'parent-width'?: number
103103
'parent-height'?: number
104104
'adjust-position': boolean,
105+
'hold-keyboard'?: boolean
105106
bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void
106107
bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
107108
bindblur?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
@@ -150,6 +151,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
150151
'parent-width': parentWidth,
151152
'parent-height': parentHeight,
152153
'adjust-position': adjustPosition = true,
154+
'hold-keyboard': holdKeyboard = false,
153155
bindinput,
154156
bindfocus,
155157
bindblur,
@@ -281,7 +283,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
281283

282284
const setKeyboardAvoidContext = () => {
283285
if (keyboardAvoid) {
284-
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition }
286+
keyboardAvoid.current = { cursorSpacing, ref: nodeRef, adjustPosition, holdKeyboard }
285287
}
286288
}
287289

packages/webpack-plugin/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const KeyboardAvoidingView = ({ children, style, contentContainerStyle }: Keyboa
5353

5454
const onTouchEnd = ({ nativeEvent }: NativeSyntheticEvent<NativeTouchEvent & { origin?: string }>) => {
5555
if (nativeEvent.origin !== 'input') {
56+
if (keyboardAvoid?.current?.holdKeyboard) {
57+
return
58+
}
5659
Keyboard.isVisible() && Keyboard.dismiss()
5760
}
5861
}

0 commit comments

Comments
 (0)