Socket
Socket
Sign inDemoInstall

react-native-numpad

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-numpad

A simple React Native number pad for quickly updating multiple number inputs.


Version published
Weekly downloads
74
decreased by-34.51%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

React Native Numpad

A simple React Native number pad for quickly updating multiple number inputs.

npm version runs with expo

  • No Dependencies
  • ✅ iOS
  • ✅ Android
  • ✅ React Native Web
  • ✅ JS-Only (No Native Code / No Linking Necessary)

Screen Recording

Demo 👉 Expo Snack

Install

yarn add react-native-numpad

Use Cases

  • Splitting expenses
  • Forms with multiple number inputs
  • Spreadsheets
  • Calculators

Usage

import React from 'react';
import NumberPad, { Input, Display } from './index';

export default () => (
  <NumberPad>
    <Display key={0} cursor value={1.0} />
    <Display key={1} cursor value={2.5} />
    <Input />
  </NumberPad>
);

Custom Icons

import React from 'react';
import NumberPad, { Input, Display } from './index';
import { Ionicons } from '@expo/vector-icons';

export default () => (
  <NumberPad>
    <Display key={0} cursor value={1.0} />
    <Display key={1} cursor value={2.5} />
    <Input
      backspaceIcon={<Ionicons icon="ios-backspace" {...Input.iconStyle} />}
      hideIcon={<Ionicons icon="ios-arrow-down" {...Input.iconStyle} />}
    />
  </NumberPad>
);

API

Under the hood, react-native-numpad uses the React Context API to link the number inputs (the <Display>s) to the number pad (the <Input>).

<NumberPad> Component

The <NumberPad> component is a HOC (Higher Order Component) that does not accept any props besides children. It creates a reactNativeNumpad context that listens for press events on the number inputs, opens the number input when it detects a press, and then updates the input values when the user presses on the number buttons in the number pad.

<Display> Component

The <Display> is the number pad's equivalent of React Native's <TextInput> component. It is a controlled component that, when pressed, opens the number pad.

PropDescriptionDefault
valueCurrent value of the input (number only)None
styleAny valid style object for <TouchableOpacity>None
textStyleAny valid style object for a <Text> componentNone
activeStyleAny valid style object for a <Text> componentNone
invalidTextStyleAny valid style object for a <Text> componentNone
placeholderTextStyleAny valid style object for a <Text> componentNone
cursorStyleAny valid style object for a <View> componentNone
blinkOnStyleAny valid style object for a <View> componentNone
blinkOffStyleAny valid style object for a <View> componentNone
onChangeAn event handler function that receives the new value (number) as an argumentNone
cursorWhether or not to show the cursor when the input is focused (boolean)true
autofocusWhether or not to autofocus the input when the component is loaded (boolean)false

<Input> Component

The <Input> a custom number pad keyboard that, unlike the native keyboard, does not minimize when the user presses on a new number input if it is already open. It is stylable and easy to customize.

PropDescriptionDefault
heightHeight of the number pad270
positionHow the number pad will be positioned'absolute' | 'relative'
styleAny valid style object for a <View> component (Animated.View, actually)None
backspaceIconAn Icon element (eg from react-native-vector-icons or @expo/vector-icons)None
hideIconAn Icon element (eg from react-native-vector-icons or @expo/vector-icons)None
onWillHideCalled just before the number pad will hideNone
onDidHideCalled just after the number pad hidesNone
onWillShowCalled just before the number pad will showNone
onDidShowCalled just after the number pad showsNone

<AvoidingView> Component

Sometimes React Native's built-in does not work smoothly with the number pad: it can either have performance issues where animations are choppy or it can be difficult to configure its height properly altogether. We've included a number pad context-aware version that adjusts it's height based on the keyboard animation to achieve a smooth frame rate.

PropDescriptionDefault
styleAny valid style object for a <View> component (Animated.View, actually)None

Version History (Change Log)

View here.

Contribute

We welcome contributions! If you are interested in contributing, consider helping us with one of the following tasks:

  • Rewrite components in TypeScript using arrow-function components and React hooks
  • Add TypeScript bindings
  • Add Tests

Glance Money

Glance Money Logo

We wrote this for, actively use, and maintain this library for Glance Money. Now it is free and open for the world to use ❤️

License

MIT licensed.

FAQs

Last updated on 29 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc