当前位置: 首页 > 软件库 > 手机/移动开发 > >

react-native-typography

授权协议 MIT License
开发语言 Java
所属分类 手机/移动开发
软件类型 开源软件
地区 不详
投 递 者 赵征
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

React Native typography

Pixel–perfect, native–looking typographic styles for React Native.

React Native Typography Human ShowcaseReact Native Typography Material Showcase

Why

Creating great Text Styles in React Nativeis not a simple task,it requires a lot of fiddling and handling edge cases.

This library provides a good set of defaults and helpers that cover the majorityof the cases you'll need, make your code much simpler and bonus rendergreat on iOS, Android and the web ��

Quick start

Add the dependency:

yarn add react-native-typography

Set a style in your component:

import { material } from 'react-native-typography'

<Text style={material.display1}>Hello Typography!</Text>

And it will look like this:

Material Design Collection

Example app

Typography collections

We provide a series of predefined collections for you to start with that matchthe native design systems for iOS and Android.

You can use them directly wherever you would supply atextStyle.

There's also the option of extending them to createyour own styles.

Material Design

Includes all the styles defined in theMaterial Design Guidelines.Defines size, weight and color.

import { material } from 'react-native-typography'

<Text style={material.display4}>Hello Material!</Text>

Material Design Collection

Human Interface Guidelines

Defined in theHuman Interface Guidelines.Defines size, weight and color.

import { human } from 'react-native-typography'

<Text style={human.largeTitle}>Hello Human!</Text>

Human Interface Collection

iOSUIKit

Extracted fromthe official Apple sketch file

These are the text styles that fall under the category of iOS UIKit, and areused to build the UI components of iOS Apps.

They build on top of the Human Interface styles, customizing some propertiessuch as weight or letter spacing.

import { iOSUIKit } from 'react-native-typography'

<Text style={iOSUIKit.largeTitleEmphasized}>Hello iOS UI Kit!</Text>

iOSUIKit Collection

Customization & Helpers

The collections provide every style in 2 different ways:

  • As a StyleSheet, e.g.: material.title
  • As a plain object, e.g.: material.titleObject

The basic way to use them is to set the StyleSheet directly where you wouldsupply atextStyle:

<Text style={material.title}>Title</Text>

To extend the styles, you can spread the object inside your own StyleSheetand override some of its attributes:

const styles = StyleSheet.create({
  yellowTitle: {
    ...material.titleObject,
    color: iOSColors.yellow,
  },
});

<Text style={styles.yellowTitle}>Title</Text>

Another option would be to combine the provided StyleSheet with your ownStyleSheet.

const styles = StyleSheet.create({
  yellow: {
    color: iOSColors.yellow,
  },
});

<Text style={[material.title, styles.yellow]}>Title</Text>

Weights

A font weight in React Native is sometimes formed by a pair of a fontFamily anda fontWeight, but not always! It depends on the typeface, sometimes it's justdefined by the fontFamily.

With these helpers, you don't have to worry about those inconsistencies.

To combine them with a collection style (or your own styles) just spread them,as they are plain objects.

const styles = StyleSheet.create({
  lightTitle: {
    ...material.titleObject,
    ...systemWeights.light,
  },
});

<Text style={styles.lightTitle}>Title</Text>

System Weights

import { systemWeights } from 'react-native-typography'

The System weights render visually similar weights of the Nativetypefaces on each platform.Read more about cross-platform here.

This is the recommended way of customizing your weights unless you really needdifferent visual styles for each platform.

They follow the San Francisco naming convention, as it has more steps, whichmakes it more future–proof.

System Weights iOS

System Weights Android

System Weights Web

San Francisco Weights

import { sanFranciscoWeights } from 'react-native-typography'

These weights are only intended for iOS, as they directly reference thenative San Francisco typeface.

San Francisco Weights

Roboto Weights

import { robotoWeights } from 'react-native-typography'

These weights are only intended for Android, as they directly reference thenative Roboto typeface.

Roboto Weights

Web Weights

import { webWeights } from 'react-native-typography'

These weights are only intended for the web, and render react-native-web's system font stack.

Web Weights

Colors

We also include the default text color hex values for each platform.

iOS

import { iOSColors } from 'react-native-typography'

Colors iOS

const styles = StyleSheet.create({
  yellowTitle: {
    ...human.title3Object,
    color: iOSColors.yellow,
  },
});

<Text style={styles.yellowTitle}>Title</Text>

Material

import { materialColors } from 'react-native-typography'

Colors Material

const styles = StyleSheet.create({
  tertiaryTitle: {
    ...material.titleObject,
    color: materialColors.blackTertiary,
  },
});

<Text style={styles.tertiaryTitle}>Title</Text>

Spacing/Kerning

San Francisco

The San Francisco typeface defines its letter spacing via Kerning. Thisis not compatible with the React Native text style properties, as they takeletter-spacing instead.

To perform this conversion on iOS you can use the sanFranciscoSpacing function, whichreceives the font size and returns the appropriate letter spacing.

This is not needed for the web as the browsers already take care of this.

import { sanFranciscoSpacing } from 'react-native-typography'

const styles = StyleSheet.create({
  customSize: {
    ..., // some other props
    fontSize: 34,
    letterSpacing: sanFranciscoSpacing(34),
  },
});

This is already taken care of on the collections, but if you want to define yourown sizes you can adjust the spacing on iOS with this helper.

Dense and tall scripts

Dense and tall scripts are fully supported, check the full documentation here!

import { materialDense } from 'react-native-typography'

<Text style={materialDense.display4}>你好排版!</Text>

Material Design Collection

Cross-platform

Quotingthe Material Design Platform recommendations

The default typeface on iOS is San Francisco. Using this typeface is theeasiest way to implement accessibility features like Dynamic Type. Using othertypefaces may require making adjustments to get the same accessibilityfeatures.

This is the approach that we like to follow, and all the collections exportedfrom this library render nicely on all the supported platforms with their respective nativetypefaces, for that we use the System weight helper.

You can check the code of the example app where we included acouple of screens that follow this philosophy, this is how they render on iOS and Android:

React Native Typography Human Showcase on iOSReact Native Typography Human Showcase on Android

React Native Typography Human Showcase on iOSReact Native Typography Material Showcase on Android

F.A.Q.

But I don't wanna use the Material Design or Human Interface Guidelines! Is there any reason why I should use this library?

Absolutely! The helpers are very convenient to build your own text styles asthey work aroundthe quirks of working with text styles on React Native,even if you want to specify your own sizes and weights,check them out!

Kerning is not 100% accurate on the Display sizes for the Material styles on Android

There's no support for letter spacing on React Native Android yet. ☹️

Where is Roboto Black?

It's not available by default on React Native Android yet. ��

Why are there less weights available for CJK(Chinese, Japanese, Korean) languages on Android than iOS?

Android uses Noto Sans CJK (also known as Source Han Sans) to render thoselanguages, andeven though it has seven weights,they're not shipped with Android. ��

There are some issues tracking this already, hopefully they will be included inthe future.

I use styled-components/glamorous/etc. Can I use react-native-typography?

Of course! There are some examples in the provided app,check the code!

Why is this library exporting StyleSheets and objects instead of components?

The idea behind it is that textStyles are the universally accepted way ofstyling text and this makes integrationwith many librarieseasier.

The StyleSheet/Object pattern isalready being usedin the React Native codebase to provide an easy way to extend exportedStyleSheets.

If you enjoy using pre-styled components for your text, you can easilydefine them and just supply the desired styles from this library! ��

Versioning

We use SemVer for versioning. For the versions available,see thetags in this repository.

Authors

See also the list ofcontributorswho participated in this project.

License

This project is licensed under the MIT License.

Acknowledgments

Pictures for the demo app by:

References

  • 随着React的日益流行和原生移动应用开发(和PWA)的崛起,React Native的采用率也在增长。与React类似,React Native也是使用独立的组件来构建UI。使用预先构建好的组件、组件库和UI工具包有助于我们更快地构建应用程序。在查看了大量有用的React和Vue组件库之后,根据大众的需求,列出了一个有用的React-Native UI库列表,可以帮助你更好地入门React Na

  • 移动跨平台框架React Native经过4年的发展,其生态已经变得异常丰富,在使用React Native开发项目的过程中,为了提高开发效率,我们经常会借鉴一些使用使用率比较高的开源库,根据大众的需求,对这些使用较高的 React-Native UI 库,我们做一个简单的总结和归类,方便大家更好地入门 React Native。 本文只是收集了一些常见的UI库和功能库,除了上面介绍的知名第三方库

 相关资料
  • 本文向大家介绍react-native 启动React Native Packager,包括了react-native 启动React Native Packager的使用技巧和注意事项,需要的朋友参考一下 示例 在最新版本的React Native上,无需运行打包程序。它将自动运行。 默认情况下,这将在端口8081上启动服务器。要指定服务器所在的端口            

  • 百度移动统计SDK支持使用react native框架的H5页面统计,封装好的插件已经在github上开源,相关用法具体请参考:https://github.com/BaiduMobileAnalysis/baidumobstat-react-native。

  • The React Native environment has a lot of little quirks, so this documentation is aimed at helping smooth those over. Please feel free to create issues on GitHub for recommendations and additions to t

  • React Native 可以基于目前大热的开源JavaScript库React.js来开发iOS和Android原生App。而且React Native已经用于生产环境——Facebook Groups iOS 应用就是基于它开发的。 React Native的原理是在JavaScript中用React抽象操作系统原生的UI组件,代替DOM元素来渲染,比如以<View>取代<div>,以<Ima

  • 本文向大家介绍react-native setState,包括了react-native setState的使用技巧和注意事项,需要的朋友参考一下 示例 要在应用程序中更改视图,可以使用setState-这将重新渲染您的组件及其任何子组件。setState在新状态和先前状态之间执行浅表合并,并触发组件的重新呈现。 setState 接受键值对象或返回键值对象的函数 键值对象 功能 使用函数对于基于

  • 诸葛io移动统计支持React Native插件,以下为集成方法。 1. 环境准备 1.1. iOS环境 iOS 8.0+ 代码支持iOS8.0的系统 pod 1.0+ iOS系统的集成依赖于cocoaPod工具 1.2. Android环境 Android SDK 16+ 代码支持Android 16+ 1.3. React Native环境 react-native 0.50+ react-n