-
Notifications
You must be signed in to change notification settings - Fork 33
Description
The responsive styling experience of tailwindcss is great. Mobile-first, then sm:, md:, lg:, xl: prefixes for breakpoints.
When thinking about the function-helpers in for lineHeight in issue #48, I thought that maybe this could work for responsive helpers, too.
Imagine:
import { t, md, xl } from 'react-native-tailwindcss';
<View style={[t.w16, md(t.w24), xl(t.w32)]} />Internally, the helpers would look something like:
const md = (styles) => Dimensions.get('window').width > 1000 ? styles : undefinedThe question is -- would this "screen-width breakpoints" approach be helpful in react-native?
I've been watching some approaches to responsive styling, and I'm not quite sure yet.
- https://github.com/tachyons-css/react-native-style-tachyons
- Global linear scaling by setting
remunits at buildtime. Left up to user.. seems difficult to use well
- Global linear scaling by setting
- https://github.com/nirsky/react-native-size-matters
- screen-width linear scaling, screen-height linear scaling, and configurably dampened non-linear scaling (they call it "moderate scaling")
- https://github.com/helderburato/react-native-scaled-sheet
- Uses a custom linear scaling based on PixelRatio, and the small-edge's distance from (hardcoded) 375px. (I think? Didn't dig too deep)
- https://github.com/FormidableLabs/react-native-responsive-styles
- Orientation-mode responsive styles. Interesting!
- https://github.com/DaniAkash/react-native-responsive-dimensions
- Provides viewport-percentage styling. Pretty much
vh&vw, plus "vw for fontSize"
- Provides viewport-percentage styling. Pretty much
- https://github.com/wcandillon/react-native-responsive-ui
- Full-blown media query breakpoints for RN. width, height, pixel ratio, aspect ratio, orientation
So, any thoughts?
It could be reasonable to omit all of this from rn-tailwind, and rely on other utilities for this functionality.
On the other hand, this is a pretty central feature to tailwind (IMO).
After reviewing the above repos, I think there could be a place for tailwinds "increasing-breakpoints" approach (min-width queries only, no max-width or ranges). "Scaling" approaches should probably stay in their own utilities.. could always do scaleSizeUtilityFromOtherLibrary(t.w16.width) or similar
The things I still want to brainstorm on are PixelRatio and orientation -- these exist on web too, but perhaps they're more critical in nativeland? Should the sm, md, etc breakpoints be based on screen width, or minimum-edge length?
If you've gotten this far, thanks a lot for reading!