React Native Paper Text Input - 调整初始状态下的标签颜色

Utk*_*mir 5 label textinput react-native react-native-paper

我想在初始状态(不是 onFocus)调整概述的react-native-paper TextInput 标签颜色。这是我的 OutlinedInput 组件:

import * as React from 'react';
import { TextInput } from 'react-native-paper';

const OutlinedInput = (props) => {
  return (
    <TextInput
      mode='outlined'
      label={props.label}
      placeholder={props.placeholder}
      placeholderTextColor='white'
      secureTextEntry={props.secureTextEntry}
      multiline={props.multiline}
      keyboardType={props.keyboardType}
      value={props.value}
      onChangeText={(value) => props.onChangeText(value)}
      style={props.style}
      theme={props.theme}
    />
  );
};

export default OutlinedInput;
Run Code Online (Sandbox Code Playgroud)

在我的 Register 组件中,我在其中创建了一个 OutlinedInput 组件:

<View style={{ justifyContent: 'center', alignItems: 'center' }}>
  <OutlinedInput
    label={'User Name'}
    value={userName}
    onChangeText={(userName) => setUserName(userName)}
    style={{ color: 'white', backgroundColor: 'rgb(35,39,42)',
            borderRadius: 5, width: '75%', height: '5%' 
    }}
    theme={{ colors: { text: 'white', primary: 'rgb(33, 151, 186)' } }}
  />
</View>
Run Code Online (Sandbox Code Playgroud)

我在 Register 组件的顶部添加了这一行:

const [userName, setUserName] = useState('');
Run Code Online (Sandbox Code Playgroud)

如果我不点击输入,我的程序的屏幕截图:

在此输入图像描述

这是点击输入的屏幕截图:

在此输入图像描述

如您所见,标签“用户名”的颜色是黑色。我想把它设置为白色。单击它时,它按预期工作,但标签颜色的初始状态不是我想要的。

我尝试使用占位符来解决这个问题。我向 OutlinedInput 添加了占位符道具,并将占位符颜色更改为白色,但在这种情况下,占位符没有变成轮廓。当我尝试有关占位符的任何内容时,它并没有被概述。

如何调整标签颜色以在打开程序后看到它为白色?

jam*_*mes 9

为了调整 React Native Paper v5 中的标签颜色,您必须更新此属性:

theme={{
    colors: {
         onSurfaceVariant: 'white'
    }
}}
Run Code Online (Sandbox Code Playgroud)

我不明白为什么他们把它做得如此不语义且难以访问(甚至不在他们的文档中)