Provide solutions to make your app flexible for different screen sizes, different devices.

Overview

react-native-size-scaling

Provide solutions to make your app flexible for different screen sizes, different devices, based on your device's pixel ratio. When developing with react-native, you need to manually adjust your app to look great on a variety of different screen sizes. This package provides some simple tooling to make your scaling a whole lot easier.

Installation

npm install react-native-size-scaling

or

yarn add react-native-size-scaling

Jest setup

  jest.mock('react-native-size-scaling', () => {
      const sizeScaling = require('react-native-size-scaling/mock');
      return sizeScaling;
  });

Demo

Before After

Documents

API Type Description
StyleSheet StyleSheet Will take the same stylesObject a regular StyleSheet will take, plus a special (optional) annotation that will automatically apply the scale functions for you
scale Function Will return a linear scaled result of the provided size
isAndroid Boolean Tells if the device is Android operating system
isIOS Boolean Tells if the device is IOS operating system
isTablet Boolean Tells if the device is a tablet
width Number Screen width
height Number Screen height

API

scale(size: number)

Will return a linear scaled result of the provided size, based on your device's pixel ratio.

import { scale } from 'react-native-size-scaling';

export default function App() {
  return (
    <View style={styles.container}>
      <Text style={styles.text}>Hello word {scale(30)}</Text>
    </View>
  );
}

StyleSheet

Will take the same stylesObject a regular StyleSheet will take, plus a special (optional) annotation that will automatically apply the scale functions for you.

import * as React from 'react';

import { View, Text } from 'react-native';
import { StyleSheet } from 'react-native-size-scaling';

export default function App() {
  return (
    <View style={styles.container}>
      <Text style={styles.text}>Hello word</Text>
      <View style={styles.box}>
      <Text style={styles.text}>Device: IPhone 13</Text>
        <Text style={styles.text}>Before: 300x300</Text>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  text: {
    fontSize: 22,
  },
  box: {
    width: 300,
    height: 300,
    marginVertical: 20,
    backgroundColor: 'gray',
    justifyContent: 'center',
    alignItems: 'center',
  },
});

Donate

Support maintainers with a donation and help them continue with activities. Buy me a coffee and you can request quick processing of issues.


fateh999




You might also like...

A weather app done with React. Allows you to make a search for the current weather by simply typing "common knowledge" cities and save them to favourites on local storage.

A weather app done with React. Allows you to make a search for the current weather by simply typing

Simpliest Weather React-App A weather app done with React. Allows you to make a search for the current weather by simply typing "common knowledge" cit

Aug 24, 2022

Math Magicians! This is a website for all fans of mathematics. It is a Single Page App (SPA) that allows users to make basic calculations and read a random math-related quote.

Math Magicians! This is a website for all fans of mathematics. It is a Single Page App (SPA) that allows users to make basic calculations and read a random math-related quote.

Math Magicians Math Magicians is the first React Project I'm building. The main objective of this is to understand React features with a project-based

Feb 26, 2022

A Single Page App (SPA) that allows users to: make simple calculations and read a random math-related quote

A Single Page App (SPA) that allows users to: make simple calculations and read a random math-related quote

Math magicians is a website for all fans of mathematics. It is a Single Page App (SPA) that allows users to: make simple calculations and read a random math-related quote.

May 31, 2022

Math magicians is a website for all fans of mathematics. It is a Single Page App (SPA) that allows users to: Make simple calculations. Read a random math-related quote.

Math magicians is a website for all fans of mathematics. It is a Single Page App (SPA) that allows users to:      Make simple calculations.     Read a random math-related quote.

Math Magicians Math magicians is a website for all fans of mathematics. It is a Single Page App (SPA) that allows users to: Make simple calculations.

Mar 23, 2022

An awesome tool to make Images and GIFs of your code!

An awesome tool to make Images and GIFs of your code!

Recoded An awesome tool to make Images and GIFs of your code! View Demo · Report Bug · Request Feature About The Project There are plenty of Apps like

Dec 18, 2022

Concircle scanner mobile app is application That helps you scan your order and position and to know if there are exact or not. it's cross-platform app.

Concircle scanner mobile app is application That helps you scan your order and position and to know if there are exact or not. it's cross-platform app.

Concircle scanner mobile app ⭐ Star on GitHub — it motivates Me a lot! Concircle scanner mobile app is application That helps you scan your order and

May 7, 2022

A web application which has leetcode questions listed on the basis of different companies.

URL A web application which has leetcode questions listed on the basis of different companies. This project was made using React.js and Flask to help

May 24, 2022

A web application to search all the different countries in the world and get details about them which can include languages, currencies, population, domain e.t.c This application is built with CSS, React, Redux-Toolkit and React-Router.

A web application to search all the different countries in the world and get details about them which can include languages, currencies, population, domain e.t.c This application is built with CSS, React, Redux-Toolkit and React-Router.

A web application to search all the different countries in the world and get details about them which can include languages, currencies, population, domain e.t.c This application is built with CSS, React, Redux-Toolkit and React-Router. It also includes a theme switcher from light to dark mode.

Jun 5, 2022

Common recipes to productively use Nx with various technologies and in different setups. Made with ❤️ by the Nx Team

Nx Recipes Welcome to Nx Recipes! Here you'll find various examples to use Nx to achieve a particular goal. Contributing Absolutely!! We're going to h

Dec 24, 2022
Comments
  • In svg element

    In svg element "d" height and circleWidth gets wrong value because of "scale()" function

    Screen Shot 2022-09-22 at 17 45 40

    const height = scale(iHeight); const circleWidth = scale(centerWidth) + scale(16);

    "scale()" function works fine for bigger screen but in my example I use iPhone 8 emulator and there is a space bottom of SVG element. Maybe issue related to your repo (react-native-curved-bottom-bar) however problem in function. Would you check it please ?

    opened by ae-loggma 3
Releases(v0.5.1)
Owner
Hoà Phan
Hoà Phan
Web application that consumes an API to provide an complete experience of an recipes app

Project: Recipes App Project developed studying in Trybe. Technologies and tools used React React Hooks Context API SCRUM / Kanban Project objective T

Ádran Farias Carnavale 0 Jun 14, 2022
null 136 Dec 30, 2022
Expo Demo: Screen Capture with Managed Workflow

Expo Demo: Screen Capture with Managed Workflow This code demonstrates how to setup screen capture on an Expo app, without having to eject from the ma

Luis Taniça 12 Dec 30, 2022
A simplified Telegraf plugin to provide users with a great interface.

telegraf-pagination A simplified Telegraf plugin to provide users with a great interface. Getting started Prerequisites You need to have telegraf inst

Alisher Ortiqov 8 Nov 21, 2022
As a user, I want to be able to post about travel locations and provide comments and ratings. As a user, I want to be able to look at other users posts and search travel locations by rating.

Travel-bug https://travelbug-project.herokuapp.com/ Table of Contents User-Story Description Installation Usage Contributions Tests License Questions

Megan 3 Mar 2, 2022
A declarative, efficient, and flexible JavaScript library for building user interfaces.

React · React is a JavaScript library for building user interfaces. Declarative: React makes it painless to create interactive UIs. Design simple view

Facebook 200.2k Jan 8, 2023
🌊 A flexible and fun JavaScript file upload library

A JavaScript library that can upload anything you throw at it, optimizes images for faster uploads, and offers a great, accessible, silky smooth user

pqina 13.1k Dec 31, 2022
🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.

downshift ?? Primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components. Read the docs | See

Downshift 11.1k Dec 28, 2022
A very lightweight and flexible accessible modal dialog script.

A11y Dialog This is a lightweight (1.3Kb) yet flexible script to create accessible dialog windows. Documentation ↗ Demo on CodeSandbox ↗ Features: Clo

Kitty Giraudel 2.1k Jan 2, 2023
Edvora App is a web application based on an external API, showing data about different types of products and the user can filter these data by choosing a specific state, city or product name. Build with React.js

Edvora App is a web application based on an external API, showing data about different types of products and the user can filter these data by choosing a specific state, city or product name. Build with React.js

Kyrillos Hany 5 Mar 11, 2022