question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for style-related props (not set via 'style') in React Native

See original GitHub issue

Presently in styled components, there is no way to affect other style-related props in React Native.

This style-related-prop-not-defined-via-style can be found in many third party libraries (such as React Native Navbar’s tintColor prop), in custom components one might write themselves, and in React Native’s core components, for example:

It’s of course possible to simply set these props manually, but styled-component’s themes are unable to be leveraged to standardize them across the codebase.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:7
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

19reactions
mxstbrcommented, Jul 1, 2017

This is now finally possible in version two with the .attrs constructor!

const Button = styled.TouchableHighlight.attrs({
  underlayColor: 'red',
})`
  color: blue;
`
1reaction
mxstbrcommented, Nov 20, 2016

That’s an unnecessary escape hatch @adamterlson, since you can already set any prop desired when rendering. I think with the list @irakli-janiashvili dug up we should be fine to publish a first version with support for these. It doesn’t matter if it’s not 100% complete, as we can always add more to the list.

Basically, what we should do is have a separate module called react-native-style-props which exports an object. This object should be keyed by primitive and each one should have an array of props like this maybe?

// react-native-style-props/index.js

module.exports = {
  ActivityIndicator: ['color', 'size'],
}

Then from styled-components we can check at creation time if the current property is supported as a prop, and pass it to the underlying primitive. What do you think, does somebody want to go ahead and create that repo?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to use styled-theming to customize ...
I'm using React-Native and i want to change the color prop of an ActivityIndicator according to the defined theme style. Is it possible...
Read more >
Style
With React Native, you style your application using JavaScript. All of the core components accept a prop named style. The style names and ......
Read more >
Layout Props
More detailed examples about those properties can be found on the Layout with Flexbox page. ... Ems and other units are not supported....
Read more >
Image Style Props
Style BorderWidth and BorderColor Function Component Example ... This is useful in cases which are not supported by the Android ...
Read more >
Props
You can put any JavaScript expression inside braces in JSX. Your own components can also use props . This lets you make a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found