Utilisation

Scroll after adding content

tsx
import { Button, For, ref, Scroll, signal, Text, VStack } from 'kuito';
import type { ScrollHandle } from 'kuito';

function Chat() {
  const messages = signal<string[]>([]);
  const thread = ref<ScrollHandle>();

  function send() {
    messages.value = [...messages.value, 'Message ' + (messages.value.length + 1)];
    thread.current?.scrollToEnd();
  }

  return (
    <VStack flex={1} gap={8}>
      <Scroll ref={thread} flex={1}>
        <For each={messages}>{(message) => <Text>{message}</Text>}</For>
      </Scroll>
      <Button onPress={send}>Send</Button>
    </VStack>
  );
}

Déclaration du type

ts
export interface ScrollHandle extends ElementHandle {
  /**
   * Scrolls to `offset` points along the view's axis, or to `page`, a whole
   * view length each from 0, as `paging` rests; animated by default.
   */
  scrollTo(
    params: { offset: number; animated?: boolean } | { page: number; animated?: boolean },
  ): void;
  /** Scrolls to the end of the content, including what the same update added. */
  scrollToEnd(params?: { animated?: boolean }): void;
}

Membres 11

NomTypeRequisDescription
scrollTo(params: { offset: number; animated?: boolean;} | { page: number; animated?: boolean;}) => voidOuiScrolls to offset points along the view's axis, or to page, a whole view length each from 0, as paging rests; animated by default.
scrollToEnd(params?: { animated?: boolean;}) => voidOuiScrolls to the end of the content, including what the same update added.
idlecture seulestringOui—
parentlecture seuleElementHandleOui—
childrenlecture seuleElementHandle[]Oui—
focus() => voidOui—
blur() => voidOui—
setProperty<K extends keyof ElementProperties>(key: K, value: ElementProperties[K] | null) => voidOuiSets a native prop on the view now, until its binding writes it again.
addEventListener(type: string, fn: (e: KuitoNativeEvent) => void, options?: boolean | { capture?: boolean; once?: boolean; signal?: AbortSignal;}) => voidOui—
removeEventListener(type: string, fn: (e: KuitoNativeEvent) => void, options?: boolean | { capture?: boolean;}) => voidOui—
dispatchEvent(event: { type: string; bubbles?: boolean; cancelable?: boolean;}) => booleanOuiSends an event through the tree, capture to bubble, as a native one travels: a KuitoCustomEvent, or any object with a type. False when a listener called preventDefault() on a cancelable event.
scrollTo — signatures de méthode

Signatures

ts
(params: { offset: number; animated?: boolean; } | { page: number; animated?: boolean; }): void

Paramètres

NomTypeRequisDescription
params{ offset: number; animated?: boolean;} | { page: number; animated?: boolean;}Oui—

Retourne

void

scrollToEnd — signatures de méthode

Signatures

ts
(params?: { animated?: boolean; }): void

Paramètres

NomTypeRequisDescription
params{ animated?: boolean;}Non—

Retourne

void

focus — signatures de méthode

Signatures

ts
(): void

Paramètres

Aucun paramètre.

Retourne

void

blur — signatures de méthode

Signatures

ts
(): void

Paramètres

Aucun paramètre.

Retourne

void

setProperty — signatures de méthode

Signatures

ts
<K extends keyof ElementProperties>(key: K, value: ElementProperties[K] | null): void

Paramètres de type

NomContraintePar défaut
Kkeyof ElementProperties—

Paramètres

NomTypeRequisDescription
keyKOui—
valueElementProperties[K]Oui—

Retourne

void

addEventListener — signatures de méthode

Signatures

ts
(type: string, fn: (e: KuitoNativeEvent) => void, options?: boolean | { capture?: boolean; once?: boolean; signal?: AbortSignal; }): void

Paramètres

NomTypeRequisDescription
typestringOui—
fn(e: KuitoNativeEvent) => voidOui—
optionsboolean | { capture?: boolean; once?: boolean; signal?: AbortSignal;}Non—

Retourne

void

removeEventListener — signatures de méthode

Signatures

ts
(type: string, fn: (e: KuitoNativeEvent) => void, options?: boolean | { capture?: boolean; }): void

Paramètres

NomTypeRequisDescription
typestringOui—
fn(e: KuitoNativeEvent) => voidOui—
optionsboolean | { capture?: boolean;}Non—

Retourne

void

dispatchEvent — signatures de méthode

Signatures

ts
(event: { type: string; bubbles?: boolean; cancelable?: boolean; }): boolean

Paramètres

NomTypeRequisDescription
event{ type: string; bubbles?: boolean; cancelable?: boolean;}Oui—

Retourne

boolean

Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.