0.5.3 • Published 5 years ago

react-native-pin-code v0.5.3

Weekly downloads
281
License
ISC
Repository
github
Last release
5 years ago

react-native-pin-code

last release monthly download license

A simple pin code component

example with blur background a simple example

Installation

npm install react-native-pin-code --save

Example

<CodePin
  code="2018" // code.length is used if you not pass number prop
  success={() => console.log('hurray!')} // If user fill '2018', success is called
  text="A simple Pin code component" // My title
  error="You fail" // If user fail (fill '2017' for instance)
  autoFocusFirst={false} // disabling auto-focus
/>

or

<CodePin
  number={4} // You must pass number prop, it will be used to display 4 (here) inputs
  checkPinCode={(code, callback) => callback(code === '1234')}
  // Check manually code (ask server for instance)
  // and call callback function with
  //    true  (code pin is correct)
  // or false (code pin is false)
  success={() => console.log('hurray!')} // If user fill '2018', success is called
  text="A simple Pin code component" // My title
  error="You fail" // If user fail (fill '2017' for instance)
  autoFocusFirst={false} // disabling auto-focus
/>

Code prop is not needed if checkPinCode is used

props

proptypedescriptionisRequireddefault value
codenumberpin codenot required''
successfunctioncall on successrequired
checkPinCodefunctionthis function is called to check pin code. The parameters are : code (the code filled by user) and a callback function. callback must be called with true (code pin is correct) or false (code pin is wrong)not requirednull
obfuscationbooleanIf true, obfuscate code with '*'false
textstringtext to display as title'Pin code.'
errorstringtext to display on error'Bad pin code.'
numbernumbernumber of input to display4
autoFocusFirstbooleanauto focus first inputtrue
containerStyleobject, StyleSheet objectcontainer style{ height: 150, width: width - 30, backgroundColor : '#FFF' }
containerPinStyleobject, StyleSheet objectinputs container style{ width: width - 30, height: 40, flexDirection: 'row', justifyContent: 'space-around', alignItems: 'center', marginTop: 20 }
pinStyleobject, StyleSheet objectinput style{ backgroundColor : '#F0F0F0', textAlign: 'center', flex: 1, marginLeft: 20, marginRight: 20, borderRadius: 5, shadowColor: '#000000', shadowOffset: {width: 1,height : 1}, shadowRadius: 5, shadowOpacity : 0.4 }
textStyleobject, StyleSheet objecttext style{ textAlign: 'center', color: 'gray', fontSize: 20, marginTop: 30 }
errorStyleobject, StyleSheet objecterror text style{ textAlign: 'center', color: 'red', paddingTop: 10 }

All other props are pass down to TextInput component.

For instance you can customize keyboardtype :

<CodePin
  //...
  keyboardType="numeric"
/>

Functions

To use pin code component function, use ref :

  <CodePin
    ref={ref => this.ref = ref}
    ...
  />

clean

clean inputs and focus first input.

this.ref.clean();

focus

focus input at specified index

this.ref.focus(1);

Examples

react-native-pin-code-examples

To test examples :

  git clone https://github.com/gkueny/react-native-pin-code-examples
  cd blurExample
  npm install
  react-native run-ios

or

  git clone https://github.com/gkueny/react-native-pin-code-examples
  cd simpleExample
  npm install
  react-native run-ios
0.5.4-beta.0

5 years ago

0.5.3

6 years ago

0.5.2

6 years ago

0.5.1

6 years ago

0.5.1-beta3

6 years ago

0.5.1-beta2

6 years ago

0.5.1-beta

6 years ago

0.5.0

6 years ago

0.4.1

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago