Skip to content

Commit 62819a9

Browse files
committed
initial launch 0.0.2
1 parent dfa876b commit 62819a9

File tree

4 files changed

+110
-6
lines changed

4 files changed

+110
-6
lines changed

Diff for: .gitignore

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
node_modules/
2-
*.log
1+
node_modules/**/*
2+
.expo/*
3+
npm-debug.*
4+
*.jks
5+
*.p12
6+
*.key
7+
*.mobileprovision
8+
.vscode

Diff for: package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-animated-loader",
3-
"version": "0.0.1",
3+
"version": "0.0.2",
44
"description": "react-native-animated-loader",
55
"main": "src/index.js",
66
"files":[
@@ -9,6 +9,9 @@
99
"scripts": {
1010
"test": "echo \"Error: no test specified\" && exit 1"
1111
},
12+
"dependencies": {
13+
"prop-types": "^15.6.2"
14+
},
1215
"author": "vikrantnegi",
1316
"license": "MIT"
1417
}

Diff for: readme.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
# react-native-animated-loader
1+
# React Native Animated Loader
22

3-
> Coming soon
3+
A React Native Loader Component which uses Airbnb's [Lottie](https://github.com/react-native-community/lottie-react-native) for beautiful loader animations.
4+
5+
## Install
6+
7+
```
8+
npm install react-native-animated-loader
9+
```
10+
11+
> Docs Coming soon

Diff for: src/index.js

+88-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,88 @@
1-
console.log('Yeah!');
1+
import React from 'react';
2+
import { StyleSheet, View, Modal, ViewPropTypes } from 'react-native';
3+
import PropTypes from 'prop-types';
4+
import LottieAnimation from 'lottie-react-native';
5+
6+
export default class AnimatedLoader extends React.PureComponent {
7+
static defaultProps = {
8+
visible: false,
9+
overlayColor: 'rgba(0, 0, 0, 0.25)',
10+
source: {},
11+
animationType: 'none',
12+
animationStyle: {},
13+
};
14+
15+
static propTypes = {
16+
animation: PropTypes.object,
17+
visible: PropTypes.bool,
18+
overlayColor: PropTypes.string,
19+
animationType: PropTypes.oneOf(['none', 'slide', 'fade']),
20+
source: PropTypes.object,
21+
animationStyle: ViewPropTypes.style,
22+
};
23+
24+
animation = React.createRef();
25+
26+
componentDidMount() {
27+
if (this.animation.current) {
28+
this.animation.current.play();
29+
}
30+
}
31+
32+
componentDidUpdate(prevProps) {
33+
const { visible } = this.props;
34+
if (visible !== prevProps.visible) {
35+
if (this.animation.current) {
36+
this.animation.current.play();
37+
}
38+
}
39+
}
40+
41+
_renderLottie = () => {
42+
const { source, animationStyle } = this.props;
43+
return (
44+
<LottieAnimation
45+
{...this.props}
46+
ref={this.animation}
47+
source={source}
48+
loop
49+
style={[styles.animationStyle, animationStyle]}
50+
/>
51+
);
52+
};
53+
54+
render() {
55+
const { visible, overlayColor, animationType } = this.props;
56+
57+
return (
58+
<Modal
59+
transparent
60+
visible={visible}
61+
animationType={animationType}
62+
supportedOrientations={['portrait']}
63+
>
64+
<View style={[styles.container, { backgroundColor: overlayColor }]}>
65+
<View>{this._renderLottie()}</View>
66+
</View>
67+
</Modal>
68+
);
69+
}
70+
}
71+
72+
const styles = StyleSheet.create({
73+
container: {
74+
flex: 1,
75+
backgroundColor: 'transparent',
76+
position: 'absolute',
77+
top: 0,
78+
bottom: 0,
79+
left: 0,
80+
right: 0,
81+
alignItems: 'center',
82+
justifyContent: 'center',
83+
},
84+
animationStyle: {
85+
height: '100%',
86+
width: '100%',
87+
},
88+
});

0 commit comments

Comments
 (0)