1.5.0 • Published 5 years ago

@monajs/rn-px2dp v1.5.0

Weekly downloads
11
License
ISC
Repository
github
Last release
5 years ago

rn 项目屏幕适配解决方案

✨✨ 解决在不同屏幕尺寸下页面展示效果不统一的布局问题

安装

$ npm i --save @monajs/rn-px2dp

demo1

import px2dp from '@monajs/rn-px2dp'

const styles = StyleSheet.create(px2dp({
	container: {
        flex: 1,
        fontSize: 20,
        margin: 10,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
    },
	welcome: {
		fontSize: 20,
		textAlign: 'center',
		margin: 10
	},
}, {
	uiWidthPx: 375,
	props: ['borderWidth']
}))

demo2

import Px2dp from '@monajs/rn-px2dp'

<Text style={{fontSize: px2dp._px2dp(20, 375)}}>@monajs/rn-px2dp</Text>

demo3

import px2dp from '@monajs/rn-px2dp'

const styles = StyleSheet.create(px2dp({
	container: {
        flex: 1,
        fontSize: px2dp._not(20),
        margin: 10,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#F5FCFF',
    })

API

px2dp(styles, config)

参数类型默认值描述
stylesObject转换前的样式对象
configObject非必传
config.uiWidthPxNumber750设计稿总宽度
config.propsArray需要自定义转换的样式属性

props: 默认会转换以下的样式属性,可以通过设置props来进行赋能

const _propList = [
	'width', 'height',
    'top', 'right', 'bottom', 'left',
    'margin', 'marginTop', 'marginRight', 'marginBottom', 'marginLeft', 'marginVertical', 'marginHorizontal',
    'padding', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'paddingVertical', 'paddingHorizontal',
    'borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius',
    'shadowRadius',
    'fontSize'
]

px2dp._px2dp(uiElementPx, uiWidthPx)

描述: 对单个样式进行转换

参数类型默认值描述
uiElementPxNumber设计稿元素宽度
uiWidthPxNumber750设计稿总宽度

px2dp._not(uiElementPx)

描述: 对单个样式进行保护

参数类型默认值描述
uiElementPxNumber设计稿元素宽度

联系我

微信:yx12032331

参考文章

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago