React-native-paper: How to use custom icons in TextInput.Icon component

Created on 13 Sep 2020  路  8Comments  路  Source: callstack/react-native-paper

Is it possible to use custom icons in TextInput.Icon component and which icon library supports for this component.

mode='outlined'
label="Label Name"
placeholder="Enter placeholder"
left={}
/>

Most helpful comment

@hbiede pass the name as a function

<TextInput
   right={<TextInput.Icon name={() => <Icon name={'camera'} size={20} />} />}
   style={styles.input}
   label={'Label'}
/>

All 8 comments

Couldn't find version numbers for the following packages in the issue:

  • react-native
  • react-native-paper
  • react-native-vector-icons

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

You can pass your own component in the name prop, like saw in #2255.

<TextInput style={commonstyles.primaryInput}
  mode='outlined'
  label="Label Name"
  placeholder="Enter placeholder"
  left={
    <TextInput.Icon
      name={<Icon name="info" color="#ff0000" />} // where <Icon /> is any component from vector-icons or anything else
      onPress={() => {}}
    />
  }
/>

It seem like that it's not too clear in the documentation, but we always can open a PR to contribute.

This isn't an option currently since a release hasn't been cut yet

@hbiede For me, it already works, even the TS giving me an error message for name prop. I'm using version 4.2.0

Edit: Seems like 4.3.0 just launched minutes ago \o/.

@hbiede pass the name as a function

<TextInput
   right={<TextInput.Icon name={() => <Icon name={'camera'} size={20} />} />}
   style={styles.input}
   label={'Label'}
/>

@ikaccc yep, it鈥檚 working now. It hadn鈥檛 been at the time as the change hadn鈥檛 been published. Thanks, though.

this didnt work for me and IMO very confusing design, this doesnt follow any standards or share any similarities to other components in the library

The fact that it requires a callback instead of a component is quite weird

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alikazemkhanloo picture alikazemkhanloo  路  4Comments

ZhengYuTay picture ZhengYuTay  路  3Comments

yaronlevi picture yaronlevi  路  3Comments

sm2017 picture sm2017  路  4Comments

timothystewart6 picture timothystewart6  路  4Comments