🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

mrn-pxtrans

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mrn-pxtrans

将 750 设计稿的尺寸,自动转成实际像素,(开发时,可直接按 750 尺寸写样式)

latest
Source
npmnpm
Version
0.0.13
Version published
Weekly downloads
7
16.67%
Maintainers
1
Weekly downloads
 
Created
Source

解决什么痛点:

痛点:我们在编写 RN 引用时,通常会使用 750 设计稿;而 RN 默认单位是 px,因此我们需要频繁的转换

本工具的目的即解决设计稿转换问题

开始使用

已支持 Typescript

create 方法将实现自动转换 (无需额外配置)

初始化之后,任意 create 里的尺寸数据,自动按照 750 设计稿算

使用 rn-pxtrans 里的 create 替代原有的 StyleSheet.create

内联样式需手动加入

非 create 创建的样式,比如直接在 jsx 直接写的 style,还是需要转换

import { styleTrans } from 'rn-pxtrans'

const Home = () => <View style={styleTrans({ height: 100, width: 100 })}>...</View> 

在内联样式中,也可以只对某个值进行转化,如

import { pxTrans } from 'rn-pxtrans'

const Home = () => <View style={{ height: pxTrans(100), width: 100 }}>...</View> 

如何排除不转换的尺寸

在有些时候,整体需要转换,但个别的属性我们希望使用原始的 px,此时,只需用 noTrans 包裹个别的尺寸即可

import { noTrans, create } from 'rn-pxtrans'
create({
  height: 100,
  width: 100,
  borderRadius: noTrans(2) // 依旧保留 2px
})

同样,在内联里,类似使用

import { styleTrans, noTrans } from 'rn-pxtrans'

const Home = () => (
  <View style={styleTrans({ height: 100, width: 100, borderRadius: noTrans(2) })}>...</View>
)

FAQs

Package last updated on 04 Sep 2019

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