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

mobile-rn-utils

v0.0.3

Published

A collection of helper modules for react native applications

Downloads

1

Readme

mobile-rn-utils

A collection of helper modules for react native applications.

Installation

yarn add mobile-rn-utils

or

npm install mobile-rn-utils --save

alert

alert - a helper module for redux-saga; it wraps react native Alert.alert() to use within sagas (generator functions). It exports two functions: alert() and confirm().

alert Usage

import { alert, confirm } from 'mobile-rn-utils/alert'

// Example 1 - alert() usage in saga
//
import { call, takeLatest } from 'redux-saga/effects';
import { alert } from 'mobile-rn-utils/alert';
import { ON_APP_ERROR } from './constants';

function* _onAppError(action) {
  console.log('----saga _onAppError saga----');

  yield call(alert, action.title, action.message);
}

export function* watchOnAppError() {
  yield takeLatest(ON_APP_ERROR, _onAppError);
}

// Example 2 - confirm() usage in saga
//
import { call, takeLatest } from 'redux-saga/effects';
import { confirm } from 'mobile-rn-utils/alert';
import { ON_DELETE_REQUEST } from './constants';

function* _onDeleteRequest(action) {
  console.log('----saga _onDeleteRequest saga----');

  const isDeleteConfirmed = yield call(confirm, 'Delete', `Do you really want to delete ${action.name}?`);
  
  if (isDeleteConfirmed) {
    // Delete logic goes here
  }
}

export function* watchOnDeleteRequest() {
  yield takeLatest(ON_DELETE_REQUEST, _onDeleteRequest);
}

alert API

alert(title: string, message: string, okButtonTitle?: string = 'OK'): Promise<void>

Displays react native Alert.alert() with given title, message, and one 'positive' button. Returns nothing.

confirm(title: string, message: string, confirmButtonTitle?: string = 'OK', cancelButtonTitle?: string = 'Cancel'): Promise<boolean>

Displays react native Alert.alert() with given title, message, and two buttons (one 'positive' and one 'negative'). If user press 'positive' button, returns true. Otherwise returns false.

constants

constants - a collection of useful constants

constants Usage

import { isAndroid } from 'mobile-rn-utils/constants'

if (isAndroid) {
  // Android specific rendering goes here
}

constants API

  • isAndroid: string true if device is Android
  • isIOS: string true if iOS device
  • deviceWidth: number Device screen width (does not depend on the current device orientation)
  • deviceHeight: number Device screen height (does not depend on the current device orientation)
  • isSmallScreen: boolean true if device has small screen
  • isShortScreen: boolean true is device has short screen
  • monospaceFontFamily: string "Courier" font family on iOS and 'monospace" font family on Android
  • baselineDeviceWidth: number iPhone 5 screen width
  • baselineDeviceHeight: number iPhone 5 screen height

scaleUtils

scaleUtils - a collection of helper functions for responsive UI

scaleUtils Usage

import { scale, verticalScale, moderateScale, widthFromPercentage, heightFromPercentage } from 'mobile-rn-utils/scaleUtils'

  const responsiveWidth = scale(60);
  const responsiveHeight = verticalScale(120);
  const padding = moderateScale(5);

  const width = widthFromPercentage('95%');
  const height = heightFromPercentage('33%');

scaleUtils API

scale(size: number): number

Scale input parameter size based on the current device screen width.

verticalScale(size: number): number

Scale input parameter size based on the current device screen height.

moderateScale(size: number, factor: number = 0.5): number

Scale input parameter based on the current device screen width and additionally provided scale factor

widthFromPercentage(widthInPercent: string): number

Translate given width in percent to width in pixels

heightFromPercentage(heightInPercent: string): number

Translate given height in percent to height in pixels

hocs - a collection of Higher-Order Components

withSize - a HOC that will dispatch onLayout method and pass to the wrapped component x, y, width, height via props (the x and y values are relative to the top left corner of the screen)

withSize Usage

import withSize from 'mobile-rn-utils/hocs/withSize'

// EnhancedComponent will receive x, y, with, height via props
const EnhancedComponent = withSize(WrappedComponent);