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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-scalesheet

v1.0.2

Published

A StyleSheet wrapper for react-native which helps actively scale items for similar display on multiple resolutions. Develop on one resolution without having to worry about the other 4 million android devices out there.

Downloads

11

Readme

react-native-scalesheet

react-native-scalesheet is a utility module designed to be a drop-in replacement for ScaleSheet.create which aids in scaling components to maintain the same design across devices with varying resolutions. There are a few added features which you can make use of which you can read about in Advanced Usage.

Questions & Bug Reporting

If you happen to find any bugs or you have any questions, please feel free to create an issue and I will get back to you as soon as possible. Please make sure to use the search function first to see if anyone else has reported the issue or asked the same question in the past. I will mark all questions with the question tag, so you can search efficiently. There is also a list of common questions.

Installation Instructions

$ npm install --save react-native-scalesheet

Example usage

In order to use react-native-scalesheet you must import it in the JavaScript file that you wish to use it, to import react-native-scalesheet you simple do the following:

import ScaleSheet from 'react-native-scalesheet';

To create a ScaleSheet you use the ScaleSheet.create function, which looks like this:

import ScaleSheet from 'react-native-scalesheet';

const styles = ScaleSheet.create({
    container: {
        flex: 1,
        backgroundColor: 'black'
    }
});

How this would look in a React Component:

import React from 'react';
import { View, Text } from 'react-native';

export default class ScalesheetExample extends React.Component {
    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.label}>Hello ScaleSheet!</Text>
            </View>
        );
    }
}

const styles = ScaleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center'
    },
    label: {
        fontWeight: '600',
        fontSize: 18,
        color: 'blue'
    }
});

Advanced Usage

There are a few features that are added to the ScaleSheet object that helps with some styling, that is the addition of screen width/height injection as well as the option to pass an object instead of a normal style in order to ignore the scaling process.

Viewport values

Numeric values can be replaced with a string representation of the percentage of the screen's width or height that you would like to use, this can be done by adding + 'vh' for the height of the screen and + 'vw' for the width of the screen. The width and height variables are interchangeable, some examples can be found below.

const styles = ScaleSheet.create({
    container: {
        // 82.5% of the devices width, can also be written as '82.5vw'
        width: 82.5 + 'vw',

        // 57% of the devices height, can also be written as 57vh
        height: 57 + 'vh',  

        // 20% of the devices height
        marginRight: '20vh'    
    }
});

Example of creating a square that is 50% of the screens size in width and height:

const styles = ScaleSheet.create({
    square: {
        width: '50vw',
        height: '50vw'
    }
});

Ignoring scaling on certain keys

If for some reason you want to ignore the scaling on a certain object, let's say for example you want the marginLeft property to be exactly 20 units on all devices regardless of their resolution, you can pass the style as an object using the { ignored: true, value: ... } syntax. Below is an example of a item that has the width and height scaled, but the marginLeft property is completely left alone.

NOTE: Viewport values will not work while ignoring scaling and will result in a RedBox in development or crashes in production.

const styles = ScaleSheet.create({
    example: {
        backgroundColor: 'red',
        width: 300,
        height: 300,
        marginLeft: { ignored: true, value: 25 }
    }
});

Please note that you should NOT pass an object as a value if you're going to set { ignored: false, ... } while I could just as easily implement this to work, it's completely redundant and unnecessary, considering it's not ignored by default.

Common Questions

  • Does this support nested styles and arrays, such as transform?

    • Yes, this properly goes through your style object and recursively styles all items, using the lesser common style values such as transform and shadowOffset work just fine.
  • Does this support applications that switch orientation? (Switch between Portrait and Landsacpe)

    • Currently we do not support re-scaling when orientation switches, we would welcome a PR. For now we recommend locking your application to either Portrait or Landscape mode. Note: Most applications only use portrait, so that was my focus.