Skip to content

Getting Started

  1. Install the package

    Terminal window
    npm install @capgo/capacitor-native-loader
    npx cap sync
  2. Show a native loader from JavaScript

    import { NativeLoader } from '@capgo/capacitor-native-loader';
    const { id } = await NativeLoader.show({
    style: 'siri',
    placement: 'fullscreen',
    message: 'Preparing workspace',
    colors: ['#71f6ff', '#8b5cf6', '#ff4ecd', '#fff7ad'],
    scrimColor: 'rgba(3, 7, 18, 0.42)',
    interactionMode: 'block',
    });
    await doExpensiveWork();
    await NativeLoader.hide({ id });
await NativeLoader.configure({
defaults: {
style: 'orbit',
placement: 'center',
size: 96,
colors: ['#38bdf8', '#a78bfa'],
reducedMotion: 'system',
interactionMode: 'passThrough',
},
});

Use style: 'chrome' when you want the familiar browser top progress bar and the WebView should stay usable below it.

const { id } = await NativeLoader.show({
style: 'chrome',
placement: 'top',
colors: ['#4285f4', '#34a853', '#fbbc05', '#ea4335'],
thickness: 4,
interactionMode: 'passThrough',
webView: {
mode: 'resize',
insets: { top: 12 },
restoreOnHide: true,
},
});
await NativeLoader.hide({ id, restoreWebView: true });
const { id } = await NativeLoader.show({
style: 'ring',
message: 'Uploading',
progress: 0,
});
for await (const progress of uploadFile(file)) {
await NativeLoader.setProgress({ id, progress });
}
await NativeLoader.hide({ id });

Use setWebViewLayout when a native loader should own part of the screen while web content remains visible and usable.

await NativeLoader.setWebViewLayout({
mode: 'inset',
insets: { top: 96, bottom: 24 },
animated: true,
});
await NativeLoader.show({
style: 'wave',
placement: 'top',
size: 72,
message: 'Syncing',
interactionMode: 'passThrough',
});

Restore the original layout when the native surface is gone:

await NativeLoader.hideAll({ restoreWebView: true });

Bundle Lottie JSON or image assets in the native app and reference them from JavaScript.

await NativeLoader.show({
style: 'lottie',
placement: 'center',
asset: {
type: 'lottie',
source: 'rocket-loader.json',
loop: true,
},
});
await NativeLoader.show({
style: 'image',
placement: 'bottom',
asset: {
type: 'image',
source: 'loader-frame',
},
});

Other iOS plugins can call the shared loader directly.

import CapgoCapacitorNativeLoader
let id = NativeLoader.shared.show(options: [
"style": "siri",
"placement": "fullscreen",
"message": "Opening secure session",
"interactionMode": "block"
])
NativeLoader.shared.setProgress(id: id, progress: 0.6)
NativeLoader.shared.hide(id: id)

Other Android plugins can call the public object from Kotlin or Java.

import app.capgo.nativeloader.NativeLoader
val id = NativeLoader.show(
activity = activity,
options = mapOf(
"style" to "orbit",
"placement" to "fullscreen",
"message" to "Loading profile",
"interactionMode" to "block",
),
webView = bridge.webView,
)
NativeLoader.setProgress(id, 0.6)
NativeLoader.hide(id)
OptionTypeDescription
style'siri' | 'chrome' | 'orbit' | 'ring' | 'pulse' | 'dots' | 'bars' | 'wave' | 'halo' | 'lottie' | 'image'Loader renderer
placement'center' | 'top' | 'bottom' | 'left' | 'right' | 'fullscreen' | 'around' | 'custom'Native surface position
interactionMode'passThrough' | 'block' | 'loaderOnly'Touch handling
backgroundColorstringOverlay color, including alpha
scrimColorstringFullscreen or around-screen scrim color
colorsstring[]Loader gradient colors
progressnumberDeterminate value from 0 to 1
autoHidenumberMilliseconds before hiding automatically
assetobjectLottie or image asset source

Use reducedMotion: 'system' to respect the user’s platform motion settings.