js
import React, { useState } from 'react';
import { View, Text, Modal, ActivityIndicator, StyleSheet, Button } from 'react-native';
const LoadingModal = () => {
const [visible, setVisible] = useState(false);
// 函数用于显示或隐藏模态框
const toggleModal = () => {
setVisible(!visible);
};
return (
<View style={styles.container}>
<Button title="Show Loading Modal" onPress={toggleModal} />
<Modal
animationType="slide"
transparent={true}
visible={visible}
onRequestClose={toggleModal}
>
<View style={styles.modalContainer}>
{/* modalContent外层框样式 */}
<View style={styles.modalContent}>
{/* color:转圈的小圆圈的颜色 */}
<ActivityIndicator size="large" color="#FFFFFF" />
</View>
</View>
</Modal>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
modalContainer: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'rgba(0, 0, 0, 0.5)',
},
modalContent: {
backgroundColor: 'black',
padding: 40,
borderRadius: 10,
alignItems: 'center',
},
});
export default LoadingModal;
效果图