score:9
i don't know if react-native supports viewport units. but, there's a module:
https://www.npmjs.com/package/react-native-viewport-units
install
npm install react-native-viewport-units --save
usage
var {vw, vh, vmin, vmax} = require('react-native-viewport-units');
notice the required operator/syntax: x * vw
<view style={{height:50*vh, width:50*vw}}/>
var styles = stylesheet.create({
lookinggood: {
width: 15*vmin,
height: 10*vmax,
padding: 2*vw,
margin: 4*vh,
}
});
score:1
i've browsed through other answers, all that works and simple for new projects. if you desire to make an existing project responsive, i'd recommend using the below package.
https://www.npmjs.com/package/react-native-responsive-view-port
assume you've already built an app for 1280 x 800 and you wish to make it responsive for all resolutions, then you can achieve it as shown below.
before
<view style={{ width:500 }} ></view>
after
const { vw, vh } = createviewportconfig({ width : 1280, height : 800 });
<view style={{ width: 500*vw }} ></view>
i find this method easier than recalculating all sizes.
score:7
viewport units: vw, vh, vmin, vmax - react native.
https://github.com/joetakara/react-native-expo-viewport-units
install
npm install react-native-expo-viewport-units
or
yarn add react-native-expo-viewport-units
usage
import { vw, vh, vmin, vmax } from 'react-native-expo-viewport-units';
<view style={{ width: vw(100), height: vh(100) }}>
...
<view>
score:14
instead of veiwport you can use dimensions in react-native. pfb the link of react-native dimensions.
Source: stackoverflow.com
Related Query
- How to use vw and vh css with React Native
- How can you use CSS modules together with Typescript, React and Webpack?
- How to Create global styles with Styled components in react and next js and is it better to use combination of css files and styled component?
- How do I transpile React JSX and ES6 modules with babel and use browser native ES6
- How to import CSS modules with Typescript, React and Webpack
- How to use React with Typescript and SASS
- How to use forwardRef with FunctionComponent in React Native using TypeScript
- How to use React Native AsyncStorage with Redux?
- How to use Django User Groups and Permissions on a React Frontend with Django Rest Framework
- How do you use CSS grid layouts with React effectively?
- How to nest Scene and navigate with direction='vertical' in React Native Router Flux?
- How to use Jest with React and Webpack
- How to use srcset 2x with React and Webpack?
- How to use inheritance with React components and es6 classes
- How to setup sublime 3 with react native so that when you click on the error and it jump to your code?
- How to use emotion/styled with React and Typescript
- How to use setTimeout() along with React Hooks useEffect and setState?
- How to Use SVG with React and ReasonML?
- How to use Sass and CSS Modules with create-react-app?
- How to determine the order of css in my create react app build with webpack and customize-cra?
- How to use Mapbox GL with React and Redux?
- Is it possible to use MaterialUI with React and css modules and access the theme inside the css module file?
- How to use Material-UI with React and ASP.net MVC
- How do I use types defined by @types/redux-form in React component with Field and FieldArray?
- How to use foundation css with webpack and react?
- How to use token-based authentication with axios and react
- How to use and specify Generic Hooks in React with Typescript?
- How to use async/await with useEffect React hook, i tried a lot of examples and nothing is working
- how to use different IP address for development and production with react and axios
- how to use button as link in material-ui react with out underline and change color text?
More Query from same tag
- React sitemap.xml file in public directory is not showing after build
- How to deal with onChange in ReactQuill Editor?
- React-Router: Force reload in browser
- React doesn't prevent form submit in IE 11
- How to get Element using useRef in ReactJS
- How to update the Redux store after Apollo GraphQL query returns
- MUI: either `image` or `src` property must be specified
- React Function component setting state variable V/s using local variable
- Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead
- How to have a loading screen until all my components are mounted in React
- Changing colors of antdesign header
- My react-dates DateRangePicker is not working/rendering when clicked
- state undefined in file tree reducer
- how to make css stylesheet to work in reactjs if components are in seperate component folder
- Is there a way to debug react interactively
- Structure Mobx project like Redux
- Context and Provider not accessible via Modal
- jest fails on third party function called on jquery selector
- i cannot make button sort by json in react
- REACT ADMIN | TEXTINPUT CHANGE VALUE
- Routing doesn't work on packaged Electron app using ReactJS and reach-router
- Axio's request gets an empty response from Node.js
- React, Fetch API & Filtering data
- Nextjs API works in local environment but not in production environment
- Prop `aria-activedescendant` did not match. react-select
- Increment and decrement counter according to select or unselect tag
- Jest Globals receive 'is not a function' error, works fine without Globals
- React Router v4 NavLink active route
- Animation in react-dnd
- How do I copy collection documents in firebase cloud store?