reactjs - TextInput 样式 Props 类型 react native
问题描述
我正在尝试将样式作为道具传递给我的自定义TextInput
组件。我发现这个片段可以在道具中键入按钮和标签样式:
import {
StyleProp,
Text,
TextStyle,
View,
ViewStyle
} from 'react-native';
interface IProps {
label: string;
buttonStyle?: StyleProp<ViewStyle>;
labelStyle?: StyleProp<TextStyle>;
}
// rest
但我没有找到任何TextInput
关于StyleProp
所以将样式传递给 TextInput 的正确方法是什么或任何文档?
解决方案
我正在检查TextInputProps
界面,发现TextStyle
也用于TextInput
:
style?: StyleProp<TextStyle>;
所以它可以通过以下方式使用:
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: {...},
});
推荐阅读
- postfix-mta - Fail2Ban 过滤器忽略 postfix 和 dovecot 中的特定用户名
- python - 如何在python中推断规则网格的点
- reactjs - 编译 react npm 自制模块的最快方法是什么?
- kubernetes - 如何为在 Prometheus 上的 Kubernetes 集群上运行的 pod 查找有关 CPU/MEM 的指标
- php - 添加换行 PHP
- python - 使用 python 烧瓶的电子 js 中的安全性
- apple-m1 - Xcode 12.4 不断加载..100% cpu m1
- kubernetes - Kubernetes:来自另一个 pod 的 kafka pod rechability 问题
- php - PHP Xdebug 在 VSCode 中不起作用 - Windows + IIS
- jquery - 日期时间查询格式问题 Google 表格