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.

Setting shorthand border property on `Image` element in React Native defaults unsupported `border-style` key

See original GitHub issue

First off I wanted to say thanks for such an awesome library. I can’t imagine going back to css modules/manual jsx inline styles.

Not entirely sure if this is intended or not, but I figured I’d raise a flag. Basically, when using the short hand border property in react-native, the border-style property defaults to a value of solid (when not specified), which is an invalid key for the Image element. This raises a nasty warning. Obviously this can be avoided by simply using border-width and border-color separately.

Of course this could be an issue on other native elements that also don’t support the border-style, but I’m not too familiar with the native spec (working on my first RN project). 🤷‍♂️

I’d be happy to read up on the spec and fix it myself, if someone could point me in the right direction of the generally related code in this repo.

Version

2.1.2

Reproduction

This code produces the following error:

const Avatar = styled.Image`
  height: 100px;
  width: 110px;
  border-radius: 5px;
  border: 2px #EFEFF2;
`;

export default (props) => (
  <Root>
    <Top>
      <Avatar source={{uri: props.avatarUrl}} />
      <Stats>
        <Stat key={1} metric="Repos" value={props.repos} onPress={props.onRepos} />
        <Stat key={2} metric="Pulls" value={props.pulls} onPress={props.onPulls} />
        <Stat key={3} metric="Followers" value={props.followers} onPress={props.onFollowers} />
      </Stats>
    </Top>
    <Bottom>
      <Name>{props.name ? props.name : `@${props.login}`}</Name>
      {props.bio ? <Bio>{props.bio}</Bio> : <NoBio>A nondescript user.</NoBio>}
    </Bottom>
  </Root>
);

img_6948

Steps to reproduce

  1. Create a styled image component.
  2. Assign the border property with only the border-width and border-color.
  3. Get a warning in runtime.

Expected Behavior

No default value set.

Actual Behavior

Default value set, warning produced.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jacobp100commented, Sep 10, 2017

We might need to override styles from other rules though.

const Comp1 = styled.View`
  border-color: red;
`

const Comp2 = styled(Comp1)`
  border: 1px solid;
`
1reaction
kittencommented, Sep 9, 2017

I noticed this as well. Generally speaking it is intended and expected behaviour. But when the border-style in the shorthand is missing, I think we should not default ourselves, but not set the value to a default and bet on React Native’s default instead.

Does that sound reasonable, @jacobp100 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create text border in React Native? - css - Stack Overflow
You need to set borderColor and borderWidth . Share.
Read more >
Layout Props - React Native
The following example shows how different properties can affect or shape a React Native layout. You can try for example to add or...
Read more >
Learn To Create Border Style in React Native - eduCBA
React Native Border Style refers to the property which helps in the styling of element's four borders. The value of this property varies...
Read more >
React Native Development Considerations | Taro 文档
The shorthand for border{Top,Right,Bottom,Left} (shorthands) is not supported, because borderStyle cannot be applied to a single border. Use sass:. /** * // ...
Read more >
border-top-left-radius - CSS: Cascading Style Sheets | MDN
A background, being an image or a color, is clipped at the border, even a rounded one; the exact location of the clipping...
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