react-native-web
类型定义(链接),可用的属性如下:outlineColor?: ColorValue,
outlineOffset?: string | number,
outlineStyle?: string,
outlineWidth?: string | number, // set to 0 to disable outline
您可以使用以下方法更改轮廓线的颜色:
<TextInput style={Platform.OS === "web" && {outlineColor: "orange" }} />
<TextInput
style={
Platform.select({
web: {
outlineColor: 'orange',
},
})
}
/>
或者:
您可以尝试删除网页的轮廓样式,并在输入框聚焦时应用 borderColor 样式。
<TextInput
style={
Platform.select({
web: {
outlineStyle: 'none',
},
})
}
/>
import * as React from 'react'
import { Platform, TextInput, TextInputProps } from 'react-native'
import { TextInput as WebTextInput } from 'react-native-web'
const XTextInput: React.FC<TextInputProps> = (props) => {
const { style, placeholderTextColor, ...otherProps } = props
return Platform.OS === 'web' ? (
<WebTextInput
{...otherProps}
style={[{ outlineColor: 'transparent' }, style]}
placeholderTextColor={placeholderTextColor ?? '#78716C'}
/>
) : (
<TextInput
style={[style]}
accessibilityLabel="Text input label"
accessibilityHint="Text input hint"
{...otherProps}
placeholderTextColor={placeholderTextColor ?? '#78716C'}
/>
)
}
export default XTextInput
使用此功能
<XTextInput placeholder="Start your search" style={[{What ever style here}]}/>