Repository: wangdicoder/react-native-indicator
Branch: master
Commit: 666e616e40a2
Files: 32
Total size: 50.3 KB
Directory structure:
gitextract_oiiy0_mm/
├── .gitignore
├── .npmignore
├── .prettierrc
├── LICENSE
├── README.md
├── index.js
├── lib/
│ ├── animated/
│ │ ├── AnimatedBar.js
│ │ └── AnimatedCircle.js
│ ├── const/
│ │ └── index.js
│ ├── loader/
│ │ ├── BreathingLoader.js
│ │ ├── BubblesLoader.js
│ │ ├── CirclesLoader.js
│ │ ├── CirclesRotationScaleLoader.js
│ │ ├── ColorDotsLoader.js
│ │ ├── DotsLoader.js
│ │ ├── DoubleCircleLoader.js
│ │ ├── EatBeanLoader.js
│ │ ├── LineDotsLoader.js
│ │ ├── LinesLoader.js
│ │ ├── MusicLoader.js
│ │ ├── NineCubesLoader.js
│ │ ├── OpacityDotsLoader.js
│ │ ├── PulseLoader.js
│ │ ├── RippleLoader.js
│ │ ├── RotationCircleLoader.js
│ │ ├── RotationHoleLoader.js
│ │ └── TextLoader.js
│ └── shape/
│ ├── Bar.js
│ ├── Bar2.js
│ ├── Bar3.js
│ └── Circle.js
└── package.json
================================================
FILE CONTENTS
================================================
================================================
FILE: .gitignore
================================================
/.idea
/node_modules
================================================
FILE: .npmignore
================================================
/screenshot
/.idea
/node_modules
.prettierrc
README.md
================================================
FILE: .prettierrc
================================================
{
"printWidth": 100,
"trailingComma": "all",
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"bracketSpacing": true,
"arrowParens": "always"
}
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2016 Di Wang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
================================================
FILE: README.md
================================================
# react-native-indicator
  [](https://www.npmjs.com/package/react-native-indicator)
A useful indicator component for React Native
## Installation
Make sure that you are in your React Native project directory and run:
```
$ npm install react-native-indicator --save
$ npm install @react-native-community/art --save
```
For react-native >= 0.60 ReactNativeART should be auto-linked and no additional action is required.
For react-native < 0.60 you need to link ReactNative ART:
```
$ react-native link @react-native-community/art
```
More info, following the [Art module](https://github.com/react-native-community/art) instruction to configure.
## Usage
Import react-native-indicator as a JavaScript module:
```
import { CirclesLoader, PulseLoader, TextLoader, DotsLoader, ... } from 'react-native-indicator';
```
Here is currently available types:
- [PulseLoader](#PulseLoader)
- [DotsLoader](#DotsLoader)
- [TextLoader](#TextLoader)
- [BubblesLoader](#BubblesLoader)
- [CirclesLoader](#CirclesLoader)
- [BreathingLoader](#BreathingLoader)
- [RippleLoader](#RippleLoader)
- [LinesLoader](#LinesLoader)
- [MusicBarLoader](#MusicBarLoader)
- [EatBeanLoader](#EatBeanLoader)
- [DoubleCircleLoader](#DoubleCircleLoader)
- [RotationCircleLoader](#RotationCircleLoader)
- [RotationHoleLoader](#RotationHoleLoader)
- [CirclesRotationScaleLoader](#CirclesRotationScaleLoader)
- [NineCubesLoader](#NineCubesLoader)
- [LineDotsLoader](#LineDotsLoader)
- [ColorDotsLoader](#ColorDotsLoader)
- [OpacityDotsLoader](#OpacityDotsLoader)
```
render(){
return(
);
}
```
## Props
##### PulseLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 30 | circle's size |
| color | string | '#1e90ff' | indicator's color |
| frequency | number | 1000 | scale's frequency |
##### DotsLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 10 | dot's size |
| color | string | '#1e90ff' | indicator's color |
| betweenSpace | number | 5 | distance between two dots |
##### TextLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| text | string | 'Loading' | contents |
| textStyle | style | inherited | text's style |
##### BubblesLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 40 | circle's size |
| color | string | '#1e90ff' | indicator's color |
| dotRadius | number | 10 | each dot's size |
##### CirclesLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 40 | circle's size |
| color | string | '#1e90ff' | indicator's color |
| dotRadius | number | 8 | each dot's size |
##### BreathingLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 10 | circle's size |
| color | string | '#1e90ff' | indicator's color |
| strokeWidth | number | 3 | outline width |
| frequency | number | 800 | scale's frequency |
##### RippleLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 10 | circle's size |
| frequency | number | 1600 | scale's frequency |
| color | string | '#1e90ff' | indicator's color |
| strokeWidth | number | 3 | outline width |
##### LinesLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| color | string | '#1e90ff' | indicator's color |
| barWidth | number | 5 | each bar's width |
| barHeight | number | 40 | each bar's height |
| barNumber | number | 5 | the number of bar |
| betweenSpace | number | 2 | distance between two bars |
##### MusicBarLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| color | string | '#1e90ff' | indicator's color |
| barWidth | number | 3 | each bar's width |
| barHeight | number | 30 | each bar's height |
| betweenSpace | number | 5 | distance between two bars |
##### EatBeanLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| color | string | '#1e90ff' | indicator's color |
| size | number | 30 | indicator's size |
##### DoubleCircleLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 30 | circle's size |
| color | string | '#1e90ff' | indicator's color |
##### RotationCircleLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 30 | indicator's size |
| color | string | '#1e90ff' | indicator's color |
| rotationSpeed | number | 800 | rotation speed |
##### RotationHoleLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 40 | indicator's size |
| color | string | '#1e90ff' | indicator's color |
| rotationSpeed | number | 800 | rotation speed |
| strokeWidth | number | 8 | circle outline's width |
##### CirclesRotationScaleLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 50 | indicator's size |
| color | string | '#1e90ff' | indicator's color |
##### NineCubesLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 20 | each cube's size |
| color | string | '#1e90ff' | indicator's color |
##### LineDotsLoader
**warning:** *this indicator will occupy a whole horizontal space automatically, which means you don't need to set any center props. Just keeping the direction of its parent View is vertical.*
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 10 | dot's size |
| color | string | '#1e90ff' | indicator's color |
| dotsNumber | number | 5 | the number of dots |
| betweenSpace | number | 5 | distance between two dots |
##### ColorDotsLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 15 | each cube's size |
| betweenSpace | number | 7 | distance between two dots |
| color1 | string | '#ff4500'(red) | 1st color |
| color2 | string | '#ffd700'(yellow) | 2nd color |
| color3 | string | '#9acd32'(green) | 3rd color |
##### OpacityDotsLoader
| prop | type | default | description |
| ---- | ---- | ---- | ---- |
| size | number | 10 | dot's size |
| color | string | '#1e90ff' | indicator's color |
| betweenSpace | number | 5 | distance between two dots |
| speed | number | 200 | change speed |
## License
MIT
================================================
FILE: index.js
================================================
import Breathing from './lib/loader/BreathingLoader';
import Bubbles from './lib/loader/BubblesLoader';
import Circles from './lib/loader/CirclesLoader';
import CirclesRotationScale from './lib/loader/CirclesRotationScaleLoader';
import ColorDots from './lib/loader/ColorDotsLoader';
import Dots from './lib/loader/DotsLoader';
import DoubleCircle from './lib/loader/DoubleCircleLoader';
import EatBean from './lib/loader/EatBeanLoader';
import Lines from './lib/loader/LinesLoader';
import LineDots from './lib/loader/LineDotsLoader';
import Music from './lib/loader/MusicLoader';
import NineCubes from './lib/loader/NineCubesLoader';
import OpacityDots from './lib/loader/OpacityDotsLoader';
import Pulse from './lib/loader/PulseLoader';
import Ripple from './lib/loader/RippleLoader';
import RotationCircle from './lib/loader/RotationCircleLoader';
import RotationHole from './lib/loader/RotationHoleLoader';
import Text from './lib/loader/TextLoader';
export const BreathingLoader = Breathing;
export const BubblesLoader = Bubbles;
export const CirclesLoader = Circles;
export const CirclesRotationScaleLoader = CirclesRotationScale;
export const ColorDotsLoader = ColorDots;
export const DotsLoader = Dots;
export const DoubleCircleLoader = DoubleCircle;
export const EatBeanLoader = EatBean;
export const LinesLoader = Lines;
export const LineDotsLoader = LineDots;
export const MusicBarLoader = Music;
export const NineCubesLoader = NineCubes;
export const OpacityDotsLoader = OpacityDots;
export const PulseLoader = Pulse;
export const RippleLoader = Ripple;
export const RotationCircleLoader = RotationCircle;
export const RotationHoleLoader = RotationHole;
export const TextLoader = Text;
================================================
FILE: lib/animated/AnimatedBar.js
================================================
import Bar from '../shape/Bar';
import { Animated } from 'react-native';
export default Animated.createAnimatedComponent(Bar);
================================================
FILE: lib/animated/AnimatedCircle.js
================================================
import Circle from '../shape/Circle';
import { Animated } from 'react-native';
export default Animated.createAnimatedComponent(Circle);
================================================
FILE: lib/const/index.js
================================================
export const color = '#1e90ff';
================================================
FILE: lib/loader/BreathingLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class BreathingLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
size: PropTypes.number,
strokeWidth: PropTypes.number,
frequency: PropTypes.number,
};
static defaultProps = {
color,
size: 30,
strokeWidth: 3,
frequency: 800,
};
constructor(props) {
super(props);
this.state = {
scale: new Animated.Value(0.1),
};
}
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = () => {
Animated.sequence([
Animated.timing(this.state.scale, {
toValue: 1,
duration: this.props.frequency,
useNativeDriver: false,
}),
Animated.timing(this.state.scale, {
toValue: 0.1,
duration: this.props.frequency,
useNativeDriver: false,
}),
]).start(() => {
!this.unmounted && this._animation();
});
};
render() {
const { color, size, strokeWidth } = this.props;
return (
);
}
}
================================================
FILE: lib/loader/BubblesLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class BubblesLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
dotRadius: PropTypes.number,
size: PropTypes.number,
};
static defaultProps = {
color,
dotRadius: 10,
size: 40,
};
state = {
opacities: [
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
],
};
eachDegree = 360 / this.state.opacities.length;
timers = [];
componentDidMount() {
this.state.opacities.forEach((item, i) => {
const id = setTimeout(() => {
this._animation(i);
}, i * 150);
this.timers.push(id);
});
}
componentWillUnmount() {
this.unmounted = true;
this.timers.forEach((id) => {
clearTimeout(id);
});
}
_animation = (i) => {
Animated.sequence([
Animated.timing(this.state.opacities[i], {
toValue: 0.2,
duration: 600,
useNativeDriver: false,
}),
Animated.timing(this.state.opacities[i], {
toValue: 1,
duration: 600,
useNativeDriver: false,
}),
]).start(() => {
!this.unmounted && this._animation(i);
});
};
render() {
const { size, dotRadius, color } = this.props;
const { opacities } = this.state;
return (
{opacities.map((item, i) => {
let radian = (i * this.eachDegree * Math.PI) / 180;
let x = Math.round((size / 2) * Math.cos(radian)) + size / 2 + dotRadius / 2;
let y = Math.round((size / 2) * Math.sin(radian)) + size / 2 + dotRadius / 2;
return (
);
})}
);
}
}
================================================
FILE: lib/loader/CirclesLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class CirclesLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
dotRadius: PropTypes.number,
size: PropTypes.number,
};
static defaultProps = {
color,
dotRadius: 8,
size: 40,
};
state = {
opacities: [
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
new Animated.Value(1),
],
};
eachDegree = 360 / this.state.opacities.length;
timers = [];
componentDidMount() {
this.state.opacities.forEach((item, i) => {
const id = setTimeout(() => {
this._animation(i);
}, i * 150);
this.timers.push(id);
});
}
componentWillUnmount() {
this.unmounted = true;
this.timers.forEach((id) => {
clearTimeout(id);
});
}
_animation = (i) => {
Animated.sequence([
Animated.timing(this.state.opacities[i], {
toValue: 0.1,
duration: 600,
useNativeDriver: false,
}),
Animated.timing(this.state.opacities[i], {
toValue: 1,
duration: 600,
useNativeDriver: false,
}),
]).start(() => {
!this.unmounted && this._animation(i);
});
};
render() {
const { size, dotRadius, color } = this.props;
const { opacities } = this.state;
return (
{opacities.map((item, i) => {
let radian = (i * this.eachDegree * Math.PI) / 180;
let x = Math.round((size / 2) * Math.cos(radian)) + size / 2 + dotRadius / 2;
let y = Math.round((size / 2) * Math.sin(radian)) + size / 2 + dotRadius / 2;
return (
);
})}
);
}
}
================================================
FILE: lib/loader/CirclesRotationScaleLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated, Easing } from 'react-native';
import { Surface, Group } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class RotationCircleLoader extends React.PureComponent {
static propTypes = {
size: PropTypes.number,
color: PropTypes.string,
};
static defaultProps = {
size: 50,
color,
};
state = {
degree: new Animated.Value(0),
scales: [new Animated.Value(0), new Animated.Value(0)]
};
timers = [];
componentDidMount() {
this._animation();
this.state.scales.forEach((item, i) => {
const id = setTimeout(() => {
this._animationCircles(i)
}, i * 500);
this.timers.push(id);
});
}
componentWillUnmount() {
this.unmounted = true;
this.timers.forEach((id) => {
clearTimeout(id);
});
}
_animation = () => {
Animated.sequence([
Animated.timing(this.state.degree, {
toValue: 360,
duration: 2000,
easing: Easing.linear,
useNativeDriver: false
})
]).start(() => {
if (!this.unmounted) {
this.state.degree.setValue(0);
this._animation();
}
});
};
_animationCircles = (i) => {
Animated.sequence([
Animated.timing(this.state.scales[i], { toValue: 1, duration: 1000, useNativeDriver: false }),
Animated.timing(this.state.scales[i], {
toValue: 0.05,
duration: 1000,
useNativeDriver: false
}),
]).start(() => {
!this.unmounted && this._animationCircles(i);
});
};
render() {
const { size, color } = this.props;
const degree = this.state.degree.interpolate({
inputRange: [0, 360],
outputRange: ['0deg', '360deg']
});
return (
);
}
}
================================================
FILE: lib/loader/ColorDotsLoader.js
================================================
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Animated, Easing } from 'react-native';
import { Surface, Group } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
export default class ColorDotsLoader extends Component {
static propTypes = {
size: PropTypes.number,
betweenSpace: PropTypes.number,
color1: PropTypes.string,
color2: PropTypes.string,
color3: PropTypes.string,
};
static defaultProps = {
size: 15,
betweenSpace: 7,
color1: '#ff4500',
color2: '#ffd700',
color3: '#9acd32',
};
constructor(props) {
super(props);
const red = this.props.color1;
const yellow = this.props.color2;
const green = this.props.color3;
this.state = {
colors: [red, red, red],
color: yellow,
x: new Animated.Value(-this.props.size / 2),
};
this.patterns = [
[yellow, red, red],
[yellow, yellow, red],
[yellow, yellow, yellow],
[green, yellow, yellow],
[green, green, yellow],
[green, green, green],
[red, green, green],
[red, red, green],
[red, red, red],
];
this.timers = [];
}
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
this.timers.forEach((id) => {
clearTimeout(id);
});
}
_animation = () => {
const { size, betweenSpace, color1, color2, color3 } = this.props;
const id1 = setTimeout(() => {
this.setState({ color: color3 });
}, 600);
const id2 = setTimeout(() => {
this.setState({ color: color1 });
}, 1200);
this.timers.push(id1);
this.timers.push(id2);
this.patterns.forEach((item, i) => {
const id = setTimeout(() => {
this.setState({ colors: this.patterns[i] });
}, i * 200 + 100);
this.timers.push(id);
});
Animated.sequence([
Animated.timing(this.state.x, {
toValue: size * 3 + betweenSpace * 2 + size / 2,
duration: 600,
easing: Easing.linear,
useNativeDriver: false,
}),
Animated.timing(this.state.x, {
toValue: -size / 2,
duration: 0,
useNativeDriver: false,
}),
Animated.timing(this.state.x, {
toValue: size * 3 + betweenSpace * 2 + size / 2,
duration: 600,
easing: Easing.linear,
useNativeDriver: false,
}),
Animated.timing(this.state.x, {
toValue: -size / 2,
duration: 0,
useNativeDriver: false,
}),
Animated.timing(this.state.x, {
toValue: size * 3 + betweenSpace * 2 + size / 2,
duration: 600,
easing: Easing.linear,
useNativeDriver: false,
}),
]).start(() => {
if (!this.unmounted) {
this.state.x.setValue(-size / 2);
this.setState({ color: color2 });
this._animation();
}
});
};
render() {
const { size, betweenSpace } = this.props;
const { color, colors } = this.state;
return (
{colors.map((item, i) => (
))}
);
}
}
================================================
FILE: lib/loader/DotsLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class DotsLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
size: PropTypes.number,
betweenSpace: PropTypes.number,
};
static defaultProps = {
color,
size: 10,
betweenSpace: 5,
};
state = {
scales: [new Animated.Value(0), new Animated.Value(0), new Animated.Value(0)],
};
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = () => {
function seq(self, i) {
return Animated.sequence([
Animated.timing(self.state.scales[i], {
toValue: 1,
duration: 300,
delay: (i + 1) * 200,
useNativeDriver: false,
}),
Animated.timing(self.state.scales[i], {
toValue: 0,
duration: 300,
delay: 50,
useNativeDriver: false,
}),
]);
}
Animated.parallel([seq(this, 0), seq(this, 1), seq(this, 2)]).start(() => {
if (!this.unmounted) this._animation();
});
};
_renderCircle = (i) => {
const { color, size, betweenSpace } = this.props;
return (
);
};
render() {
const { size, betweenSpace } = this.props;
return (
{this._renderCircle(0)}
{this._renderCircle(1)}
{this._renderCircle(2)}
);
}
}
================================================
FILE: lib/loader/DoubleCircleLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class DoubleCircleLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
size: PropTypes.number,
};
static defaultProps = {
color,
size: 30,
};
state = {
scales: [new Animated.Value(0), new Animated.Value(0)],
};
timers = [];
componentDidMount() {
this.state.scales.forEach((item, i) => {
const id = setTimeout(() => {
this._animation(i);
}, i * 1000);
this.timers.push(id);
});
}
componentWillUnmount() {
this.unmounted = true;
this.timers.forEach((id) => {
clearTimeout(id);
});
}
_animation = (i) => {
Animated.sequence([
Animated.timing(this.state.scales[i], { toValue: 1, duration: 1000, useNativeDriver: false }),
Animated.timing(this.state.scales[i], { toValue: 0, duration: 1000, useNativeDriver: false }),
]).start(() => {
!this.unmounted && this._animation(i);
});
};
render() {
const { color, size } = this.props;
const { scales } = this.state;
return (
);
}
}
================================================
FILE: lib/loader/EatBeanLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface, Shape } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class EatBeanLoader extends React.PureComponent {
static propTypes = {
size: PropTypes.number,
color: PropTypes.string,
};
static defaultProps = {
size: 30,
color,
};
state = {
dotsY: [
new Animated.Value(this.props.size * 2.2),
new Animated.Value(this.props.size * 2.2),
new Animated.Value(this.props.size * 2.2),
new Animated.Value(this.props.size * 2.2),
],
};
timers = [];
componentDidMount() {
this.state.dotsY.forEach((item, i) => {
const id = setTimeout(() => {
this._animation(i);
}, i * 300);
this.timers.push(id);
});
}
componentWillUnmount() {
this.unmounted = true;
this.timers.forEach((id) => {
clearTimeout(id);
});
}
_animation = (i) => {
Animated.timing(this.state.dotsY[i], {
toValue: this.props.size / 2,
duration: 1200,
useNativeDriver: false,
}).start(() => {
if (!this.unmounted) {
this.state.dotsY[i].setValue(this.props.size * 2.2);
this._animation(i);
}
});
};
render() {
const { size, color } = this.props;
const sinValue = Math.sqrt(2) / 2;
const x = Math.floor((size / 2) * sinValue) + size / 2;
const startY = Math.floor((size / 2) * sinValue) + size / 2;
const endY = size / 2 - Math.floor((size / 2) * sinValue);
const d = `M${x} ${startY} A ${size / 2} ${size / 2}, 0, 1, 1, ${x} ${endY} L ${size /
2} ${size / 2} Z`;
return (
{this.state.dotsY.map((item, i) => (
))}
);
}
}
================================================
FILE: lib/loader/LineDotsLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated, Dimensions } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class LineDotsLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
size: PropTypes.number,
dotsNumber: PropTypes.number,
betweenSpace: PropTypes.number,
};
static defaultProps = {
color,
size: 10,
dotsNumber: 5,
betweenSpace: 5,
};
constructor(props) {
super(props);
this.screenWidth = Dimensions.get('window').width;
const { size, dotsNumber, betweenSpace } = this.props;
const midX =
this.screenWidth / 2 + (size * dotsNumber + betweenSpace * (dotsNumber - 1)) / 2 - size / 2;
let circlesX = [];
this.beginX = [];
this.centerX = [];
this.destX = [];
for (let i = 0; i < dotsNumber; i++) {
let beginX = -size / 2 - (size + betweenSpace) * i;
circlesX.push(new Animated.Value(beginX));
this.beginX.push(beginX);
this.centerX.push(midX - i * (size + betweenSpace));
this.destX.push(this.screenWidth + size / 2 + i * (size + betweenSpace));
}
this.state = {
x: circlesX,
};
}
render() {
const { color, size } = this.props;
return (
{this.state.x.map((item, i) => (
))}
);
}
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = () => {
this.state.x.forEach((item, i) => {
Animated.sequence([
Animated.timing(this.state.x[i], {
toValue: this.centerX[i],
duration: 600,
delay: i * 50,
useNativeDriver: false,
}),
Animated.timing(this.state.x[i], {
toValue: this.centerX[i],
duration: 600,
delay: 300,
useNativeDriver: false,
}),
Animated.timing(this.state.x[i], {
toValue: this.destX[i],
duration: 600,
delay: i * 50,
useNativeDriver: false,
}),
]).start(() => {
if (i === this.props.dotsNumber - 1) {
for (let idx in this.state.x) {
this.state.x[idx].setValue(this.beginX[idx]);
}
!this.unmounted && this._animation();
}
});
});
};
}
================================================
FILE: lib/loader/LinesLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedBar from '../animated/AnimatedBar';
import { color } from '../const';
export default class LinesLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
barWidth: PropTypes.number,
barHeight: PropTypes.number,
betweenSpace: PropTypes.number,
barNumber: PropTypes.number,
};
static defaultProps = {
color,
betweenSpace: 2,
barNumber: 5,
barWidth: 5,
barHeight: 40,
};
constructor(props) {
super(props);
const heights = [];
for (let i = 0; i < this.props.barNumber; i++) {
heights.push(new Animated.Value(this.props.barHeight / 3));
}
this.state = {
heights,
};
}
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = () => {
function seq(self, i) {
return Animated.sequence([
Animated.timing(self.state.heights[i], {
toValue: self.props.barHeight,
duration: 400,
delay: i * 200,
useNativeDriver: false,
}),
Animated.timing(self.state.heights[i], {
toValue: self.props.barHeight / 3,
duration: 400,
useNativeDriver: false,
}),
]);
}
const anim = [];
for (let i = 0; i < this.props.barNumber; i++) anim.push(seq(this, i));
Animated.parallel(anim).start(() => {
!this.unmounted && this._animation();
});
};
render() {
const { color, betweenSpace, barWidth, barHeight, barNumber } = this.props;
return (
{this.state.heights.map((item, i) => (
))}
);
}
}
================================================
FILE: lib/loader/MusicLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import Bar from '../shape/Bar2';
import { color } from '../const';
const AnimatedBar = Animated.createAnimatedComponent(Bar);
export default class LinesLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
barWidth: PropTypes.number,
barHeight: PropTypes.number,
betweenSpace: PropTypes.number,
};
static defaultProps = {
color,
betweenSpace: 5,
barWidth: 3,
barHeight: 30,
};
constructor(props) {
super(props);
this.fixedMaxValue = [
this.props.barHeight * 0.8,
this.props.barHeight * 0.4,
this.props.barHeight,
this.props.barHeight * 0.2,
];
this.fixedMinValue = [
this.props.barHeight * 0.3,
this.props.barHeight,
this.props.barHeight * 0.5,
this.props.barHeight * 0.8,
];
this.state = {
heights: [
new Animated.Value(this.fixedMinValue[0]),
new Animated.Value(this.fixedMinValue[1]),
new Animated.Value(this.fixedMinValue[2]),
new Animated.Value(this.fixedMinValue[3]),
],
};
}
componentDidMount() {
this.state.heights.forEach((item, i) => {
this._animation(i);
});
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = (i) => {
Animated.sequence([
Animated.timing(this.state.heights[i], {
toValue: this.fixedMaxValue[i],
duration: 500,
useNativeDriver: false,
}),
Animated.timing(this.state.heights[i], {
toValue: this.fixedMinValue[i],
duration: 500,
useNativeDriver: false,
}),
]).start(() => {
!this.unmounted && this._animation(i);
});
};
render() {
const { color, betweenSpace, barWidth, barHeight, barNumber } = this.props;
return (
{this.state.heights.map((item, i) => {
return (
);
})}
);
}
}
================================================
FILE: lib/loader/NineCubesLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import Bar3 from '../shape/Bar3';
import { color } from '../const';
const AnimatedBar = Animated.createAnimatedComponent(Bar3);
export default class NineCubesLoader extends React.PureComponent {
state = {
scales: [
new Animated.Value(0),
new Animated.Value(0),
new Animated.Value(0),
new Animated.Value(0),
new Animated.Value(0),
],
};
static propTypes = {
size: PropTypes.number,
color: PropTypes.string,
};
static defaultProps = {
size: 20,
color,
};
_renderCube(i, j, scaleID) {
const { size, color } = this.props;
return (
);
}
render() {
const { size, color } = this.props;
return (
{this._renderCube(0, 0, 2)}
{this._renderCube(0, 1, 1)}
{this._renderCube(0, 2, 0)}
{this._renderCube(1, 0, 3)}
{this._renderCube(1, 1, 2)}
{this._renderCube(1, 2, 1)}
{this._renderCube(2, 0, 4)}
{this._renderCube(2, 1, 3)}
{this._renderCube(2, 2, 2)}
);
}
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = () => {
function seq(self, i) {
return Animated.sequence([
Animated.timing(self.state.scales[i], {
toValue: 1,
duration: 300,
delay: (i + 1) * 100,
useNativeDriver: false,
}),
Animated.timing(self.state.scales[i], {
toValue: 0,
duration: 300,
delay: 200,
useNativeDriver: false,
}),
]);
}
Animated.parallel([seq(this, 0), seq(this, 1), seq(this, 2), seq(this, 3), seq(this, 4)]).start(
() => {
!this.unmounted && this._animation();
},
);
};
}
================================================
FILE: lib/loader/OpacityDotsLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class OpacityDotsLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
size: PropTypes.number,
betweenSpace: PropTypes.number,
speed: PropTypes.number,
};
static defaultProps = {
color,
size: 10,
betweenSpace: 5,
speed: 200,
};
state = {
opacity: [new Animated.Value(0.5), new Animated.Value(0.5), new Animated.Value(0.5)],
};
_renderCircle(i) {
const { color, size, betweenSpace } = this.props;
return (
);
}
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = () => {
const { speed } = this.props;
function seq(self, i) {
return Animated.sequence([
Animated.timing(self.state.opacity[i], {
toValue: 1,
duration: speed,
delay: i * speed,
useNativeDriver: false,
}),
Animated.timing(self.state.opacity[i], {
toValue: 0.3,
duration: speed,
delay: speed,
useNativeDriver: false,
}),
]);
}
Animated.parallel([seq(this, 0), seq(this, 1), seq(this, 2)]).start(() => {
!this.unmounted && this._animation();
});
};
render() {
const { size, betweenSpace } = this.props;
return (
{this._renderCircle(0)}
{this._renderCircle(1)}
{this._renderCircle(2)}
);
}
}
================================================
FILE: lib/loader/PulseLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class PulseLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
size: PropTypes.number,
frequency: PropTypes.number,
};
static defaultProps = {
color,
size: 30,
frequency: 1000,
};
state = {
effect: new Animated.ValueXY({ x: 0, y: 1 }),
};
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = () => {
Animated.parallel([
Animated.timing(this.state.effect.x, {
toValue: 1,
duration: this.props.frequency,
useNativeDriver: false,
}),
Animated.timing(this.state.effect.y, {
toValue: 0.05,
duration: this.props.frequency,
useNativeDriver: false,
}),
]).start(() => {
if (!this.unmounted) {
this.state.effect.setValue({ x: 0, y: 1 });
this._animation();
}
});
};
render() {
const { color, size } = this.props;
return (
);
}
}
================================================
FILE: lib/loader/RippleLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated } from 'react-native';
import { Surface } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class RippleLoader extends React.PureComponent {
static propTypes = {
color: PropTypes.string,
size: PropTypes.number,
strokeWidth: PropTypes.number,
frequency: PropTypes.number,
};
static defaultProps = {
color,
size: 40,
strokeWidth: 3,
frequency: 1600,
};
state = {
scales: [new Animated.Value(0.1), new Animated.Value(0.1)],
opacities: [new Animated.Value(1), new Animated.Value(1)],
};
timers = [];
componentDidMount() {
this.state.scales.forEach((item, i) => {
const id = setTimeout(() => {
this._animation(i);
}, i * this.props.frequency * 0.75);
this.timers.push(id);
});
}
componentWillUnmount() {
this.unmounted = true;
this.timers.forEach((id) => {
clearTimeout(id);
});
}
_animation = (i) => {
const { frequency } = this.props;
Animated.parallel([
Animated.timing(this.state.scales[i], {
toValue: 1,
duration: frequency,
useNativeDriver: false,
}),
Animated.timing(this.state.opacities[i], {
toValue: 0,
duration: frequency,
delay: frequency / 2,
useNativeDriver: false,
}),
]).start(() => {
if (!this.unmounted) {
this.state.scales[i].setValue(0.1);
this.state.opacities[i].setValue(1);
this._animation(i);
}
});
};
render() {
const { color, size, strokeWidth } = this.props;
const { scales, opacities } = this.state;
return (
{scales.map((item, i) => (
))}
);
}
}
================================================
FILE: lib/loader/RotationCircleLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated, Easing } from 'react-native';
import { Surface, Group } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class RotationCircleLoader extends React.PureComponent {
static propTypes = {
size: PropTypes.number,
color: PropTypes.string,
rotationSpeed: PropTypes.number
};
static defaultProps = {
size: 40,
color,
rotationSpeed: 800
};
state = {
degree: new Animated.Value(0)
};
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = () => {
Animated.sequence([
Animated.timing(this.state.degree, {
toValue: 360,
duration: this.props.rotationSpeed,
easing: Easing.linear,
useNativeDriver: false
})
]).start(() => {
if (!this.unmounted) {
this.state.degree.setValue(0);
this._animation();
}
});
};
render() {
const { size, color } = this.props;
const degree = this.state.degree.interpolate({
inputRange: [0, 360],
outputRange: ['0deg', '360deg']
});
return (
);
}
}
================================================
FILE: lib/loader/RotationHoleLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Animated, Easing } from 'react-native';
import { Surface, Group } from '@react-native-community/art';
import AnimatedCircle from '../animated/AnimatedCircle';
import { color } from '../const';
export default class RotationHoleLoader extends React.PureComponent {
static propTypes = {
size: PropTypes.number,
color: PropTypes.string,
strokeWith: PropTypes.number,
rotationSpeed: PropTypes.number
};
static defaultProps = {
size: 40,
color,
rotationSpeed: 800,
strokeWith: 8
};
state = {
degree: new Animated.Value(0)
};
componentDidMount() {
this._animation();
}
componentWillUnmount() {
this.unmounted = true;
}
_animation = () => {
Animated.sequence([
Animated.timing(this.state.degree, {
toValue: 360,
duration: this.props.rotationSpeed,
easing: Easing.linear,
useNativeDriver: false
})
]).start(() => {
if (!this.unmounted) {
this.state.degree.setValue(0);
this._animation();
}
});
};
render() {
const { size, color, strokeWith } = this.props;
const degree = this.state.degree.interpolate({
inputRange: [0, 360],
outputRange: ['0deg', '360deg']
});
return (
);
}
}
================================================
FILE: lib/loader/TextLoader.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Text, View } from 'react-native';
export default class TextLoader extends React.PureComponent {
static propTypes = {
text: PropTypes.string,
textStyle: Text.propTypes.style,
};
static defaultProps = {
text: 'Loading',
};
state = {
opacities: [0, 0, 0],
};
patterns = [[0, 0, 0], [1, 0, 0], [1, 1, 0], [1, 1, 1]];
timers = [];
componentDidMount() {
this._animation(1);
}
componentWillUnmount() {
this.unmounted = true;
this.timers.forEach((id) => {
clearTimeout(id);
});
}
_animation = (index) => {
if (!this.unmounted) {
const id = setTimeout(() => {
this.setState({ opacities: this.patterns[index] });
index++;
if (index >= this.patterns.length) index = 0;
this._animation(index);
}, 500);
this.timers.push(id);
}
};
render() {
const { text, textStyle } = this.props;
return (
{text}
{this.state.opacities.map((item, i) => (
.
))}
);
}
}
================================================
FILE: lib/shape/Bar.js
================================================
/**
* The scale center of this bar is left-center
*/
import React from 'react';
import PropTypes from 'prop-types';
import { Shape, Path } from '@react-native-community/art';
export default class Bar extends React.PureComponent {
static propTypes = {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
};
render() {
const { width, height } = this.props;
const path = Path()
.moveTo(width, height / 2)
.lineTo(0, height / 2)
.lineTo(0, -height / 2)
.lineTo(width, -height / 2)
.close();
return ;
}
}
================================================
FILE: lib/shape/Bar2.js
================================================
/**
* The scale center of this bar is bottom-center
*/
import React from 'react';
import PropTypes from 'prop-types';
import { Shape, Path } from '@react-native-community/art';
export default class Bar2 extends React.PureComponent {
static propTypes = {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
};
render() {
const { width, height } = this.props;
const path = Path()
.moveTo(0, 0)
.lineTo(0, -height)
.lineTo(width, -height)
.lineTo(width, 0)
.close();
return ;
}
}
================================================
FILE: lib/shape/Bar3.js
================================================
/**
* The scale center of this bar is center
*/
import React from 'react';
import PropTypes from 'prop-types';
import { Shape, Path } from '@react-native-community/art';
export default class Bar3 extends React.PureComponent {
static propTypes = {
width: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
};
render() {
const { width, height } = this.props;
const path = Path()
.moveTo(width / 2, height / 2)
.lineTo(-width / 2, height / 2)
.lineTo(-width / 2, -height / 2)
.lineTo(width / 2, -height / 2)
.close();
return ;
}
}
================================================
FILE: lib/shape/Circle.js
================================================
import React from 'react';
import PropTypes from 'prop-types';
import { Shape, Path } from '@react-native-community/art';
export default class Circle extends React.PureComponent {
static propTypes = {
radius: PropTypes.number.isRequired,
opacity: PropTypes.number,
};
render() {
const { radius } = this.props;
const path = Path()
.moveTo(0, -radius / 2)
.arc(0, radius, 1)
.arc(0, -radius, 1)
.close();
return ;
}
}
================================================
FILE: package.json
================================================
{
"name": "react-native-indicator",
"version": "1.2.2",
"description": "React Native Indicator Component",
"main": "index.js",
"scripts": {
"lint": "./node_modules/.bin/prettier --config .prettierrc --write lib/**/*.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/wangdicoder/react-native-indicator.git"
},
"keywords": [
"react-native",
"indicator",
"loader",
"progress"
],
"author": "Di Wang ",
"license": "MIT",
"bugs": {
"url": "https://github.com/wangdicoder/react-native-indicator/issues"
},
"homepage": "https://github.com/wangdicoder/react-native-indicator#readme",
"dependencies": {
"prop-types": "^15.6.0"
},
"devDependencies": {
"prettier": "^1.19.1"
}
}