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.

Style Object Creation in React Native

See original GitHub issue

First of all, I love styled components, so thank you guys a lot!!!

I have a question about react-native styles. Can I somehow generate a style sheet like object for react native with styled components. Many React Native components take several style objects, e.g. ScrollView (which takes an additional contentContainerStyle) or react navigation components (which take several styles in their factory methods), it would be nice to define those styles with styled components as well, including the use of theme variables. I would have expected the css function to do something like that on native, but that doesn’t seem to be the case.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
wood1986commented, Apr 9, 2020

v5 still does not support this natively

const SectionList = styled.SectionList.attrs((props: SectionListProps) => ({
  contentContainerStyle: css`
    "width": ${props.width}px;
    "margin": "auto";
    "padding-vertical": ${props.gripGap}px;
  `
}))``;

Any update?

5reactions
MrLohcommented, Feb 14, 2019

I built a tiny lib for convenience a while back. https://github.com/MrLoh/styled-css

Read more comments on GitHub >

github_iconTop Results From Across the Web

Style - React Native
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 >
React Native styling tutorial with examples - LogRocket Blog
Styling in React Native is done using JavaScript. Since React components have support for the style prop, you can also create an object...
Read more >
Styling in React Native - Bits and Pieces
You can add styling to your component using style props you simply add style props to your element it accepts an object of...
Read more >
How to combine multiple inline style objects? - reactjs
Array notaion is the best way of combining styles in react native. This shows how to combine 2 Style objects, <Text style={[styles.base, ...
Read more >
React Native Styling: Structure for Style Organization
Conclusion · Styles are important: make them easy to find: Keep styles in the root application folder · Get atomic!: Build complicated Styles...
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