Skip to content

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

Closed

Description

@adamterlson

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.

Activity

  1. modified the milestone: on Oct 30, 2016
  2. IrakliJani commented on Nov 9, 2016

    @IrakliJani

    This definitely will be a great enhancement!

  3. mxstbr commented on Nov 9, 2016

    @mxstbr
    Member

    Is there a list of the ones that exist somewhere? We should definitely add support for them!

  4. adamterlson commented on Nov 9, 2016

    @adamterlson
    Author

    @mxstbr I'm unaware of any existing list. The only option would be to go through every available component and manually catalog them, as far as I know

  5. IrakliJani commented on Nov 9, 2016

    @IrakliJani

    I can volunteer to go through and get the list of those items.

  6. mxstbr commented on Nov 10, 2016

    @mxstbr
    Member

    That would be amazing @irakli-janiashvili! 🙏

  7. IrakliJani commented on Nov 10, 2016

    @IrakliJani

    @mxstbr @adamterlson

    Here's the list of all possible attributes that can go in styles -> https://gist.github.com/irakli-janiashvili/dac99f8ceb0c1a9bafa78aad0f19d861

    I put a question marks in front of some attrs that I'm not sure we have to put in styles..

  8. adamterlson commented on Nov 12, 2016

    @adamterlson
    Author

    It seems like a lot to maintain manually.

    Why not simply provide a way to generally set any prop desired?

  9. mxstbr commented on Nov 20, 2016

    @mxstbr
    Member

    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?

  10. removed this from the milestone on Jan 17, 2017
  11. mxstbr commented on Jul 1, 2017

    @mxstbr
    Member

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

    const Button = styled.TouchableHighlight.attrs({
      underlayColor: 'red',
    })`
      color: blue;
    `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions