Embed a live camera preview and capture photos or video. Use it for a scanner or a custom capture screen.

Capture a photo and preview the result

tsx
import { Button, Camera, Image, VStack, cameraRef, signal } from 'kuito';

export default function Snap() {
  const camera = cameraRef();
  const photo = signal<string | null>(null);

  async function take() {
    try {
      const picture = await camera.current?.takePicture({ quality: 0.8 });

      photo.value = picture?.uri ?? null;
    } catch (error) {
      console.log('No picture:', error);
    }
  }

  return (
    <VStack flex={1}>
      <Camera
        ref={camera}
        flex={1}
        facing="back"
        onError={(event) => console.log(event.code, event.message)}
      />
      <Button disabled={!camera.ready.value} onPress={() => void take()}>
        Take picture
      </Button>
      {photo.value ? <Image src={photo.value} width={96} height={96} /> : null}
    </VStack>
  );
}

Behavior

Declare camera permission in config; recording with audio also needs microphone permission. Wait for camera.ready before calling methods. Captures return cache files, so copy a result to documents when it must persist. Test capture on a physical device.

Continue

Read Permissions for a complete workflow. See the complete prop reference for types and documented defaults.

Referência

Assinaturas

ts
(props: NativeViewProps<CameraProps, CameraMethods>): KuitoElement

Parâmetros

NomeTipoObrigatórioDescrição
propsNativeViewProps<CameraProps, CameraMethods>Sim—

Devolve

KuitoElement

Props: NativeViewProps<CameraProps, CameraMethods>

Props (incluindo props herdadas) 93

NomeTipoObrigatórioDescrição
opacityAnimatable<number>Não—
backgroundColorAnimatable<string>Não—
borderRadiusAnimatable<number>Não—
borderColorAnimatable<string>Não—
widthAnimatable<SizeValue>Não—
heightAnimatable<SizeValue>Não—
translateXAnimatable<number>Não—
translateYAnimatable<number>Não—
scaleAnimatable<number>Não—
scaleXAnimatable<number>Não—
scaleYAnimatable<number>Não—
rotateAnimatable<number>NãoDegrees.
shadowColorAnimatable<string>Não—
shadowRadiusAnimatable<number>Não—
shadowOffsetXAnimatable<number>Não—
shadowOffsetYAnimatable<number>Não—
hiddenProp<boolean>NãoTakes the view out of layout and off screen, as CSS display: none.
paddingProp<LengthPercentage>Não—
positionProp<"relative" | "absolute">Não—
idstringNão—
classProp<ClassNames>NãoClass names from a .css import or styles(): a string, or a list with falsy entries skipped, following the signals it reads.
styleStyleDeclarationsNãoStyles of this view alone, compiled at build time: CSS properties in camelCase. A value that changes must set a native prop (opacity).
keystring | numberNão—
paddingTopProp<LengthPercentage>Não—
paddingRightProp<LengthPercentage>Não—
paddingBottomProp<LengthPercentage>Não—
paddingLeftProp<LengthPercentage>Não—
minWidthProp<SizeValue>Não—
maxWidthProp<SizeValue>Não—
minHeightProp<SizeValue>Não—
maxHeightProp<SizeValue>Não—
aspectRatioProp<number>NãoWidth divided by height; sizes the missing side from the other.
topProp<LengthPercentageAuto>Não—
rightProp<LengthPercentageAuto>Não—
bottomProp<LengthPercentageAuto>Não—
leftProp<LengthPercentageAuto>Não—
marginProp<LengthPercentageAuto>Não—
marginTopProp<LengthPercentageAuto>Não—
marginRightProp<LengthPercentageAuto>Não—
marginBottomProp<LengthPercentageAuto>Não—
marginLeftProp<LengthPercentageAuto>Não—
flexGrowProp<number>Não—
flexShrinkProp<number>Não—
flexBasisProp<SizeValue | "content">Não—
flexProp<number>NãoA grow factor from a zero basis, as CSS flex: n; 0 is inflexible.
alignSelfProp<"auto" | SelfAlignment>Não—
directionProp<"ltr" | "rtl">NãoThe way lines run; unset, the parent's, and the app's first language's at the root.
boxSizingProp<"border-box" | "content-box">Não—
paddingInlineStartProp<LengthPercentage>NãoPadding on the side lines start from: the left in ltr, the right in rtl.
paddingInlineEndProp<LengthPercentage>NãoPadding on the side lines end at: the right in ltr, the left in rtl.
marginInlineStartProp<LengthPercentageAuto>NãoMargin on the side lines start from: the left in ltr, the right in rtl.
marginInlineEndProp<LengthPercentageAuto>NãoMargin on the side lines end at: the right in ltr, the left in rtl.
insetInlineStartProp<LengthPercentageAuto>Nãoleft in ltr, right in rtl.
insetInlineEndProp<LengthPercentageAuto>Nãoright in ltr, left in rtl.
roleProp<Role>Não—
onAction(event: AccessibilityActionEvent) => voidNãoThe screen reader action taken, by name.
accessibleProp<boolean>NãoMakes the view one screen reader element, read as its label or its children's text.
labelProp<string>NãoWhat a screen reader says for the view.
hintProp<string>NãoWhat happens when the view is activated, read after the label.
aria-hiddenProp<boolean>NãoScreen readers skip the view and its subtree.
actionsProp<readonly AccessibilityAction[]>NãoActions a screen reader offers; onAction receives the one taken.
liveProp<"off" | "polite" | "assertive">NãoARIA's aria-live: announces changes to the view's content, on iOS too.
aria-disabledProp<boolean>Não—
aria-selectedProp<boolean>Não—
aria-checkedProp<boolean | "mixed">Não—
aria-busyProp<boolean>Não—
aria-expandedProp<boolean>Não—
aria-valueminProp<number>Não—
aria-valuemaxProp<number>Não—
aria-valuenowProp<number>Não—
aria-valuetextProp<string>Não—
gesturesreadonly Composable[]NãoThe view's gestures; several race unless composed with together or orElse.
transitionPartial<Record<"opacity" | "backgroundColor" | "transform" | "borderRadius" | "borderColor" | "shadow" | "width" | "height" | "all", Animation<unknown> | AnimationSpec>>NãoHow the animatable props move when they change, enter or leave, by group; a CSS transition compiles to it.
animatePartial<Record<AnimatableProps, string | number>>NãoAnimatable props whose every change moves as transition says; the first value applies at once.
enterEffectNãoWhere the view enters from: fade.and(slide.up(12)).
exitProp<Effect>NãoWhere the view leaves to; it stays on screen until it is there. The renderer gets true, and keeps the view until exited.
layoutAnimation<number>NãoHow the view moves to a new frame the layout gives it: layout={spring()}.
overflowProp<"visible" | "hidden" | "clip" | "scroll">Nãohidden and scroll clip; as in CSS, either lets a flex item shrink below its content.
borderWidthProp<number>Não—
backgroundGradient{ angle: number; colors: string[];}Não—
colorProp<string>Não—
sharedIdProp<string>NãoA view the navigation stack flies to the view with the same sharedId on the screen it pushes or pops to (docs/navigation.md#shared-elements).
refElementRef<NativeViewHandle<CameraMethods>>Não—
facingBound<CameraFacing>Nãoback by default.
flashBound<CameraFlash>Nãooff by default.
torchBound<boolean>NãoKeeps the light on while the preview runs.
zoomBound<number>NãoFrom 0 (none) to 1 (the most the camera can), linearly. 0 by default.
modeBound<CameraMode>Nãopicture by default. Record videos in video.
muteBound<boolean>NãoRecords videos without sound, and without asking for the microphone.
barcodesBound<BarcodeType[]>NãoScans for these codes while the preview runs.
onReady(event: CameraReadyEvent) => voidNãoThe preview is running: the camera can take pictures and record.
onError(event: CameraErrorEvent) => voidNão—
onBarcode(event: BarcodeEvent) => voidNãoEach time a code of barcodes comes into view.
onAction — assinaturas de método

Assinaturas

ts
(event: AccessibilityActionEvent): void

Parâmetros

NomeTipoObrigatórioDescrição
eventAccessibilityActionEventSim—

Devolve

void

backgroundGradient — campos aninhados

backgroundGradient campos

NomeTipoObrigatórioDescrição
anglenumberSim—
colorsstring[]Sim—
onReady — assinaturas de método

Assinaturas

ts
(event: CameraReadyEvent): void

Parâmetros

NomeTipoObrigatórioDescrição
eventCameraReadyEventSim—

Devolve

void

onError — assinaturas de método

Assinaturas

ts
(event: CameraErrorEvent): void

Parâmetros

NomeTipoObrigatórioDescrição
eventCameraErrorEventSim—

Devolve

void

onBarcode — assinaturas de método

Assinaturas

ts
(event: BarcodeEvent): void

Parâmetros

NomeTipoObrigatórioDescrição
eventBarcodeEventSim—

Devolve

void

Gerado a partir das declarações TypeScript públicas: assinaturas, props e predefinições vêm da fonte verificada, as descrições da sua JSDoc. Nenhuma predefinição é inventada.