-
Notifications
You must be signed in to change notification settings - Fork 173
/
Copy pathindex.js
30 lines (30 loc) · 1.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import * as React from 'react';
import { View, Text, Modal, ActivityIndicator } from 'react-native';
import styles from './style';
const transparent = 'transparent';
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 }) => {
const [spinnerVisible, setSpinnerVisibility] = React.useState(visible);
const close = () => {
setSpinnerVisibility(false);
};
const _handleOnRequestClose = () => {
if (cancelable) {
close();
}
};
React.useEffect(() => {
setSpinnerVisibility(visible);
}, [visible]);
const _renderDefaultContent = () => {
return (React.createElement(View, { style: styles.background },
customIndicator || (React.createElement(ActivityIndicator, { color: color, size: size, style: [styles.activityIndicator, { ...indicatorStyle }] })),
React.createElement(View, { style: [styles.textContainer, { ...indicatorStyle }] },
React.createElement(Text, { style: [styles.textContent, textStyle] }, textContent))));
};
const _renderSpinner = () => {
const spinner = (React.createElement(View, { style: [styles.container, { backgroundColor: overlayColor }], key: spinnerKey || `spinner_${Date.now()}` }, children || _renderDefaultContent()));
return (React.createElement(Modal, { animationType: animation, onRequestClose: () => _handleOnRequestClose(), supportedOrientations: ['landscape', 'portrait'], transparent: true, visible: spinnerVisible, statusBarTranslucent: true }, spinner));
};
return _renderSpinner();
};
export default Spinner;