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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-native-normalization-text

v0.1.3

Published

react-native 字体大小、样式规范化管理,自适应缩放组件。

Readme

react-native-normalization-text

react-native 字体大小、样式规范化管理,自适应缩放组件。

功能介绍

字体缩放

根据不同设备屏幕尺寸调整字体大小,可自定义缩放规则。

未适配:

图片

适配:

图片

字体管理

一次配置(或者使用默认配置),不在app中到处书写字体样式,也促进UI设计输出规范的字体。

安装

npm install react-native-normaliztion-text --save

或者使用yarn

yarn add react-native-normaliztion-text 

使用

import {Text, H1, H2} from 'react-native-normalization-text';  
...

// jsx
<Text>不带自定义样式的Text<Text>
<H1>带h1预设样式、props的Text<H1>

// 接受RN中Text的属性和配置中映射的size、color属性
<H2 size="large" color="danger" style={{...}}>带h2预设样式、props的Text<H2>

Text除了rn提供的属性,新添以下属性:

| props | type | 描述 | | --- | --- | --- | | scalableItems | Array<string> | 参与缩放的属性。例:['fontSize', 'paddingLeft'] | | size | Number | 字体大小。默认配置或者自定义配置中sizes的key | | color | Number | String | 字体颜色。默认配置或者自定义配置中colors的key | | darkness | Number | String | 颜色亮加深/减弱。支持数字或者百分比。例:加深100亮度值:darkness={100} 减少10%亮度值: darkness="-10%" |

更多配置

默认配置:

| 配置项 | type | 描述 | 默认值 | | --- | --- | --- | --- | | scale | Function | 字体缩放方法 | 见defaultConfig.scale | | scalableItems | Array<string> | 参与缩放的属性 | ['fontSize', 'lightHeight'] | | sizes | Object | 罗列所有字号,sizes[key]的key映射为Text的fontSize样式。例:配置了sizes: {big: 36},则可使用<Text size="big" /> | 见defaultConfig.sizes | | colors | Object | 罗列所有字体颜色,类似sizes,colors[key]的key映射为Text的color样式。例:配置了colors: {danger: 'red'},则可使用 <Text color="danger" /> | 见defaultConfig.colors | | categories | Object | 分级字体。比如在categories中预设H1,则可以使用<Text.H1 /> | 见defaultConfig.categories |

默认sizes规范:

| name | value | | --- | --- | | huge | 36 | | xxxLarger | 24 | | xxLarger | 20 | | xLarger | 18 | | lager | 16 | | normal | 14 | | small | 12 | | tiny | 10 |

默认colors规范:

| name | value | | --- | --- | | title | rgba(0,0,0,0.85) | | primary | rgba(0,0,0,0.65) | | secondary | rgba(0,0,0,0.45) | | disabled | rgba(0,0,0,0.25) | | border | rgba(0,0,0,0.15) | | dividers | rgba(0,0,0,0.09) | | white | rgb(255,255,255) | | grey1 | rgba(255,255,255,0.85) | | grey2 | rgba(255,255,255,0.65) | | grey3 | rgba(255,255,255,0.45) | | grey4 | rgba(255,255,255,0.25) | | grey5 | rgba(255,255,255,0.15) | | grey6 | rgba(255,255,255,0.09) | | success | #52c41a | | warning | #faad14 | | error | #ff190c |

默认可用字体:

  • H1
  • H2
  • H3
  • H4
  • PrimaryText
  • SmallText
  • TinyText

自定义配置:

  1. 在项目根目录执行初始化脚本,或者在根目录手动新建新建 text.config.js
  2. 根据自身需求配置需要调整的配置项,可以只修改你需要修改的配置项,其余的默认配置项仍会起作用。
  3. 在项目根目录下执行 更新脚本让自定义配置生效,或者使用重置脚本恢复默认配置。

脚本

| script | 描述 | | --- | --- | | node node_modules/react-native-norma/scripts/makeConfig.js --init | 初始化配置文件 | | node node_modules/react-native-norma/scripts/makeConfig.js --update | 读取自定义脚本 | | node node_modules/react-native-norma/scripts/makeConfig.js --reset | 重置成默认脚本 |

可以将脚本添加至package.json的script字段中,方便调用。

样式优先级:

jsx中style样式 > jsx中color、size属性映射样式 > config.categories.h1.style

属性配置优先级(scalableItems):

jsx中scalableItems > config.categories.h1.props.scalableItems > config.scalableItems

配置文件引用依赖:

配置文件支持引用项目中的依赖,支持 require('..') 和 import res from '..'两种形式,比如在需要引用项目中的样式:

// text.config.js
import colors from '../../Theme/colors';
import scale from '../../Theme/fontScale';

module.exports = {
    scale
    colors: {
        primary: colors.primary,
        success: colors.success,
        error: colors.error
    }
};

颜色支持:

React Native支持的颜色格式