Skip to content
LIBRARYBase

ImageViewer ​

Added in RC.11.1

Included in Mavis 0.1.0-rc.11.1 for Vue + Vite, Nuxt and NativeScript iOS/Android. Keep core and renderers on the same version.

Web preview
Open example ↗
vue
<MImageViewer v-model="photo" v-model:open="open" :images="images" label="Postcards" />
PropTypeContract
imagesreadonly ViewerImage[]Required. Unique key, full src, descriptive alt; optional thumbnail, caption, aspectRatio.
modelValue / openChoiceValue / booleanControlled selection and presentation. Removed selection falls back to the first image.
maxZoom / disablednumber / boolean4 / false. Zoom range starts at 1.
closeLabel / previousLabel / nextLabel / zoomInLabel / zoomOutLabel / resetLabel / errorLabelstringLocalizable controls and failure message.

Open a thumbnail to follow it into the viewer. Jolt shared layout connects the two presentations; its zoom controller owns pinch, pan, double tap and vertical dismissal. Buttons provide zoom/reset/navigation without requiring a gesture. At zoom greater than 1, closing first returns to the resting scale. Rapid selection, interrupted closing and unloading release the previous controller.

Web uses a modal dialog with Escape, contained Tab navigation and return focus. At base scale, arrow keys on the image area change photos. While zoomed, Jolt uses arrows to pan and Escape first resets the zoom; another Escape closes. +/− zoom and 0 resets. Native uses the MScreen layer host and handles Android back. Keep the viewer inside an MScreen on NativeScript. Images must fit in one page/window for the connected transition; Jolt safely falls back when the source is unavailable, clipped or cannot be captured. The standalone viewer returns to its own thumbnail grid.

update:modelValue, update:open, close and error let the app own state and respond to unavailable images. Source values never change as a side effect of zoom.

Feel ​

While you drag a photo down to dismiss it, the background and the top bar fade with your finger, so the page underneath shows through; releasing early brings them back. On the Web the bottom controls fade too. Changing photos slides the next one in from the side you asked for, and zoom becomes available as soon as it rests. Under reduced motion the photo changes in place. Opening and closing still follow the thumbnail through Jolt's shared layout.

On the Web the photo area now comes after the controls in keyboard order, and Tab cycles through the controls and the photo area. Arrow keys on the photo area still change photos.

Returning to a virtualized photo collection ​

Postcards opens a separate route from a recycled MVirtualList row. The application owns the collection, route guards and route commitment. When the thumbnail image emits load, tag its labelled MCard link and the detail MBox containing the zoomable MImage with the same sharedTag. The detail frame has a fixed height while its image decodes. Matching two containers lets NativeScript capture both ends of the transition. The link is the return target for keyboard focus, VoiceOver and TalkBack. Set zoom above 1 and pass returnEntry to the detail image. At minimum scale, Jolt holds the released image in place while the application decides whether to go back. A veto returns it to the viewer. At higher scale, a vertical drag pans the photograph.

Create the entry with gesture: 'photo', a stable item key, and a detail region. Implement realize(context) with the current list handle after the collection route has mounted. The handle finds the item in the current data, realizes the row, and verifies the identity and stable bounds of its tagged surface. fallbackFocusId identifies a focusable collection action for a deleted item or a thumbnail that misses the deadline. On NativeScript, coordinate the semantic card and fallback with the router’s useNavigationFocus return target so the page announcement lands on the same control. With Android touch exploration enabled, the catalogue keeps the collection accessible throughout the return. It uses the current key and skips the snapshot that would temporarily hide the page from TalkBack. The Back button exposes the same return to keyboard and assistive technology. Sending a native app to the background ends the visual entry. On resume, Back checks the guard again and restores the collection by the current key.

This example is in the repository and uses Mavis RC.19 with Jolt RC.19.

Chromium. A held photo returns after a veto. Reordering changes its visible row, and deleting it returns focus to the collection action.

iPhone Simulator. System drags exercise veto, return to the moved photograph, and return after deletion. After returning from the Home screen, Back honors a veto and restores the moved photograph.

Android emulator. System touches pull the photo, return to its current row, and reopen the collection after removal. The final sequence returns from Home, exercises a veto and restores the moved photograph.

vue
<script setup lang="ts">
import { computed, ref } from 'vue'
import type { ChoiceValue, ViewerImage } from '@getcortexlabs/mavis-core'
import { mountains, lake, coast } from '../atlas/photos'
import { useCatalog } from '../context'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
const { navigation } = useCatalog()
const current = ref<ChoiceValue>('mountains')
const open = ref(false)
const images = computed<ViewerImage[]>(() => [
  {
    key: 'mountains',
    src: mountains,
    alt: t('Above the clouds', 'Acima das nuvens'),
    caption: t('Leave a little room for wonder.', 'Deixe espaço para se surpreender.'),
  },
  {
    key: 'lake',
    src: lake,
    alt: t('Still waters', 'Águas tranquilas'),
    caption: t('Some places ask you to slow down.', 'Alguns lugares pedem calma.'),
  },
  {
    key: 'coast',
    src: coast,
    alt: t('The long way home', 'O caminho mais bonito'),
    caption: t('Follow the coastline a little further.', 'Siga o litoral um pouco mais.'),
  },
])
</script>
<template>
  <MColumn gap="lg">
    <MRow justify="between" align="center" wrap gap="md"
      ><MColumn gap="xs"
        ><MText text="POSTCARDS / VOL. 01" variant="overline" tone="primary" /><MText
          :text="t('A little further.', 'Um pouco mais longe.')"
          variant="title" /></MColumn
      ><MBadge :text="t('3 moments', '3 momentos')"
    /></MRow>
    <MText
      :text="
        t(
          'Open a photograph. Look closer. Find your way back.',
          'Abra uma fotografia. Veja de perto. Encontre o caminho de volta.',
        )
      "
      tone="muted"
    />
    <MImageViewer
      v-model="current"
      v-model:open="open"
      :images="images"
      :label="t('Postcards', 'Cartões-postais')"
      :closeLabel="t('Close viewer', 'Fechar galeria')"
      :previousLabel="t('Previous image', 'Imagem anterior')"
      :nextLabel="t('Next image', 'Próxima imagem')"
      :zoomInLabel="t('Zoom in', 'Ampliar')"
      :zoomOutLabel="t('Zoom out', 'Reduzir')"
      :resetLabel="t('Reset zoom', 'Restaurar zoom')"
      :errorLabel="t('Image unavailable', 'Imagem indisponível')"
    />
    <MButton
      id="postcards-link"
      variant="secondary"
      @click="navigation.push('/showcase/postcards')"
      >{{ t('Open the postcard collection', 'Abrir a coleção de cartões') }}</MButton
    >
    <MText id="viewer-value" :text="`${current}:${open}`" variant="caption" tone="muted" />
  </MColumn>
</template>

Desktop ​

On the Mac and on Windows the viewer opens in a layer above the screen, keeps the keyboard inside it and gives it back to the picture that opened it. +, - and 0 zoom, the arrow keys turn the page or move a zoomed picture, and a drag does the same with the pointer. See Desktop components.

Components for NativeScript and Web. Starting with Vue.