[
  {
    "path": ".gitignore",
    "content": ".DS_Store"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2017 Chad Sahlhoff\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# React Native Pulse Animation\n\n![react native pulse](https://raw.githubusercontent.com/sahlhoff/react-native-pulse/master/pulse-gif.gif)\n\n## Installation\n\n```\n  npm install react-native-pulse --save\n```\n\n## Usage\n\n```js\nconst Pulse = require('react-native-pulse').default;\n\nclass helloWorld extends Component {\n  render() {\n    return (\n      <View style={styles.container}>\n        <Pulse color='orange' numPulses={3} diameter={400} speed={20} duration={2000} />\n      </View>\n    );\n  }  \n}\n\n```\n\n## Props\n\nComponent accepts several self-descriptive properties:\n\n\n- **`color`** _(String)_ - Backgroundcolor for pulse. React-native colors supported. Default color is blue.\n- **`diameter`** _(Number)_ - This is the maximum diameter that a pulse will be. Defaults to 400.\n- **`duration`** _(Number)_ - Duration in milliseconds this is the delay new pulses will be created. Defaults to 1000.\n- **`image`** _(Object)_ - Image for center pulse thumbnail.\n- **`initialDiameter`** _(Number)_ - The diameter new pulses will start with. Defaults to 0.\n- **`numPulses`** _(Number)_ - This is the number of pulses that will be rendered. Defaults to 3.\n- **`pulseStyle`** _(Object)_ - Style properties for pulses (borderColor eg.)\n- **`speed`** _(Number)_ - Speed in milliseconds pulse will redraw. Defaults to 10.\n- **`style`** _(Object)_ - Style properties for pulse container (positioning eg.)\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"react-native-pulse\",\n  \"version\": \"1.0.7\",\n  \"description\": \"React Native Pulse Animation\",\n  \"main\": \"pulse.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"git+https://github.com/sahlhoff/react-native-pulse.git\"\n  },\n  \"keywords\": [\n    \"react\",\n    \"react-component\",\n    \"ios\",\n    \"react-native\",\n    \"animation\",\n    \"ui\",\n    \"pulse\"\n  ],\n  \"author\": \"Chad Sahlhoff\",\n  \"license\": \"ISC\",\n  \"bugs\": {\n    \"url\": \"https://github.com/sahlhoff/react-native-pulse/issues\"\n  },\n  \"homepage\": \"https://github.com/sahlhoff/react-native-pulse#readme\"\n}\n"
  },
  {
    "path": "pulse.js",
    "content": "import React, {\n  Component\n} from 'react';\nimport PropTypes from 'prop-types';\nimport {\n  View,\n  Text,\n  Image,\n  StyleSheet,\n} from 'react-native';\n\nconst styles = StyleSheet.create({\n    container: {\n        position: 'absolute',\n        left: 0,\n        right: 0,\n        alignItems: 'center'\n    },\n    pulse: {\n        position: 'absolute',\n        flex: 1\n    }\n});\n\nexport default class Pulse extends Component {\n    static propTypes = {\n        color: PropTypes.string,\n        diameter: PropTypes.number,\n        duration: PropTypes.number,\n        image: PropTypes.object,\n        initialDiameter: PropTypes.number,\n        numPulses: PropTypes.number,\n        pulseStyle: PropTypes.object,\n        speed: PropTypes.number,\n        style: PropTypes.object\n    };\n\n    static defaultProps = {\n        color: 'blue',\n        diameter: 400,\n        duration: 1000,\n        image: null,\n        initialDiameter: 0,\n        numPulses: 3,\n        pulseStyle: {},\n        speed: 10,\n        style: {\n            top: 0,\n            bottom: 0,\n            flexDirection: 'row',\n            justifyContent: 'center',\n            alignItems: 'center'\n        }\n    }\n\n    constructor(props){\n        super(props);\n\n        this.state = {\n            color: this.props.color,\n            duration: this.props.duration,\n            image: this.props.image,\n            maxDiameter: this.props.diameter,\n            numPulses: this.props.numPulses,\n            pulses: [],\n            pulseStyle: this.props.pulseStyle,\n            speed: this.props.speed,\n            started: false,\n            style: this.props.style\n        };\n    }\n\n    mounted = true;\n\n    componentDidMount(){\n        const {numPulses, duration, speed} = this.state;\n\n        this.setState({started: true});\n\n        let a = 0;\n        while(a < numPulses){\n            this.createPulseTimer = setTimeout(()=>{\n                this.createPulse(a);\n            }, a * duration);\n\n            a++;\n        }\n\n        this.timer = setInterval(() => {\n            this.updatePulse();\n        }, speed);\n    }\n\n    componentWillUnmount(){\n        this.mounted = false;\n        clearTimeout(this.createPulseTimer);\n        clearInterval(this.timer);\n    }\n\n    createPulse = (pKey) => {\n        if (this.mounted) {\n            let pulses = this.state.pulses;\n\n            let pulse = {\n                pulseKey: pulses.length + 1,\n                diameter: this.props.initialDiameter,\n                opacity: .5,\n                centerOffset: ( this.state.maxDiameter - this.props.initialDiameter ) / 2\n            };\n\n            pulses.push(pulse);\n\n            this.setState({pulses});\n        }\n    }\n\n    updatePulse = () => {\n        if (this.mounted) {\n            const pulses = this.state.pulses.map((p, i) => {\n                let maxDiameter = this.state.maxDiameter;\n                let newDiameter = (p.diameter > maxDiameter ? 0 : p.diameter + 2);\n                let centerOffset = ( maxDiameter - newDiameter ) / 2;\n                let opacity = Math.abs( ( newDiameter / this.state.maxDiameter ) - 1 );\n\n                let pulse = {\n                    pulseKey: i + 1,\n                    diameter: newDiameter,\n                    opacity: (opacity > .5 ? .5 : opacity),\n                    centerOffset: centerOffset\n                };\n\n                return pulse;\n\n            });\n\n            this.setState({pulses});\n        }\n    }\n\n    render(){\n        const {color, image, maxDiameter, pulses, pulseStyle, started, style} = this.state;\n        const containerStyle = [styles.container, style];\n        const pulseWrapperStyle = {width: maxDiameter, height: maxDiameter};\n\n        return (\n            <View style={containerStyle}>\n                {started &&\n                    <View style={pulseWrapperStyle}>\n                        {pulses.map((pulse) =>\n                            <View\n                                key={pulse.pulseKey}\n                                style={[\n                                    styles.pulse,\n                                    {\n                                        backgroundColor: color,\n                                        width: pulse.diameter,\n                                        height: pulse.diameter,\n                                        opacity: pulse.opacity,\n                                        borderRadius: pulse.diameter / 2,\n                                        top: pulse.centerOffset,\n                                        left: pulse.centerOffset\n                                    },\n                                    pulseStyle\n                                ]}\n                            />\n                        )}\n                        {image &&\n                            <Image\n                                style={image.style}\n                                source={image.source}\n                            />\n                        }\n                    </View>\n                }\n            </View>\n        )\n    }\n}\n"
  }
]