📅  最后修改于: 2023-12-03 15:04:48.826000             🧑  作者: Mango
React Native ActivityIndicator is a component that is used for indicating that something is loading or processing. It is a built-in component in React Native and it is really easy to use. In this article, we will learn how to use the React Native ActivityIndicator component.
To use the React Native ActivityIndicator component, you need to have a React Native project set up. If you do not have a React Native project set up, follow these steps to set up a new project:
react-native init myapp
cd myapp
npm start
To use the React Native ActivityIndicator component, follow these steps:
import { ActivityIndicator } from 'react-native';
<ActivityIndicator />
<ActivityIndicator size="large" color="#0000ff" />
Here are some of the props that you can use to customize the ActivityIndicator component:
size
: The size of the ActivityIndicator. Possible values: small
, large
.color
: The color of the ActivityIndicator.animating
: Whether to animate the ActivityIndicator. Possible values: true
, false
.hidesWhenStopped
: Whether to hide the ActivityIndicator when it is stopped.Here is an example that shows how to use the React Native ActivityIndicator component:
import React from 'react';
import { View, Text, ActivityIndicator, StyleSheet } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<Text style={styles.title}>Loading...</Text>
<ActivityIndicator size="large" color="#0000ff" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#fafafa',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 16,
},
});
React Native ActivityIndicator is a really useful component that can be used to indicate that something is loading or processing. It is really easy to use and it comes with a lot of props that can be used to customize it. If you are building a React Native app, make sure to check out the React Native ActivityIndicator component!