Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
ActivityIndicator Component | Advanced Concepts
Foundations of React Native
course content

Conteúdo do Curso

Foundations of React Native

Foundations of React Native

1. Introduction
2. Basic Concepts
3. Common Principles
4. Advanced Concepts

bookActivityIndicator Component

Theory

The ActivityIndicator component in is used to indicate that a task is ongoing, providing visual feedback to the user. It typically appears as a spinning wheel or other animated indicator to convey that the application is busy performing an operation.

Why Do We Need It?

Indicates that the application is working on a task, preventing the user from assuming the application has frozen.

How to Work with ActivityIndicator

  • The ActivityIndicator is straightforward to use and does not require state management;
  • We can control its visibility by conditionally rendering it based on the status of a task.

Example

Explanation

  • Initially, the component renders a welcome message using the Text component and a button using the TouchableOpacity component;
  • When the button is pressed, the fetchData function is called, which sets isLoading to true to display the ActivityIndicator;
  • After a 3-second delay (simulating data fetching), the fetchData function sets isLoading back to false and updates the additionalData state with some text;
  • The ActivityIndicator is displayed while isLoading is true, and once isLoading becomes false, the additionalData is shown using the Text component.

Result

In Practice

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 4. Capítulo 2
We're sorry to hear that something went wrong. What happened?
some-alt