Browse React Native
React NativeComponentsNo. 16 of 22
Spinner
The platform's activity indicator in the theme's muted colour, announced as Loading.
For the web: Spinner, with the same name and variants.
Preview
Loading the preview
The gallery's web build, through react-native-web. On a phone the same code draws native views.
Installation
npx shadcn@latest add @corsair-native/spinnerThe app's components.json needs the @corsair-native registry first; see Installation. The files land in your project as source: edit them like your own code.
- Also adds
- theme
API
Read from the source's own comments and types. Props marked * are required.
SpinnerComponent
The platform's own activity indicator in the theme's muted colour, so it looks native on iOS and Android. It is announced as "Loading"; pass a more specific accessibilityLabel when you can ("Loading courts"). Inside a Button, use the Button's loading prop instead.
| Prop | Type | Default |
|---|---|---|
size | "sm" | "default" | "lg" | "default" |
ref | Ref<ActivityIndicator> | — |
accessibilityLabel | ActivityIndicatorProps["accessibilityLabel"] | "Loading" |
Also takes every ActivityIndicatorProps prop (React Native docs).
Compatibility
- Expo SDK
- 54 and 57, both checked in CI
- React Native
- 0.81 and 0.86, New Architecture
- Web
- Expo's web target, through react-native-web
Source
1 file, installed as source you own
spinner.tsxView on GitHubimport type { Ref } from "react";
import { ActivityIndicator, type ActivityIndicatorProps } from "react-native";
import { useTheme } from "@/registry/native/lib/theme";
type SpinnerSize = "sm" | "default" | "lg";
interface SpinnerProps extends Omit<ActivityIndicatorProps, "size"> {
size?: SpinnerSize;
ref?: Ref<ActivityIndicator>;
}
/**
* The platform's own activity indicator in the theme's muted colour, so it
* looks native on iOS and Android. It is announced as "Loading"; pass a more
* specific `accessibilityLabel` when you can ("Loading courts"). Inside a
* Button, use the Button's `loading` prop instead.
*/
function Spinner({
size = "default",
color,
accessibilityLabel = "Loading",
style,
...props
}: SpinnerProps) {
const { colors } = useTheme();
return (
<ActivityIndicator
// The native view is not an accessibility element on its own.
accessible
role="progressbar"
aria-busy
accessibilityLabel={accessibilityLabel}
size={size === "lg" ? "large" : "small"}
color={color ?? colors.mutedForeground}
style={[size === "sm" ? { transform: [{ scale: 0.75 }] } : null, style]}
{...props}
/>
);
}
export { Spinner, type SpinnerProps, type SpinnerSize };