如何在 React Native 中顯示載入指示器?
當我們想要告訴使用者他們在 UI 上發出的請求需要時間時,請使用載入指示器。如果使用者在填寫表單後點擊了提交按鈕,或點擊了搜尋按鈕以取得一些資料。
ReactNative 提供了一個ActivityIndicator 元件,它可以透過不同的方式在UI 上顯示載入指示器.
基本的ActivityIndicator 元件如下-
<ActivityIndicator animating = {animating} color = '#bc2b78' size = "large" style = {yourstyle}/>
要使用ActivityIndicator,您需要如下匯入它-
import { ActivityIndicator} from 'react-native';
以下是ActivityIndicator 提供的一些重要屬性。
Sr.No | 道具和說明 |
---|---|
1 | 動畫 p> 用於載入指示器的動畫。它採用布林值 true 則顯示指示器, false 則隱藏指示器。 |
2 | 顏色 p> 載入指示器顯示的顏色。 |
3 | hidesWhenStopped 當指示器沒有動畫時停止。其值為 正確/錯誤。 |
4 | 大小 大小指標。數值有小有大。 |
範例:載入指標的顯示
#載入指示器是使用ActivityIndicator 實作的,因此首先導入-
import { ActivityIndicator, View, StyleSheet } from 'react-native';
這是使用的ActivityIndicator 元件-
<ActivityIndicator animating = {animating} color = '#bc2b78' size = "large" style = {styles.activityIndicator}/>
動畫設定為動畫變量,預設為true。在 componentDidMount() 函數中呼叫 closeActivityIndicator 方法,該函數將在 1 分鐘後將動畫狀態設為 false。
state = { animating: true } closeActivityIndicator = () => setTimeout(() => this.setState({ animating: false }), 60000) componentDidMount = () => this.closeActivityIndicator()
這是顯示載入指示器的完整程式碼 -
import React, { Component } from 'react'; import { ActivityIndicator, View, StyleSheet } from 'react-native'; class ActivityIndicatorExample extends Component { state = { animating: true } closeActivityIndicator = () => setTimeout(() => this.setState({ animating: false }), 60000) componentDidMount = () => this.closeActivityIndicator() render() { const animating = this.state.animating return () } } export default ActivityIndicatorExample const styles = StyleSheet.create ({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', marginTop: 70 }, activityIndicator: { flex: 1, justifyContent: 'center', alignItems: 'center', height: 80 } })
輸出
以上是如何在 React Native 中顯示載入指示器?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

本文討論了在瀏覽器中優化JavaScript性能的策略,重點是減少執行時間並最大程度地減少對頁面負載速度的影響。

本文討論了使用瀏覽器開發人員工具的有效JavaScript調試,專注於設置斷點,使用控制台和分析性能。

Python和JavaScript開發者的薪資沒有絕對的高低,具體取決於技能和行業需求。 1.Python在數據科學和機器學習領域可能薪資更高。 2.JavaScript在前端和全棧開發中需求大,薪資也可觀。 3.影響因素包括經驗、地理位置、公司規模和特定技能。

本文說明瞭如何使用源地圖通過將其映射回原始代碼來調試JAVASCRIPT。它討論了啟用源地圖,設置斷點以及使用Chrome DevTools和WebPack之類的工具。

如何在JavaScript中將具有相同ID的數組元素合併到一個對像中?在處理數據時,我們常常會遇到需要將具有相同ID�...

深入探討console.log輸出差異的根源本文將分析一段代碼中console.log函數輸出結果的差異,並解釋其背後的原因。 �...
