Web experiences should be built mobile first, customizing the experience for non-mobile users with media queries.
You can specify any CSS valid media query as an object key, like this:
<Viewextend={{'@media (min-device-pixel-ratio: 2)': {color: 'red',},}}>Helo Retina Red!</View>
The default media queries are available as keys on any extend
style block:
<Viewextend={{color: 'red'fromM: {color: 'green'},fromL: {color: 'blue'},}}>Hello Responsive!</View>
They are also available on the theme:
const { breakpoints } = useTheme();// breakpoints.fromM === '@media (min-width: 480px)' etc
For the common use case of setting a layout property to different values depending on the breakpoint, you can use an object with breakpoints as a value, or an array representing the same breakpoints.
<Viewextend={{backgroundColor: 'background.secondary',borderColor: 'ornament.border',borderWidth: 1,borderStyle: 'solid',padding: 8,width: {default: 100,fromM: 200,fromL: 300,fromXL: 400,},}}><Text>object breakpoints</Text></View>
<Viewextend={{backgroundColor: 'background.secondary',borderColor: 'ornament.border',borderWidth: 1,borderStyle: 'solid',padding: 8,width: [100, 200, 300, 400],}}><Text>array breakpoints</Text></View>
The following CSS properties accept responsive object or array values:
alignContent
alignItems
alignSelf
aspectRatio
columnGap
display
flex
flexBasis
flexDirection
flexGrow
flexShrink
flexWrap
gap
height
justifyContent
margin
marginBottom
marginLeft
marginRight
marginTop
maxHeight
maxWidth
minHeight
minWidth
order
padding
paddingBottom
paddingLeft
paddingRight
paddingTop
rowGap
textAlign
width
key | media query |
---|---|
onlyS@media (max-width: 479px) | 0 |
untilM@media (max-width: 479px) | 1 |
fromM@media (min-width: 480px) | 2 |
onlyM@media (min-width: 480px) and (max-width: 1023px) | 3 |
untilL@media (max-width: 1023px) | 4 |
fromL@media (min-width: 1024px) | 5 |
onlyL@media (min-width: 1024px) and (max-width: 1599px) | 6 |
untilXL@media (max-width: 1599px) | 7 |
fromXL@media (min-width: 1600px) | 8 |
onlyXL@media (min-width: 1600px) | 9 |