|
| 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; |
0 commit comments