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
npx 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-sheets` 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-sheets
  2. Registra i web component

    import '@capgo/capacitor-sheets';
  3. Aggiungi l'impostazione viewport per le safe areas

    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
  4. Renderizza uno sheet

    <cap-sheet-trigger for="booking-sheet" action="present">Open route</cap-sheet-trigger>
    <cap-sheet id="booking-sheet" detents="18em 32em" content-placement="bottom">
    <cap-sheet-portal>
    <cap-sheet-view>
    <cap-sheet-backdrop></cap-sheet-backdrop>
    <cap-sheet-content class="route-sheet">
    <cap-sheet-bleeding-background></cap-sheet-bleeding-background>
    <cap-sheet-handle></cap-sheet-handle>
    <cap-sheet-title>Evening route</cap-sheet-title>
    <cap-sheet-description>Choose a route and confirm pickup.</cap-sheet-description>
    <cap-sheet-trigger action="dismiss">Done</cap-sheet-trigger>
    </cap-sheet-content>
    </cap-sheet-view>
    </cap-sheet-portal>
    </cap-sheet>
    .route-sheet {
    width: min(100%, 34em);
    padding: 0 1.25em 1.25em;
    }
  • Registra i componenti: importa @capgo/capacitor-sheets once at bootstrap or elements will not upgrade.
  • Adattamento viewport: mancante viewport-fit=cover rompe il padding della safe area sui telefoni con notch.
  • Tastiera: attiva la prevenzione dello scroll al focus documentata quando gli input si trovano all'interno di bottom sheet.

Le safe area sono abilitate di default tramite safe-area="auto". La viewport del sheet legge sia i valori dell'ambiente browser sia le variabili di fallback Capacitor:

env(safe-area-inset-top)
env(safe-area-inset-bottom)
env(safe-area-inset-left)
env(safe-area-inset-right)
var(--safe-area-inset-top)
var(--safe-area-inset-bottom)
var(--safe-area-inset-left)
var(--safe-area-inset-right)

Scegli i bordi protetti per ogni sheet:

<cap-sheet safe-area="auto"></cap-sheet>
<cap-sheet safe-area="bottom left right"></cap-sheet>
<cap-sheet safe-area="none"></cap-sheet>

Per le app con barre di stato o di sistema sovrapposte, mantieni i plugin nativi responsabili dell'esposizione dei valori di inset corretti:

import type { CapacitorConfig } from '@capacitor/cli';
const config: CapacitorConfig = {
plugins: {
StatusBar: {
overlaysWebView: true,
},
Keyboard: {
resize: 'body',
resizeOnFullScreen: true,
},
SystemBars: {
insetsHandling: 'css',
},
},
};
export default config;

La gestione della tastiera è controllata da native-focus-scroll-prevention, che di default è impostato su true. Disabilitalo solo se la tua app gestisce già l'keyboard avoidance:

<cap-sheet native-focus-scroll-prevention="false"></cap-sheet>

Tutti gli helper del framework configurano lo stesso custom element sottostante. Puoi anche controllare uno sheet direttamente:

const sheet = document.querySelector('cap-sheet');
await sheet?.present();
await sheet?.stepTo(2);
await sheet?.step('down');
await sheet?.dismiss();

Ascolta gli eventi per gestire lo stato controllato, l'analytics o animazioni coordinate:

sheet?.addEventListener('cap-sheet-presented-change', (event) => {
console.log(event.detail.presented);
});
sheet?.addEventListener('cap-sheet-active-detent-change', (event) => {
console.log(event.detail.activeDetent);
});
sheet?.addEventListener('cap-sheet-travel', (event) => {
console.log(event.detail.progress);
});
import { useEffect, useRef } from 'react';
import { setupSheet } from '@capgo/capacitor-sheets/react';
import '@capgo/capacitor-sheets';
export function BookingSheet() {
const sheetRef = useRef<HTMLElement>(null);
useEffect(() => {
if (!sheetRef.current) return;
return setupSheet(sheetRef.current, {
detents: ['18em', '32em'],
contentPlacement: 'bottom',
onPresentedChange: ({ presented }) => console.log({ presented }),
});
}, []);
return (
<cap-sheet id="booking-sheet" ref={sheetRef}>
<cap-sheet-trigger action="present">Open</cap-sheet-trigger>
<cap-sheet-view>
<cap-sheet-backdrop />
<cap-sheet-content>
<cap-sheet-handle />
<cap-sheet-title>React sheet</cap-sheet-title>
</cap-sheet-content>
</cap-sheet-view>
</cap-sheet>
);
}

Importazione da @capgo/capacitor-sheets/react registra anche i typings JSX per i custom elements. Se TypeScript segnala ancora tag sconosciuti, aggiungi un file di dichiarazione nel tuo source tree:

src/capgo-sheets.d.ts
import '@capgo/capacitor-sheets/react';
<script setup lang="ts">
import { onMounted, onUnmounted, ref } from 'vue';
import { setupSheet } from '@capgo/capacitor-sheets/vue';
import '@capgo/capacitor-sheets';
const sheetRef = ref<HTMLElement | null>(null);
let cleanup: (() => void) | undefined;
onMounted(() => {
if (sheetRef.value) {
cleanup = setupSheet(sheetRef.value, {
detents: ['18em', '32em'],
contentPlacement: 'bottom',
});
}
});
onUnmounted(() => cleanup?.());
</script>
<template>
<cap-sheet id="booking-sheet" ref="sheetRef">
<cap-sheet-trigger action="present">Open</cap-sheet-trigger>
<cap-sheet-view>
<cap-sheet-backdrop />
<cap-sheet-content>
<cap-sheet-handle />
<cap-sheet-title>Vue sheet</cap-sheet-title>
</cap-sheet-content>
</cap-sheet-view>
</cap-sheet>
</template>
import { AfterViewInit, Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, ViewChild } from '@angular/core';
import { setupSheet } from '@capgo/capacitor-sheets/angular';
import '@capgo/capacitor-sheets';
@Component({
selector: 'app-root',
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
template: `
<cap-sheet id="booking-sheet" #sheet>
<cap-sheet-trigger action="present">Open</cap-sheet-trigger>
<cap-sheet-view>
<cap-sheet-backdrop></cap-sheet-backdrop>
<cap-sheet-content>
<cap-sheet-handle></cap-sheet-handle>
<cap-sheet-title>Angular sheet</cap-sheet-title>
</cap-sheet-content>
</cap-sheet-view>
</cap-sheet>
`,
})
export class AppComponent implements AfterViewInit {
@ViewChild('sheet', { static: true }) sheet?: ElementRef<HTMLElement>;
ngAfterViewInit(): void {
if (this.sheet?.nativeElement) {
setupSheet(this.sheet.nativeElement, {
detents: ['18em', '32em'],
contentPlacement: 'bottom',
});
}
}
}
<script lang="ts">
import { sheet } from '@capgo/capacitor-sheets/svelte';
import '@capgo/capacitor-sheets';
</script>
<cap-sheet id="booking-sheet" use:sheet={{ detents: ['18em', '32em'], contentPlacement: 'bottom' }}>
<cap-sheet-trigger action="present">Open</cap-sheet-trigger>
<cap-sheet-view>
<cap-sheet-backdrop />
<cap-sheet-content>
<cap-sheet-handle />
<cap-sheet-title>Svelte sheet</cap-sheet-title>
</cap-sheet-content>
</cap-sheet-view>
</cap-sheet>
import { onCleanup, onMount } from 'solid-js';
import { setupSheet } from '@capgo/capacitor-sheets/solid';
import '@capgo/capacitor-sheets';
export function BookingSheet() {
let sheetEl!: HTMLElement;
onMount(() => {
const cleanup = setupSheet(sheetEl, {
detents: ['18em', '32em'],
contentPlacement: 'bottom',
});
onCleanup(cleanup);
});
return (
<cap-sheet id="booking-sheet" ref={sheetEl}>
<cap-sheet-trigger action="present">Open</cap-sheet-trigger>
<cap-sheet-view>
<cap-sheet-backdrop />
<cap-sheet-content>
<cap-sheet-handle />
<cap-sheet-title>Solid sheet</cap-sheet-title>
</cap-sheet-content>
</cap-sheet-view>
</cap-sheet>
);
}
ElementoScopo
cap-sheetStato dello sheet, detents, gesture, comportamento modale ed eventi
cap-sheet-triggerAzioni dichiarative per present, dismiss, toggle e step
cap-sheet-portalBody portal opzionale per il layering degli overlay
cap-sheet-viewHost con viewport fisso e padding per safe-area e tastiera
cap-sheet-backdropBackdrop sincronizzata con il progresso
cap-sheet-contentSuperficie del sheet accessibile
cap-sheet-bleeding-backgroundEstensione dello sfondo per i bordi arrotondati dei sheet
cap-sheet-handleManiglia detent trascinabile e accessibile da tastiera
cap-sheet-titleTitolo accessibile
cap-sheet-descriptionDescrizione accessibile
cap-sheet-special-wrapperHook di composizione per sheet staccati, card e lightbox
cap-sheet-stackRaggruppamento di sheet impilati
cap-sheet-outletOutlet di progresso per profondità, parallasse ed effetti di pagina
cap-scrollHelper per il progresso dello scroll
cap-fixedHelper per il layer fisso
cap-islandContenuti correlati alla floating island
cap-external-overlayContenuti overlay gestiti fuori dall'albero dello sheet
OpzioneAttributoPredefinitoDescrizione
contentPlacementcontent-placementbottomtop, bottom, left, right, o center
detentsdetentsnessunoLunghezze CSS separate da spazi come 18em 32em
safeAreasafe-areaautoBordi protetti della safe area
swipeswipetrueAbilita gesti con puntatore, touch, trackpad e rotella
swipeDismissalswipe-dismissaltrueConsenti i gesti per chiudere al detent 0
inertOutsideinert-outsidetrueImpedisci l'interazione dietro i fogli modali
focusTrapfocus-traptrueMantieni il focus della tastiera all'interno del sheet
closeOnOutsideClickclose-on-outside-clicktrueChiudi al clic sullo sfondo o sulla vista
closeOnEscapeclose-on-escapetrueChiudi premendo Escape
nativeFocusScrollPreventionnative-focus-scroll-preventiontrueMantieni i campi in focus visibili sopra la tastiera
themeColorDimmingtheme-color-dimmingautoDim the WebView theme color while modal
  • @capgo/capacitor-sheets
  • @capgo/capacitor-sheets/react
  • @capgo/capacitor-sheets/vue
  • @capgo/capacitor-sheets/angular
  • @capgo/capacitor-sheets/svelte
  • @capgo/capacitor-sheets/solid

Se stai usando Per iniziare per pianificare il lavoro sui plugin nativi, collegalo a Directory dei plugin di Capgo per il workflow del prodotto nella Capgo Plugin Directory, Plugin Capacitor di Capgo per i dettagli di implementazione in Capacitor Plugins di Capgo, Aggiunta o aggiornamento dei plugin per i dettagli sull'implementazione in Adding or Updating Plugins, Alternative ai plugin Ionic Enterprise per il workflow del prodotto in Ionic Enterprise Plugin Alternatives, e Capgo Native Build per il workflow di prodotto in Capgo Native Builds.