React Native - @emotion/native - TextInput 占位符文本颜色属性

Posted

技术标签:

【中文标题】React Native - @emotion/native - TextInput 占位符文本颜色属性【英文标题】:React Native - @emotion/native - TextInput placeholder text color attribute 【发布时间】:2020-03-12 15:33:14 【问题描述】:

我正在尝试通过styled.TextInput.attrs 函数传递placeholderTextColor 属性。我这样做的原因是我可以访问主题props

这就是我所拥有的:

const TextInput = styled.TextInput.attrs(props => (
  placeholderTextColor: "red",
  type: "password"
))`
  color: $( theme ) => theme.colors.text;
`

但我收到以下错误:

_native.default.TextInput.attrs is not a function. (In '_native.default.TextInput.attrs(function (props) 
    return 
      placeholderTextColor: "red",
      type: "password"
    ;
  )', '_native.default.TextInput.attrs' is undefined)

【问题讨论】:

你是如何导入你的'styled'的? @AshwinMothilal 像这样:import styled from "@emotion/native" 【参考方案1】:

我猜@emotion/native 还不支持attrs 功能,所以我转到styled-components

【讨论】:

以上是关于React Native - @emotion/native - TextInput 占位符文本颜色属性的主要内容,如果未能解决你的问题,请参考以下文章

react native 增加react-native-camera

更新 react-native-maps 以使用 create-react-native-app

react native 增加react-native-storage

React-Native 和 Expo:create-react-native-app 和 react-native init 之间的区别

什么是 react-native-cli 和 @react-native-community/cli?

React Native - 当 react-native 版本 > 0.55 时,无法通过 react-native-cli 创建新项目