1.1.5 β€’ Published 2 years ago

react-native-numeric-pad v1.1.5

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

πŸ“± React Native Numeric Pad πŸ“±

A React Native component for amount or verification code input. It easily handles both decimals and integers, and runs smoothly for both IOS and Android. The design is simple and clear with numbers, dot, and one custom button.

πŸ’ƒ Demo

Decimal InputInteger Input

πŸ“— Note 1. This keyboard has basic input validation such as number of point and the point's position. 2. This package only contains the number pad(second half screen). You need to bind the value and a handler function with your onw component(see my example). 3. The value output form this keyboard is a string type. Don't forget to convert to achieve your goalπŸ€™

πŸš€ Getting Started

via NPM

npm i react-native-numeric-pad

πŸ“— Note
This component has a peer dependency: "react-native": "^0.63.4", to smoothly match your 
project you may ues:

npm i react-native-numeric-pad --legacy-peer-deps

via Yarn

yarn add react-native-numeric-pad

πŸ›» Usage

import  NumericPad  from  'react-native-numeric-pad'

...

<NumericPad
  numLength={8}
  onValueChange={(v) => { setState(v)} }
  allowDecimal={true}
}/>

πŸ‘‰πŸΌ Props

PropTypeDefaultRequired
numLengthnumber-Yes
onValueChangefunc-No
activeOpacitynumber0.9No
buttonSizenumber60No
allowDecimalbooleantrueNo
styleViewStyle-No
buttonAreaStyleViewStyle-No
buttonItemStyleViewStyle-No
buttonTextStyleTextStyle{ color: '#000', fontSize: 30, fontWeight: '400' }No
numericDisabledbooleanfalseNo
accessiblebooleanfalseNo
buttonTextByKeyobject{one: "1",two: "2",three: "3",four: "4",five: "5",six: "6",seven: "7",eight: "8",nine: "9",dot: '.',zero: "0",}No
rightBottomButtonReact.ComponentnullNo
onRightBottomButtonPressfunc-No
rightBottomButtonDisabledbooleanfalseNo
rightBottomButtonSizenumber60No
rightBottomAccessibilityLabelstring"right_bottom"No
rightBottomButtonItemStyleViewStyle-No

πŸ‘‰πŸΌ Ref Actions

const numpadRef = useRef(null)

PropDescription
numpadRef.current.clearAll()This method completely clears the entered code.
numpadRef.current.clear()This method only delete last number of entered code.

πŸ— My Example

import  React, { useState, useRef } from  'react'
import { StyleSheet, Text, View, TextInput } from  'react-native'
import { Button } from  '@ant-design/react-native'
import { Ionicons } from  '@expo/vector-icons'
import  NumericPad  from  'react-native-numeric-pad'
import { I18n } from  '../../i18n'
import { LAYOUT, COLORS } from  '../../theme'
import { deviceHeight, deviceWidth } from  '../../theme/devices'

export  default  function  Widget ({ navigation, route }) {
const [amount, setAmount] = useState('')
const numpadRef = useRef(null)

return (
  <View style={styles.container}>
    <View style={styles.shadowBox}>
      <Text>{I18n.translate('amount')} $</Text>
      <TextInput
        style={styles.amountTxt}
        showSoftInputOnFocus={false}
        maxLength={8}
        autoFocus={true}
        editable={false}
        selectTextOnFocus={false}
        value={amount}
        />
    </View>

    <View style={styles.keyboardContainer}>
      <Button style={styles.btn}  type='primary'
        onPress={() => {}}
        disabled={!amount}>
        {I18n.translate('confirm') + ' β†’'}
      </Button>

      <NumericPad
        ref={numpadRef}
        numLength={8}
        buttonSize={60}
        activeOpacity={0.1}
        onValueChange={value => setAmount(value)}
        allowDecimal={true}
        // Try them to understand each area :)
        // style={{ backgroundColor: 'black', paddingVertical: 12 }}
        // buttonAreaStyle={{ backgroundColor: 'gray' }}
        // buttonItemStyle={{ backgroundColor: 'red' }}
        rightBottomButton={<Ionicons name={'ios-backspace-outline'} size={28} color={'#000'}/>}
        onRightBottomButtonPress={() => {numpadRef.current.clear()}
        }
      />
    </View>
  </View>
  )
}


const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: LAYOUT['spacing-05']
  },
  shadowBox: {
    width: '100%',
    borderRadius: LAYOUT['spacing-03'],
    padding: LAYOUT['spacing-05'],
    backgroundColor: COLORS.WHITE,
    shadowOffset: {
      height: 3,
      width: 3
    },
    shadowOpacity: 0.15,
    shadowRadius: 5,
    shadowColor: '#1D2660',
    elevation: 5
  },
  amountTxt: {
    fontSize: 38,
    fontWeight: '700',
    lineHeight: 40,
    marginTop: LAYOUT['spacing-06'],
    color: COLORS['brand-01']
  },
  keyboardContainer: {
    width: deviceWidth,
    height: deviceHeight * 0.46,
    borderRadius: 26,
    justifyContent: 'center',
    alignItems: 'center',
    paddingHorizontal: 16,
    position: 'absolute',
    bottom: 0,
    backgroundColor: COLORS.WHITE,
    shadowOffset: {
      height: 3,
      width: 3
    },
    shadowOpacity: 0.15,
    shadowRadius: 5,
    shadowColor: '#1D2660',
    elevation: 5
  },
  btn: {
    width: '100%',
    marginTop: 10,
    backgroundColor: COLORS['brand-01']
  }
})

πŸ“° License

This project is licensed under the MIT License - see the LICENSE.md file for details