Loader
The Loader component is used to display visual loading indicators with various animation styles and configurations.
Installation
$ cbui-cli install @crossbuildui/loader
expo-blur
is installed if using glass variant. Loader also depends on react-native-reanimated
for animations.Import
1import Loader from '@/crossbuildui/loader';
Basic Usage
1<Loader isVisible text="Loading..." />
Using LoaderProvider (Optional)
Wrap your app in LoaderProvider
to pass a global configuration for size, color, etc.
1<LoaderProvider globalConfig={{ size: 'sm', color: 'secondary' }}>
2 <App />
3</LoaderProvider>
You can access theme, layout and loader config via useLoaderContext()
:
1const { themeColors, layoutConfig, globalLoaderConfig } = useLoaderContext();
Variants
Loader supports multiple animation variants:spinner
, pulse
, dots
, bars
, wave
, skeleton
, and custom
.
1
2<Loader isVisible variant="spinner" text="Loading..." />
3<Loader isVisible variant="pulse" />
4<Loader isVisible variant="dots" elementCount={4} />
5<Loader isVisible variant="bars" />
6<Loader isVisible variant="wave" />
7<Loader isVisible variant="skeleton" />
8
Sizes
Choose from xs
, sm
, md
, lg
, or xl
sizes.
1
2<Loader isVisible size="xs" />
3<Loader isVisible size="sm" />
4<Loader isVisible size="md" />
5<Loader isVisible size="lg" />
6<Loader isVisible size="xl" />
7
Glass Mode
Enable glassmorphism using the isGlass
prop along with glassTint
and glassIntensity
. Works best on images or textured backgrounds.
1<Loader
2 isVisible
3 isGlass
4 glassTint="light"
5 glassIntensity={40}
6 variant="pulse"
7 text="Glass Effect"
8 subtitle="Beautiful glassmorphism background"
9/>
Inline Toggle Example
You can use loaders in inline mode conditionally based on state:
1<Loader
2 isVisible={loading}
3 variant="dots"
4 position="inline"
5 text="Loading content..."
6/>
Props Overview
PROP | TYPE | DEFAULT | DESCRIPTION |
---|---|---|---|
isVisible | boolean | false | Show or hide the loader. |
variant | 'spinner' | 'pulse' | 'dots' | 'bars' | 'wave' | 'skeleton' | 'custom' | 'spinner' | Loader animation style. |
size | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'md' | Size of loader. |
color | ColorShade | string | 'primary' | Color of loader elements. |
position | 'top' | 'bottom' | 'center' | 'inline' | 'center' | Position of the loader within the screen. |
text | string | - | Text below loader. |
subtitle | string | - | Subtitle below text. |
children | ReactNode | - | Custom loader element (for variant='custom'). |
elementCount | number | 3 | Number of elements (dots, bars, etc). |
disableAnimation | boolean | false | Disable animation. |
animationDuration | number | 1500 | Duration of animation in ms. |
showOverlay | boolean | false | Show overlay background. |
overlayOpacity | number | 0.5 | Opacity for the overlay. |
glassTint | 'default' | 'light' | 'dark' | - | Tint color for blur background (glass mode). |
glassIntensity | number | 30 | Blur intensity for glass mode. |
isGlass | boolean | false | Enable glass (blur) background. |
fullScreen | boolean | false | Expand loader to full screen. |
icon | ReactNode | - | Custom icon for spinner variant. |
onAnimationComplete | () => void | - | Callback after animation ends. |
styles | Partial<LoaderSlotStyles> | - | Custom style overrides per slot. |
style | StyleProp<ViewStyle> | - | Style for the loader root container. |
Styling
Customize the loader layout and appearance using:
style
: to override the root container.styles
: an object to override slot styles likebase
,overlay
,loader
,text
,subtitle
, andelement
.
Accessibility
The Loader component is accessible by default and uses ActivityIndicator
where possible. You can also set custom labels if needed using wrapping elements.
Custom Animations
You can disable animations using disableAnimation
or configure duration using animationDuration
. Each variant has unique native-driver-powered animations, including spin
, pulse
, and interpolated dots
.