Зміст курсу
Foundations of React Native
Foundations of React Native
2. Core Concepts of React Native
Setting Up the React Native ProjectUnderstanding React Native ComponentsWorking with View and Text ComponentsUsing the Image ComponentStyling in React NativeChallenge: Apply Styles to ComponentsWorking with TouchableOpacity for User InteractionImplementing ScrollView for Scrolling ContentRendering Lists in React NativeChallenge: Build an Interactive Resort ListQuiz: React Native Basics
3. Essential React Native Principles
Managing Loading States with ActivityIndicator
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 theTouchableOpacity
component; - When the button is pressed, the
fetchData
function is called, which setsisLoading
totrue
to display theActivityIndicator
; - After a 3-second delay (simulating data fetching), the
fetchData
function setsisLoading
back tofalse
and updates theadditionalData
state with some text; - The
ActivityIndicator
is displayed whileisLoading
istrue
, and onceisLoading
becomesfalse
, theadditionalData
is shown using theText
component.
Result
In Practice
Все було зрозуміло?
Дякуємо за ваш відгук!
Секція 4. Розділ 2