Skip to content
LIBRARYBaseUpdated

Image ​

An image, thoughtfully presented.

Added in alpha.7

Available in Mavis 0.1.0-alpha.7.

Web preview
Open example ↗
vue
<m-image src="https://example.com/print.png" alt="Art print" :aspectRatio="4 / 3" />

Reserves space during loading and failure. Obsolete source results are ignored. Uses platform loading, without its own global cache or a network cancellation guarantee.

PropertyTypeDefaultDescription
srcstringrequiredLocal image, data URI or URL according to the platform.
altstringrequiredDescription; empty text for a decorative image.
aspectRationumber4 / 3Positive ratio that reserves height.
fitcover / containcoverCrop or fit the image.
radiustoken / numbermdTheme radius or number.
loadingLabel / errorLabelstringLoading image / Image unavailableLoading and error copy.
revealfade / settle / nonefadeHow a decoded photo appears.
zoomnumber1Largest pinch or double-tap scale, up to 8. Above 1 the photo owns its transform, so motionSurface cannot be set.
gestureMotionGesture—Experimental. Receives the photo pan and pinch while zoom is above 1, for gesture relations.
vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import { useCatalogLocale } from '../locale'
import { formaImage } from '../assets/forma-image'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const broken = ref(false)
const reveal = ref<'fade' | 'settle' | 'none'>('settle')
const replay = ref(0)
const reveals = computed(() => [
  { value: 'fade', label: 'Fade' },
  { value: 'settle', label: pt.value ? 'Assentar' : 'Settle' },
  { value: 'none', label: pt.value ? 'Nenhuma' : 'None' },
])
</script>
<template>
  <m-column gap="md">
    <m-image
      id="image-demo"
      :key="replay"
      :src="broken ? 'data:image/png;base64,broken' : formaImage"
      :alt="
        pt
          ? 'Gravura Forma com arcos azuis e círculos rosa'
          : 'Forma art print with blue arches and pink circles'
      "
      :aspectRatio="4 / 3"
      :reveal="reveal"
      :loadingLabel="pt ? 'Carregando imagem' : 'Loading image'"
      :errorLabel="pt ? 'Imagem indisponível' : 'Image unavailable'"
    />
    <m-segmented-control
      :modelValue="reveal"
      :options="reveals"
      :label="pt ? 'Revelação' : 'Reveal'"
      @update:modelValue="(value) => (reveal = value as typeof reveal)"
    />
    <m-row gap="sm" wrap align="center" justify="between">
      <m-switch v-model="broken" :label="pt ? 'Simular erro' : 'Simulate error'" />
      <m-button
        id="image-demo-replay"
        variant="secondary"
        icon="rotate-ccw"
        :text="pt ? 'Revelar de novo' : 'Reveal again'"
        @click="replay++"
      />
    </m-row>
  </m-column>
</template>

load and error emit the source that completed. An empty source displays the fallback without starting a request. If a photo was visible, it fades out and its image view is released. Explicit height takes precedence over the computed ratio; otherwise width and aspectRatio reserve the image space.

Reveal ​

A decoded photo fades in by default. With reveal="settle" it also eases in from a slight zoom and, on the Web, comes into focus from a soft blur. The reserved frame shimmers while the image loads, and if it fails the fallback text slides in instead of popping. reveal="none" shows the photo at once.

vue
<m-image :src="cover" alt="Lighthouse at dusk" reveal="settle" />

The reveal plays each time a new source finishes decoding. It never delays load, error or the accessible name. Under reduced motion the zoom is skipped, and the fallback appears without travel (on the Web, at once). Native renderers fade and settle the photo but do not blur it, because the iOS backend is a tinted material rather than a content blur. When you pass your own motionSurface, the built-in reveal steps aside.

Experimental image, icon, Sheet and Dialog integrations are described in Images and physics. They require Jolt RC.11 and are included in Mavis alpha.8.

Responsive Web images ​

Included in alpha.11. srcset, sizes, loading (eager or lazy), decoding (sync, async or auto) and fetchpriority (high, low or auto) go to the inner <img>, with no default override. IDs, classes, styles and other wrapper attributes stay on the outer container. Keep a fallback src and the reserved aspectRatio.

vue
<m-image
  src="/photo-320.webp"
  srcset="/photo-320.webp 320w, /photo-960.webp 960w"
  sizes="(min-width: 800px) 50vw, 100vw"
  loading="lazy"
  decoding="async"
  fetchpriority="low"
  alt="A landscape"
  :aspect-ratio="1.5"
/>

Changes to src, srcset or sizes invalidate pending load/decode results while preserving geometry. The browser chooses the candidate and scheduling; loading does not guarantee request timing. These attributes are Web-only. Ripple/distortion may use the selected image, but dissolve source replacement rejects an active srcset because the application owns responsive source selection.

After an image has loaded, changing its source keeps the previous picture visible while the next one loads. The two cross-fade once the new picture is ready. The first image still uses its configured reveal.

Desktop ​

On the Mac and on Windows the host loads the picture off the drawing thread, keeps the frame while it loads and shows the error label if it fails. srcset, sizes, loading, decoding, fetchpriority, sharedTag, returnEntry, zoom and gesture are accepted and have no effect there. See Desktop components.

Components for NativeScript and Web. Starting with Vue.