Code Monkey home page Code Monkey logo

react-native-make-it-rain's Introduction

React Native "Make It Rain"


v1.0.0 breaking changes

Prop names have been generalized to represent that any type of component can be passed in as the falling pieces. The itemComponent (previously moneyComponent) no longer defaults to an SVG. This allowed for removal of the dependency on react-native-svg. Refer to the Example project for how to pass in an SVG itemComponent.

Summary

This is a self-contained component that may be placed in any component. It takes up the entire parent view and is positioned absolutely, overlaying other content in the parent.

The default animation was adapted from Shopify's Arrive confetti example.

The original Make It Rain animation was adapted from Joel Arvidsson's MakeItRain example. It has been rewritten to use react-native-reanimated.

The flavor prop selects between them.

Sample Code

import React, {Component} from 'react';
import { View, Text } from 'react-native';
import MakeItRain from 'react-native-make-it-rain';

class Demo extends Component {
  render() {
    return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
        <Text>Make It Rain</Text>
        <MakeItRain
          numItems={80}
          itemDimensions={{width: 40, height: 20}}
          itemComponent={<Text>๐Ÿค</Text>}
          itemTintStrength={0.8}
        />
      </View>
    );
  }
}

Usage

npm install react-native-make-it-rain --save

Props

Prop Description Type Default
numItems How many items fall Integer 100
itemComponent Replaces the built-in item component. Can use any React component (Icon, Image, View, SVG etc) Component <View/>
itemDimensions Size of item. If itemComponent is supplied, size should be set to match. Object { width: 20, height: 10 }
itemColors Colors of falling items. Array ['#00e4b2', '#09aec5', '#107ed5']
itemTintStrength Opacity of color overlay on item (0 - 1.0) Number 1.0
flavor The animation behavior ("arrive" or "rain") String "arrive"
fallSpeed How fast the item falls Integer 50
flipSpeed Item flip speed Integer 3
horizSpeed How fast the item moves horizontally Integer 50
continuous Rain down continuously Boolean true

Sample Application

If you'd like to see it in action, run these commands:

cd Example
npm run cp
npm install
npm start

The sample app is an Expo project created with create-react-native-app.

Development

The source files are copied from the project root directory into Example/react-native-make-it-rain using npm run cp. If a source file is modified, it must be copied over again with npm run cp.

Ideally the Example project could include the parent's source files using package.json, but that causes a babel interopRequireDefault runtime error.

Credits

Cash SVG in the Example project was sourced from IconFinder and is used under the Creative Commons license.

ToDo

  • Tests

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.