Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-credit-card-input-view

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-credit-card-input-view

Easy (and good looking) credit-card input and credit-card View with swipe gestures , click and long press for your React Native Project

  • 0.0.7
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
10
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Credit Card Input View

Easy (and good looking) credit-card input and credit-card View with swipe gestures , click and long press for your React Native Project 💳💳


Code:

<CreditCardInput onChange={this._onChange} />
// or
<LiteCreditCardInput onChange={this._onChange} />

Features

  • Skeuomorphic credit-card 💳 (inspired by: card, react-native-credit-card)
  • Scale the Credit Card for smaller screens
  • CardView as a Component. example use case: showing saved payment details, etc.
  • Lite version for smaller screens (or if skeuomorphic is not really your thing)
  • Credit-card input validations & formatting while you're typing
  • Form is fully navigatable using keypad
  • Works on both Android and iOS

License

This is an updated and maintained version by arunahuja94.
Original author sbycrosz,

Usage

npm i --save react-native-credit-card-input-view

then add these lines in your react-native codebase

import { CreditCardInput, LiteCreditCardInput } from "react-native-credit-card-input-view";

<CreditCardInput onChange={this._onChange} />
// or
<LiteCreditCardInput onChange={this._onChange} />

// Note: You'll need to enable LayoutAnimation on android to see LiteCreditCardInput's animations
// UIManager.setLayoutAnimationEnabledExperimental(true);

And then on your onChange handler:

_onChange => form => console.log(form);

// will print:
{
  valid: true, // will be true once all fields are "valid" (time to enable the submit button)
  values: { // will be in the sanitized and formatted form
  	number: "4242 4242",
  	expiry: "06/19",
  	cvc: "300",
  	type: "visa", // will be one of [null, "visa", "master-card", "american-express", "diners-club", "discover", "jcb", "unionpay", "maestro"]
  	name: "Sam",
  	postalCode: "34567",
  },
  status: {  // will be one of ["incomplete", "invalid", and "valid"]
	number: "incomplete",
	expiry: "incomplete",
	cvc: "incomplete",
	name: "incomplete", 
	postalCode: "incomplete",
  },
};

// Notes: 
// cvc, name, & postalCode will only be available when the respective props is enabled (e.g. requiresName, requiresCVC)

Props

LiteCreditCardInput

PropertyTypeDescription
autoFocusPropTypes.boolAutomatically focus Card Number field on render
onChangePropTypes.funcReceives a formData object every time the form changes
onFocusPropTypes.funcReceives the name of currently focused field
placeholdersPropTypes.objectDefaults to
{ number: "1234 5678 1234 5678", expiry: "MM/YY", cvc: "CVC" }
inputStyleText.propTypes.styleStyle for credit-card form's textInput
validColorPropTypes.stringColor that will be applied for valid text input. Defaults to: "{inputStyle.color}"
invalidColorPropTypes.stringColor that will be applied for invalid text input. Defaults to: "red"
placeholderColorPropTypes.stringColor that will be applied for text input placeholder. Defaults to: "gray"
additionalInputsPropsPropTypes.objectOf(TextInput.propTypes)An object with Each key of the object corresponding to the name of the field. Allows you to change all props documented in RN TextInput.
NOTES

LiteCreditCardInput does not support requiresName, requiresCVC, and requiresPostalCode at the moment, PRs are welcome :party:

CreditCardInput

PropertyTypeDescription
autoFocusPropTypes.boolAutomatically focus Card Number field on render
onChangePropTypes.funcReceives a formData object every time the form changes
onFocusPropTypes.funcReceives the name of currently focused field
labelsPropTypes.objectDefaults to
{ number: "CARD NUMBER", expiry: "EXPIRY", cvc: "CVC/CCV" }
placeholdersPropTypes.objectDefaults to
{ number: "1234 5678 1234 5678", expiry: "MM/YY", cvc: "CVC" }
cardScalePropTypes.numberScales the credit-card view.
Defaults to 1, which translates to { width: 300, height: 190 }
cardFontFamilyPropTypes.stringFont family for the CreditCardView, works best with monospace fonts. Defaults to Courier (iOS) or monospace (android)
cardImageFrontPropTypes.numberImage for the credit-card view e.g. require("./card.png")
cardImageBackPropTypes.numberImage for the credit-card view e.g. require("./card.png")
labelStyleText.propTypes.styleStyle for credit-card form's labels
inputStyleText.propTypes.styleStyle for credit-card form's textInput
inputContainerStyleViewPropTypes.styleStyle for textInput's container
Defaults to: { borderBottomWidth: 1, borderBottomColor: "black" }
validColorPropTypes.stringColor that will be applied for valid text input. Defaults to: "{inputStyle.color}"
invalidColorPropTypes.stringColor that will be applied for invalid text input. Defaults to: "red"
placeholderColorPropTypes.stringColor that will be applied for text input placeholder. Defaults to: "gray"
requiresNamePropTypes.boolShows cardholder's name field
Default to false
requiresCVCPropTypes.boolShows CVC field
Default to true
requiresPostalCodePropTypes.boolShows postalCode field
Default to false
validatePostalCodePropTypes.funcFunction to validate postalCode, expects incomplete, valid, or invalid as return values
allowScrollPropTypes.boolenables horizontal scrolling on CreditCardInput
Defaults to false
useVerticalPropTypes.boolchange horizontal to vertical scrolling on CreditCardInput
Defaults to false
cardBrandIconsPropTypes.objectbrand icons for CardView. see ./src/Icons.js for details
additionalInputsPropsPropTypes.objectOf(TextInput.propTypes)An object with Each key of the object corresponding to the name of the field. Allows you to change all props documented in RN TextInput.

##CardView Usage

import { CardView } from "react-native-credit-card-input-view";

<CardView
  number="4410235123791414"
  cvc="121"
  expiry="12/25"
  brand="visa"
  name="Arun Ahuja"
  display={true}
  flipDirection="h"
  onPressfunc={() => alert('clicked')}
  onLongPressfunc={() => alert('Long clicked')} />

PropertyTypeDescription
focusedPropTypes.stringDetermines the front face of the card
brandPropTypes.stringBrand of the credit card
namePropTypes.stringCardholder's name (Use empty string if you need to hide the placeholder)
numberPropTypes.stringCredit card number (you'll need to the formatting yourself)
expiryPropTypes.stringCredit card expiry (should be in MM/YY format)
cvcPropTypes.stringCredit card CVC
placeholderPropTypes.objectPlaceholder texts
scalePropTypes.numberScales the card
fontFamilyPropTypes.stringDefaults to Courier and monospace in iOS and Android respectively
imageFrontPropTypes.numberImage for the credit-card
imageBackPropTypes.numberImage for the credit-card
displayPropTypes.numberSet display to true if using CardView
Defaults to false
customIconsPropTypes.objectbrand icons for CardView. see ./src/Icons.js for details
Note on additionalInputsProps

additionalInputsProps gives you more control over the inputs in LiteCreditCardInput and CreditCardInput. An example object is as follows:

addtionalInputsProps = {
  name: {
    defaultValue: 'my name',
    maxLength: 40,
  },
  postalCode: {
    returnKeyType: 'go',
  },
};

The above would set the default value of the name field to my name and limit the input to a maximum of 40 character. In addition, it would set the returnKeyType of the postalcode field to go.

Methods

setValues

Set values into credit card form

	// sets 4242 on credit card number field
	// other fields will stay unchanged
	this.refs.CCInput.setValues({ number: "4242" });

Known issues: clearing a field e.g. setValues({ expiry: "" }) will trigger the logic to move to previous field and trigger other kind of weird side effects. PR plz

focus

focus on to specified field

	// focus to expiry field
	this.refs.CCInput.focus("expiry");

Example

In the example directory, run:

npm install

react-native run-ios
# or
react-native run-android

Missing Something? Something is not working?

  • Open a GitHub issue, or
  • Send a pull request :D
  • Make sure npm run lint passed

Future Improvement

  • Add unit tests

Breaking Changes from 0.2.*

  • cardViewSize prop are removed from CreditCardInput, use cardScale instead (because changing the size will break most of the texts)
  • bgColor prop are removed from CreditCardInput, ask your designer friend to make a credit card image instead (or use the prebundled image)
  • imageFront and imageBack props are renamed to cardImageFront and cardImageBack respectively,
  • Android monospace fonts doesn't looks as nice as iOS Courier, bundle custom fonts into your app and override the default using cardFontFamily instead

Keywords

FAQs

Package last updated on 15 Apr 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc