Skip to content

Commit 52667f7

Browse files
authored
Feat: Re-written in typescript (#109)
* feat: bug fixes, js to ts, class to hooks * build: build files, package.json bugs * bug:missing export bug * fix: fixed type issue
1 parent f59c605 commit 52667f7

File tree

13 files changed

+21388
-8345
lines changed

13 files changed

+21388
-8345
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
node_modules
55
*.sw*
66
.cache-loader
7+

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ We recommend that you follow two rules when implementing this component.
7777
| Name | Website |
7878
| ------------------- | ------------------------- |
7979
| **Nick Baugh** | <http://niftylettuce.com> |
80+
| **Rohit Bhatia** | <http://blendtale.com> |
8081
| **Spencer Snyder** | <http://spencersnyder.io> |
8182
| **Luciano Lima** | |
8283
| **George Savvidis** | |

index.js

Lines changed: 0 additions & 171 deletions
This file was deleted.

lib/index.d.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as React from 'react';
2+
import { TextStyle, ViewStyle } from 'react-native';
3+
export interface SpinnerPropTypes {
4+
cancelable?: boolean;
5+
color?: string;
6+
animation?: 'none' | 'slide' | 'fade';
7+
overlayColor?: string;
8+
size?: 'small' | 'large' | number;
9+
textContent?: string;
10+
textStyle?: TextStyle;
11+
visible?: boolean;
12+
indicatorStyle?: ViewStyle;
13+
customIndicator?: React.ReactNode;
14+
children?: React.ReactNode;
15+
spinnerKey?: string;
16+
}
17+
declare const Spinner: ({ cancelable, color, animation, overlayColor, size, textContent, textStyle, visible, indicatorStyle, customIndicator, children, spinnerKey }: SpinnerPropTypes) => JSX.Element;
18+
export default Spinner;

lib/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import * as React from 'react';
2+
import { View, Text, Modal, ActivityIndicator } from 'react-native';
3+
import styles from './style';
4+
const transparent = 'transparent';
5+
const Spinner = ({ cancelable = false, color = 'white', animation = 'none', overlayColor = 'rgba(0, 0, 0, 0.25)', size = 'large', textContent = '', textStyle, visible = false, indicatorStyle, customIndicator, children, spinnerKey }) => {
6+
const [spinnerVisible, setSpinnerVisibility] = React.useState(visible);
7+
const close = () => {
8+
setSpinnerVisibility(false);
9+
};
10+
const _handleOnRequestClose = () => {
11+
if (cancelable) {
12+
close();
13+
}
14+
};
15+
const _renderDefaultContent = () => {
16+
return (React.createElement(View, { style: styles.background },
17+
customIndicator || (React.createElement(ActivityIndicator, { color: color, size: size, style: [styles.activityIndicator, { ...indicatorStyle }] })),
18+
React.createElement(View, { style: [styles.textContainer, { ...indicatorStyle }] },
19+
React.createElement(Text, { style: [styles.textContent, textStyle] }, textContent))));
20+
};
21+
const _renderSpinner = () => {
22+
const spinner = (React.createElement(View, { style: [styles.container, { backgroundColor: overlayColor }], key: spinnerKey || `spinner_${Date.now()}` }, children || _renderDefaultContent()));
23+
return (React.createElement(Modal, { animationType: animation, onRequestClose: () => _handleOnRequestClose(), supportedOrientations: ['landscape', 'portrait'], transparent: true, visible: spinnerVisible, statusBarTranslucent: true }, spinner));
24+
};
25+
return _renderSpinner();
26+
};
27+
export default Spinner;

lib/style.d.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
declare const styles: {
2+
activityIndicator: {
3+
flex: number;
4+
};
5+
background: {
6+
alignItems: "center";
7+
bottom: number;
8+
justifyContent: "center";
9+
left: number;
10+
position: "absolute";
11+
right: number;
12+
top: number;
13+
};
14+
container: {
15+
backgroundColor: string;
16+
bottom: number;
17+
flex: number;
18+
left: number;
19+
position: "absolute";
20+
right: number;
21+
top: number;
22+
};
23+
textContainer: {
24+
alignItems: "center";
25+
bottom: number;
26+
flex: number;
27+
justifyContent: "center";
28+
left: number;
29+
position: "absolute";
30+
right: number;
31+
top: number;
32+
};
33+
textContent: {
34+
fontSize: number;
35+
fontWeight: "bold";
36+
height: number;
37+
top: number;
38+
};
39+
};
40+
export default styles;

lib/style.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { StyleSheet } from 'react-native';
2+
const transparent = 'transparent';
3+
const styles = StyleSheet.create({
4+
activityIndicator: {
5+
flex: 1
6+
},
7+
background: {
8+
alignItems: 'center',
9+
bottom: 0,
10+
justifyContent: 'center',
11+
left: 0,
12+
position: 'absolute',
13+
right: 0,
14+
top: 0
15+
},
16+
container: {
17+
backgroundColor: transparent,
18+
bottom: 0,
19+
flex: 1,
20+
left: 0,
21+
position: 'absolute',
22+
right: 0,
23+
top: 0
24+
},
25+
textContainer: {
26+
alignItems: 'center',
27+
bottom: 0,
28+
flex: 1,
29+
justifyContent: 'center',
30+
left: 0,
31+
position: 'absolute',
32+
right: 0,
33+
top: 0
34+
},
35+
textContent: {
36+
fontSize: 20,
37+
fontWeight: 'bold',
38+
height: 50,
39+
top: 80
40+
}
41+
});
42+
export default styles;

0 commit comments

Comments
 (0)