Vai al contenuto

Per iniziare

GitHub

Puoi usare il nostro setup assistito dall'IA per installare il plugin. Aggiungi le skill Capgo al tuo strumento di IA usando il seguente comando:

Finestra del terminale
bunx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins

Poi usa il seguente prompt:

Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-native-loader` plugin in my project.

Se preferisci la configurazione manuale, installa il plugin eseguendo questi comandi e segui le istruzioni specifiche per piattaforma qui sotto:

  1. Installa il pacchetto

    Finestra del terminale
    bun add @capgo/capacitor-native-loader
    bunx cap sync
  2. Mostra un loader nativo da 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 });
import { NativeLoader } from '@capgo/capacitor-native-loader';
await NativeLoader.configure({ defaults: {} });
import { NativeLoader } from '@capgo/capacitor-native-loader';
const result = await NativeLoader.show();
console.log(result);
import { NativeLoader } from '@capgo/capacitor-native-loader';
await NativeLoader.update({ id: 'id-123' });
  • Inizializza una volta: esegui il setup durante il bootstrap dell'app.
  • Sync nativo: esegui bunx cap sync dopo gli aggiornamenti dei plugin.
  • Fonte di verità: fidati src/definitions.ts nel repo GitHub.
await NativeLoader.configure({
defaults: {
style: 'orbit',
placement: 'center',
size: 96,
colors: ['#38bdf8', '#a78bfa'],
reducedMotion: 'system',
interactionMode: 'passThrough',
},
});

Usa style: 'chrome' quando vuoi la classica barra di progresso in alto del browser e la WebView deve restare utilizzabile sotto.

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 });

Usa style: 'siri-v2' quando lo stato di caricamento deve essere un movimento di colore nativo a tutto schermo lungo il bordo dell'app, invece di una card centrata.

const { id } = await NativeLoader.show({
style: 'siri-v2',
placement: 'fullscreen',
colors: ['#71f6ff', '#8b5cf6', '#ff4ecd', '#fff7ad'],
thickness: 10,
scrimColor: 'rgba(3, 7, 18, 0.10)',
interactionMode: 'passThrough',
});
await NativeLoader.hide({ id });
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 });

Usa setWebViewLayout quando un loader nativo deve occupare parte dello schermo mentre i contenuti web restano visibili e utilizzabili.

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',
});

Ripristina il layout originale quando la superficie nativa non è più presente:

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

Includi asset Lottie JSON o immagini nell'app nativa e fai riferimento da 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',
},
});

Altri plugin iOS possono chiamare direttamente il loader condiviso.

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)

Altri plugin Android possono chiamare l'oggetto pubblico da Kotlin o 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)
OpzioneTipoDescrizione
style'siri' | 'siri-v2' | 'chrome' | 'orbit' | 'ring' | 'pulse' | 'dots' | 'bars' | 'wave' | 'halo' | 'lottie' | 'image'Renderer del loader
placement'center' | 'top' | 'bottom' | 'left' | 'right' | 'fullscreen' | 'around' | 'custom'Posizione della superficie nativa
interactionMode'passThrough' | 'block' | 'loaderOnly'Gestione del touch
backgroundColorstringColore overlay, incluso alpha
scrimColorstringColore scrim fullscreen o perimetrale
colorsstring[]Colori del gradiente del loader
progressnumberValore determinato da 0 a 1
autoHidenumberMillisecondi prima della scomparsa automatica
assetobjectSorgente dell'asset Lottie o immagine

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