├── .babelrc ├── .flowconfig ├── .gitignore ├── .watchmanconfig ├── LICENSE ├── README.md ├── WebViewBraintree.js ├── config └── enzymeAdapter.js ├── coverage ├── clover.xml ├── coverage-final.json ├── lcov-report │ ├── base.css │ ├── config │ │ ├── enzymeAdapter.js.html │ │ └── index.html │ ├── index.html │ ├── prettify.css │ ├── prettify.js │ ├── sort-arrow-sprite.png │ ├── sorter.js │ └── web │ │ ├── braintreeReact.js.html │ │ └── index.html └── lcov.info ├── dist ├── index.html └── main.bundle.js ├── gulpfile.js ├── package.json ├── react-dom.production.min.js ├── react.production.min.js ├── web ├── braintreeReact.html ├── braintreeReactHTML.js ├── braintreeReactHTML.test.js └── component.js ├── webpack.config.js ├── yarn directions.md ├── yarn-error.log └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015", "stage-0", "react"], 3 | "env": { 4 | "development": { 5 | "plugins": [ 6 | "transform-react-jsx-source", 7 | "transform-es2015-arrow-functions" 8 | ] 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | .*/Libraries/react-native/ReactNative.js 16 | 17 | ; Additional create-react-native-app ignores 18 | 19 | ; Ignore duplicate module providers 20 | .*/node_modules/fbemitter/lib/* 21 | 22 | ; Ignore misbehaving dev-dependencies 23 | .*/node_modules/xdl/build/* 24 | .*/node_modules/reqwest/tests/* 25 | 26 | ; Ignore missing expo-sdk dependencies (temporarily) 27 | ; https://github.com/expo/expo/issues/162 28 | .*/node_modules/expo/src/* 29 | 30 | ; Ignore react-native-fbads dependency of the expo sdk 31 | .*/node_modules/react-native-fbads/* 32 | 33 | [include] 34 | 35 | [libs] 36 | node_modules/react-native/Libraries/react-native/react-native-interface.js 37 | node_modules/react-native/flow 38 | flow/ 39 | 40 | [options] 41 | module.system=haste 42 | 43 | emoji=true 44 | 45 | experimental.strict_type_args=true 46 | 47 | munge_underscores=true 48 | 49 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 50 | 51 | suppress_type=$FlowIssue 52 | suppress_type=$FlowFixMe 53 | suppress_type=$FixMe 54 | 55 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 56 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 57 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 58 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 59 | 60 | unsafe.enable_getters_and_setters=true 61 | 62 | [version] 63 | ^0.49.1 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .expo/ 3 | npm-debug.* 4 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Reginald Johnson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Native Webview Braintree 2 | ## A Braintree payment component with no native code for React Native apps. 3 | 4 | [![npm](https://img.shields.io/npm/v/react-native-webview-braintreee.svg)](https://www.npmjs.com/package/react-native-webview-braintree) 5 | [![npm](https://img.shields.io/npm/dm/react-native-webview-braintree.svg)](https://www.npmjs.com/package/react-native-webview-braintree) 6 | [![npm](https://img.shields.io/npm/dt/react-native-webview-braintree.svg)](https://www.npmjs.com/package/react-native-webview-braintree) 7 | [![npm](https://img.shields.io/npm/l/react-native-webview-braintree.svg)](https://github.com/react-native-component/react-native-webview-braintree/blob/master/LICENSE) 8 | 9 | ## Usage 10 | ~~~~ 11 | 17 | ~~~~ 18 | 19 | This component accepts the following props 20 | * clientToken 21 | * nonceObtainedCallback 22 | * navigationBackCallback 23 | * paymentAPIResponse 24 | 25 | | Name | Required | Description | 26 | | ---------------------- | ------------- | ----------- | 27 | | clientToken | yes | Braintree [client token used to create the dropin UI](https://developers.braintreepayments.com/start/hello-client/javascript/v3#get-a-client-token)| 28 | | nonceObtainedCallback | yes | Function called once a Braintree payment nonce is obtained, the nonce value is passed to the function as the only parameter| 29 | | paymentAPIResponse | yes | A string indicated the success of the an API to Braintree transaction API. The string should be either "PAYMENT_SUCCESS" "PAYMENT_REJECTED"| 30 | | navigationBackCallback | no | Function that can be called in order to initiate navigation. This function will be called when the user clicks on a button labeled "Return to Shop" that appears after a rejected or successful purchase | 31 | 32 | 33 | Example use of the paymentAPIResponse string 34 | ~~~ 35 | brainTreeUtils 36 | .postPurchase(nonce, this.props.cart.totalPrice, {}) 37 | .then(response => { 38 | if (response.type === "success") { 39 | this.setState({ paymentAPIResponse: "PAYMENT_SUCCESS" }); 40 | this.props.dispatch(actions.cartActions.emptyCart()); 41 | } else { 42 | this.setState({ paymentAPIResponse: "PAYMENT_REJECTED" }); 43 | } 44 | }); 45 | ~~~ 46 | 47 | ## Example Application 48 | [React Native Webview Braintree test application](https://github.com/reggie3/react-native-webview-braintree-test-app) 49 | 50 | ## TODOs 51 | Integrate Paypal payments 52 | 53 | ## LICENSE 54 | 55 | MIT 56 | -------------------------------------------------------------------------------- /WebViewBraintree.js: -------------------------------------------------------------------------------- 1 | import React from './react.production.min.js'; 2 | import { View, ActivityIndicator, StyleSheet } from 'react-native'; 3 | import { WebView } from 'react-native-webview-messaging/WebView'; 4 | import PropTypes from 'prop-types'; 5 | import renderIf from 'render-if'; 6 | 7 | export default class BraintreePaymentWebview extends React.Component { 8 | constructor() { 9 | super(); 10 | 11 | this.state = { 12 | paymentAPIResponse: null, 13 | showGetNonceActivityIndicator: false, 14 | showSubmitPaymentActivityIndicator: false 15 | }; 16 | } 17 | componentDidMount() { 18 | // register listeners to listen for events from the html 19 | // we'll receive a nonce once the requestPaymentMethodComplete is completed 20 | this.registerMessageListeners(); 21 | console.log('wbvw braintree mounted'); 22 | } 23 | 24 | registerMessageListeners = () => { 25 | const { messagesChannel } = this.webview; 26 | 27 | messagesChannel.on('RETRIEVE_NONCE_PENDING', event => { 28 | this.setState({ showGetNonceActivityIndicator: true }); 29 | console.log('RETRIEVE_NONCE_PENDING'); 30 | }); 31 | 32 | messagesChannel.on('RETRIEVE_NONCE_FULFILLED', event => { 33 | console.log('RETRIEVE_NONCE_FULFILLED'); 34 | this.setState({ showGetNonceActivityIndicator: false }); 35 | this.setState({ showSubmitPaymentActivityIndicator: true }); 36 | this.props.nonceObtainedCallback(event.payload.response.nonce); 37 | }); 38 | 39 | messagesChannel.on('RETRIEVE_NONCE_REJECTED', event => { 40 | console.log('RETRIEVE_NONCE_REJECTED'); 41 | this.setState({ showGetNonceActivityIndicator: false }); 42 | }); 43 | 44 | messagesChannel.on('GO_BACK', () => { 45 | this.props.navigationBackCallback(); 46 | }); 47 | }; 48 | 49 | // send the client token to HTML file to begin the braintree flow 50 | // called when the HTML in the webview is loaded 51 | sendClientTokenToHTML = () => { 52 | this.webview.emit('TOKEN_RECEIVED', { 53 | payload: { 54 | clientToken: this.props.clientToken, 55 | options: this.props.options 56 | } 57 | }); 58 | }; 59 | 60 | // handle purchase responses that parent component sends after making purchase API call 61 | handlePurchaseResponse = response => { 62 | console.log('handlePurchaseResponse'); 63 | if (response === 'PAYMENT_SUCCESS') { 64 | console.log('emitting purchaseSuccess'); 65 | this.setState({ showSubmitPaymentActivityIndicator: false }); 66 | this.webview.emit('PURCHASE_FULFILLED'); 67 | } else { 68 | this.setState({ showSubmitPaymentActivityIndicator: false }); 69 | this.webview.emit('PURCHASE_REJECTED'); 70 | } 71 | }; 72 | 73 | componentWillReceiveProps = nextProps => { 74 | console.log({ nextProps }); 75 | if (nextProps.paymentAPIResponse !== this.state.paymentAPIResponse) { 76 | console.log(nextProps.paymentAPIResponse); 77 | this.setState({ paymentAPIResponse: nextProps.paymentAPIResponse }); 78 | this.handlePurchaseResponse(nextProps.paymentAPIResponse); 79 | } 80 | }; 81 | 82 | render() { 83 | return ( 84 | 90 | 97 | (this.webview = component)} 102 | scalesPageToFit ={false} 103 | /> 104 | 105 | {renderIf(this.state.showGetNonceActivityIndicator)( 106 | 107 | 108 | 113 | 114 | 115 | )} 116 | {renderIf(this.state.showSubmitPaymentActivityIndicator)( 117 | 118 | 119 | 124 | 125 | 126 | )} 127 | 128 | ); 129 | } 130 | } 131 | 132 | BraintreePaymentWebview.propTypes = { 133 | options: PropTypes.object, 134 | clientToken: PropTypes.string.isRequired, 135 | paymentAPIResponse: PropTypes.string.isRequired, 136 | nonceObtainedCallback: PropTypes.func.isRequired, 137 | navigationBackCallback: PropTypes.func 138 | }; 139 | 140 | const styles = StyleSheet.create({ 141 | activityOverlayStyle: { 142 | ...StyleSheet.absoluteFillObject, 143 | backgroundColor: 'rgba(150, 150, 150, .55)', 144 | marginHorizontal: 20, 145 | marginVertical: 60, 146 | display: 'flex', 147 | justifyContent: 'center', 148 | alignContent: 'center', 149 | borderRadius: 5 150 | }, 151 | activityIndicatorContainer: { 152 | backgroundColor: 'white', 153 | padding: 10, 154 | borderRadius: 50, 155 | alignSelf: 'center', 156 | shadowColor: '#000000', 157 | shadowOffset: { 158 | width: 0, 159 | height: 3 160 | }, 161 | shadowRadius: 5, 162 | shadowOpacity: 1.0 163 | } 164 | }); -------------------------------------------------------------------------------- /config/enzymeAdapter.js: -------------------------------------------------------------------------------- 1 | import Enzyme from 'enzyme'; 2 | import Adapter from 'enzyme-adapter-react-16'; 3 | 4 | Enzyme.configure({ adapter: new Adapter() }); -------------------------------------------------------------------------------- /coverage/clover.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /coverage/coverage-final.json: -------------------------------------------------------------------------------- 1 | {"C:\\Users\\regin\\OneDrive\\Development\\react-native-webview-braintree\\config\\enzymeAdapter.js": {"path":"C:\\Users\\regin\\OneDrive\\Development\\react-native-webview-braintree\\config\\enzymeAdapter.js","statementMap":{"0":{"start":{"line":4,"column":0},"end":{"line":4,"column":45}}},"fnMap":{},"branchMap":{},"s":{"0":1},"f":{},"b":{},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"020b47468cc9ea2c5e3a543012b5b1a601313027"} 2 | ,"C:\\Users\\regin\\OneDrive\\Development\\react-native-webview-braintree\\web\\braintreeReact.js": {"path":"C:\\Users\\regin\\OneDrive\\Development\\react-native-webview-braintree\\web\\braintreeReact.js","statementMap":{"0":{"start":{"line":9,"column":13},"end":{"line":9,"column":28}},"1":{"start":{"line":11,"column":24},"end":{"line":13,"column":2}},"2":{"start":{"line":14,"column":24},"end":{"line":16,"column":2}},"3":{"start":{"line":17,"column":15},"end":{"line":26,"column":2}},"4":{"start":{"line":27,"column":26},"end":{"line":35,"column":2}},"5":{"start":{"line":39,"column":21},"end":{"line":49,"column":1}},"6":{"start":{"line":40,"column":2},"end":{"line":48,"column":3}},"7":{"start":{"line":41,"column":13},"end":{"line":41,"column":42}},"8":{"start":{"line":42,"column":4},"end":{"line":42,"column":74}},"9":{"start":{"line":43,"column":4},"end":{"line":43,"column":56}},"10":{"start":{"line":44,"column":9},"end":{"line":48,"column":3}},"11":{"start":{"line":45,"column":13},"end":{"line":45,"column":42}},"12":{"start":{"line":46,"column":4},"end":{"line":46,"column":24}},"13":{"start":{"line":47,"column":4},"end":{"line":47,"column":56}},"14":{"start":{"line":53,"column":4},"end":{"line":53,"column":12}},"15":{"start":{"line":54,"column":4},"end":{"line":56,"column":6}},"16":{"start":{"line":61,"column":4},"end":{"line":61,"column":36}},"17":{"start":{"line":71,"column":4},"end":{"line":79,"column":7}},"18":{"start":{"line":73,"column":6},"end":{"line":75,"column":7}},"19":{"start":{"line":74,"column":8},"end":{"line":74,"column":59}},"20":{"start":{"line":76,"column":6},"end":{"line":78,"column":7}},"21":{"start":{"line":77,"column":8},"end":{"line":77,"column":55}},"22":{"start":{"line":83,"column":4},"end":{"line":86,"column":7}},"23":{"start":{"line":85,"column":6},"end":{"line":85,"column":68}},"24":{"start":{"line":90,"column":4},"end":{"line":93,"column":7}},"25":{"start":{"line":92,"column":6},"end":{"line":92,"column":68}},"26":{"start":{"line":97,"column":4},"end":{"line":100,"column":7}},"27":{"start":{"line":98,"column":6},"end":{"line":98,"column":67}},"28":{"start":{"line":99,"column":6},"end":{"line":99,"column":40}},"29":{"start":{"line":109,"column":4},"end":{"line":109,"column":34}},"30":{"start":{"line":118,"column":4},"end":{"line":132,"column":9}},"31":{"start":{"line":124,"column":8},"end":{"line":124,"column":36}},"32":{"start":{"line":128,"column":8},"end":{"line":131,"column":11}},"33":{"start":{"line":139,"column":4},"end":{"line":139,"column":63}},"34":{"start":{"line":143,"column":4},"end":{"line":147,"column":7}},"35":{"start":{"line":150,"column":4},"end":{"line":168,"column":7}},"36":{"start":{"line":151,"column":6},"end":{"line":167,"column":7}},"37":{"start":{"line":153,"column":8},"end":{"line":158,"column":11}},"38":{"start":{"line":161,"column":8},"end":{"line":166,"column":11}},"39":{"start":{"line":172,"column":4},"end":{"line":172,"column":37}},"40":{"start":{"line":176,"column":4},"end":{"line":215,"column":6}},"41":{"start":{"line":179,"column":10},"end":{"line":179,"column":40}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":39,"column":21},"end":{"line":39,"column":22}},"loc":{"start":{"line":39,"column":29},"end":{"line":49,"column":1}},"line":39},"1":{"name":"(anonymous_1)","decl":{"start":{"line":52,"column":2},"end":{"line":52,"column":3}},"loc":{"start":{"line":52,"column":16},"end":{"line":57,"column":3}},"line":52},"2":{"name":"(anonymous_2)","decl":{"start":{"line":59,"column":22},"end":{"line":59,"column":23}},"loc":{"start":{"line":59,"column":28},"end":{"line":62,"column":3}},"line":59},"3":{"name":"(anonymous_3)","decl":{"start":{"line":67,"column":29},"end":{"line":67,"column":30}},"loc":{"start":{"line":67,"column":35},"end":{"line":103,"column":3}},"line":67},"4":{"name":"(anonymous_4)","decl":{"start":{"line":71,"column":42},"end":{"line":71,"column":43}},"loc":{"start":{"line":71,"column":51},"end":{"line":79,"column":5}},"line":71},"5":{"name":"(anonymous_5)","decl":{"start":{"line":83,"column":44},"end":{"line":83,"column":45}},"loc":{"start":{"line":83,"column":53},"end":{"line":86,"column":5}},"line":83},"6":{"name":"(anonymous_6)","decl":{"start":{"line":90,"column":46},"end":{"line":90,"column":47}},"loc":{"start":{"line":90,"column":55},"end":{"line":93,"column":5}},"line":90},"7":{"name":"(anonymous_7)","decl":{"start":{"line":97,"column":45},"end":{"line":97,"column":46}},"loc":{"start":{"line":97,"column":54},"end":{"line":100,"column":5}},"line":97},"8":{"name":"(anonymous_8)","decl":{"start":{"line":108,"column":19},"end":{"line":108,"column":20}},"loc":{"start":{"line":108,"column":34},"end":{"line":110,"column":3}},"line":108},"9":{"name":"(anonymous_9)","decl":{"start":{"line":115,"column":23},"end":{"line":115,"column":24}},"loc":{"start":{"line":115,"column":38},"end":{"line":133,"column":3}},"line":115},"10":{"name":"(anonymous_10)","decl":{"start":{"line":123,"column":12},"end":{"line":123,"column":13}},"loc":{"start":{"line":123,"column":24},"end":{"line":125,"column":7}},"line":123},"11":{"name":"(anonymous_11)","decl":{"start":{"line":126,"column":13},"end":{"line":126,"column":14}},"loc":{"start":{"line":126,"column":27},"end":{"line":132,"column":7}},"line":126},"12":{"name":"(anonymous_12)","decl":{"start":{"line":137,"column":38},"end":{"line":137,"column":39}},"loc":{"start":{"line":137,"column":44},"end":{"line":169,"column":3}},"line":137},"13":{"name":"(anonymous_13)","decl":{"start":{"line":150,"column":45},"end":{"line":150,"column":46}},"loc":{"start":{"line":150,"column":69},"end":{"line":168,"column":5}},"line":150},"14":{"name":"(anonymous_14)","decl":{"start":{"line":171,"column":29},"end":{"line":171,"column":30}},"loc":{"start":{"line":171,"column":35},"end":{"line":173,"column":3}},"line":171},"15":{"name":"(anonymous_15)","decl":{"start":{"line":175,"column":11},"end":{"line":175,"column":12}},"loc":{"start":{"line":175,"column":17},"end":{"line":216,"column":3}},"line":175},"16":{"name":"(anonymous_16)","decl":{"start":{"line":178,"column":13},"end":{"line":178,"column":14}},"loc":{"start":{"line":178,"column":26},"end":{"line":180,"column":9}},"line":178}},"branchMap":{"0":{"loc":{"start":{"line":40,"column":2},"end":{"line":48,"column":3}},"type":"if","locations":[{"start":{"line":40,"column":2},"end":{"line":48,"column":3}},{"start":{"line":40,"column":2},"end":{"line":48,"column":3}}],"line":40},"1":{"loc":{"start":{"line":44,"column":9},"end":{"line":48,"column":3}},"type":"if","locations":[{"start":{"line":44,"column":9},"end":{"line":48,"column":3}},{"start":{"line":44,"column":9},"end":{"line":48,"column":3}}],"line":44},"2":{"loc":{"start":{"line":73,"column":6},"end":{"line":75,"column":7}},"type":"if","locations":[{"start":{"line":73,"column":6},"end":{"line":75,"column":7}},{"start":{"line":73,"column":6},"end":{"line":75,"column":7}}],"line":73},"3":{"loc":{"start":{"line":76,"column":6},"end":{"line":78,"column":7}},"type":"if","locations":[{"start":{"line":76,"column":6},"end":{"line":78,"column":7}},{"start":{"line":76,"column":6},"end":{"line":78,"column":7}}],"line":76},"4":{"loc":{"start":{"line":151,"column":6},"end":{"line":167,"column":7}},"type":"if","locations":[{"start":{"line":151,"column":6},"end":{"line":167,"column":7}},{"start":{"line":151,"column":6},"end":{"line":167,"column":7}}],"line":151}},"s":{"0":1,"1":1,"2":1,"3":1,"4":1,"5":1,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":2,"15":2,"16":2,"17":2,"18":0,"19":0,"20":0,"21":0,"22":2,"23":0,"24":2,"25":0,"26":2,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":2,"41":1},"f":{"0":0,"1":2,"2":2,"3":2,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":2,"16":1},"b":{"0":[0,0],"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0]},"_coverageSchema":"332fd63041d2c1bcb487cc26dd0d5f7d97098a6c","hash":"c8abaeea23b681d2e6eecd5ea0deb47a27d538f8"} 3 | } 4 | -------------------------------------------------------------------------------- /coverage/lcov-report/base.css: -------------------------------------------------------------------------------- 1 | body, html { 2 | margin:0; padding: 0; 3 | height: 100%; 4 | } 5 | body { 6 | font-family: Helvetica Neue, Helvetica, Arial; 7 | font-size: 14px; 8 | color:#333; 9 | } 10 | .small { font-size: 12px; } 11 | *, *:after, *:before { 12 | -webkit-box-sizing:border-box; 13 | -moz-box-sizing:border-box; 14 | box-sizing:border-box; 15 | } 16 | h1 { font-size: 20px; margin: 0;} 17 | h2 { font-size: 14px; } 18 | pre { 19 | font: 12px/1.4 Consolas, "Liberation Mono", Menlo, Courier, monospace; 20 | margin: 0; 21 | padding: 0; 22 | -moz-tab-size: 2; 23 | -o-tab-size: 2; 24 | tab-size: 2; 25 | } 26 | a { color:#0074D9; text-decoration:none; } 27 | a:hover { text-decoration:underline; } 28 | .strong { font-weight: bold; } 29 | .space-top1 { padding: 10px 0 0 0; } 30 | .pad2y { padding: 20px 0; } 31 | .pad1y { padding: 10px 0; } 32 | .pad2x { padding: 0 20px; } 33 | .pad2 { padding: 20px; } 34 | .pad1 { padding: 10px; } 35 | .space-left2 { padding-left:55px; } 36 | .space-right2 { padding-right:20px; } 37 | .center { text-align:center; } 38 | .clearfix { display:block; } 39 | .clearfix:after { 40 | content:''; 41 | display:block; 42 | height:0; 43 | clear:both; 44 | visibility:hidden; 45 | } 46 | .fl { float: left; } 47 | @media only screen and (max-width:640px) { 48 | .col3 { width:100%; max-width:100%; } 49 | .hide-mobile { display:none!important; } 50 | } 51 | 52 | .quiet { 53 | color: #7f7f7f; 54 | color: rgba(0,0,0,0.5); 55 | } 56 | .quiet a { opacity: 0.7; } 57 | 58 | .fraction { 59 | font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; 60 | font-size: 10px; 61 | color: #555; 62 | background: #E8E8E8; 63 | padding: 4px 5px; 64 | border-radius: 3px; 65 | vertical-align: middle; 66 | } 67 | 68 | div.path a:link, div.path a:visited { color: #333; } 69 | table.coverage { 70 | border-collapse: collapse; 71 | margin: 10px 0 0 0; 72 | padding: 0; 73 | } 74 | 75 | table.coverage td { 76 | margin: 0; 77 | padding: 0; 78 | vertical-align: top; 79 | } 80 | table.coverage td.line-count { 81 | text-align: right; 82 | padding: 0 5px 0 20px; 83 | } 84 | table.coverage td.line-coverage { 85 | text-align: right; 86 | padding-right: 10px; 87 | min-width:20px; 88 | } 89 | 90 | table.coverage td span.cline-any { 91 | display: inline-block; 92 | padding: 0 5px; 93 | width: 100%; 94 | } 95 | .missing-if-branch { 96 | display: inline-block; 97 | margin-right: 5px; 98 | border-radius: 3px; 99 | position: relative; 100 | padding: 0 4px; 101 | background: #333; 102 | color: yellow; 103 | } 104 | 105 | .skip-if-branch { 106 | display: none; 107 | margin-right: 10px; 108 | position: relative; 109 | padding: 0 4px; 110 | background: #ccc; 111 | color: white; 112 | } 113 | .missing-if-branch .typ, .skip-if-branch .typ { 114 | color: inherit !important; 115 | } 116 | .coverage-summary { 117 | border-collapse: collapse; 118 | width: 100%; 119 | } 120 | .coverage-summary tr { border-bottom: 1px solid #bbb; } 121 | .keyline-all { border: 1px solid #ddd; } 122 | .coverage-summary td, .coverage-summary th { padding: 10px; } 123 | .coverage-summary tbody { border: 1px solid #bbb; } 124 | .coverage-summary td { border-right: 1px solid #bbb; } 125 | .coverage-summary td:last-child { border-right: none; } 126 | .coverage-summary th { 127 | text-align: left; 128 | font-weight: normal; 129 | white-space: nowrap; 130 | } 131 | .coverage-summary th.file { border-right: none !important; } 132 | .coverage-summary th.pct { } 133 | .coverage-summary th.pic, 134 | .coverage-summary th.abs, 135 | .coverage-summary td.pct, 136 | .coverage-summary td.abs { text-align: right; } 137 | .coverage-summary td.file { white-space: nowrap; } 138 | .coverage-summary td.pic { min-width: 120px !important; } 139 | .coverage-summary tfoot td { } 140 | 141 | .coverage-summary .sorter { 142 | height: 10px; 143 | width: 7px; 144 | display: inline-block; 145 | margin-left: 0.5em; 146 | background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent; 147 | } 148 | .coverage-summary .sorted .sorter { 149 | background-position: 0 -20px; 150 | } 151 | .coverage-summary .sorted-desc .sorter { 152 | background-position: 0 -10px; 153 | } 154 | .status-line { height: 10px; } 155 | /* dark red */ 156 | .red.solid, .status-line.low, .low .cover-fill { background:#C21F39 } 157 | .low .chart { border:1px solid #C21F39 } 158 | /* medium red */ 159 | .cstat-no, .fstat-no, .cbranch-no, .cbranch-no { background:#F6C6CE } 160 | /* light red */ 161 | .low, .cline-no { background:#FCE1E5 } 162 | /* light green */ 163 | .high, .cline-yes { background:rgb(230,245,208) } 164 | /* medium green */ 165 | .cstat-yes { background:rgb(161,215,106) } 166 | /* dark green */ 167 | .status-line.high, .high .cover-fill { background:rgb(77,146,33) } 168 | .high .chart { border:1px solid rgb(77,146,33) } 169 | 170 | 171 | .medium .chart { border:1px solid #666; } 172 | .medium .cover-fill { background: #666; } 173 | 174 | .cbranch-no { background: yellow !important; color: #111; } 175 | 176 | .cstat-skip { background: #ddd; color: #111; } 177 | .fstat-skip { background: #ddd; color: #111 !important; } 178 | .cbranch-skip { background: #ddd !important; color: #111; } 179 | 180 | span.cline-neutral { background: #eaeaea; } 181 | .medium { background: #eaeaea; } 182 | 183 | .cover-fill, .cover-empty { 184 | display:inline-block; 185 | height: 12px; 186 | } 187 | .chart { 188 | line-height: 0; 189 | } 190 | .cover-empty { 191 | background: white; 192 | } 193 | .cover-full { 194 | border-right: none !important; 195 | } 196 | pre.prettyprint { 197 | border: none !important; 198 | padding: 0 !important; 199 | margin: 0 !important; 200 | } 201 | .com { color: #999 !important; } 202 | .ignore-none { color: #999; font-weight: normal; } 203 | 204 | .wrapper { 205 | min-height: 100%; 206 | height: auto !important; 207 | height: 100%; 208 | margin: 0 auto -48px; 209 | } 210 | .footer, .push { 211 | height: 48px; 212 | } 213 | -------------------------------------------------------------------------------- /coverage/lcov-report/config/enzymeAdapter.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for config/enzymeAdapter.js 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | All files / config enzymeAdapter.js 20 |

21 |
22 |
23 | 100% 24 | Statements 25 | 1/1 26 |
27 |
28 | 100% 29 | Branches 30 | 0/0 31 |
32 |
33 | 100% 34 | Functions 35 | 0/0 36 |
37 |
38 | 100% 39 | Lines 40 | 1/1 41 |
42 |
43 |
44 |
45 |

46 | 
56 | 
1 47 | 2 48 | 3 49 | 4  50 |   51 |   52 | 1x
import Enzyme from 'enzyme';
53 | import Adapter from 'enzyme-adapter-react-16';
54 |  
55 | Enzyme.configure({ adapter: new Adapter() });
57 |
58 |
59 | 63 | 64 | 65 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /coverage/lcov-report/config/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for config 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | All files config 20 |

21 |
22 |
23 | 100% 24 | Statements 25 | 1/1 26 |
27 |
28 | 100% 29 | Branches 30 | 0/0 31 |
32 |
33 | 100% 34 | Functions 35 | 0/0 36 |
37 |
38 | 100% 39 | Lines 40 | 1/1 41 |
42 |
43 |
44 |
45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
FileStatementsBranchesFunctionsLines
enzymeAdapter.js
100%1/1100%0/0100%0/0100%1/1
76 |
77 |
78 | 82 | 83 | 84 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /coverage/lcov-report/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for All files 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | All files 20 |

21 |
22 |
23 | 37.21% 24 | Statements 25 | 16/43 26 |
27 |
28 | 0% 29 | Branches 30 | 0/10 31 |
32 |
33 | 29.41% 34 | Functions 35 | 5/17 36 |
37 |
38 | 37.21% 39 | Lines 40 | 16/43 41 |
42 |
43 |
44 |
45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 |
FileStatementsBranchesFunctionsLines
config
100%1/1100%0/0100%0/0100%1/1
web
35.71%15/420%0/1029.41%5/1735.71%15/42
89 |
90 |
91 | 95 | 96 | 97 | 104 | 105 | 106 | 107 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.css: -------------------------------------------------------------------------------- 1 | .pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/prettify.js: -------------------------------------------------------------------------------- 1 | window.PR_SHOULD_USE_CONTINUATION=true;(function(){var h=["break,continue,do,else,for,if,return,while"];var u=[h,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var p=[u,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var l=[p,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var x=[p,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var R=[x,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var"];var r="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,true,try,unless,until,when,while,yes";var w=[p,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var s="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var I=[h,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var f=[h,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var H=[h,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var A=[l,R,w,s+I,f,H];var e=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)/;var C="str";var z="kwd";var j="com";var O="typ";var G="lit";var L="pun";var F="pln";var m="tag";var E="dec";var J="src";var P="atn";var n="atv";var N="nocode";var M="(?:^^\\.?|[+-]|\\!|\\!=|\\!==|\\#|\\%|\\%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|\\,|\\-=|\\->|\\/|\\/=|:|::|\\;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|\\?|\\@|\\[|\\^|\\^=|\\^\\^|\\^\\^=|\\{|\\||\\|=|\\|\\||\\|\\|=|\\~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function k(Z){var ad=0;var S=false;var ac=false;for(var V=0,U=Z.length;V122)){if(!(al<65||ag>90)){af.push([Math.max(65,ag)|32,Math.min(al,90)|32])}if(!(al<97||ag>122)){af.push([Math.max(97,ag)&~32,Math.min(al,122)&~32])}}}}af.sort(function(av,au){return(av[0]-au[0])||(au[1]-av[1])});var ai=[];var ap=[NaN,NaN];for(var ar=0;arat[0]){if(at[1]+1>at[0]){an.push("-")}an.push(T(at[1]))}}an.push("]");return an.join("")}function W(al){var aj=al.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var ah=aj.length;var an=[];for(var ak=0,am=0;ak=2&&ai==="["){aj[ak]=X(ag)}else{if(ai!=="\\"){aj[ak]=ag.replace(/[a-zA-Z]/g,function(ao){var ap=ao.charCodeAt(0);return"["+String.fromCharCode(ap&~32,ap|32)+"]"})}}}}return aj.join("")}var aa=[];for(var V=0,U=Z.length;V=0;){S[ac.charAt(ae)]=Y}}var af=Y[1];var aa=""+af;if(!ag.hasOwnProperty(aa)){ah.push(af);ag[aa]=null}}ah.push(/[\0-\uffff]/);V=k(ah)})();var X=T.length;var W=function(ah){var Z=ah.sourceCode,Y=ah.basePos;var ad=[Y,F];var af=0;var an=Z.match(V)||[];var aj={};for(var ae=0,aq=an.length;ae=5&&"lang-"===ap.substring(0,5);if(am&&!(ai&&typeof ai[1]==="string")){am=false;ap=J}if(!am){aj[ag]=ap}}var ab=af;af+=ag.length;if(!am){ad.push(Y+ab,ap)}else{var al=ai[1];var ak=ag.indexOf(al);var ac=ak+al.length;if(ai[2]){ac=ag.length-ai[2].length;ak=ac-al.length}var ar=ap.substring(5);B(Y+ab,ag.substring(0,ak),W,ad);B(Y+ab+ak,al,q(ar,al),ad);B(Y+ab+ac,ag.substring(ac),W,ad)}}ah.decorations=ad};return W}function i(T){var W=[],S=[];if(T.tripleQuotedStrings){W.push([C,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(T.multiLineStrings){W.push([C,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{W.push([C,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(T.verbatimStrings){S.push([C,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var Y=T.hashComments;if(Y){if(T.cStyleComments){if(Y>1){W.push([j,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{W.push([j,/^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}S.push([C,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h|[a-z]\w*)>/,null])}else{W.push([j,/^#[^\r\n]*/,null,"#"])}}if(T.cStyleComments){S.push([j,/^\/\/[^\r\n]*/,null]);S.push([j,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(T.regexLiterals){var X=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");S.push(["lang-regex",new RegExp("^"+M+"("+X+")")])}var V=T.types;if(V){S.push([O,V])}var U=(""+T.keywords).replace(/^ | $/g,"");if(U.length){S.push([z,new RegExp("^(?:"+U.replace(/[\s,]+/g,"|")+")\\b"),null])}W.push([F,/^\s+/,null," \r\n\t\xA0"]);S.push([G,/^@[a-z_$][a-z_$@0-9]*/i,null],[O,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[F,/^[a-z_$][a-z_$@0-9]*/i,null],[G,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[F,/^\\[\s\S]?/,null],[L,/^.[^\s\w\.$@\'\"\`\/\#\\]*/,null]);return g(W,S)}var K=i({keywords:A,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function Q(V,ag){var U=/(?:^|\s)nocode(?:\s|$)/;var ab=/\r\n?|\n/;var ac=V.ownerDocument;var S;if(V.currentStyle){S=V.currentStyle.whiteSpace}else{if(window.getComputedStyle){S=ac.defaultView.getComputedStyle(V,null).getPropertyValue("white-space")}}var Z=S&&"pre"===S.substring(0,3);var af=ac.createElement("LI");while(V.firstChild){af.appendChild(V.firstChild)}var W=[af];function ae(al){switch(al.nodeType){case 1:if(U.test(al.className)){break}if("BR"===al.nodeName){ad(al);if(al.parentNode){al.parentNode.removeChild(al)}}else{for(var an=al.firstChild;an;an=an.nextSibling){ae(an)}}break;case 3:case 4:if(Z){var am=al.nodeValue;var aj=am.match(ab);if(aj){var ai=am.substring(0,aj.index);al.nodeValue=ai;var ah=am.substring(aj.index+aj[0].length);if(ah){var ak=al.parentNode;ak.insertBefore(ac.createTextNode(ah),al.nextSibling)}ad(al);if(!ai){al.parentNode.removeChild(al)}}}break}}function ad(ak){while(!ak.nextSibling){ak=ak.parentNode;if(!ak){return}}function ai(al,ar){var aq=ar?al.cloneNode(false):al;var ao=al.parentNode;if(ao){var ap=ai(ao,1);var an=al.nextSibling;ap.appendChild(aq);for(var am=an;am;am=an){an=am.nextSibling;ap.appendChild(am)}}return aq}var ah=ai(ak.nextSibling,0);for(var aj;(aj=ah.parentNode)&&aj.nodeType===1;){ah=aj}W.push(ah)}for(var Y=0;Y=S){ah+=2}if(V>=ap){Z+=2}}}var t={};function c(U,V){for(var S=V.length;--S>=0;){var T=V[S];if(!t.hasOwnProperty(T)){t[T]=U}else{if(window.console){console.warn("cannot override language handler %s",T)}}}}function q(T,S){if(!(T&&t.hasOwnProperty(T))){T=/^\s*]*(?:>|$)/],[j,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[L,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);c(g([[F,/^[\s]+/,null," \t\r\n"],[n,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[m,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[P,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[L,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);c(g([],[[n,/^[\s\S]+/]]),["uq.val"]);c(i({keywords:l,hashComments:true,cStyleComments:true,types:e}),["c","cc","cpp","cxx","cyc","m"]);c(i({keywords:"null,true,false"}),["json"]);c(i({keywords:R,hashComments:true,cStyleComments:true,verbatimStrings:true,types:e}),["cs"]);c(i({keywords:x,cStyleComments:true}),["java"]);c(i({keywords:H,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);c(i({keywords:I,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);c(i({keywords:s,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);c(i({keywords:f,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);c(i({keywords:w,cStyleComments:true,regexLiterals:true}),["js"]);c(i({keywords:r,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);c(g([],[[C,/^[\s\S]+/]]),["regex"]);function d(V){var U=V.langExtension;try{var S=a(V.sourceNode);var T=S.sourceCode;V.sourceCode=T;V.spans=S.spans;V.basePos=0;q(U,T)(V);D(V)}catch(W){if("console" in window){console.log(W&&W.stack?W.stack:W)}}}function y(W,V,U){var S=document.createElement("PRE");S.innerHTML=W;if(U){Q(S,U)}var T={langExtension:V,numberLines:U,sourceNode:S};d(T);return S.innerHTML}function b(ad){function Y(af){return document.getElementsByTagName(af)}var ac=[Y("pre"),Y("code"),Y("xmp")];var T=[];for(var aa=0;aa=0){var ah=ai.match(ab);var am;if(!ah&&(am=o(aj))&&"CODE"===am.tagName){ah=am.className.match(ab)}if(ah){ah=ah[1]}var al=false;for(var ak=aj.parentNode;ak;ak=ak.parentNode){if((ak.tagName==="pre"||ak.tagName==="code"||ak.tagName==="xmp")&&ak.className&&ak.className.indexOf("prettyprint")>=0){al=true;break}}if(!al){var af=aj.className.match(/\blinenums\b(?::(\d+))?/);af=af?af[1]&&af[1].length?+af[1]:true:false;if(af){Q(aj,af)}S={langExtension:ah,sourceNode:aj,numberLines:af};d(S)}}}if(X]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); 2 | -------------------------------------------------------------------------------- /coverage/lcov-report/sort-arrow-sprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/reggie3/react-native-webview-braintree/03587490bb9bc5caad93a5bca5975e50ad41f148/coverage/lcov-report/sort-arrow-sprite.png -------------------------------------------------------------------------------- /coverage/lcov-report/sorter.js: -------------------------------------------------------------------------------- 1 | var addSorting = (function () { 2 | "use strict"; 3 | var cols, 4 | currentSort = { 5 | index: 0, 6 | desc: false 7 | }; 8 | 9 | // returns the summary table element 10 | function getTable() { return document.querySelector('.coverage-summary'); } 11 | // returns the thead element of the summary table 12 | function getTableHeader() { return getTable().querySelector('thead tr'); } 13 | // returns the tbody element of the summary table 14 | function getTableBody() { return getTable().querySelector('tbody'); } 15 | // returns the th element for nth column 16 | function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; } 17 | 18 | // loads all columns 19 | function loadColumns() { 20 | var colNodes = getTableHeader().querySelectorAll('th'), 21 | colNode, 22 | cols = [], 23 | col, 24 | i; 25 | 26 | for (i = 0; i < colNodes.length; i += 1) { 27 | colNode = colNodes[i]; 28 | col = { 29 | key: colNode.getAttribute('data-col'), 30 | sortable: !colNode.getAttribute('data-nosort'), 31 | type: colNode.getAttribute('data-type') || 'string' 32 | }; 33 | cols.push(col); 34 | if (col.sortable) { 35 | col.defaultDescSort = col.type === 'number'; 36 | colNode.innerHTML = colNode.innerHTML + ''; 37 | } 38 | } 39 | return cols; 40 | } 41 | // attaches a data attribute to every tr element with an object 42 | // of data values keyed by column name 43 | function loadRowData(tableRow) { 44 | var tableCols = tableRow.querySelectorAll('td'), 45 | colNode, 46 | col, 47 | data = {}, 48 | i, 49 | val; 50 | for (i = 0; i < tableCols.length; i += 1) { 51 | colNode = tableCols[i]; 52 | col = cols[i]; 53 | val = colNode.getAttribute('data-value'); 54 | if (col.type === 'number') { 55 | val = Number(val); 56 | } 57 | data[col.key] = val; 58 | } 59 | return data; 60 | } 61 | // loads all row data 62 | function loadData() { 63 | var rows = getTableBody().querySelectorAll('tr'), 64 | i; 65 | 66 | for (i = 0; i < rows.length; i += 1) { 67 | rows[i].data = loadRowData(rows[i]); 68 | } 69 | } 70 | // sorts the table using the data for the ith column 71 | function sortByIndex(index, desc) { 72 | var key = cols[index].key, 73 | sorter = function (a, b) { 74 | a = a.data[key]; 75 | b = b.data[key]; 76 | return a < b ? -1 : a > b ? 1 : 0; 77 | }, 78 | finalSorter = sorter, 79 | tableBody = document.querySelector('.coverage-summary tbody'), 80 | rowNodes = tableBody.querySelectorAll('tr'), 81 | rows = [], 82 | i; 83 | 84 | if (desc) { 85 | finalSorter = function (a, b) { 86 | return -1 * sorter(a, b); 87 | }; 88 | } 89 | 90 | for (i = 0; i < rowNodes.length; i += 1) { 91 | rows.push(rowNodes[i]); 92 | tableBody.removeChild(rowNodes[i]); 93 | } 94 | 95 | rows.sort(finalSorter); 96 | 97 | for (i = 0; i < rows.length; i += 1) { 98 | tableBody.appendChild(rows[i]); 99 | } 100 | } 101 | // removes sort indicators for current column being sorted 102 | function removeSortIndicators() { 103 | var col = getNthColumn(currentSort.index), 104 | cls = col.className; 105 | 106 | cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, ''); 107 | col.className = cls; 108 | } 109 | // adds sort indicators for current column being sorted 110 | function addSortIndicators() { 111 | getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted'; 112 | } 113 | // adds event listeners for all sorter widgets 114 | function enableUI() { 115 | var i, 116 | el, 117 | ithSorter = function ithSorter(i) { 118 | var col = cols[i]; 119 | 120 | return function () { 121 | var desc = col.defaultDescSort; 122 | 123 | if (currentSort.index === i) { 124 | desc = !currentSort.desc; 125 | } 126 | sortByIndex(i, desc); 127 | removeSortIndicators(); 128 | currentSort.index = i; 129 | currentSort.desc = desc; 130 | addSortIndicators(); 131 | }; 132 | }; 133 | for (i =0 ; i < cols.length; i += 1) { 134 | if (cols[i].sortable) { 135 | // add the click event handler on the th so users 136 | // dont have to click on those tiny arrows 137 | el = getNthColumn(i).querySelector('.sorter').parentElement; 138 | if (el.addEventListener) { 139 | el.addEventListener('click', ithSorter(i)); 140 | } else { 141 | el.attachEvent('onclick', ithSorter(i)); 142 | } 143 | } 144 | } 145 | } 146 | // adds sorting functionality to the UI 147 | return function () { 148 | if (!getTable()) { 149 | return; 150 | } 151 | cols = loadColumns(); 152 | loadData(cols); 153 | addSortIndicators(); 154 | enableUI(); 155 | }; 156 | })(); 157 | 158 | window.addEventListener('load', addSorting); 159 | -------------------------------------------------------------------------------- /coverage/lcov-report/web/braintreeReact.js.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for web/braintreeReact.js 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | All files / web braintreeReact.js 20 |

21 |
22 |
23 | 35.71% 24 | Statements 25 | 15/42 26 |
27 |
28 | 0% 29 | Branches 30 | 0/10 31 |
32 |
33 | 29.41% 34 | Functions 35 | 5/17 36 |
37 |
38 | 35.71% 39 | Lines 40 | 15/42 41 |
42 |
43 |
44 |
45 |

 46 | 
701 | 
1 47 | 2 48 | 3 49 | 4 50 | 5 51 | 6 52 | 7 53 | 8 54 | 9 55 | 10 56 | 11 57 | 12 58 | 13 59 | 14 60 | 15 61 | 16 62 | 17 63 | 18 64 | 19 65 | 20 66 | 21 67 | 22 68 | 23 69 | 24 70 | 25 71 | 26 72 | 27 73 | 28 74 | 29 75 | 30 76 | 31 77 | 32 78 | 33 79 | 34 80 | 35 81 | 36 82 | 37 83 | 38 84 | 39 85 | 40 86 | 41 87 | 42 88 | 43 89 | 44 90 | 45 91 | 46 92 | 47 93 | 48 94 | 49 95 | 50 96 | 51 97 | 52 98 | 53 99 | 54 100 | 55 101 | 56 102 | 57 103 | 58 104 | 59 105 | 60 106 | 61 107 | 62 108 | 63 109 | 64 110 | 65 111 | 66 112 | 67 113 | 68 114 | 69 115 | 70 116 | 71 117 | 72 118 | 73 119 | 74 120 | 75 121 | 76 122 | 77 123 | 78 124 | 79 125 | 80 126 | 81 127 | 82 128 | 83 129 | 84 130 | 85 131 | 86 132 | 87 133 | 88 134 | 89 135 | 90 136 | 91 137 | 92 138 | 93 139 | 94 140 | 95 141 | 96 142 | 97 143 | 98 144 | 99 145 | 100 146 | 101 147 | 102 148 | 103 149 | 104 150 | 105 151 | 106 152 | 107 153 | 108 154 | 109 155 | 110 156 | 111 157 | 112 158 | 113 159 | 114 160 | 115 161 | 116 162 | 117 163 | 118 164 | 119 165 | 120 166 | 121 167 | 122 168 | 123 169 | 124 170 | 125 171 | 126 172 | 127 173 | 128 174 | 129 175 | 130 176 | 131 177 | 132 178 | 133 179 | 134 180 | 135 181 | 136 182 | 137 183 | 138 184 | 139 185 | 140 186 | 141 187 | 142 188 | 143 189 | 144 190 | 145 191 | 146 192 | 147 193 | 148 194 | 149 195 | 150 196 | 151 197 | 152 198 | 153 199 | 154 200 | 155 201 | 156 202 | 157 203 | 158 204 | 159 205 | 160 206 | 161 207 | 162 208 | 163 209 | 164 210 | 165 211 | 166 212 | 167 213 | 168 214 | 169 215 | 170 216 | 171 217 | 172 218 | 173 219 | 174 220 | 175 221 | 176 222 | 177 223 | 178 224 | 179 225 | 180 226 | 181 227 | 182 228 | 183 229 | 184 230 | 185 231 | 186 232 | 187 233 | 188 234 | 189 235 | 190 236 | 191 237 | 192 238 | 193 239 | 194 240 | 195 241 | 196 242 | 197 243 | 198 244 | 199 245 | 200 246 | 201 247 | 202 248 | 203 249 | 204 250 | 205 251 | 206 252 | 207 253 | 208 254 | 209 255 | 210 256 | 211 257 | 212 258 | 213 259 | 214 260 | 215 261 | 216 262 | 217 263 | 218 264 | 219  265 |   266 |   267 |   268 |   269 |   270 |   271 |   272 | 1x 273 |   274 | 1x 275 |   276 |   277 | 1x 278 |   279 |   280 | 1x 281 |   282 |   283 |   284 |   285 |   286 |   287 |   288 |   289 |   290 | 1x 291 |   292 |   293 |   294 |   295 |   296 |   297 |   298 |   299 |   300 |   301 |   302 | 1x 303 |   304 |   305 |   306 |   307 |   308 |   309 |   310 |   311 |   312 |   313 |   314 |   315 |   316 | 2x 317 | 2x 318 |   319 |   320 |   321 |   322 |   323 |   324 | 2x 325 |   326 |   327 |   328 |   329 |   330 |   331 |   332 |   333 |   334 | 2x 335 |   336 |   337 |   338 |   339 |   340 |   341 |   342 |   343 |   344 |   345 |   346 | 2x 347 |   348 |   349 |   350 |   351 |   352 |   353 | 2x 354 |   355 |   356 |   357 |   358 |   359 |   360 | 2x 361 |   362 |   363 |   364 |   365 |   366 |   367 |   368 |   369 |   370 |   371 |   372 |   373 |   374 |   375 |   376 |   377 |   378 |   379 |   380 |   381 |   382 |   383 |   384 |   385 |   386 |   387 |   388 |   389 |   390 |   391 |   392 |   393 |   394 |   395 |   396 |   397 |   398 |   399 |   400 |   401 |   402 |   403 |   404 |   405 |   406 |   407 |   408 |   409 |   410 |   411 |   412 |   413 |   414 |   415 |   416 |   417 |   418 |   419 |   420 |   421 |   422 |   423 |   424 |   425 |   426 |   427 |   428 |   429 |   430 |   431 |   432 |   433 |   434 |   435 |   436 |   437 |   438 |   439 | 2x 440 |   441 |   442 | 1x 443 |   444 |   445 |   446 |   447 |   448 |   449 |   450 |   451 |   452 |   453 |   454 |   455 |   456 |   457 |   458 |   459 |   460 |   461 |   462 |   463 |   464 |   465 |   466 |   467 |   468 |   469 |   470 |   471 |   472 |   473 |   474 |   475 |   476 |   477 |   478 |   479 |   480 |   481 |   482 |  
// download and use react an react-dom from local directory
483 | // to avoid conflicts with Expo version of react
484 | import React from "react";
485 |  
486 | import renderIf from "render-if";
487 | import dropin from "braintree-web-drop-in";
488 | import glamorous from "glamorous";
489 | import RNMessageChannel from "react-native-webview-messaging";
490 | const util = require("util");
491 |  
492 | const DropInContainer = glamorous.div({
493 |   flex: 1
494 | });
495 | const ButtonContainer = glamorous.div({
496 |   flex: 1
497 | });
498 | const Button = glamorous.div({
499 |   borderRadius: "2px",
500 |   padding: "2px 10px 2px 10px",
501 |   backgroundColor: "#2ecc71",
502 |   fontSize: "1.25em",
503 |   color: "white",
504 |   fontFamily: "arial",
505 |   boxShadow: "0 1px 4px rgba(0, 0, 0, .6)",
506 |   textAlign: "center"
507 | });
508 | const PaymentBackground = glamorous.div({
509 |   position: "absolute",
510 |   top: 0,
511 |   bottom: 0,
512 |   left: 0,
513 |   right: 0,
514 |   display: "flex",
515 |   flexDirection: "column"
516 | });
517 |  
518 | // print passed information in an html element; useful for debugging
519 | // since console.log and debug statements won't work in a conventional way
520 | const PrintElement = data => {
521 |   if (typeof data === "object") {
522 |     let el = document.createElement("pre");
523 |     el.innerHTML = util.inspect(data, { showHidden: false, depth: null });
524 |     document.getElementById("messages").appendChild(el);
525 |   } else if (typeof data === "string") {
526 |     let el = document.createElement("pre");
527 |     el.innerHTML = data;
528 |     document.getElementById("messages").appendChild(el);
529 |   }
530 | };
531 |  
532 | export default class BraintreeReact extends React.Component {
533 |   constructor() {
534 |     super();
535 |     this.state = {
536 |       currentPaymentStatus: null
537 |     };
538 |   }
539 |  
540 |   componentDidMount = () => {
541 |     // PrintElement("componentDidMount success");
542 |     this.registerMessageListeners();
543 |   };
544 |  
545 |   /*******************************
546 |    * register message listeners to receive events from parent
547 |   */
548 |   registerMessageListeners = () => {
549 |     // PrintElement("registering message listeners");
550 |  
551 |     // will receive client token as a prop immediately upon mounting
552 |     RNMessageChannel.on("TOKEN_RECEIVED", event => {
553 |       //PrintElement(event);
554 |       if (event.payload.options.creditCard) {
555 |         this.createCreditCardUI(event.payload.clientToken);
556 |       }
557 |       if (event.payload.options.paypal) {
558 |         this.createPaypalUI(event.payload.clientToken);
559 |       }
560 |     });
561 |  
562 |     // when the call is made to the braintree purchasing server
563 |     // used to show the user some feedback that the purchase is in process
564 |     RNMessageChannel.on("PURCHASE_PENDING", event => {
565 |       // PrintElement("PURCHASE_PENDING");
566 |       this.setState({ currentPaymentStatus: "PURCHASE_FULFILLED" });
567 |     });
568 |  
569 |     // when the purchase succeeds
570 |     // used to show the user some feedback that the purchase has completed successfully
571 |     RNMessageChannel.on("PURCHASE_FULFILLED", event => {
572 |       //PrintElement("PURCHASE_FULFILLED");
573 |       this.setState({ currentPaymentStatus: "PURCHASE_FULFILLED" });
574 |     });
575 |  
576 |     // when the purchase succeeds
577 |     // used to show the user some feedback that the purchase has failed to complete
578 |     RNMessageChannel.on("PURCHASE_REJECTED", event => {
579 |       this.setState({ currentPaymentStatus: "PURCHASE_REJECTED" });
580 |       PrintElement("PURCHASE_REJECTED");
581 |     });
582 |  
583 |     // PrintElement("registering message listeners - completed");
584 |   };
585 |  
586 |   /*******************************
587 |    * create the Paypal payment UI element
588 |   */
589 |   createPaypalUI = clientToken => {
590 |     console.log("Not implmented");
591 |   };
592 |  
593 |   /*******************************
594 |    * create the Braintree UI element
595 |   */
596 |   createCreditCardUI = clientToken => {
597 |     //PrintElement(`createCreditCardUI: ${clientToken}`);
598 |  
599 |     dropin
600 |       .create({
601 |         authorization: clientToken,
602 |         container: "#dropin-container"
603 |       })
604 |       .then(instance => {
605 |         this.setState({ instance });
606 |       })
607 |       .catch(function(err) {
608 |         // Handle any errors that might've occurred when creating Drop-in
609 |         RNMessageChannel.sendJSON({
610 |           type: "error",
611 |           err
612 |         });
613 |       });
614 |   };
615 |   /***********************************************
616 |   *  handler for when the purchase button is clicke
617 |   */
618 |   handleSubmitPurchaseButtonClicked = () => {
619 |     // PrintElement(`handleSubmitPurchaseButtonClicked: ${this.state.instance}`);
620 |     this.setState({ currentPaymentStatus: "PAYMENT_PENDING" });
621 |  
622 |     // send a message to the parent WebView so that it
623 |     // can display feedback to user
624 |     RNMessageChannel.emit("RETRIEVE_NONCE_PENDING", {
625 |       payload: {
626 |         type: "success"
627 |       }
628 |     });
629 |  
630 |     // request a purchase nonce from the Braintree server
631 |     this.state.instance.requestPaymentMethod(function(err, response) {
632 |       if (err) {
633 |         // notify the parent WebView if there is an error
634 |         RNMessageChannel.emit("RETRIEVE_NONCE_REJECTED", {
635 |           payload: {
636 |             type: "error",
637 |             err
638 |           }
639 |         });
640 |       } else {
641 |         // pass the nonce to the parent WebView if the purchase is successful
642 |         RNMessageChannel.emit("RETRIEVE_NONCE_FULFILLED", {
643 |           payload: {
644 |             type: "success",
645 |             response
646 |           }
647 |         });
648 |       }
649 |     });
650 |   };
651 |  
652 |   handleGoBackButtonSubmit = () => {
653 |     RNMessageChannel.emit("GO_BACK");
654 |   };
655 |  
656 |   render = () => {
657 |     return (
658 |       <PaymentBackground
659 |         ref={component => {
660 |           this.webComponent = component;
661 |         }}
662 |       >
663 |         <DropInContainer>
664 |           <div id="dropin-container" />
665 |         </DropInContainer>
666 |         <ButtonContainer>
667 |           {renderIf(this.state.currentPaymentStatus === null)(
668 |             <Button
669 |               id="submit-button"
670 |               onClick={this.handleSubmitPurchaseButtonClicked}
671 |             >
672 |               Submit Purchase
673 |             </Button>
674 |           )}
675 |           {renderIf(this.state.currentPaymentStatus === "PURCHASE_FULFILLED")(
676 |             <div>
677 |               <div>Thank you for your purchase! </div>
678 |               <Button onClick={this.handleGoBackButtonSubmit}>
679 |                 Return to Shop
680 |               </Button>
681 |             </div>
682 |           )}
683 |           {renderIf(this.state.currentPaymentStatus === "PURCHASE_REJECTED")(
684 |             <div>
685 |               <div>
686 |                 There was a problem with your purchase, please try again
687 |               </div>
688 |               <Button onClick={this.handleGoBackButtonSubmit}>
689 |                 Return to Shop
690 |               </Button>
691 |             </div>
692 |           )}
693 |           <div id="messages" />
694 |         </ButtonContainer>
695 |       </PaymentBackground>
696 |     );
697 |   };
698 | }
699 |  
700 |  
702 |
703 |
704 | 708 | 709 | 710 | 717 | 718 | 719 | 720 | -------------------------------------------------------------------------------- /coverage/lcov-report/web/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Code coverage report for web 5 | 6 | 7 | 8 | 9 | 14 | 15 | 16 |
17 |
18 |

19 | All files web 20 |

21 |
22 |
23 | 35.71% 24 | Statements 25 | 15/42 26 |
27 |
28 | 0% 29 | Branches 30 | 0/10 31 |
32 |
33 | 29.41% 34 | Functions 35 | 5/17 36 |
37 |
38 | 35.71% 39 | Lines 40 | 15/42 41 |
42 |
43 |
44 |
45 |
46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 |
FileStatementsBranchesFunctionsLines
braintreeReact.js
35.71%15/420%0/1029.41%5/1735.71%15/42
76 |
77 |
78 | 82 | 83 | 84 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /coverage/lcov.info: -------------------------------------------------------------------------------- 1 | TN: 2 | SF:C:\Users\regin\OneDrive\Development\react-native-webview-braintree\config\enzymeAdapter.js 3 | FNF:0 4 | FNH:0 5 | DA:4,1 6 | LF:1 7 | LH:1 8 | BRF:0 9 | BRH:0 10 | end_of_record 11 | TN: 12 | SF:C:\Users\regin\OneDrive\Development\react-native-webview-braintree\web\braintreeReact.js 13 | FN:39,(anonymous_0) 14 | FN:52,(anonymous_1) 15 | FN:59,(anonymous_2) 16 | FN:67,(anonymous_3) 17 | FN:71,(anonymous_4) 18 | FN:83,(anonymous_5) 19 | FN:90,(anonymous_6) 20 | FN:97,(anonymous_7) 21 | FN:108,(anonymous_8) 22 | FN:115,(anonymous_9) 23 | FN:123,(anonymous_10) 24 | FN:126,(anonymous_11) 25 | FN:137,(anonymous_12) 26 | FN:150,(anonymous_13) 27 | FN:171,(anonymous_14) 28 | FN:175,(anonymous_15) 29 | FN:178,(anonymous_16) 30 | FNF:17 31 | FNH:5 32 | FNDA:0,(anonymous_0) 33 | FNDA:2,(anonymous_1) 34 | FNDA:2,(anonymous_2) 35 | FNDA:2,(anonymous_3) 36 | FNDA:0,(anonymous_4) 37 | FNDA:0,(anonymous_5) 38 | FNDA:0,(anonymous_6) 39 | FNDA:0,(anonymous_7) 40 | FNDA:0,(anonymous_8) 41 | FNDA:0,(anonymous_9) 42 | FNDA:0,(anonymous_10) 43 | FNDA:0,(anonymous_11) 44 | FNDA:0,(anonymous_12) 45 | FNDA:0,(anonymous_13) 46 | FNDA:0,(anonymous_14) 47 | FNDA:2,(anonymous_15) 48 | FNDA:1,(anonymous_16) 49 | DA:9,1 50 | DA:11,1 51 | DA:14,1 52 | DA:17,1 53 | DA:27,1 54 | DA:39,1 55 | DA:40,0 56 | DA:41,0 57 | DA:42,0 58 | DA:43,0 59 | DA:44,0 60 | DA:45,0 61 | DA:46,0 62 | DA:47,0 63 | DA:53,2 64 | DA:54,2 65 | DA:61,2 66 | DA:71,2 67 | DA:73,0 68 | DA:74,0 69 | DA:76,0 70 | DA:77,0 71 | DA:83,2 72 | DA:85,0 73 | DA:90,2 74 | DA:92,0 75 | DA:97,2 76 | DA:98,0 77 | DA:99,0 78 | DA:109,0 79 | DA:118,0 80 | DA:124,0 81 | DA:128,0 82 | DA:139,0 83 | DA:143,0 84 | DA:150,0 85 | DA:151,0 86 | DA:153,0 87 | DA:161,0 88 | DA:172,0 89 | DA:176,2 90 | DA:179,1 91 | LF:42 92 | LH:15 93 | BRDA:40,0,0,0 94 | BRDA:40,0,1,0 95 | BRDA:44,1,0,0 96 | BRDA:44,1,1,0 97 | BRDA:73,2,0,0 98 | BRDA:73,2,1,0 99 | BRDA:76,3,0,0 100 | BRDA:76,3,1,0 101 | BRDA:151,4,0,0 102 | BRDA:151,4,1,0 103 | BRF:10 104 | BRH:0 105 | end_of_record 106 | -------------------------------------------------------------------------------- /dist/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 16 |
23 | 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | const gulp = require('gulp'); 2 | const log = require('fancy-log'); 3 | const intercept = require('gulp-intercept'); 4 | const concat = require('gulp-concat'); 5 | const jeditor = require('gulp-json-editor'); 6 | const bump = require('gulp-bump'); 7 | const webpack_stream = require('webpack-stream'); 8 | const webpack_config = require('./webpack.config.js'); 9 | const run = require('gulp-run'); 10 | const inlinesource = require('gulp-inline-source'); 11 | // dependencies for npm publishing 12 | const npmDeps = { 13 | glamor: '^2.20.40', 14 | glamorous: '^4.11.2', 15 | 'is-valid-coordinates': '^1.0.0', 16 | 'prop-types': '^15.6.0', 17 | util: '^0.10.3', 18 | 'render-if': '^0.1.1' 19 | }; 20 | // additional dependencies for expo app 21 | const expoDeps = { 22 | expo: '^25.0.0', 23 | react: '16.2.0', 24 | 'react-dom': '^16.2.0', 25 | 'react-native': 26 | 'https://github.com/expo/react-native/archive/sdk-25.0.0.tar.gz' 27 | }; 28 | 29 | // main for npm publishing 30 | const npmMain = 'index.js'; 31 | // main for expo app 32 | const expoMain = 'node_modules/expo/AppEntry.js'; 33 | 34 | const paths = { 35 | src: './Scripts/', 36 | bundled: './bundled/' 37 | }; 38 | 39 | /****package.json stuff****/ 40 | gulp.task('test', function() { 41 | console.log('Hello'); 42 | }); 43 | 44 | const updatePackageJSONforNPM = json => {}; 45 | // read the package.json and update it for npm publishing 46 | gulp.task('forNPM', done => { 47 | gulp 48 | .src('./package.json') 49 | .pipe(bump()) 50 | .pipe( 51 | jeditor(function(json) { 52 | json.dependencies = npmDeps; 53 | json.main = npmMain; 54 | return json; 55 | }) 56 | ) 57 | .pipe(concat('package.json')) 58 | .pipe(gulp.dest('./')); 59 | done(); 60 | }); 61 | 62 | 63 | // pack the files 64 | gulp.task('webpack', done => { 65 | return run('webpack').exec(); 66 | done(); 67 | }); 68 | 69 | // build the distribution HTML files with inline JS and CSS 70 | gulp.task('inlinesource', done=>{ 71 | return gulp.src('./bundled/*.html') 72 | .pipe(intercept(function(file){ 73 | console.log('FILE: ' + file.path ); 74 | return file; 75 | })) 76 | .pipe(inlinesource()) 77 | .pipe(gulp.dest('./assets/dist')); 78 | 79 | }) 80 | 81 | gulp.task('npm-publish', done => { 82 | return run('npm publish').exec(); // run "npm start". 83 | done(); 84 | }); 85 | 86 | gulp.task('git-add', done => { 87 | return run('git add .').exec(); 88 | done(); 89 | }); 90 | 91 | gulp.task('git-commit', done => { 92 | return run('git commit -m "publishing"').exec(); 93 | 94 | done(); 95 | }); 96 | 97 | gulp.task('git-push', done => { 98 | return run('git push origin master').exec(); 99 | done(); 100 | }); 101 | 102 | gulp.task('forExpo', done => { 103 | gulp 104 | .src('./package.json') 105 | .pipe( 106 | jeditor({ 107 | dependencies: expoDeps, 108 | main: expoMain 109 | }) 110 | ) 111 | .pipe(concat('package.json')) 112 | .pipe(gulp.dest('./')); 113 | done(); 114 | }); 115 | 116 | 117 | 118 | gulp.task( 119 | 'prod', 120 | gulp.series( 121 | 'forNPM', 122 | 'webpack', 123 | 'inlinesource', 124 | gulp.parallel( 125 | gulp.series('git-add', 'git-commit', 'git-push'), 126 | 'npm-publish' 127 | ), 128 | 'forExpo' 129 | ) 130 | ); 131 | 132 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-webview-braintree", 3 | "version": "0.0.34", 4 | "devDependencies": { 5 | "babel-jest": "^21.2.0", 6 | "babel-loader": "^7.1.2", 7 | "babel-plugin-transform-es2015-arrow-functions": "^6.22.0", 8 | "babel-preset-env": "^1.6.0", 9 | "babel-preset-es2015": "^6.24.1", 10 | "babel-preset-react": "^6.24.1", 11 | "babel-preset-stage-0": "^6.24.1", 12 | "enzyme": "^3.1.0", 13 | "enzyme-adapter-react-16": "^1.0.1", 14 | "enzyme-to-json": "^3.1.2", 15 | "html-webpack-plugin": "^2.30.1", 16 | "jest": "^21.2.1", 17 | "jest-glamor-react": "^3.1.2", 18 | "react-native-scripts": "1.5.0", 19 | "react-test-renderer": "16", 20 | "webpack": "^3.6.0" 21 | }, 22 | "files": [ 23 | "dist", 24 | "WebViewBraintree.js", 25 | "react.production.min.js", 26 | "react-dom.production.min" 27 | ], 28 | "main": "./WebViewBraintree.js", 29 | "scripts": { 30 | "test": "jest --watch", 31 | "build": "webpack --progress" 32 | }, 33 | "jest": { 34 | "setupFiles": [ 35 | "/config/enzymeAdapter.js" 36 | ] 37 | }, 38 | "peerDependencies": { 39 | "react": "*", 40 | "react-native": "*" 41 | }, 42 | "dependencies": { 43 | "braintree-web-drop-in": "^1.8.0", 44 | "glamor": "^2.20.40", 45 | "glamorous": "^4.9.7", 46 | "prop-types": "^15.6.0", 47 | "react-dom": "^16.0.0", 48 | "react-native": "^0.49.3", 49 | "react-native-webview-messaging": "1.2.1", 50 | "render-if": "^0.1.1", 51 | "util": "^0.10.3" 52 | }, 53 | "description": "A React Native component for making payments using Braintree that uses no native code, only JavaScript.", 54 | "repository": { 55 | "type": "git", 56 | "url": "git+https://github.com/reggie3/react-native-webview-braintree.git" 57 | }, 58 | "keywords": [ 59 | "react-native", 60 | "braintree", 61 | "expo", 62 | "webview" 63 | ], 64 | "author": "Reginald Johnson", 65 | "license": "MIT", 66 | "bugs": { 67 | "url": "https://github.com/reggie3/react-native-webview-braintree/issues" 68 | }, 69 | "homepage": "https://github.com/reggie3/react-native-webview-braintree#readme" 70 | } 71 | -------------------------------------------------------------------------------- /react.production.min.js: -------------------------------------------------------------------------------- 1 | /* 2 | React v16.0.0 3 | react.production.min.js 4 | 5 | Copyright (c) 2013-present, Facebook, Inc. 6 | 7 | This source code is licensed under the MIT license found in the 8 | LICENSE file in the root directory of this source tree. 9 | */ 10 | 'use strict';function y(){function q(){}function n(a,b,c,d,e,f,g){return{$$typeof:J,type:a,key:b,ref:c,props:g,_owner:f}}function z(a){for(var b=arguments.length-1,c="Minified React error #"+a+"; visit http://facebook.github.io/react/docs/error-decoder.html?invariant\x3d"+a,d=0;dw.length&&w.push(a)}function u(a,b,c,d){var e=typeof a;if("undefined"===e||"boolean"===e)a=null;if(null===a||"string"===e||"number"===e||"object"===e&&a.$$typeof===S)return c(d,a,""===b?"."+F(a,0):b),1;var f=0;b=""===b?".":b+":";if(Array.isArray(a))for(var g=0;ga;a++)b["_"+String.fromCharCode(a)]= 15 | a;if("0123456789"!==Object.getOwnPropertyNames(b).map(function(a){return b[a]}).join(""))return!1;var c={};"abcdefghijklmnopqrst".split("").forEach(function(a){c[a]=a});return"abcdefghijklmnopqrst"!==Object.keys(Object.assign({},c)).join("")?!1:!0}catch(d){return!1}}()?Object.assign:function(a,b){if(null===a||void 0===a)throw new TypeError("Object.assign cannot be called with null or undefined");var c=Object(a);for(var d,e=1;e 2 | 3 | 4 | 5 | 6 | 7 | 8 | 15 |
22 | 23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /web/braintreeReactHTML.js: -------------------------------------------------------------------------------- 1 | import renderIf from "render-if"; 2 | import dropin from "braintree-web-drop-in"; 3 | import glamorous from "glamorous"; 4 | import RNMessageChannel from "react-native-webview-messaging"; 5 | import React from '../react.production.min.js'; 6 | import PropTypes from 'prop-types'; 7 | const util = require("util"); 8 | 9 | const DropInContainer = glamorous.div({ 10 | flex: 1 11 | }); 12 | const ButtonContainer = glamorous.div({ 13 | flex: 1 14 | }); 15 | const Button = glamorous.div({ 16 | borderRadius: "2px", 17 | padding: "2px 10px 2px 10px", 18 | backgroundColor: "#2ecc71", 19 | fontSize: "1.25em", 20 | color: "white", 21 | fontFamily: "arial", 22 | boxShadow: "0 1px 4px rgba(0, 0, 0, .6)", 23 | textAlign: "center" 24 | }); 25 | const PaymentBackground = glamorous.div({ 26 | position: "absolute", 27 | top: 0, 28 | bottom: 0, 29 | left: 0, 30 | right: 0, 31 | display: "flex", 32 | flexDirection: "column" 33 | }); 34 | 35 | // print passed information in an html element; useful for debugging 36 | // since console.log and debug statements won't work in a conventional way 37 | const PrintElement = data => { 38 | if (typeof data === "object") { 39 | let el = document.createElement("pre"); 40 | el.innerHTML = util.inspect(data, { showHidden: false, depth: null }); 41 | document.getElementById("messages").appendChild(el); 42 | } else if (typeof data === "string") { 43 | let el = document.createElement("pre"); 44 | el.innerHTML = data; 45 | document.getElementById("messages").appendChild(el); 46 | } 47 | }; 48 | 49 | export default class BraintreeReactHTML extends React.Component { 50 | constructor() { 51 | super(); 52 | this.state = { 53 | currentPaymentStatus: null 54 | }; 55 | } 56 | 57 | componentDidMount = () => { 58 | // PrintElement("componentDidMount success"); 59 | this.registerMessageListeners(); 60 | }; 61 | 62 | /******************************* 63 | * register message listeners to receive events from parent 64 | */ 65 | registerMessageListeners = () => { 66 | // PrintElement("registering message listeners"); 67 | 68 | // will receive client token as a prop immediately upon mounting 69 | RNMessageChannel.on("TOKEN_RECEIVED", event => { 70 | //PrintElement(event); 71 | // if (event.payload.options.creditCard) { 72 | this.createCreditCardUI(event.payload.clientToken); 73 | /* } 74 | if (event.payload.options.paypal) { 75 | this.createPaypalUI(event.payload.clientToken); 76 | } */ 77 | }); 78 | 79 | // when the call is made to the braintree purchasing server 80 | // used to show the user some feedback that the purchase is in process 81 | RNMessageChannel.on("PURCHASE_PENDING", event => { 82 | // PrintElement("PURCHASE_PENDING"); 83 | this.setState({ currentPaymentStatus: "PURCHASE_FULFILLED" }); 84 | }); 85 | 86 | // when the purchase succeeds 87 | // used to show the user some feedback that the purchase has completed successfully 88 | RNMessageChannel.on("PURCHASE_FULFILLED", event => { 89 | //PrintElement("PURCHASE_FULFILLED"); 90 | this.setState({ currentPaymentStatus: "PURCHASE_FULFILLED" }); 91 | }); 92 | 93 | // when the purchase succeeds 94 | // used to show the user some feedback that the purchase has failed to complete 95 | RNMessageChannel.on("PURCHASE_REJECTED", event => { 96 | this.setState({ currentPaymentStatus: "PURCHASE_REJECTED" }); 97 | PrintElement("PURCHASE_REJECTED"); 98 | }); 99 | 100 | // PrintElement("registering message listeners - completed"); 101 | }; 102 | 103 | /******************************* 104 | * create the Paypal payment UI element 105 | */ 106 | createPaypalUI = clientToken => { 107 | console.log("Not implmented"); 108 | }; 109 | 110 | /******************************* 111 | * create the Braintree UI element 112 | */ 113 | createCreditCardUI = clientToken => { 114 | //PrintElement(`createCreditCardUI: ${clientToken}`); 115 | 116 | dropin 117 | .create({ 118 | authorization: clientToken, 119 | container: "#dropin-container" 120 | }) 121 | .then(instance => { 122 | this.setState({ instance }); 123 | }) 124 | .catch(function(err) { 125 | // Handle any errors that might've occurred when creating Drop-in 126 | RNMessageChannel.sendJSON({ 127 | type: "error", 128 | err 129 | }); 130 | }); 131 | }; 132 | /*********************************************** 133 | * handler for when the purchase button is clicke 134 | */ 135 | handleSubmitPurchaseButtonClicked = () => { 136 | // PrintElement(`handleSubmitPurchaseButtonClicked: ${this.state.instance}`); 137 | this.setState({ currentPaymentStatus: "PAYMENT_PENDING" }); 138 | 139 | // send a message to the parent WebView so that it 140 | // can display feedback to user 141 | RNMessageChannel.emit("RETRIEVE_NONCE_PENDING", { 142 | payload: { 143 | type: "success" 144 | } 145 | }); 146 | 147 | // request a purchase nonce from the Braintree server 148 | this.state.instance.requestPaymentMethod(function(err, response) { 149 | if (err) { 150 | // notify the parent WebView if there is an error 151 | RNMessageChannel.emit("RETRIEVE_NONCE_REJECTED", { 152 | payload: { 153 | type: "error", 154 | err 155 | } 156 | }); 157 | } else { 158 | // pass the nonce to the parent WebView if the purchase is successful 159 | RNMessageChannel.emit("RETRIEVE_NONCE_FULFILLED", { 160 | payload: { 161 | type: "success", 162 | response 163 | } 164 | }); 165 | } 166 | }); 167 | }; 168 | 169 | handleGoBackButtonSubmit = () => { 170 | RNMessageChannel.emit("GO_BACK"); 171 | }; 172 | 173 | render = () => { 174 | return ( 175 | { 177 | this.webComponent = component; 178 | }} 179 | > 180 | 181 |
182 | 183 | 184 | {renderIf(this.state.currentPaymentStatus === null)( 185 | 191 | )} 192 | {renderIf(this.state.currentPaymentStatus === "PURCHASE_FULFILLED")( 193 |
194 |
Thank you for your purchase!
195 | 198 |
199 | )} 200 | {renderIf(this.state.currentPaymentStatus === "PURCHASE_REJECTED")( 201 |
202 |
203 | There was a problem with your purchase, please try again 204 |
205 | 208 |
209 | )} 210 |
211 | 212 | 213 | ); 214 | }; 215 | } 216 | 217 | -------------------------------------------------------------------------------- /web/braintreeReactHTML.test.js: -------------------------------------------------------------------------------- 1 | import React from '../react.production.min.js'; 2 | import BraintreeReactHTML from './braintreeReactHTML.js'; 3 | import { shallow, mount } from 'enzyme'; 4 | 5 | describe('', () => { 6 | it('renders without crashing', () => { 7 | const component = shallow(); 8 | expect(component).toHaveLength(1); 9 | }); 10 | 11 | it('displays purchase button if the payment has not been submitted', () => { 12 | const component = shallow(); 13 | if (component.state().currentPaymentStatus !== true) { 14 | expect(component.find('#submit-button').exists()).toBe(true); 15 | } 16 | }); 17 | it('displays a thank you message after purchase is fulfilled', () => { 18 | const component = shallow(); 19 | component.setState({currentPaymentStatus: "PURCHASE_FULFILLED"}) 20 | if (component.state().currentPaymentStatus !== true) { 21 | expect(component.find('#purchase-fulfilled-message').exists()).toBe(true); 22 | } 23 | }); 24 | it('displays a rejection message if purchase is rejected', () => { 25 | const component = shallow(); 26 | component.setState({currentPaymentStatus: "PURCHASE_REJECTED"}) 27 | if (component.state().currentPaymentStatus !== true) { 28 | expect(component.find('#purchase-reject-message').exists()).toBe(true); 29 | } 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /web/component.js: -------------------------------------------------------------------------------- 1 | 2 | import ReactDOM from "react-dom"; 3 | import BraintreeReactHTML from './braintreeReactHTML'; 4 | import React from "react"; 5 | 6 | ReactDOM.render(, document.getElementById("root")); -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const webpack = require("webpack"); 3 | const HtmlWebpackPlugin = require("html-webpack-plugin"); 4 | 5 | module.exports = { 6 | entry: "./web/component.js", 7 | output: { 8 | path: path.join(__dirname, "dist"), 9 | filename: "[name].bundle.js" 10 | }, 11 | module: { 12 | rules: [ 13 | { 14 | test: /\.js$/, 15 | include: [path.resolve(__dirname, "web")], 16 | exclude: /(node_modules|bower_components)/, 17 | use: { 18 | loader: "babel-loader", 19 | options: { 20 | presets: [ 21 | [ 22 | "env", 23 | { 24 | targets: { 25 | browsers: ["last 2 versions", "safari >= 7"] 26 | } 27 | } 28 | ], 29 | "react", 30 | "stage-2" 31 | ], 32 | plugins: ["babel-plugin-transform-object-rest-spread"], 33 | babelrc: false 34 | } 35 | } 36 | } 37 | ] 38 | }, 39 | plugins: [ 40 | new HtmlWebpackPlugin({ 41 | template: "./web/braintreeReact.html", 42 | inject: "body" 43 | }) 44 | ] 45 | }; -------------------------------------------------------------------------------- /yarn directions.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app). 2 | 3 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md). 4 | 5 | ## Table of Contents 6 | 7 | * [Updating to New Releases](#updating-to-new-releases) 8 | * [Available Scripts](#available-scripts) 9 | * [npm start](#npm-start) 10 | * [npm test](#npm-test) 11 | * [npm run ios](#npm-run-ios) 12 | * [npm run android](#npm-run-android) 13 | * [npm run eject](#npm-run-eject) 14 | * [Writing and Running Tests](#writing-and-running-tests) 15 | * [Environment Variables](#environment-variables) 16 | * [Configuring Packager IP Address](#configuring-packager-ip-address) 17 | * [Adding Flow](#adding-flow) 18 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon) 19 | * [Sharing and Deployment](#sharing-and-deployment) 20 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community) 21 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app) 22 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app) 23 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio) 24 | * [Should I Use ExpoKit?](#should-i-use-expokit) 25 | * [Troubleshooting](#troubleshooting) 26 | * [Networking](#networking) 27 | * [iOS Simulator won't open](#ios-simulator-wont-open) 28 | * [QR Code does not scan](#qr-code-does-not-scan) 29 | 30 | ## Updating to New Releases 31 | 32 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never. 33 | 34 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies. 35 | 36 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility. 37 | 38 | ## Available Scripts 39 | 40 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing. 41 | 42 | ### `npm start` 43 | 44 | Runs your app in development mode. 45 | 46 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal. 47 | 48 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script: 49 | 50 | ``` 51 | npm start -- --reset-cache 52 | # or 53 | yarn start -- --reset-cache 54 | ``` 55 | 56 | #### `npm test` 57 | 58 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests. 59 | 60 | #### `npm run ios` 61 | 62 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed. 63 | 64 | #### `npm run android` 65 | 66 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App: 67 | 68 | ##### Using Android Studio's `adb` 69 | 70 | 1. Make sure that you can run adb from your terminal. 71 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location). 72 | 73 | ##### Using Genymotion's `adb` 74 | 75 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`. 76 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)). 77 | 3. Make sure that you can run adb from your terminal. 78 | 79 | #### `npm run eject` 80 | 81 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project. 82 | 83 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up. 84 | 85 | ## Customizing App Display Name and Icon 86 | 87 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key. 88 | 89 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string. 90 | 91 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency. 92 | 93 | ## Writing and Running Tests 94 | 95 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/tutorial-react-native.html). 96 | 97 | ## Environment Variables 98 | 99 | You can configure some of Create React Native App's behavior using environment variables. 100 | 101 | ### Configuring Packager IP Address 102 | 103 | When starting your project, you'll see something like this for your project URL: 104 | 105 | ``` 106 | exp://192.168.0.2:19000 107 | ``` 108 | 109 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides. 110 | 111 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable: 112 | 113 | Mac and Linux: 114 | 115 | ``` 116 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start 117 | ``` 118 | 119 | Windows: 120 | ``` 121 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' 122 | npm start 123 | ``` 124 | 125 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`. 126 | 127 | ## Adding Flow 128 | 129 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept. 130 | 131 | React Native works with [Flow](http://flowtype.org/) out of the box, as long as your Flow version matches the one used in the version of React Native. 132 | 133 | To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps: 134 | 135 | 1. Find the Flow `[version]` at the bottom of the included [.flowconfig](.flowconfig) 136 | 2. Run `npm install --save-dev flow-bin@x.y.z` (or `yarn add --dev flow-bin@x.y.z`), where `x.y.z` is the .flowconfig version number. 137 | 3. Add `"flow": "flow"` to the `scripts` section of your `package.json`. 138 | 4. Add `// @flow` to any files you want to type check (for example, to `App.js`). 139 | 140 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors. 141 | You can optionally use a [plugin for your IDE or editor](https://flow.org/en/docs/editors/) for a better integrated experience. 142 | 143 | To learn more about Flow, check out [its documentation](https://flow.org/). 144 | 145 | ## Sharing and Deployment 146 | 147 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service. 148 | 149 | ### Publishing to Expo's React Native Community 150 | 151 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account. 152 | 153 | Install the `exp` command-line tool, and run the publish command: 154 | 155 | ``` 156 | $ npm i -g exp 157 | $ exp publish 158 | ``` 159 | 160 | ### Building an Expo "standalone" app 161 | 162 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself. 163 | 164 | ### Ejecting from Create React Native App 165 | 166 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio. 167 | 168 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html). 169 | 170 | #### Should I Use ExpoKit? 171 | 172 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option. 173 | 174 | ## Troubleshooting 175 | 176 | ### Networking 177 | 178 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports. 179 | 180 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see: 181 | 182 | ``` 183 | exp://192.168.0.1:19000 184 | ``` 185 | 186 | Try opening Safari or Chrome on your phone and loading 187 | 188 | ``` 189 | http://192.168.0.1:19000 190 | ``` 191 | 192 | and 193 | 194 | ``` 195 | http://192.168.0.1:19001 196 | ``` 197 | 198 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received. 199 | 200 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager. 201 | 202 | ### iOS Simulator won't open 203 | 204 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`: 205 | 206 | * "non-zero exit code: 107" 207 | * "You may need to install Xcode" but it is already installed 208 | * and others 209 | 210 | There are a few steps you may want to take to troubleshoot these kinds of errors: 211 | 212 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store. 213 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so. 214 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`. 215 | 216 | ### QR Code does not scan 217 | 218 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses. 219 | 220 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually. 221 | --------------------------------------------------------------------------------