Command palette

@yasinsensoy/native

React Native · Components

Image

An image that manages its loading, error and placeholder states itself (same API as Image on web).

5 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Cappadocia

Code

import { Image } from "@yasinsensoy/native";

<Image src="/kapak.jpg" alt="Cappadocia" width={1200} height={800}
  className="rounded-xl"
/>

// In Next.js, when optimizeImages is passed to the @yasinsensoy/web/next provider
// it renders with next/image (resizing, WebP/AVIF).

Events

  1. Events appear here when you interact with the preview.

An image filling the box in a card (fill) and a custom error view

Aegean cove

Aegean cove

Profile

Custom error view

Import

import { Image } from "@yasinsensoy/native";

Image

component

An image that manages its loading, error and placeholder states itself (same API as Image on web). Gallery thumbnails are drawn with it too.

  • While loading: a shimmering skeleton, the image's dominant color or a small blurred image (placeholder); it fades in smoothly on load (native driver).
  • No layout shift: with width + height, ratio or fill the box reserves space before the image loads.
  • Error: an icon and "Retry"; it retries by itself when the app returns to the foreground.
Image({ src, alt, width, height, ratio, fill, fit, placeholder, appear, fallback, priority, headers, onLoad, onError, style, imageStyle, effect, ref, testID, }: ImageProps): JSX.Element

Examples

<Image src="https://…/cover.jpg" alt="Cover" width={1200} height={630} style={{ borderRadius: 12 }} />

// An image covering the box in a card, with the dominant color until it loads
<View style={{ aspectRatio: 16 / 9 }}>
  <Image src={product.image} alt={product.name} fill placeholder="#d6c7b0" />
</View>

How the image fits the box (the same names as object-fit on web).

type ImageFit = "cover" | "contain" | "fill" | "none" | "scale-down"

Image source: an address or a file in the bundle (require("./cover.png")).

type ImageSource = string | number

ImageLoadInfo

interface

Original dimensions of the loaded image.

NameTypeDescription
widthnumberOriginal width (pixels).
heightnumberOriginal height (pixels).

ImageProps

interface

Props of Image.

NameTypeDefaultDescription
srcImageSourceImage address or a file in the bundle (require(...)).
altstringAlternative text (screen readers). Give "" for a decorative image.
width?numberOriginal width. Given together with height, the box reserves space in the right ratio before the image loads; it shrinks if it does not fit the container.
height?numberOriginal height. See width.
ratio?numberBox ratio (width / height, e.g. 16 / 9). When given the box is full width.
fill?booleanfalseFill the container completely (background in a positioned container, card cover, gallery).
fit?ImageFit"cover"How the image fits the box.
placeholder?string"shimmer"Shown until it loads: a color ("#8a9bb0", the image's dominant color), a small blurred image (an address or a data: address), "shimmer" a shimmering skeleton, or "none".
appear?"fade" | "scale" | "none""fade"Reveal on load: "fade", "scale" (growing slightly) or "none".
fallback?ReactNode | ((retry: () => void) => ReactNode)Content shown if it fails to load. If omitted an icon, "Image could not be loaded" and "Retry" appear. A function receives the retry function. null shows nothing. It retries by itself when the app returns to the foreground.
priority?booleanfalseThe first visible image (cover, product image): download starts before it renders. Limit it to one or two images per screen.
headers?Record<string, string>Request headers (e.g. Authorization for protected images).
onLoad?(info: ImageLoadInfo) => voidOn load; with the image's original dimensions.
onError?() => voidWhen it fails to load.
style?StyleProp<ViewStyle>Style of the box (corners, border, size). Corners clip the image too.
imageStyle?StyleProp<ImageStyle>Style of the image itself.
effect?EffectPropEffect or effects of the image box (e.g. "shine", ["tilt", "glow"]). Defaults to UIProvider appearance.defaults.image.effect.
ref?Ref<ViewRef>Access to the box.
testID?stringTest id.