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

react-native-worry-free-style-sheet

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

react-native-worry-free-style-sheet

省心的React-Native StyleSheet工具方法

  • 1.0.0-rc.0
  • next
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

react-native-worry-free-style-sheet

一个省心的React-Native StyleSheet工具方法

使用

yarn add react-native-worry-free-style-sheet

import StyleSheet, { IgnoreValue } from 'react-native-worry-free-style-sheet';
const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  box1: {
    marginTop: 50,
    width: 375,
    height: new IgnoreValue(30),
    backgroundColor: 'red',
    borderWidth: 0.6,
    borderColor: 'red',
    borderRadius: 20,
    marginLeft: 10,
  },
  text: {
    fontSize: 15,
  },
});
注意
  • 如果需要忽略转换 使用 IgnoreValue 类
  • 如果需要设置屏幕宽度使用你设置的基准值 默认375
  • 转换结果小于一个像素的时候会返回一个像素(比如iPhone 11 width: 0.1)返回onePixel一个像素0.3333
自动转换设计稿尺寸 默认 375
  • 修改基准值
import StyleSheet from 'react-native-worry-free-style-sheet';
StyleSheet.setConfig({
    baseWidth: 750,
});
方法

包含默认StyleSheet的方法

方法/常量参数类型描述
scaleSizenumber屏幕适配, 缩放size , 默认根据宽度适配,纵向也可以使用此方法
setConfig{ baseWidth }修改配置
IgnoreValuenew IgnoreValue(100)忽略转换
isIphoneX判断是否为iphoneX
ifIphoneXiphoneXStyle,iosStyle,androidStyle根据是否是iPhoneX返回不同的样式
statusBarHeight状态栏高度
navigationBarHeight常规导航栏高度(包含状态栏)
navBarHeight状态栏加导航栏的高度
navBarUnlessStatusHeight导航栏高度(不包含状态栏)
getBottomSpace获取底部边距
onePixel常量1个像素
screenW常量屏幕宽度
screenH常量屏幕高度
isIOS常量是否 iOS
isAndroid常量是否 Android
支持转换的样式表
const transformKeys = {
    fontSize: true,
    width: true,
    height: true,
    start: true,
    end: true,
    top: true,
    left: true,
    right: true,
    bottom: true,
    minWidth: true,
    maxWidth: true,
    minHeight: true,
    maxHeight: true,
    margin: true,
    marginVertical: true,
    marginHorizontal: true,
    marginTop: true,
    marginBottom: true,
    marginLeft: true,
    marginRight: true,
    marginStart: true,
    marginEnd: true,
    padding: true,
    paddingVertical: true,
    paddingHorizontal: true,
    paddingTop: true,
    paddingBottom: true,
    paddingLeft: true,
    paddingRight: true,
    paddingStart: true,
    paddingEnd: true,
    lineHeight: true,
    borderRadius: true,
    borderWidth: true,
    borderTopWidth: true,
    borderStartWidth: true,
    borderEndWidth: true,
    borderRightWidth: true,
    borderBottomWidth: true,
    borderLeftWidth: true,
    borderBottomEndRadius: true,
    borderBottomLeftRadius: true,
    borderBottomRightRadius: true,
    borderBottomStartRadius: true,
    borderTopEndRadius: true,
    borderTopLeftRadius: true,
    borderTopRightRadius: true,
    borderTopStartRadius: true,
};
待办
  • 新增Colors常量
  • 新增公共样式配置文件
  • 新增中间件 方便自定义处理scaleSize转换方法
  • 优化文档

Keywords

FAQs

Package last updated on 02 Apr 2021

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