0.0.7 • Published 7 years ago

rn-utils v0.0.7

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

React Native Utils

npm version

React Native Utilities is a package born out of the incessant rewriting of utility functions while developing scalable and maintainable React Native applications. It aims to be a repository that holds trivial yet useful utility functions that are most times copied over/recreated in every new React Native project.

Installation

npm install rn-utils --save

Utilities

Dimensions

FunctionUsageUtility
getDeviceHeightRNUtils.getDeviceHeight()Returns the device's current viewport height.
getDeviceWidthRNUtils.getDeviceWidth()Returns the device's current viewport width.

Orientation

Currently the only 3rd party package with native dependecies used by React Native Utilities is the React Native Orientation module. If you wish to use any of the Orientation functionalities of React Native Utils, remember to link its native dependencies.

react-native link react-native-orientation
FunctionUsageUtility
addOrientationListenerRNUtils.addOrientationListener((orientation) => this.setState({ orientation }))Creates an event listener that triggers whenever the orientation of the device changes.
getOrientationRNUtils.getOrientation()Function that returns the current device's orientation. It uses getInitialOrientation method from React Native Orientation module to allow for Async/Initial orientation checks. Orientation will either return LANDSCAPE or PORTRAIT.
isLandscapeRNUtils.isLandscape(orientation)Helper that returns true if current device orientation is Landscape. The orientation argument must be passed. This is usually used with the addOrientationListener or getOrientation utility functions.
lockLandscapeRNUtils.lockLandscape()Locks the device's viewport to the Landscape mode. Disables portrait.
lockPortraitRNUtils.lockPortrait()Locks the device's viewport to the Portrait mode. Disables landscape.
unlockOrientationsRNUtils.unlockOrientations()Unlocks any previous locking behavior applied by lockPortrait or lockLandscape.

Text Helpers

FunctionUsageUtility
getFontSizetextHelpers.getFontSize(size)Returns a font size based on size argument
getLineHeighttextHelpers.getLineHeight(size)Returns a line height based on size argument
getFontStylestextHelpers.getFontStyles(size)Returns an object with a font size and line height based on size argument

Example Usage

import TextHelpers from 'rn-utils'

const fontSizes = {small: 8, medium: 12};
const lineHeights = {small: 12, medium: 16};

const textHelpers = new TextHelpers(fontSizes, lineHeights);

const fontStyles = {
  ...textHelpers.getFontStyles('small');
}

Roadmap

The aim for this package is to introduce an ever growing list of React Native utilities that can be used when developing real-world scalable applications. With that in mind, below is the list of items I'd like to tackle next. These could be full rewrites of utilities or extracting it from current React Native projects.

  • Font Sizes / Line Heights
  • Legacy Operating Systems
  • Themes (?)
  • Animations (?)

Contributing & PRs

If you believe you have a utility that should be added to this list, please submit a Pull Request and I'll evaluate whether it should be merged. At this moment, I'd like to stay away from integrating other 3rd party libraries that have native dependencies as it creates yet another abstraction on top of those modules (harder to debug).

Issues

If you face issues while using this package, please open an issue on the Issues Tab. I'll try to resolve them as soon as possible.


MIT LICENSED
0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.1

7 years ago