Easy (and good looking) credit-card input for your React Native Project
Code:
<CreditCardInput onChange={this._onChange} />
// or
<LiteCreditCardInput onChange={this._onChange} />
npm i --save react-native-credit-card-input
then add these lines in your react-native codebase
import { CreditCardInput, LiteCreditCardInput } from "react-native-credit-card-input";
<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)
Property | Type | Description |
---|---|---|
autoFocus | PropTypes.bool | Automatically focus Card Number field on render |
onChange | PropTypes.func | Receives a formData object every time the form changes |
onFocus | PropTypes.func | Receives the name of currently focused field |
placeholders | PropTypes.object | Defaults to { number: "1234 5678 1234 5678", expiry: "MM/YY", cvc: "CVC" } |
inputStyle | Text.propTypes.style | Style for credit-card form's textInput |
validColor | PropTypes.string | Color that will be applied for valid text input. Defaults to: "{inputStyle.color}" |
invalidColor | PropTypes.string | Color that will be applied for invalid text input. Defaults to: "red" |
placeholderColor | PropTypes.string | Color that will be applied for text input placeholder. Defaults to: "gray" |
additionalInputsProps | PropTypes.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. |
LiteCreditCardInput does not support requiresName
, requiresCVC
, and requiresPostalCode
at the moment, PRs are welcome :party:
Property | Type | Description |
---|---|---|
autoFocus | PropTypes.bool | Automatically focus Card Number field on render |
onChange | PropTypes.func | Receives a formData object every time the form changes |
onFocus | PropTypes.func | Receives the name of currently focused field |
labels | PropTypes.object | Defaults to { number: "CARD NUMBER", expiry: "EXPIRY", cvc: "CVC/CCV" } |
placeholders | PropTypes.object | Defaults to { number: "1234 5678 1234 5678", expiry: "MM/YY", cvc: "CVC" } |
cardScale | PropTypes.number | Scales the credit-card view. Defaults to 1 , which translates to { width: 300, height: 190 } |
cardFontFamily | PropTypes.string | Font family for the CreditCardView, works best with monospace fonts. Defaults to Courier (iOS) or monospace (android) |
cardImageFront | PropTypes.number | Image for the credit-card view e.g. require("./card.png") |
cardImageBack | PropTypes.number | Image for the credit-card view e.g. require("./card.png") |
labelStyle | Text.propTypes.style | Style for credit-card form's labels |
inputStyle | Text.propTypes.style | Style for credit-card form's textInput |
inputContainerStyle | ViewPropTypes.style | Style for textInput's container Defaults to: { borderBottomWidth: 1, borderBottomColor: "black" } |
validColor | PropTypes.string | Color that will be applied for valid text input. Defaults to: "{inputStyle.color}" |
invalidColor | PropTypes.string | Color that will be applied for invalid text input. Defaults to: "red" |
placeholderColor | PropTypes.string | Color that will be applied for text input placeholder. Defaults to: "gray" |
requiresName | PropTypes.bool | Shows cardholder's name field Default to false |
requiresCVC | PropTypes.bool | Shows CVC field Default to true |
requiresPostalCode | PropTypes.bool | Shows postalCode field Default to false |
validatePostalCode | PropTypes.func | Function to validate postalCode, expects incomplete , valid , or invalid as return values |
allowScroll | PropTypes.bool | enables horizontal scrolling on CreditCardInput Defaults to false |
cardBrandIcons | PropTypes.object | brand icons for CardView. see ./src/Icons.js for details |
additionalInputsProps | PropTypes.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
Property | Type | Description |
---|---|---|
focused | PropTypes.string | Determines the front face of the card |
brand | PropTypes.string | Brand of the credit card |
name | PropTypes.string | Cardholder's name (Use empty string if you need to hide the placeholder) |
number | PropTypes.string | Credit card number (you'll need to the formatting yourself) |
expiry | PropTypes.string | Credit card expiry (should be in MM/YY format) |
cvc | PropTypes.string | Credit card CVC |
placeholder | PropTypes.object | Placeholder texts |
scale | PropTypes.number | Scales the card |
fontFamily | PropTypes.string | Defaults to Courier and monospace in iOS and Android respectively |
imageFront | PropTypes.number | Image for the credit-card |
imageBack | PropTypes.number | Image for the credit-card |
customIcons | PropTypes.object | brand icons for CardView. see ./src/Icons.js for details |
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
.
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 on to specified field
// focus to expiry field
this.refs.CCInput.focus("expiry");
In the example
directory, run:
npm install
react-native run-ios
# or
react-native run-android
npm run lint
passedcardViewSize
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,monospace
fonts doesn't looks as nice as iOS Courier
, bundle custom fonts into your app and override the default using cardFontFamily
insteadEmber Credit card This is an Ember wrapper for the amazing Card project. Installation ember install ember-credit-card Usage <CreditCard/> Default By simply adding {{credit-card}} a basic form will be
本文向大家介绍react-native 启动React Native Packager,包括了react-native 启动React Native Packager的使用技巧和注意事项,需要的朋友参考一下 示例 在最新版本的React Native上,无需运行打包程序。它将自动运行。 默认情况下,这将在端口8081上启动服务器。要指定服务器所在的端口
CreditAnalytics是固定收入的金融信用分析,信用风险,债券分析,债券的风险库,特别注重了对信用交易和债券交易社区的需求(CDS的,对CDX,CDO的各类债券和开发变种)。
百度移动统计SDK支持使用react native框架的H5页面统计,封装好的插件已经在github上开源,相关用法具体请参考:https://github.com/BaiduMobileAnalysis/baidumobstat-react-native。
The React Native environment has a lot of little quirks, so this documentation is aimed at helping smooth those over. Please feel free to create issues on GitHub for recommendations and additions to t
React Native 可以基于目前大热的开源JavaScript库React.js来开发iOS和Android原生App。而且React Native已经用于生产环境——Facebook Groups iOS 应用就是基于它开发的。 React Native的原理是在JavaScript中用React抽象操作系统原生的UI组件,代替DOM元素来渲染,比如以<View>取代<div>,以<Ima