Reactjs text输入样式道具类型react native
我正在尝试将样式作为道具传递给我的自定义Reactjs text输入样式道具类型react native,reactjs,typescript,react-native,Reactjs,Typescript,React Native,我正在尝试将样式作为道具传递给我的自定义TextInput组件。我在道具中找到了用于键入按钮和标签样式的代码段: import { StyleProp, Text, TextStyle, View, ViewStyle } from 'react-native'; interface IProps { label: string; buttonStyle?: StyleProp<ViewStyle>; labelStyle?: StyleProp&
TextInput
组件。我在道具中找到了用于键入按钮和标签样式的代码段:
import {
StyleProp,
Text,
TextStyle,
View,
ViewStyle
} from 'react-native';
interface IProps {
label: string;
buttonStyle?: StyleProp<ViewStyle>;
labelStyle?: StyleProp<TextStyle>;
}
// rest
import{
StyleProp,
文本,
文本样式,
看法
视图样式
}从“反应本机”;
接口IProps{
标签:字符串;
按钮样式?:样式属性;
labelStyle?:StyleProp;
}
//休息
但是我没有找到任何关于TextInput
的内容,也没有找到任何关于StyleProp
那么,将样式传递给TextInput的正确方法是什么呢?我正在检查
TextInputProps
界面,发现TextStyle
也用于TextInput
:
style?: StyleProp<TextStyle>;
style?:StyleProp;
因此,它可以通过以下方式使用:
import {StyleSheet, TextInput, TextInputProps , StyleProp ,
TextStyle } from 'react-native';
type Props = {
style?: StyleProp<TextStyle>,
// or
style?: Pick<TextInputProps, "style">
};
const Input: React.FC<Props> = ({style: propStyles}) =>
<TextInput
style={ [styles.input, propStyles] }
/>
const styles = StyleSheet.create({
input: {...},
});
import{StyleSheet,TextInput,TextInputProps,StyleProp,
TextStyle}来自“react native”;
类型道具={
风格?:风格道具,
//或
风格?:选择
};
常量输入:React.FC=({style:propStyles})=>
const styles=StyleSheet.create({
输入:{…},
});
您能为自定义文本输入组件添加一些代码吗?@DevAttendant我找到了答案