oblador / react-native-vector-icons

Customizable Icons for React Native with support for image source and full styling.
https://oblador.github.io/react-native-vector-icons/
MIT License
17.31k stars 2.12k forks source link

Inherit text size from parent Text element #1432

Open jadar opened 2 years ago

jadar commented 2 years ago

Is your feature request related to a problem? Please describe. I've noticed that I am repeating text sizes all over the place when I am placing an icon next to another Text element. I'm working on setting up common text style variants, and it would be really convenient if that worked to specify the icon size, too.

Describe the solution you'd like I'd like Icons to inherit the parent text size if it's nested in a Text component, and no size prop is passed to the Icon element.

Describe alternatives you've considered I considered using styles, but that seems error-prone if the user forgets to use them.

Additional context None

krosenberg commented 1 year ago

If you set size={null}, the icon will avoid applying the default fontSize. If you wrap that icon in a Text component, the icon should inherit its size.

<Text style={{fontSize: 24}}>
  <Icon name="alert" size={null} />
</Text>

Note: If you're enforcing types with Typescript, the style prop will complain because null isn't a number. Possible solutions: