如何在 React Native Paper 中更改 TextInput 的文本颜色而不用在 PaperProvider 中换行?
目前这有效:
const theme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
text: "orange",
}
};
<PaperProvider theme={theme}>
<TargetComponent />
</PaperProvider>
Run Code Online (Sandbox Code Playgroud)
但是我想通过从父组件传递的道具来控制文本颜色。奇怪的是,传球backgroundColor有效但color无效。
去除PaperProvider包装也无济于事。
这是 TargetComponent 中的相关代码:
return (
<View style={styles.container}>
<TextInput
type="outlined"
style={this.props.style}
onChangeText={this.props.onChange}
label={this.props.label}
value={this.props.value || "Replace this text"}
placeholder={this.props.placeholder}
/>
</View>
)
Run Code Online (Sandbox Code Playgroud)
this.props.style 是:
{
color: "orange", // This does not work
backgroundColor: "transparent" // This works
},
Run Code Online (Sandbox Code Playgroud) 我对 React Native 比较陌生。
我可以轻松地显示按钮(带有阴影等),如下所示。
<Button
mode="contained"
color={'#f08e25'}
contentStyle={{ height: 44 }}
onPress={this.onPressSubmit}
theme={theme} >SUBMIT </Button>
Run Code Online (Sandbox Code Playgroud)
我也参考了这个文档。
https://callstack.github.io/react-native-paper/button.html#contentStyle
问题是如果模式是“包含”,我无法更改文本颜色。我在 contentStyle 或 theme 中尝试过,但它不起作用。如果模式是“包含”,我该如何更改文本颜色?
问题出在 React-native-papers 和 TextInput 组件上。(也许是我缺乏 css/flexbox 知识)
当在树中 TextInput 上方的视图上使用alignItems: 'center' 时,TextInput 的渲染会不稳定。它占据了屏幕的整个高度,并且宽度非常窄。必须在具有alignItems: 'center' 的视图和TextInput 之间或在TextInput 本身的组件层次结构中指定css 宽度属性。
有一个 Github 问题已关闭。 https://github.com/callstack/react-native-paper/issues/2335
return (
<View style={{flex: 1, alignItems: "center", justifyContent: "center"}}>
<TextInput label='Email' value='' />
<TextInput label='Password' value='' />
</View>
);
}
Run Code Online (Sandbox Code Playgroud)
可以使用此 Snack 重现问题。仅在设备上,在网络上看起来不错。 https://snack.expo.dev/@parriz/paper---weird-textinput-behaviour
完全相同的代码设置。但具有核心 React Native 组件。(按预期工作) https://snack.expo.dev/@parriz/default-react-native
完全相同的代码设置。但具有核心 React-native-element 组件。(按预期工作) https://snack.expo.dev/@parriz/great-donuts
我的问题:
这是一个React Native使用React Native Paper. 我跟在指令https://callstack.github.io/react-native-paper/getting-started.html并安装react-native-paper和react-native-vector-icons。
例如,我Searchbar在这个屏幕的顶部有一个带有以下代码的。据我所知,我什至不必在那里指定一个图标。它应该自动显示一个放大镜,但没有显示图标。
<Searchbar placeholder="New to do item..." />
Run Code Online (Sandbox Code Playgroud)
知道为什么以及如何解决它吗?
我想改变react-native-paper导航的颜色。我怎样才能改变颜色。我可以更改背景颜色,但无法更改活动选项卡圆形按钮的颜色。
图片链接 = https://i.stack.imgur.com/3Edpm.png
我想把粉红色变成蓝色我该如何改变。
import * as React from 'react';
import { BottomNavigation} from 'react-native-paper';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
const Tab = createBottomTabNavigator();
const HomePage =({route,navigation}) => {
const [index, setIndex] = React.useState(0);
const [routes] = React.useState([
{ key: 'home', title: 'Home', focusedIcon: 'home', unfocusedIcon : 'home-outline', },
{ key: 'orderHistory', title: 'Order History', focusedIcon: 'clock', unfocusedIcon: 'clock-outline' },
{ key: 'profile', title: 'Profile', focusedIcon: 'account', unfocusedIcon : 'account-outline'},
{ key: 'other', title: 'Other', focusedIcon: 'dots-horizontal-circle', unfocusedIcon: …Run Code Online (Sandbox Code Playgroud) reactjs react-hooks react-native-paper bottom-navigation-bar
我想在焦点之前更改此代码中的颜色或边框,我想要红色,在焦点上我想要黄色。
这是我的作品 https://prnt.sc/o8evi5
这是我拥有的代码,我正在使用 React Native Paper https://callstack.github.io/react-native-paper/text-input.html
<TextInput
label='Email or username'
mode='outlined'
theme={{ colors: { underlineColor:'red',}}}
style={(this.state.isFocused) ? {borderColor: 'black', borderColor: 'black',} : {fontStyle: 'italic', color: 'white'}}
selectionColor='red'
underlineColor='red'
placeholder='name@example.com'
keyboardType='email-address'
underlineColorAndroid='transparent'
autoCorrect='false'
autoCapitalize='none'
onChangeText={formikProps.handleChange('email')}
onBlur={formikProps.handleBlur('email')}
//autoFocus
/>
Run Code Online (Sandbox Code Playgroud)
我试过了,但它没有给我我想要的 https://github.com/callstack/react-native-paper/issues/656
react-native-paper文档建议您可以使用主题设置禁用按钮的颜色,但此代码不起作用:
export const buttonTheme = {
colors: {
primary: COL_BASE_YELLOW,
disabled: COL_DARK_HIGHLIGHT,
},
}
<Button
loading={submittedPhoneNumber ? true : false}
mode="contained"
onPress={() => handleSubmitPhoneNumber(phoneNumber)}
theme={buttonTheme}
disabled={phoneNumber.length < 5 ? true : false}>
Continue
</Button>
Run Code Online (Sandbox Code Playgroud)
然而,颜色primary有效。当按钮被禁用时如何更改按钮的颜色?
我的最终目标是根据其他地方设置的几个状态为一些抽屉项目提供自定义背景颜色。我知道为了给抽屉项目提供独特的背景颜色,我需要设置自定义抽屉内容。但是,我遇到了一个问题,我无法让自定义抽屉图标知道它们是否处于焦点。
我最初认为我可以做一个const [bHomeFocused, setbHomeFocused] = useState(false)(等)并设置状态onPress然后设置focused属性,但是当更多的抽屉物品进来时,我认为这听起来像是一个笨拙的解决方案。
我确定我缺少一个简单的答案,因为非自定义 DrawerItems 固有地具有此功能......
import { Drawer } from 'react-native-paper'
import { createDrawerNavigator, DrawerNavigationProp, DrawerItem, DrawerContentScrollView, DrawerItemList, DrawerContentComponentProps, DrawerContentOptions } from '@react-navigation/drawer';
function CustomDrawerContent(props: DrawerContentComponentProps<DrawerContentOptions>) {
return (
<DrawerContentScrollView {...props}>
<Drawer.Section>
<DrawerItem
label="Dashboard"
labelStyle={{ color: colorTheme.normalText }}
icon={() => <Icon name="book" type="feather" size={26} color={colorTheme.normalText} />}
activeBackgroundColor={colorTheme.panel}
inactiveBackgroundColor={colorTheme.cyan}
onPress={() => {
props.navigation.navigate('Dashboard')
}}
/>
</Drawer.Section>
<DrawerItem
label="Home"
labelStyle={{ color: colorTheme.normalText }}
icon={() => <Icon name="home" type="feather" size={26} color={colorTheme.normalText} />}
activeBackgroundColor={colorTheme.panel} …Run Code Online (Sandbox Code Playgroud) react-native ×9
css ×2
reactjs ×2
expo ×1
flexbox ×1
native-base ×1
react-hooks ×1
stylesheet ×1
typescript ×1