Skip to content

Commit d6adb37

Browse files
authored
Merge pull request #2318 from didi/feat-inputMode
feat: RN input组件keyboardType属性修改为 RN76 inputMode属性 & 新增支持keyboard-type属性
2 parents 211f7a5 + c5a4a38 commit d6adb37

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

  • packages/webpack-plugin/lib/runtime/components/react

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ export interface InputProps {
9595
'selection-start'?: number
9696
'selection-end'?: number
9797
'placeholder-style'?: { color?: string }
98-
'enable-offset'?: boolean,
98+
'enable-offset'?: boolean
9999
'enable-var'?: boolean
100100
'external-var-context'?: Record<string, any>
101101
'parent-font-size'?: number
102102
'parent-width'?: number
103103
'parent-height'?: number
104-
'adjust-position': boolean,
104+
// 只有 RN 环境读取
105+
'keyboard-type'?: string
106+
'adjust-position': boolean
105107
'hold-keyboard'?: boolean
106108
bindinput?: (evt: NativeSyntheticEvent<TextInputTextInputEventData> | unknown) => void
107109
bindfocus?: (evt: NativeSyntheticEvent<TextInputFocusEventData> | unknown) => void
@@ -119,11 +121,11 @@ export interface PrivateInputProps {
119121

120122
type FinalInputProps = InputProps & PrivateInputProps
121123

122-
const keyboardTypeMap: Record<Type, string> = {
123-
text: 'default',
124+
const inputModeMap: Record<Type, string> = {
125+
text: 'text',
124126
number: 'numeric',
125-
idcard: 'default',
126-
digit: isIOS ? 'decimal-pad' : 'numeric'
127+
idcard: 'text',
128+
digit: 'decimal'
127129
}
128130

129131
const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps>((props: FinalInputProps, ref): JSX.Element => {
@@ -151,6 +153,7 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
151153
'parent-width': parentWidth,
152154
'parent-height': parentHeight,
153155
'adjust-position': adjustPosition = true,
156+
'keyboard-type': originalKeyboardType,
154157
'hold-keyboard': holdKeyboard = false,
155158
bindinput,
156159
bindfocus,
@@ -184,7 +187,6 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
184187
return ''
185188
}
186189

187-
const keyboardType = keyboardTypeMap[type]
188190
const defaultValue = parseValue(value)
189191
const textAlignVertical = multiline ? 'top' : 'auto'
190192

@@ -465,7 +467,8 @@ const Input = forwardRef<HandlerRef<TextInput, FinalInputProps>, FinalInputProps
465467
ref: nodeRef,
466468
style: extendObject({}, normalStyle, layoutStyle),
467469
allowFontScaling,
468-
keyboardType: keyboardType,
470+
inputMode: originalKeyboardType ? undefined : inputModeMap[type],
471+
keyboardType: originalKeyboardType,
469472
secureTextEntry: !!password,
470473
defaultValue: defaultValue,
471474
value: inputValue,

0 commit comments

Comments
 (0)