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

rn-responsive-utility

v1.0.7

Published

A utility library for React Native that provides hooks for responsive scaling and device orientation information.

Downloads

47

Readme

rn-responsive-utility

RN-Responsive-Utility is a utility library for React Native that provides hooks for responsive scaling and device orientation information. This library allows developers to easily scale their UI based on screen size and device orientation, and also provides hooks for accessing device orientation information.

Installation

To install the library, you can use npm by running the following command:

  npm install rn-responsive-utility

Usage / Example

Once the library is installed, you can import the hooks and start using them in your application.

The useScreenOrientation hook returns an object containing the following properties:

screenWidth: the current width of the screen in pixels

screenHeight: the current height of the screen in pixels

screenOrientation: the current orientation of the device, either PORTRAIT or LANDSCAPE

You can use this hook like this:

import { useScreenOrientation } from "rn-responsive-utility";

function MyComponent() {
	const { screenWidth, screenHeight, screenOrientation } =
		useScreenOrientation();

	// use the screenWidth, screenHeight and screenOrientation properties
}

The useScale hook returns an object containing the following properties:

hScale: the horizontal scale factor based on the screen width

vScale: the vertical scale factor based on the screen height

phScale: the percentage horizontal scale factor based on the screen width

pvScale: the percentage vertical scale factor based on the screen height

mhScale: the medium horizontal scale factor based on the screen width (where it can take second parameter as scaling factor).

mvScale: the medium vertical scale factor based on the screen height (where it can take second parameter as scaling factor).

useScale can take boolean to unlock scaling with orientation change. default is true by considering orientation is locked to PORTRAIT

You can use this hook like this:

import { useScale } from "rn-responsive-utility";

function MyComponent() {
	const { hScale, vScale, mhScale, mvScale } = useScale();

	// use the hScale, vScale,mhScale,mvScale properties
}

Code Snippet

import { useScale } from "rn-responsive-utility";

function MyComponent() {
	const { hScale, vScale, mhScale, mvScale } = useScale();

	// use the hScale, vScale,mhScale,mvScale properties
	return (
		<View
			style={{
				backgroundColor: "red",
				borderWidth: vScale(2),
				paddingHorizontal: hScale(SIZES.padding),
				borderRadius: vScale(SIZES.radius),
				paddingVertical: vScale(20),
			}}
		>
			<Text style={{ fontSize: vScale(SIZES.font) }}>
				Lorem, ipsum dolor sit amet consectetur adipisicing elit. Dolorem itaque
				perferendis, labore possimus sed eius nihil tempore modi! Nihil soluta
				nobis quae architecto praesentium ipsa mollitia minima error ipsum
				veritatis!
			</Text>
		</View>
	);
}

You can use the hScale and vScale functions to scale the values of different styles properties based on the screen size.

For example, in the above code snippet, the borderWidth and paddingHorizontal properties of the View component are being scaled using vScale and hScale respectively.

The paddingVertical and borderRadius are also being scaled using vScale.

The fontSize of the Text component is also being scaled using vScale function.

It's important to note that you can provide the values to be scaled in the form of an object like SIZES, which will have the key-value pairs of different sizes as per your requirement.

With these hooks, you can easily create responsive and adaptive interfaces without the need for additional dependencies or libraries.

The hooks can be used in any component of your application and can be combined with other hooks and libraries. This library is a great tool for building responsive and user-friendly applications in React Native.

Authors

Tip:

For better use of this library scale vertical properties like fontSize, height, marginVertical with vScale and horizontal properties like width, marginHorizontal with hScale.