Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support media queries with React Native #203

Closed
tlvenn opened this issue Nov 15, 2016 · 13 comments
Closed

Support media queries with React Native #203

tlvenn opened this issue Nov 15, 2016 · 13 comments

Comments

@tlvenn
Copy link

tlvenn commented Nov 15, 2016

Thanks for the fantastic project guys, I am primarily targeting RN and I though it would be awesome if styled components could provide support for media queries seamlessly in RN.

Turns out that there is a new very promising project to add media queries support to both React and React Native.

https://github.com/tuckerconnelly/uranium

It would be pretty neat if a bridge would exist to embed this functionality so that I dont have to wrap my style component (which is already a wrapper) with Uranium wrapper.

@tlvenn
Copy link
Author

tlvenn commented Nov 15, 2016

@mxstbr any though on the subject ?

@jacobp100
Copy link
Contributor

Just so I understand correctly, are you looking to have this,

height: 120;

@media (min-width: 600) {
  width: 56;
}

Go to,

const styles = {
  base: {
    height: 120,

    '@media (min-width: 600px)': {
      height: 56,
    },
  },
}

@knowbody
Copy link

I'm curious what would media queries in RN do? What sort of problems are you trying to solve? Would you like to get something what https://github.com/aybadb/react-native-responsive does?

@tlvenn
Copy link
Author

tlvenn commented Nov 21, 2016

@knowbody you can check this proposal https://gist.github.com/grabbou/72767db51f97fe86cfea
That should give you an idea on what media queries could do on RN.

It addresses the same kind of problem domain that media queries solve on the web. When you have an RN app that target ios, android, phones and tablets alike and need to adapt its layout depending on the device orientation and so on...

I dont really like how react-native-responsive is implementing media queries, for me, media queries should be expressed as css rules, just like on the web. In that regard, Uranium is a much better prospect imho.

Extended Stylesheet implemented the proposal above:

https://github.com/vitalets/react-native-extended-stylesheet#media-queries

shripadk added a commit to shripadk/styled-components that referenced this issue Feb 12, 2017
* Supports REM/Percent units
* Supports Media Queries (Fixes styled-components#203)
@mxstbr
Copy link
Member

mxstbr commented Jul 1, 2017

As nobody has asked for this custom extension in more than half a year I doubt we'll include it in the library. On top of that many workarounds already exist that make media query functionality possible on ReactNative.

Thank you for suggesting improvements to the library!

@mxstbr mxstbr closed this as completed Jul 1, 2017
@corysimmons
Copy link

corysimmons commented Feb 16, 2018

Why didn't shripadk@d4fe1a9 get merged?

Does it add support for this?

I would love to use styled-components with RN but I need media queries. react-native-extended-stylesheet syntax is RN pojo nastiness...

Seems like a really valid request. Please re-open.

@shripadk Can you comment on this and if your fork is working open a PR to this lib please?

@edsonayllon
Copy link

edsonayllon commented Jul 5, 2018

So, is media-query not possible in React-Native? Why not support all CSS3? Media queries would be very helpful when making a responsive ui for tablets and phones.

@quantizor
Copy link
Contributor

I'm open to it if someone wants to make a new PR and lots of tests.

@hosseinalipour
Copy link

Any new information on this? what does community use right now?
there are many projects support the feature but all of them use different ways of defining styles and queries, making projects unintegrated and messy.

@corysimmons
Copy link

@hosseinalipour Look at the PR I linked above. It's really simple. See if you can replicate that into a new PR like Evan suggested.

If that solution works for you locally, I'm sure someone could point you towards where a small test suite like that might live.

I haven't used RN in a long time, but would love media queries to be available next time I need to. :)

@nandorojo
Copy link

I'm working on a responsive, Theme UI-like library for React Native. It would be great if the styled.View from styled-components/native supported the web media queries the way styled.div does. This would be fine even if it only works on web. On web, it makes the most sense for media queries to be done using CSS, not JS, as some people have mentioned above.

I already got the media queries to work on native using the useDimensions hook from @react-native-community/hooks.

That said, if you try to use React Native's Dimensions API to create JS-based media queries on web (instead of using CSS,) you'll break server side rendering (see vercel/next.js#14469 (reply in thread).) That's why it would be great if the styled.View had the same functionality as styled.div for media queries.

@jamesone
Copy link

Is this something that's being considered?

@abumalick
Copy link

I'm working on a responsive, Theme UI-like library for React Native. It would be great if the styled.View from styled-components/native supported the web media queries the way styled.div does. This would be fine even if it only works on web. On web, it makes the most sense for media queries to be done using CSS, not JS, as some people have mentioned above.

I already got the media queries to work on native using the useDimensions hook from @react-native-community/hooks.

That said, if you try to use React Native's Dimensions API to create JS-based media queries on web (instead of using CSS,) you'll break server side rendering (see vercel/next.js#14469 (reply in thread).) That's why it would be great if the styled.View had the same functionality as styled.div for media queries.

And it is here: https://github.com/nandorojo/dripsy

Thank you very much for building this, I was missing theme-ui so much ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.