Skip to content

Commit

Permalink
refactor(rn): 实现 rn 端 input 组件中 placeholder color 的设置 (#11594)
Browse files Browse the repository at this point in the history
* fix(rn): input 组件 TS 语法错误 #11562

* refactor(rn): 实现 placeholderStyle 设置 placeholderTextColor

Co-authored-by: Ren Yubin <[email protected]>
Co-authored-by: tony chen <[email protected]>
  • Loading branch information
3 people authored Apr 9, 2022
1 parent 3d4f6bd commit 93493fa
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export interface InputProps extends FormItemProps{
cursor?: number;
selectionStart: number;
selectionEnd: number;
placeholderStyle?: string;
placeholderTextColor?: string;
onInput?: (evt: Event) => void;
onChange?: (evt: Event) => void;
onFocus?: (evt: Event) => void;
Expand Down
65 changes: 38 additions & 27 deletions packages/taro-components-rn/src/components/Input/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
TextInputContentSizeChangeEventData,
KeyboardTypeOptions
} from 'react-native'
import { noop, omit } from '../../utils'
import { noop, omit, parseStyles } from '../../utils'
import { InputProps, InputState } from './PropsType'

const keyboardTypeMap: { [key: string]: string } = {
Expand Down Expand Up @@ -193,8 +193,8 @@ class _Input extends React.Component<InputProps, InputState> {
_autoHeight,
autoFocus,
focus,
placeholderStyle,
} = this.props

const keyboardType: KeyboardTypeOptions = keyboardTypeMap[type] as KeyboardTypeOptions

const selection = (() => {
Expand All @@ -210,30 +210,36 @@ class _Input extends React.Component<InputProps, InputState> {
// fix: https://reactnative.dev/docs/textinput#multiline
const textAlignVertical = _multiline ? 'top' : 'auto'

const placeholderTextColor = this.props.placeholderTextColor || parseStyles(placeholderStyle)?.color

const props = omit(this.props, [
'style',
'value',
'type',
'password',
'placeholder',
'disabled',
'maxlength',
'confirmType',
'confirmHold',
'cursor',
'selectionStart',
'selectionEnd',
'onInput',
'onFocus',
'onBlur',
'onKeyDown',
'onConfirm',
'_multiline',
'_autoHeight',
'_onLineChange',
'placeholderStyle',
'placeholderTextColor',
])

return (
<TextInput
{...omit(this.props, [
'style',
'value',
'type',
'password',
'placeholder',
'disabled',
'maxlength',
'confirmType',
'confirmHold',
'cursor',
'selectionStart',
'selectionEnd',
'onInput',
'onFocus',
'onBlur',
'onKeyDown',
'onConfirm',
'_multiline',
'_autoHeight',
'_onLineChange'
])}
{...props}
defaultValue={value}
keyboardType={keyboardType}
secureTextEntry={!!password}
Expand All @@ -255,9 +261,14 @@ class _Input extends React.Component<InputProps, InputState> {
textAlignVertical={textAlignVertical}
onContentSizeChange={this.onContentSizeChange}
underlineColorAndroid="rgba(0,0,0,0)"
style={[{
padding: 0,
}, style, _multiline && _autoHeight && { height: Math.max(35, this.state.height) }]}
placeholderTextColor={placeholderTextColor}
style={[
{
padding: 0
},
style,
_multiline && _autoHeight && { height: Math.max(35, this.state.height) }
]}
/>
)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/taro-components/types/Input.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ interface InputProps extends StandardProps, FormItemProps {
*/
placeholderClass?: string

/** 指定 placeholder 文字的颜色
* @supported rn
*/
placeholderTextColor?: string
/** 是否禁用
* @supported weapp, h5, rn
*/
Expand Down

0 comments on commit 93493fa

Please sign in to comment.