Styled-components: react-native shadowOffet not supported as inline style

Created on 14 Feb 2018  路  3Comments  路  Source: styled-components/styled-components

This does not seem to work.

 const  myShadowed =  {
        shadowOffset: { width: 0, height: 2 },
        shadowColor: '#000',
        shadowOpacity: 0.2,
      },

 const StyledThumbnail = styled(View)`
    ${ifProp('shadow', myShadowed)};
  `;

Produces the error:
Node of type rule not supported as an inline style

I appreciate any help in advance.

Most helpful comment

We don't support "inline" styles as interpolations in this way. I'm pretty sure it's because of how our stringifier works, in that it assumes that objects as values on an interpolation-object must be nested rules. Hence the message:

Node of type rule not supported as an inline style

What does work is: shadow-offset: 0 2px; in similar instance, since that will be converted into coordinates.

cc @jacobp100 @mxstbr: Do we need a different syntax? I suppose not, but this should maybe be documented in a nicer way.

All 3 comments

Similar problem. It鈥檚 some issue with using shadowOffset: { width: 0, height: 2 },. Removing that clears the warning. Not sure why and what you鈥檙e supposed to use instead.

We don't support "inline" styles as interpolations in this way. I'm pretty sure it's because of how our stringifier works, in that it assumes that objects as values on an interpolation-object must be nested rules. Hence the message:

Node of type rule not supported as an inline style

What does work is: shadow-offset: 0 2px; in similar instance, since that will be converted into coordinates.

cc @jacobp100 @mxstbr: Do we need a different syntax? I suppose not, but this should maybe be documented in a nicer way.

We have an open issue #1509 - we can keep discussing there. No idea what we should actually do though!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Cap32 picture Cap32  路  3Comments

artalar picture artalar  路  3Comments

arstin picture arstin  路  3Comments

ivan-navarro-75 picture ivan-navarro-75  路  3Comments

maciossek picture maciossek  路  3Comments