• Stars
    star
    265
  • Rank 153,872 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

React Native Text scales the font size based on a device width

React Native Text

About

React Native Text scales the font size based on a device width.

This is the comparison of two screens (iPhone 4s and iPhone 6s Plus), with applied style:

welcome: {
  fontSize: 31,
  textAlign: 'center',
  margin: 10,
},
instructions: {
  fontSize: 16,
  textAlign: 'center',
  color: '#333333',
  marginBottom: 5,
}

You can also check out the example usage on Snack: https://snack.expo.io/@knowbody/react-native-text-example

With react-native-text

with

Without (using <Text /> from React Native Core)

without

Get Started

  1. yarn add react-native-text
  2. Example usage:
import React, { PropTypes } from 'react';
import { StyleSheet } from 'react-native';
import ScalableText from 'react-native-text';

const WelcomeText = ({ text }) => <ScalableText style={styles.text}>{text}</ScalableText>;

const styles = StyleSheet.create({
  text: {
    color: 'tomato',
    fontSize: 28,
  },
});

export default WelcomeText;

Cool! Can I get the same effect outside a <Text /> element?

Yes, you can! The scaleText function is a named export. Invoke it with the following signature:

import { scaleText } from 'react-native-text';

const style = scaleText({
  deviceBaseWidth: 375,
  fontSize: 14,
  lineHeight: 14 * 1.2,
}); // returns: { fontSize, lineHeight }

Or with a React Hook useScaleText:

import { useScaleText } from 'react-native-text';

const { fontSize, lineHeight } = useScaleText({ fontSize: 18 });

LICENSE

MIT

More Repositories

1

redux-react-router-example-app

Example blog like application
JavaScript
386
star
2

crra

Create Reason React App
379
star
3

react-native-online-meetups

Help make this amazing, add any suggestions in the GH issues
197
star
4

react-native-platform-stylesheet

React Native Platform Specific Stylesheet
JavaScript
89
star
5

react-redux-boilerplate

React Redux Boilerplate
JavaScript
85
star
6

react-router-docs

Rewrite of the React Router docs - work in progress
JavaScript
55
star
7

ParisHilton.js

ParisHilton.js - removes everything between the <head></head> tags
CSS
19
star
8

react-boilerplate

Boilerplate for React app
JavaScript
18
star
9

ReasonReactNativeApp

Objective-C
17
star
10

thinking-in-reason-react

"Thinking in React" in Reason React
OCaml
10
star
11

markdown-collaboration

Markdown Collaboration Tool
JavaScript
8
star
12

react-native-release-notes

Script to generate a draft of release notes for React Native
JavaScript
6
star
13

node-settings

Simple way of storing your app's settings (e.g. for development or production)
JavaScript
6
star
14

HNdump

Dump of HN historical data
5
star
15

whenkarma

Exploring R language, when to post on hacker news to get noticed
Python
4
star
16

reason-native

The future of Reason Native
4
star
17

redux-immutable-example

copy of the original counter example from redux with us of Immutable.js
JavaScript
3
star
18

react-router-sitemap

A sitemap generator
2
star
19

awesome-ecmascript

Curated list of resources on ES6 and ES7
1
star
20

react-router-playground

just playing with react router
JavaScript
1
star
21

ArgyleTest

Java
1
star
22

Team6

hackathon JPM
1
star
23

rr2

JavaScript
1
star
24

books-to-read

My 2016 reading challenge
1
star
25

vagrant_rails

work in progress...
Shell
1
star
26

PythonBasics

Some basic exercises using Python - exercises from "Learn Python Hard Way"
Python
1
star