Reference version

This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 56).

LoadingIndicator

用于显示加载状态的 Jetpack Compose 加载指示器组件。

Android
Included in Expo Go

For the complete documentation index, see llms.txt. Use this file to discover all available pages.

Expo UI 加载指示器与官方 Jetpack Compose Loading Indicator API 保持一致。

默认和带容器的加载指示器,处于不确定模式

安装

Terminal
npx expo install @expo/ui

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

加载指示器

来自 Material 3 Expressive 的一种变形形状加载动画。

LoadingIndicatorExample.tsx
import { Host, LoadingIndicator } from '@expo/ui/jetpack-compose'; export default function LoadingIndicatorExample() { return ( <Host matchContents> <LoadingIndicator /> </Host> ); }

带容器的加载指示器

位于彩色背景中的加载指示器。

ContainedLoadingIndicatorExample.tsx
import { Host, ContainedLoadingIndicator } from '@expo/ui/jetpack-compose'; export default function ContainedLoadingIndicatorExample() { return ( <Host matchContents> <ContainedLoadingIndicator /> </Host> ); }

不确定

省略 progress 属性,以持续动画方式运行,而不指示具体完成进度。

IndeterminateExample.tsx
import { ContainedLoadingIndicator, Host, LoadingIndicator, Row } from '@expo/ui/jetpack-compose'; export default function IndeterminateExample() { return ( <Host matchContents> <Row horizontalArrangement={{ spacedBy: 16 }}> <LoadingIndicator /> <ContainedLoadingIndicator /> </Row> </Host> ); }

确定

useNativeState 返回的可观察状态作为 progress 传入。将 progress.value 更新为 01 之间。

DeterminateExample.tsx
import { ContainedLoadingIndicator, Host, LoadingIndicator, Row, useNativeState, } from '@expo/ui/jetpack-compose'; import { useEffect } from 'react'; export default function DeterminateExample() { const progress = useNativeState(0); useEffect(() => { const interval = setInterval(() => { progress.value = (progress.value + 0.05) % 1; }, 500); return () => clearInterval(interval); }, [progress]); return ( <Host matchContents> <Row horizontalArrangement={{ spacedBy: 16 }}> <LoadingIndicator progress={progress} /> <ContainedLoadingIndicator progress={progress} /> </Row> </Host> ); }

API

import { LoadingIndicator, ContainedLoadingIndicator } from '@expo/ui/jetpack-compose';

Components

ContainedLoadingIndicator

Android

Type: React.Element<ComponentType<ContainedLoadingIndicatorProps>>

A loading indicator that displays loading using morphing shapes inside a container.

Matches the Jetpack Compose ContainedLoadingIndicator.

ContainedLoadingIndicatorProps

containerColor

Android
Optional • Type: ColorValue

Loading indicator's container color

LoadingIndicator

Android

Type: React.Element<ComponentType<LoadingIndicatorCommonConfig>>

A loading indicator that displays loading using morphing shapes.

Matches the Jetpack Compose LoadingIndicator.

Types

LoadingIndicatorCommonConfig

Android

Common props shared by loading indicator variants.

PropertyTypeDescription
color(optional)ColorValue

Loading indicator color.

modifiers(optional)ModifierConfig[]

Modifiers for the component.

progress(optional)ObservableState<number | null>

An observable state that holds the current progress value. Create one with useNativeState(0). Omit for indeterminate loading.

ObservableState

Android

Observable state shared between JavaScript and native views (Jetpack Compose on Android and SwiftUI on iOS).

Type: SharedObject extended by:

PropertyTypeDescription
onChange[listener] | null

A single listener invoked on the native UI runtime whenever the value changes (after iOS didSet and Android's setter). Assigning replaces the previous listener; assign null to clear. The initial value does not fire onChange.

The callback must be a worklet so it can run synchronously on the UI thread. Attach it inside useEffect and clear it in the cleanup so the listener lifecycle matches the component lifecycle.

Example

const state = useNativeState(0); useEffect(() => { state.onChange = (value) => { 'worklet'; console.log('changed to', value); }; return () => { state.onChange = null; }; }, []);
valueT

The current value.

Writes from a UI worklet are synchronous and immediately readable. Writes from the JS thread are scheduled to the UI thread asynchronously, the new value is not readable until the update has been applied. Prefer writing from a worklet when you need synchronous updates