react-native-web-responsive
Universal media queries for React Native and web.
Installation
Using npm:
npm install --save react-native-web-responsive
or yarn:
yarn add react-native-web-responsive
Usage
Since MediaQuery component built on components from react-responsive and react-native-responsive it can utilize any props supported by them with next limitations:
- There is no difference between viewport- and device-based measurements on native.
- The only supported unit for the resolution property is dppx.
- Child function, properties
aspectRatio
,component
,color
,colorIndex
,monochrome
,scan
andtype
are unsupported on native.
Example
import React from "react";import View Text from "react-primitives";import MediaQuery from "react-native-web-responsive"; { return <View> <Text>Device Test!</Text> <MediaQuery => <Text>You are a desktop or laptop</Text> <MediaQuery => <Text>You also have a huge screen</Text> </MediaQuery> </MediaQuery> <MediaQuery => <Text>You are a tablet or mobile phone</Text> </MediaQuery> <MediaQuery ="portrait"> <Text>You are portrait</Text> </MediaQuery> <MediaQuery ="landscape"> <Text>You are landscape</Text> </MediaQuery> <MediaQuery => <Text>You are retina</Text> </MediaQuery> </View> ;}