Socket
Socket
Sign inDemoInstall

@dev-vortex/react-native-responsive-styles

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @dev-vortex/react-native-responsive-styles

React Native responsive styling


Version published
Weekly downloads
7
Maintainers
1
Created
Weekly downloads
 

Readme

Source

react-native-responsive-styles

A React-Native utility created to allow correct size attribution to elements on your apps UI across different sized devices.

Instalation

yarn add @dev-vortex/react-native-responsive-styles

or

npm install --save @dev-vortex/react-native-responsive-styles

Motivation

When developing with react-native, we constantly need to manually adjust styles to look great on a variety of different screen sizes.

The idea was to allow a "replacement" or improvement to react styling by allowing a "chain" that will "understand" the provided styling, calculate the values and return the styles from react native style.

ResponsiveSheets

import { StyleSheet, PixelRatio } from 'react-native'
import ResponsiveStyles, { getDpPtCorrection } from '@dev-vortex/react-native-responsive-styles'

const dpPtCorrectionPlugin = getDpPtCorrection(PixelRatio.get(), PixelRatio.getFontScale())

const pluginsChain = [
    dpPtCorrectionPlugin, 
    StyleSheet.create
]

const styles = ResponsiveStyles.create({
    container: {
        height: '80@dp',
    },
    titleText: {
        fontSize: '20@pt',
    },
    descriptionText: {
        fontSize: '14@pt',
    },
}, pluginsChain)

...

ResponsiveSheets will take the same stylesObject a regular StyleSheet will take. It is also possible to use annotations that will automatically apply the formulas to provide the expected result:

  • <size>@dp - will convert the Density-independent Pixels to device real pixels (based on density).
  • <size>@pt - will convert the points into correct font size.

Custom plugins

It is possible to create and add plugins to the chain (second argument in create)

The plugin signature is defined by the interface ConvertPluginFunction. And it should expect to receive the value of a style attribute and return the same value but with the conversion applied (or the same if nothing need to be converted).

Keywords

FAQs

Last updated on 21 Jul 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc