1.3.4 • Published 2 years ago

react-native-awesome-pin v1.3.4

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

react-native-awesome-pin

All Contributors

npm npm licence npm downloads

A highly interactive and customizable PIN code screen for React Native.

  • Plug and play PIN screen with dozens of props (can be themed to suit your brand).
  • Keyboard and PIN components can be used independently for more fine-grained customization.
  • Animations and micro-feedback included to create a great user experience.

Install

To get started install via npm:

 npm install react-native-awesome-pin --save

Usage

PinScreen

The <PinScreen /> will take up the full view. It is a plug and play component... pass your logo, tagline, background colour, callback function and start verifying PINs.

Import:

import { PinScreen } from "react-native-awesome-pin";

Then add it to your code:

<PinScreen
    onRef={ ref => (this.pinScreen = ref) }
    tagline='Please enter your PIN'
    logo={ require('../../img/mylogohere.png') }
    containerStyle={{ backgroundColor: '#AAA' }}
    keyDown={ this.recievePin.bind(this) }
/>

// Callback function which receives the current PIN value
recievePin(pin){
   // Check if the PIN is correct here
}

You need to add a ref to your PinScreen, this allows you to throw an error from the parent component when a PIN is incorrect. Errors can be thrown using the throwError(message) method. Keyboard errors can be cleared using clearError()

recievePin(pin){
   // Clear error on interaction
   this.pinScreen.clearError();

   if(pin != '56771'){
       this.pinScreen.throwError('Your PIN is incorrect');
   }
}

PinKeyboard

The on-screen keyboard can be used separately if you do not want to use the plug and play <PinScreen /> component.

Import:

import { PinKeyboard } from "react-native-awesome-pin";

Then add it to your code:

<PinKeyboard
    onRef={ref => (this.keyboard = ref)}
    keyDown={this.keyDown.bind(this)}
/>

// Callback function which receives the key pressed
keyDown(key){
   // Key pressed
}

The <PinKeyboard /> also has a throwError(message) method. This will create a popup above the keyboard displaying the given error message. The style of the popup can be customized through props.

PinInput

The PIN input circles can be used separately if you do not want to use the plug and play <PinScreen /> component. They come with a shake animation and configurable device vibration.

Import:

import { PinInput } from "react-native-awesome-pin";

Then add it to your code:

<PinInput
  onRef={(ref) => (this.pins = ref)}
  numberOfPins={5}
  numberOfPinsActive={2}
/>

The <PinInput /> has a shake() method which can be called through the reference this.pins.shake(). This will perform a shake animation and vibration if enabled. A callback can be passed through props which will be fired when the animation is complete. See props below.

Props

PinScreen

The <PinScreen /> is a great plug and play solution for a PIN screen.

PropTypeOptionalDefaultDescription
onRefstringNoonRef allows you to call the throwError(message) method.
keyDownstringNoCallback function triggered when a key is pressed. Returns the current PIN value.
taglinestringYes'Enter your PIN'Tagline which sits above the PINS.
logoobjectYesLogo to place at top of screen.
numberOfPinsnumberYes5Number of pins to render.
keyVibrationboolYestrueShould vibration be enabled for key press.
shakeVibrationboolYestrueShould vibration be enabled for shake.
headerBackgroundColorstringYes#e2e2e2Header colour for the SafeAreaView.
footerBackgroundColorstringYes#fffFooter colour for the SafeAreaView.
ItemFooterelementYesA footer component to render below the PinScreen.
containerStyleobjectYesSee PinScreen.jsStyle applied to the container. Background colour can be set here.
logoStyleobjectYesStyle applied to your logo.
taglineStyleobjectYesSee PinScreen.jsStyle applied to the tagline.
pinstringYesThe pin value.
pinContainerStyleobjectYesSee PinInput.jsStyle applied to PINS container.
pinStyleobjectYesSee PinInput.jsStyle applied to each circle PIN.
pinActiveStyleobjectYesSee PinInput.jsStyle applied to each circle PIN when it is active.
keyboardarrayYesSee PinKeyboard.js4 x 3 matrix containing the value for each key. Image or text.
keyboardStyleobjectYesSee PinKeyboard.jsStyle applied to the keyboard.
keyboardDisabledStyleobjectYesSee PinKeyboard.jsStyle applied when the keyboard is disabled.
disableRippleEffectboolYesfalseDisables the ripple effect from the keys.
keyStyleobjectYesSee PinKeyboard.jsStyle applied to each key on the keyboard.
keyTextStyleobjectYesSee PinKeyboard.jsStyle applied to the text inside each key.
keyImageStyleobjectYesSee PinKeyboard.jsStyle applied to image in a key. If an image is passed.
errorStyleobjectYesSee PinKeyboard.jsStyle applied to popup error. Can set the background colour here.
errorTextStyleobjectYesSee PinKeyboard.jsStyle applied to the text inside the popup error.

PinKeyboard

The <PinKeyboard /> uses two arrays to allow you to set keys and define custom functions for each key. This is not the most fine-tune solution and will be upgraded in the future.

PropTypeOptionalDefaultDescription
onRefstringNoonRef allows you to call the throwError(message) method.
keyDownstringNoCallback function triggered when a key is pressed. Returns the key value.
keyboardarrayYesSee PinKeyboard.js4 x 3 matrix containing the value for each key. Image or text.
keyboardFuncarrayYesSee PinKeyboard.js4 x 3 matrix containing custom functions for each key. Pass null for no function.
keyboardStyleobjectYesSee PinKeyboard.jsStyle applied to the keyboard.
keyboardDisabledStyleobjectYesSee PinKeyboard.jsStyle applied when the keyboard is disabled.
disableRippleEffectboolYesfalseDisables the ripple effect from the keys.
keyStyleobjectYesSee PinKeyboard.jsStyle applied to each key on the keyboard.
keyTextStyleobjectYesSee PinKeyboard.jsStyle applied to the text inside each key.
keyImageStyleobjectYesSee PinKeyboard.jsStyle applied to image in a key. If an image is passed.
errorStyleobjectYesSee PinKeyboard.jsStyle applied to popup error. Can set the background colour here.
errorTextStyleobjectYesSee PinKeyboard.jsStyle applied to the text inside the popup error.

PinInput

PropTypeOptionalDefaultDescription
onRefanyNoonRef allows you to call the shake() method.
numberOfPinsnumberYes5Number of pins to render.
numberOfPinsActivenumberYes0Number of active pins. You can pass the pin.length here.
vibrationboolYestrueShould vibration be enabled on shake?
animationShakeCallbackfuncYesA callback triggered when the pin shake animation has finished.
containerStyleobjectYesSee PinInput.jsStyle applied to PINS container.
pinStyleobjectYesSee PinInput.jsStyle applied to each circle PIN.
pinActiveStyleobjectYesSee PinInput.jsStyle applied to each circle PIN when it is active.

Contributing

If you want to issue a PR, go ahead ;)

License

This project is licensed under the MIT License

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

1.3.4

2 years ago

1.3.3

2 years ago

1.3.2

3 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.1

5 years ago

1.1.6

5 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago