diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b849c4..f364cfed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Unreleased -- [Fields, images, placeholders and status marks](docs/guide/motion.md#replacing-content-in-place) cross-fade or turn when content changes in place. Outgoing marks keep their previous ink, and validation and accessible names update immediately. Includes iOS and Android recordings. +- [Fields, images, placeholders and status marks](docs/guide/motion.md#replacing-content-in-place) cross-fade or turn when content changes in place. Clearing a photo restores the avatar initials and releases the outgoing image. Outgoing marks keep their previous ink, and validation and accessible names update immediately. Includes iOS and Android recordings. - Adopt Jolt 0.1.0-rc.22. [Web virtual lists](docs/components/virtual-list.md#reordering-a-thousand-rows-on-the-web) keep the dragged row mounted through a continuous reorder. Native speed dials align their panel with the visible trigger in wide rows and stay open when Android repeats a scroll notification for the same offset. Web layout exits preserve static form values, simple SVG and generated text. Gradients support endless playback, and desktop loops hold when their view detaches. - AppBar, TabBar and SpeedDial accept `material="glass"` or a shared `chromeMaterial` theme setting. They use Liquid Glass on iOS 26+, system blur on earlier iOS versions, and backdrop filtering on supported browsers. The bars follow contrast and transparency preferences. [Material and recordings](docs/guide/platform-motion.md#chrome-material) diff --git a/docs/components/avatar.md b/docs/components/avatar.md index 410c6ded..7e3d6d46 100644 --- a/docs/components/avatar.md +++ b/docs/components/avatar.md @@ -41,7 +41,7 @@ Initials use the first letter of the first and last words; a single word produce A photo appears only once it can paint: on Web the component waits for the image to decode, then fades it in while it eases from a slight zoom into its frame. NativeScript plays the same settle when the decoded image replaces the initials. Reduced motion keeps the fade and drops the zoom. -Changing `src` immediately restores the fallback. Stale results are ignored, including native results after unmount. Native requests already in flight may finish in the background: the component does not cancel the connection, implement its own cache or resize files before download. Supply appropriately sized images. There is no automatic retry; change `src` or remount to retry. +Clearing `src` fades the current photo back to the initials or icon, then releases the old image. Stale results are ignored, including native results after unmount. Native requests already in flight may finish in the background: the component does not cancel the connection, implement its own cache or resize files before download. Supply appropriately sized images. There is no automatic retry; change `src` or remount to retry. Without a name or `accessibilityLabel`, the avatar is decorative. Inner images, initials and icons are not separately announced. There are no slots, events, image picker, upload or built-in action. Compose an appropriate, clearly named control for an action. diff --git a/docs/components/image.md b/docs/components/image.md index 3b63c399..395afbf1 100644 --- a/docs/components/image.md +++ b/docs/components/image.md @@ -33,7 +33,7 @@ Reserves space during loading and failure. Obsolete source results are ignored. <<< @/../examples/catalog/shared/demos/ImageDemo.vue -`load` and `error` emit the source that completed. An empty source displays the fallback without starting a request. Explicit `height` takes precedence over the computed ratio; otherwise width and `aspectRatio` reserve the image space. +`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 diff --git a/docs/components/virtual-list.md b/docs/components/virtual-list.md index e7d04f06..b1ebe2dc 100644 --- a/docs/components/virtual-list.md +++ b/docs/components/virtual-list.md @@ -48,7 +48,7 @@ For a keyed shared-photo return, call `realizeKey({ key, tag, signal })` on the ## Rows of different heights -With `rowHeight="auto"` each row takes the height of its content: text that wraps, a picture whose size is known only once it loads, replies that open. Give `estimatedRowHeight` the height of a typical row; rows not measured yet count at that height, so the scroll bar can change length as you scroll. +With `rowHeight="auto"` each row takes the height of its content: text that wraps, a picture whose size is known only once it loads, replies that open. Give `estimatedRowHeight` the height of a typical row; rows not measured yet count at that height, so the scroll bar can change length as you scroll. On WebKit, a jump to a measured row uses the nearest scroll position the browser can represent, including when the preceding rows have fractional heights. ```vue (v instanceof Label ? String(v.text ?? '') : '') const photo = () => tree(byId('replacement-image')).filter((v) => v instanceof Image && v.isLoaded && v.imageSource) + const avatar = () => + tree(byId('replacement-avatar')).filter((v) => v instanceof Image && v.imageSource) const labels = () => tree().map(text) const update = await until(() => byId('replacement-change')) await until(() => (photo().length ? true : undefined)) @@ -95,6 +97,8 @@ async function run() { labels().filter((x) => /caption|Describe/.test(x)), ) check('the replacement leaves one decoded photo', photo().length === 1, photo().length) + await until(() => avatar().length === 1 || undefined) + check('the avatar shows its decoded photo', avatar().length === 1, avatar().length) check('the updated counter remains at ten', labels().includes('10'), '10') const trigger = await until(() => control(/^Actions$/)) tap(trigger) @@ -124,6 +128,12 @@ async function run() { !byId('replacement-content') && !labels().includes('Add a caption'), labels().filter((x) => /caption|Describe/.test(x)), ) + await until(() => avatar().length === 0 || undefined) + check( + 'clearing the avatar releases the old photo and reveals the initials', + tree(byId('replacement-avatar')).some((v) => text(v) === 'AR'), + avatar().length, + ) // An actual ancestor scroll still dismisses the built-in popover. let ancestor = trigger.parent while (ancestor && !(ancestor instanceof ScrollView)) ancestor = ancestor.parent diff --git a/packages/desktop/src/components/MImage.ts b/packages/desktop/src/components/MImage.ts index 86a525cb..52a78132 100644 --- a/packages/desktop/src/components/MImage.ts +++ b/packages/desktop/src/components/MImage.ts @@ -50,22 +50,26 @@ export const MImage = defineComponent({ }, { flush: 'sync', immediate: true }, ) - const handOver = () => { - const outgoing = held.value - const node = leaving.value - if (!outgoing || !node || host.reducedMotion()) { - held.value = undefined - return - } - const { exit } = replacementMotion(theme.value, 'fade') - away = host.motion(node).animate('opacity', 0, { - duration: exit.transition.duration, - ease: theme.value.motion.ease, - }) - void away.finished.then(() => { - if (held.value === outgoing) held.value = undefined - }) - } + watch( + [status, held], + ([state, outgoing]) => { + if (state === 'loading' || !outgoing) return + const node = leaving.value + if (!node || host.reducedMotion()) { + held.value = undefined + return + } + const { exit } = replacementMotion(theme.value, 'fade') + away = host.motion(node).animate('opacity', 0, { + duration: exit.transition.duration, + ease: theme.value.motion.ease, + }) + void away.finished.then(() => { + if (held.value === outgoing) held.value = undefined + }) + }, + { flush: 'post' }, + ) onBeforeUnmount(() => { generation++ fade?.cancel() @@ -84,7 +88,6 @@ export const MImage = defineComponent({ if (status.value === next) return status.value = next const crossing = held.value !== undefined - handOver() if (!ready) { emit('error', src) return diff --git a/packages/desktop/src/components/avatar.ts b/packages/desktop/src/components/avatar.ts index 8def7c92..42770688 100644 --- a/packages/desktop/src/components/avatar.ts +++ b/packages/desktop/src/components/avatar.ts @@ -70,8 +70,8 @@ export const MAvatar = defineComponent({ { flush: 'post', immediate: true }, ) watch( - settled, - (done) => { + [settled, held], + ([done]) => { const outgoing = held.value const node = leaving.value if (!done || !outgoing) return diff --git a/packages/nativescript/src/vue/components/MAvatar.ts b/packages/nativescript/src/vue/components/MAvatar.ts index 2165e2aa..d8ef671f 100644 --- a/packages/nativescript/src/vue/components/MAvatar.ts +++ b/packages/nativescript/src/vue/components/MAvatar.ts @@ -82,8 +82,8 @@ export const MAvatar = defineComponent({ { immediate: true }, ) watch( - () => image.value !== null || failed.value || !props.src.trim(), - (settled) => { + [() => image.value !== null || failed.value || !props.src.trim(), held], + ([settled]) => { if (!settled || !held.value) return handed = held.value.key handing.value = true diff --git a/packages/nativescript/src/vue/components/MImage.ts b/packages/nativescript/src/vue/components/MImage.ts index 3a22269b..aaafd0ca 100644 --- a/packages/nativescript/src/vue/components/MImage.ts +++ b/packages/nativescript/src/vue/components/MImage.ts @@ -63,8 +63,8 @@ export const MImage = defineComponent({ const image = shallowRef(null) const status = ref<'loading' | 'ready' | 'error'>('loading') watch( - status, - (value) => { + [status, held], + ([value]) => { if (!held.value || value === 'loading') return handed = held.value.key handing.value = true diff --git a/packages/web/src/components/MAvatar.ts b/packages/web/src/components/MAvatar.ts index fd6f3b14..fff01c44 100644 --- a/packages/web/src/components/MAvatar.ts +++ b/packages/web/src/components/MAvatar.ts @@ -7,6 +7,7 @@ import { useHandover, useMavisTheme, } from '@getcortexlabs/mavis-core/vue' +import { useMotionContext } from '../motion-context.js' import { useMotionSurface } from '../use-motion-surface.js' import { avatarSizes, avatarInitials } from '@getcortexlabs/mavis-core' import { webAttrs } from '../style.js' @@ -21,7 +22,8 @@ export const MAvatar = defineComponent({ const ready = ref(false) const failed = ref(false) const photo = useAvatarPhoto(() => ready.value) - const motion = useMotionSurface(() => photo) + const context = useMotionContext() + const motion = useMotionSurface(() => photo, undefined, context) // The photo shown before a new source stays until the next one decodes or fails. const held = shallowRef<{ key: number; src: string }>() const handing = ref(false) @@ -31,7 +33,11 @@ export const MAvatar = defineComponent({ held.value = undefined handing.value = false }) - const handoverMotion = useMotionSurface(() => (handing.value ? handover : undefined)) + const handoverMotion = useMotionSurface( + () => (handing.value ? handover : undefined), + undefined, + context, + ) // Initials and photo cross: the initials fade out as a photo arrives and back as it leaves. const fade = useFadeState(() => !ready.value && (!held.value || handing.value)) const initials = useMotionSurface(() => fade) @@ -52,8 +58,8 @@ export const MAvatar = defineComponent({ { flush: 'sync' }, ) watch( - () => ready.value || failed.value || !props.src.trim(), - (settled) => { + [() => ready.value || failed.value || !props.src.trim(), held], + ([settled]) => { if (!settled || !held.value) return handed = held.value.key handing.value = true diff --git a/packages/web/src/components/MImage.ts b/packages/web/src/components/MImage.ts index e22551cf..4e6112eb 100644 --- a/packages/web/src/components/MImage.ts +++ b/packages/web/src/components/MImage.ts @@ -61,7 +61,12 @@ export const MImage = defineComponent({ held.value = undefined handing.value = false }) - const handoverMotion = useMotionSurface(() => (handing.value ? handover : undefined)) + const context = useMotionContext() + const handoverMotion = useMotionSurface( + () => (handing.value ? handover : undefined), + undefined, + context, + ) const status = ref<'loading' | 'ready' | 'error'>('loading') const shared = useSharedTag( () => (status.value === 'ready' ? props.sharedTag : undefined), @@ -73,8 +78,10 @@ export const MImage = defineComponent({ releaseImage: (() => void) | undefined, committing: string | undefined const zooms = () => props.zoom > 1 - const motion = useMotionSurface(() => - status.value === 'ready' && !zooms() ? (props.motionSurface ?? reveal) : undefined, + const motion = useMotionSurface( + () => (status.value === 'ready' && !zooms() ? (props.motionSurface ?? reveal) : undefined), + undefined, + context, ) const photo = shallowRef() const syncPhoto = () => { @@ -82,8 +89,8 @@ export const MImage = defineComponent({ } watch(status, syncPhoto, { flush: 'post' }) watch( - status, - (value) => { + [status, held], + ([value]) => { if (!held.value || value === 'loading') return handed = held.value.key handing.value = true @@ -104,7 +111,7 @@ export const MImage = defineComponent({ void nextTick(syncPhoto) }, ) - useConnectedMotion(photo, useMotionContext(), (runtime, target) => { + useConnectedMotion(photo, context, (runtime, target) => { const image = target as HTMLImageElement const zoom = runtime.zoomable(image, { viewport: image.parentElement!, @@ -246,7 +253,7 @@ export const MImage = defineComponent({ width: '100%', height: '100%', objectFit: props.fit, - opacity: 1, + visibility: 'visible', }, }) : null, @@ -321,7 +328,7 @@ export const MImage = defineComponent({ width: '100%', height: '100%', objectFit: props.fit, - opacity: status.value === 'ready' ? 1 : 0, + visibility: status.value === 'ready' ? 'visible' : 'hidden', }, }) : null, diff --git a/packages/web/src/components/MVirtualList.ts b/packages/web/src/components/MVirtualList.ts index fb1c3afd..3c051c7f 100644 --- a/packages/web/src/components/MVirtualList.ts +++ b/packages/web/src/components/MVirtualList.ts @@ -130,8 +130,11 @@ const VirtualList = defineComponent({ instance.update() const list = root.value if (list && Math.abs(list.scrollTop - top) >= 0.5) { - written = top list.scrollTop = top + // Some WebKit hosts truncate fractional scrollTop even when row edges are fractional. + // Keep the closest available position so the preceding row does not peek over the edge. + if (Math.abs(list.scrollTop - top) > 0.5) list.scrollTop = Math.round(top) + written = list.scrollTop } } /** Rows drawn off their logical place leave a gap or hide a row only at the ends. */ diff --git a/packages/web/src/use-motion-surface.ts b/packages/web/src/use-motion-surface.ts index 87f596aa..10e638bd 100644 --- a/packages/web/src/use-motion-surface.ts +++ b/packages/web/src/use-motion-surface.ts @@ -16,6 +16,7 @@ import { reviveDetachedEffects } from './detached-effects.js' export function useMotionSurface( surface: () => MotionSurface | undefined, plainText: () => boolean = () => false, + context = useMotionContext(), ) { const element = shallowRef() const connected = computed(() => (surface() ? element.value : undefined)) @@ -35,7 +36,7 @@ export function useMotionSurface( } useConnectedMotion( connected, - useMotionContext(), + context, (runtime, target) => { // Responsive layout can resize a declared surface before an animation ends. // Keep Jolt's geometry lease alive until every playback has been released. diff --git a/test/browser/adoption.browser.ts b/test/browser/adoption.browser.ts index 40b34841..0648157f 100644 --- a/test/browser/adoption.browser.ts +++ b/test/browser/adoption.browser.ts @@ -102,7 +102,7 @@ test('forwards responsive image attributes and recovers when the chosen candidat page, }) => { const image = page.locator('#adoption-image'), - inner = image.locator('img') + inner = image.getByAltText('Responsive sample', { exact: true }) await expect(inner).toHaveAttribute('srcset', /320w.*960w/) await expect(inner).toHaveAttribute('sizes', '320px') for (const [attribute, value] of [ @@ -126,6 +126,7 @@ test('forwards responsive image attributes and recovers when the chosen candidat await expect(image).toHaveAttribute('data-state', 'error') await page.getByRole('button', { name: 'Restore image source' }).click() await expect(image).toHaveAttribute('data-state', 'ready') + await expect(image.locator('img')).toHaveCount(1) expect( await image.evaluate( (el) => el.getBoundingClientRect().width / el.getBoundingClientRect().height, diff --git a/test/browser/item-motion.browser.ts b/test/browser/item-motion.browser.ts index 340967b9..678778d3 100644 --- a/test/browser/item-motion.browser.ts +++ b/test/browser/item-motion.browser.ts @@ -237,6 +237,9 @@ test('reduced motion settles every item gesture immediately', async ({ page }) = await page.goto('/playground/#/components/avatar') for (const name of ['Iniciais', 'Imagem indisponível', 'Imagem']) await page.getByRole('button', { name, exact: true }).click() - await expect(page.locator('#avatar-preview img')).toHaveCSS('opacity', '1') + const avatar = page.locator('#avatar-preview') + await expect(avatar.locator('img:not([data-leaving])')).toBeVisible() + await expect(avatar.locator('img[data-leaving]')).toHaveCount(0) + await expect(avatar.locator('img')).toHaveCSS('opacity', '1') expect(errors).toEqual([]) }) diff --git a/test/browser/media-motion.browser.ts b/test/browser/media-motion.browser.ts index 8716be4d..3abc5269 100644 --- a/test/browser/media-motion.browser.ts +++ b/test/browser/media-motion.browser.ts @@ -72,12 +72,17 @@ test('the comparison handle stretches while held and the hint never changes the const handle = page.locator('.m-image-compare-handle') const line = handle.locator('xpath=..') const positions = new Set() - for (let index = 0; index < 10; index++) { - positions.add(await line.evaluate((node) => (node as HTMLElement).style.left)) - await expect(slider).toHaveAttribute('aria-valuenow', '50') - await page.waitForTimeout(90) - } - expect(positions.size).toBeGreaterThan(2) + // The hint starts once both photos decode, which can take longer than the animation itself. + await expect + .poll( + async () => { + positions.add(await line.evaluate((node) => (node as HTMLElement).style.left)) + await expect(slider).toHaveAttribute('aria-valuenow', '50') + return positions.size + }, + { intervals: [16] }, + ) + .toBeGreaterThan(2) await expect.poll(() => line.evaluate((node) => (node as HTMLElement).style.left)).toBe('50%') await expect(page.locator('#compare-value')).toHaveText('50') diff --git a/test/desktop/sections/replaced.ts b/test/desktop/sections/replaced.ts index 4e517b16..584b7407 100644 --- a/test/desktop/sections/replaced.ts +++ b/test/desktop/sections/replaced.ts @@ -44,7 +44,7 @@ export const Section = defineComponent({ h(MRow, { gap: 'md', align: 'center' }, () => [ h(MImage, { id: 'replaced-image', - src: odd ? portrait : landscape, + src: round.value === 3 ? '' : odd ? portrait : landscape, alt: 'A picture', width: 120, aspectRatio: 1, @@ -205,8 +205,15 @@ export async function appkit(context: AppKitContext) { } assert.ok(await wait(() => images(image).length === 1), 'and the previous one is let go') assert.equal(opacity(images(image)[0]!), 1) - await wait(() => opacity(initials) === 1) - assert.equal(opacity(initials), 1, 'The initials come back as the photo goes') + assert.ok( + await wait(() => opacity(initials) === 1 && images(avatar).length === 0), + 'Clearing the avatar shows the initials and releases the photo', + ) + find('replaced-next').native.performClick(null) + assert.ok( + await wait(() => image.props.state === 'error' && images(image).length === 0), + 'An empty image source releases the old photo after its exit', + ) pass('A picture crosses into the next one and initials cross with a photo, both ways') }