Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-css-vh-vw

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-css-vh-vw

Ditto of CSS vh and vw for React Native.

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
179
decreased by-11.39%
Maintainers
1
Weekly downloads
 
Created
Source

react-native-css-vh-vw

A ditto of CSS vw and vh units - returns, in pixels, a percentage of the device's viewport width or height.

Install

npm install react-native-css-vh-vw

Dependencies

react-native-css-vh-vw itself has no dependencies, but it must be used within a React Native project. The only React Native API that it relies on is Dimensions, which has support all the way back to React Native's first release.

Usage

Simply pass a value between 1 and 1000 to vh() or vw() to style React Native components.
50% of your device's viewport height: vh(50).
33.3% of your device's viewport width: vw(33.3).
Examples
  • Using vh() and vw() to set dimensions of <View>: Component:
const VhVwDemo = (props) => {

  return (
    <View style={{
      height: vh(60),
      width: vw(50),
      backgroundColor: 'blue',
      justifyContent: 'center',
      alignItems: 'center'
    }}>
      <Text style={{ color: 'white' }}>height: vh(60)</Text>
      <Text style={{ color: 'white' }}>width: vh(50)</Text>
    </View>
  );
}

export default VhVwDemo;

Output:
vh() and vw() <View> example

  • Using vh() and vw() to set dimensions of <Text>:
const VhVwDemo = (props) => {

  return (
    <View style={{ justifyContent: 'center', alignItems: 'center' }}>
      <Text style={{ fontSize: vw(10) }}>fontSize: vw(10)</Text>
      <Text style={{ fontSize: vh(5) }}>fontSize: vh(5)</Text>
    </View>
  );
}

export default VhVwDemo;

Output:
vh() and vw() <Text> example

Keywords

FAQs

Package last updated on 28 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc