npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-styled-px2dp

v1.1.5

Published

Write CSS px in react-native using styled-components and adapt multi resolution screens automatically.

Downloads

25

Readme

react-native-styled-px2dp 🎩

Write CSS px in react-native using styled-components and adapt multi resolution screens automatically.

How to use

1. install

yarn add react-native-styled-px2dp

or

npm i react-native-styled-px2dp --save

note: react-native and styled-components are required peer dependencies.

2. configure your styled

Setup a styled according to your visual design.

Say we have an iphone6 visual design which is 750x1334, then:

// my-styled.js
import getFlexibleStyled from 'react-native-styled-px2dp';

export const { styled } = getFlexibleStyled({
  designWidth: 750
})

3. use your configured styled

Now you can write css px values exactly what your visual design tells you ;)

The library will translate px into dp according to the design width of your visual design.

import { styled } from 'path-to-your/my-styled'
export const Logo = styled.Image`
  position: absolute;
  width: 413px;
  height: 175px;
  top: 50px;
  left: 50px;
  margin-left: -206px;
`

Further Usage

Get px2dp caculator in javascript

Sometimes you might want to caculate style programmatically, you can get the caculator directly from getFlexibleStyled

export const { styled, px2dp} = getFlexibleStyled({
  designWidth: 750
})

and then you can use it in your code like:

<View style={{width: parseInt(px2dp(1368))}}></View>

Deal with orientation

In some complex applications, you might need to deal with device orientation and re-render your application in a width-height-switched resolution, but don't worry, react-native-styled-px2dp will cover your back.

First, you need to specify both width and height of your visual design, and the original orientation.

export const {styled, updateOrientation} = getFlexibleStyled({
  designWidth: 1920,
  designHeight: 1080,
  orientation: 'landscape' // 'landscape' or 'portrait'
})

Second, call updateOrientation when the orientation changes, the library will change its inside logic for the changed orientation (like switch the value of designWidth and designHeight).

() => { // some orientation change callback
  updateOrientation('portrait')  // 'landscape' or 'portrait'
}

**Note: ** You should always call updateOrientation before you render components in your target orientation. In some cases you might need to add some delay before render using setTimeout.

links:

How it works?

to be continued.

Inspirations

inspired by: