WIP: Per-sheet drawer heights and minimized background sheets
Give each bottom sheet its own default height and remember the size the user drags it to, per sheet, so one sheet's height no longer leaks into the next. - App menu now opens at the medium detent instead of near-full-screen. - Place details opens at the short (collapsed) detent; the results and list sheets stay at medium. - Detent memory is keyed by route (map-ui.sheetDetents) instead of one shared slot, and the `detent` arg is authoritative on mount. - Background (parent) sheets are pinned to the minimum reachable detent on mount and on viewport changes, so they can never peek above the top sheet no matter how short it is. They still never write the detent memory.
This commit is contained in:
5 files changed
+179
-40
No files matched your search
@@ -37,11 +37,7 @@ export default class AppMenu extends Component {
|
||||
<template>
|
||||
<div
|
||||
class="sidebar app-menu-pane"
|
||||
{{bottomSheet
|
||||
detent="expanded"
|
||||
onDismiss=@onClose
|
||||
background=@background
|
||||
}}
|
||||
{{bottomSheet detent="medium" onDismiss=@onClose background=@background}}
|
||||
>
|
||||
{{#if (eq this.currentView "menu")}}
|
||||
<AppMenuHome
|
||||
|
||||
@@ -170,7 +170,11 @@ export default class PlacesSidebar extends Component {
|
||||
<template>
|
||||
<div
|
||||
class="sidebar"
|
||||
{{bottomSheet detent="medium" onDismiss=@onClose background=@background}}
|
||||
{{bottomSheet
|
||||
detent=(if @selectedPlace "collapsed" "medium")
|
||||
onDismiss=@onClose
|
||||
background=@background
|
||||
}}
|
||||
>
|
||||
<div
|
||||
class="sidebar-header
|
||||
|
||||
@@ -31,6 +31,7 @@ const INTERACTIVE_SELECTOR = 'button, a, input, select, textarea';
|
||||
|
||||
export default class BottomSheetModifier extends Modifier {
|
||||
@service mapUi;
|
||||
@service router;
|
||||
|
||||
element = null;
|
||||
named = {};
|
||||
@@ -114,8 +115,8 @@ export default class BottomSheetModifier extends Modifier {
|
||||
this.cancelRelease();
|
||||
|
||||
// A background sheet sits behind the interactive one: it must not steal
|
||||
// inset ownership, take gestures, or inject a handle. It only restores the
|
||||
// remembered detent so the parent shows at the right size.
|
||||
// inset ownership, take gestures, or inject a handle. It is pinned to the
|
||||
// minimum detent (see initialDetentName) so it stays hidden.
|
||||
if (!this.named.background) {
|
||||
this.mapUi.claimSheetInset(this);
|
||||
this.injectHandle();
|
||||
@@ -124,11 +125,34 @@ export default class BottomSheetModifier extends Modifier {
|
||||
|
||||
this.measure();
|
||||
|
||||
const restored = this.mapUi.sheetDetent;
|
||||
const initialName =
|
||||
restored ?? this.named.detent ?? this.layout[this.layout.length - 1].name;
|
||||
this.previousDetentArg = this.named.detent ?? null;
|
||||
this.enterAt(initialName);
|
||||
this.enterAt(this.initialDetentName());
|
||||
}
|
||||
|
||||
// The detent this sheet opens at. A background sheet is always minimized so
|
||||
// it can never peek above the interactive top sheet; a top sheet opens at the
|
||||
// detent remembered for its route, falling back to its declared default.
|
||||
initialDetentName() {
|
||||
if (this.named.background) return this.minimumDetent().name;
|
||||
return (
|
||||
this.mapUi.getSheetDetent(this.sheetKey()) ??
|
||||
this.named.detent ??
|
||||
this.minimumDetent().name
|
||||
);
|
||||
}
|
||||
|
||||
// The least-visible reachable detent (largest offset). The top sheet can
|
||||
// never be shorter than this, so a background sheet parked here is always
|
||||
// fully covered.
|
||||
minimumDetent() {
|
||||
return this.layout[this.layout.length - 1];
|
||||
}
|
||||
|
||||
// Sheet identity for the remembered-detent map. Background sheets never use
|
||||
// it (they are pinned to the minimum), so deriving it from the active route
|
||||
// is safe even though a background is rendered under a different route.
|
||||
sheetKey() {
|
||||
return this.router.currentRouteName ?? null;
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
@@ -262,12 +286,12 @@ export default class BottomSheetModifier extends Modifier {
|
||||
// targets so the release settles correctly.
|
||||
if (this.dragging || this.pending) return;
|
||||
|
||||
const name =
|
||||
this.mapUi.sheetDetent ??
|
||||
this.named.detent ??
|
||||
this.layout[this.layout.length - 1].name;
|
||||
const detent =
|
||||
findDetent(this.layout, name) ?? this.layout[this.layout.length - 1];
|
||||
const name = this.named.background
|
||||
? this.minimumDetent().name
|
||||
: (this.mapUi.getSheetDetent(this.sheetKey()) ??
|
||||
this.named.detent ??
|
||||
this.minimumDetent().name);
|
||||
const detent = findDetent(this.layout, name) ?? this.minimumDetent();
|
||||
|
||||
// Skip the settle (and its map-pan signal) when nothing actually moved,
|
||||
// e.g. an iOS keyboard opening resizes the visual viewport but not
|
||||
@@ -277,6 +301,10 @@ export default class BottomSheetModifier extends Modifier {
|
||||
}
|
||||
|
||||
handleDetentArgChange() {
|
||||
// Background sheets are pinned to the minimum; a changing arg must not
|
||||
// un-minimize them.
|
||||
if (this.named.background) return;
|
||||
|
||||
const requested = this.named.detent ?? null;
|
||||
if (requested === this.previousDetentArg) return;
|
||||
this.previousDetentArg = requested;
|
||||
@@ -301,10 +329,10 @@ export default class BottomSheetModifier extends Modifier {
|
||||
this.currentOffset = detent.offset;
|
||||
this.element.style.setProperty('--sheet-offset', `${detent.offset}px`);
|
||||
this.queueInset(this.sheetHeight - detent.offset);
|
||||
// Background sheets restore from the detent slot but must never write it:
|
||||
// Background sheets restore from the detent memory but must never write it:
|
||||
// the top sheet's position is the one worth remembering.
|
||||
if (!this.named.background) {
|
||||
this.mapUi.setSheetDetent(detent.name);
|
||||
this.mapUi.setSheetDetent(this.sheetKey(), detent.name);
|
||||
}
|
||||
this.queueSnap();
|
||||
}
|
||||
@@ -448,9 +476,9 @@ export default class BottomSheetModifier extends Modifier {
|
||||
this.currentOffset = this.sheetHeight;
|
||||
this.element.style.setProperty('--sheet-offset', `${this.sheetHeight}px`);
|
||||
this.queueInset(0);
|
||||
// A drag-dismiss ends the session: the next sheet should use its own
|
||||
// default detent, not this sheet's remembered position.
|
||||
this.mapUi.setSheetDetent(null);
|
||||
// A drag-dismiss forgets this sheet: the next time it opens it should use
|
||||
// its declared default, not the position the user dragged it to.
|
||||
this.mapUi.setSheetDetent(this.sheetKey(), null);
|
||||
|
||||
const onDismiss = this.named.onDismiss;
|
||||
const delay = this.reducedMotionQuery.matches ? 0 : TRANSITION_MS;
|
||||
|
||||
+25
-8
@@ -23,14 +23,18 @@ export default class MapUiService extends Service {
|
||||
@tracked isSidebarVisible = false;
|
||||
@tracked isSidebarOpening = false;
|
||||
// Mobile bottom-sheet state. `sheetInsetPx` is how many pixels the sheet
|
||||
// currently covers from the bottom of the viewport, `sheetSnapSeq` bumps
|
||||
// whenever a drag settles so the map can react once (not per frame), and
|
||||
// `sheetDetent` is the active detent name. `sheetDetent` is intentionally
|
||||
// NOT tracked: the modifier reads it while setting up to restore the
|
||||
// previous position, and reading a tracked value there would re-run setup on
|
||||
// every drag frame.
|
||||
// currently covers from the bottom of the viewport, and `sheetSnapSeq` bumps
|
||||
// whenever a drag settles so the map can react once (not per frame).
|
||||
//
|
||||
// `sheetDetents` remembers the detent per sheet, keyed by sheet identity
|
||||
// (route name), so a sheet reopens at the size the user last dragged it to.
|
||||
// `sheetDetent` mirrors the interactive (top) sheet's current detent. Both
|
||||
// are intentionally NOT tracked: the modifier reads them while setting up to
|
||||
// restore the previous position, and reading a tracked value there would
|
||||
// re-run setup on every drag frame.
|
||||
@tracked sheetInsetPx = 0;
|
||||
@tracked sheetSnapSeq = 0;
|
||||
sheetDetents = {};
|
||||
sheetDetent = null;
|
||||
// The modifier that currently owns the covered-height signal. A plain field
|
||||
// so it is safe to write during render. Writes to sheetInsetPx/sheetSnapSeq
|
||||
@@ -101,13 +105,26 @@ export default class MapUiService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
setSheetDetent(name) {
|
||||
this.sheetDetent = name;
|
||||
getSheetDetent(key) {
|
||||
return this.sheetDetents[key] ?? null;
|
||||
}
|
||||
|
||||
// A null name forgets the sheet (used when a drag dismisses it), so the next
|
||||
// open falls back to the sheet's declared default.
|
||||
setSheetDetent(key, name) {
|
||||
if (key == null) return;
|
||||
if (name == null) {
|
||||
delete this.sheetDetents[key];
|
||||
} else {
|
||||
this.sheetDetents[key] = name;
|
||||
}
|
||||
this.sheetDetent = name ?? null;
|
||||
}
|
||||
|
||||
resetSheet() {
|
||||
this.sheetInsetOwner = null;
|
||||
this.sheetInsetPx = 0;
|
||||
this.sheetDetents = {};
|
||||
this.sheetDetent = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,10 @@ import {
|
||||
waitUntil,
|
||||
} from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'marco/tests/helpers';
|
||||
import {
|
||||
computeDetentLayout,
|
||||
computeSheetHeight,
|
||||
} from 'marco/utils/sheet-detents';
|
||||
import Service from '@ember/service';
|
||||
import sinon from 'sinon';
|
||||
|
||||
@@ -112,8 +116,8 @@ module('Acceptance | bottom sheet', function (hooks) {
|
||||
);
|
||||
assert.strictEqual(
|
||||
mapUi.sheetDetent,
|
||||
'expanded',
|
||||
'the app menu opens at the expanded detent'
|
||||
'medium',
|
||||
'the app menu opens at the medium detent'
|
||||
);
|
||||
} finally {
|
||||
matchMediaStub.restore();
|
||||
@@ -152,21 +156,21 @@ module('Acceptance | bottom sheet', function (hooks) {
|
||||
pointerId: 1,
|
||||
pointerType: 'touch',
|
||||
isPrimary: true,
|
||||
clientY: 450,
|
||||
clientY: 370,
|
||||
});
|
||||
await triggerEvent(handle, 'pointerup', {
|
||||
pointerId: 1,
|
||||
pointerType: 'touch',
|
||||
isPrimary: true,
|
||||
clientY: 450,
|
||||
clientY: 370,
|
||||
});
|
||||
|
||||
const after = parseFloat(sheet.style.getPropertyValue('--sheet-offset'));
|
||||
assert.true(after > before, `sheet moved down (${before} -> ${after})`);
|
||||
assert.notStrictEqual(
|
||||
mapUi.sheetDetent,
|
||||
'expanded',
|
||||
'sheet left the expanded detent'
|
||||
'medium',
|
||||
'sheet left its opening detent'
|
||||
);
|
||||
// The inset is published on a deferred animation-frame flush.
|
||||
await waitUntil(() => mapUi.sheetInsetPx > 0);
|
||||
@@ -205,10 +209,12 @@ module('Acceptance | bottom sheet', function (hooks) {
|
||||
test('opening a place keeps the search sheet stacked behind it (mobile)', async function (assert) {
|
||||
const matchMediaStub = installMobileMatchMedia();
|
||||
try {
|
||||
const mapUi = this.owner.lookup('service:map-ui');
|
||||
await visit('/search?lat=1&lon=1');
|
||||
assert.dom('.place-item').exists('search results are rendered');
|
||||
|
||||
await click('.place-item');
|
||||
await waitUntil(() => mapUi.sheetDetent === 'collapsed');
|
||||
|
||||
assert.dom('.sheet-top').exists('the interactive top sheet is marked');
|
||||
assert
|
||||
@@ -223,6 +229,92 @@ module('Acceptance | bottom sheet', function (hooks) {
|
||||
assert
|
||||
.dom('.sheet-background .place-item')
|
||||
.exists('the parent shows the search results');
|
||||
|
||||
// Place details defaults to the short detent, and the background is
|
||||
// pinned to the minimum so it can never peek above the top sheet.
|
||||
const sheetHeight = computeSheetHeight(window.innerHeight);
|
||||
const layout = computeDetentLayout({
|
||||
viewportHeight: window.innerHeight,
|
||||
sheetHeight,
|
||||
});
|
||||
const minimumOffset = layout[layout.length - 1].offset;
|
||||
const top = document.querySelector('.sheet-top');
|
||||
const background = document.querySelector('.sheet-background');
|
||||
assert.strictEqual(
|
||||
parseFloat(top.style.getPropertyValue('--sheet-offset')),
|
||||
minimumOffset,
|
||||
'place details opens at the short (collapsed) detent'
|
||||
);
|
||||
assert.strictEqual(
|
||||
parseFloat(background.style.getPropertyValue('--sheet-offset')),
|
||||
minimumOffset,
|
||||
'the background sheet is minimized'
|
||||
);
|
||||
} finally {
|
||||
matchMediaStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('background sheets stay minimized when the top sheet is taller (mobile)', async function (assert) {
|
||||
const matchMediaStub = installMobileMatchMedia();
|
||||
try {
|
||||
const mapUi = this.owner.lookup('service:map-ui');
|
||||
await visit('/search?lat=1&lon=1');
|
||||
await click('.place-item');
|
||||
await waitUntil(() => mapUi.sheetDetent === 'collapsed');
|
||||
|
||||
const top = document.querySelector('.sheet-top');
|
||||
const handle = top.querySelector('[data-test-sheet-handle]');
|
||||
const background = document.querySelector('.sheet-background');
|
||||
const backgroundBefore = parseFloat(
|
||||
background.style.getPropertyValue('--sheet-offset')
|
||||
);
|
||||
const topBefore = parseFloat(
|
||||
top.style.getPropertyValue('--sheet-offset')
|
||||
);
|
||||
|
||||
// Drag the top sheet all the way up.
|
||||
await triggerEvent(handle, 'pointerdown', {
|
||||
pointerId: 1,
|
||||
pointerType: 'touch',
|
||||
isPrimary: true,
|
||||
clientY: 500,
|
||||
button: 0,
|
||||
});
|
||||
await triggerEvent(handle, 'pointermove', {
|
||||
pointerId: 1,
|
||||
pointerType: 'touch',
|
||||
isPrimary: true,
|
||||
clientY: 490,
|
||||
});
|
||||
await triggerEvent(handle, 'pointermove', {
|
||||
pointerId: 1,
|
||||
pointerType: 'touch',
|
||||
isPrimary: true,
|
||||
clientY: 0,
|
||||
});
|
||||
await triggerEvent(handle, 'pointerup', {
|
||||
pointerId: 1,
|
||||
pointerType: 'touch',
|
||||
isPrimary: true,
|
||||
clientY: 0,
|
||||
});
|
||||
|
||||
await waitUntil(() => mapUi.sheetDetent !== 'collapsed');
|
||||
const topAfter = parseFloat(top.style.getPropertyValue('--sheet-offset'));
|
||||
const backgroundAfter = parseFloat(
|
||||
background.style.getPropertyValue('--sheet-offset')
|
||||
);
|
||||
assert.true(topAfter < topBefore, 'the top sheet expanded');
|
||||
assert.true(
|
||||
topAfter < backgroundAfter,
|
||||
'the top sheet is more visible than the background'
|
||||
);
|
||||
assert.strictEqual(
|
||||
backgroundAfter,
|
||||
backgroundBefore,
|
||||
'the background stayed minimized'
|
||||
);
|
||||
} finally {
|
||||
matchMediaStub.restore();
|
||||
}
|
||||
@@ -240,10 +332,11 @@ module('Acceptance | bottom sheet', function (hooks) {
|
||||
await visit('/search?lat=1&lon=1');
|
||||
await click('.place-item');
|
||||
assert.ok(currentURL().includes('/place/'), 'on the place sheet');
|
||||
await waitUntil(() => mapUi.sheetDetent === 'collapsed');
|
||||
assert.strictEqual(
|
||||
mapUi.sheetDetent,
|
||||
'medium',
|
||||
'the place sheet opened at the medium detent'
|
||||
'collapsed',
|
||||
'place details opened at the short (collapsed) detent'
|
||||
);
|
||||
|
||||
await waitFor('canvas', { timeout: 2000 });
|
||||
@@ -271,10 +364,11 @@ module('Acceptance | bottom sheet', function (hooks) {
|
||||
currentURL().includes('/search'),
|
||||
'the outside tap popped back to the search route'
|
||||
);
|
||||
await waitUntil(() => mapUi.sheetDetent === 'medium');
|
||||
assert.strictEqual(
|
||||
mapUi.sheetDetent,
|
||||
'medium',
|
||||
'the remembered detent survives the pop'
|
||||
'the search sheet returns to its remembered medium detent'
|
||||
);
|
||||
assert.dom('.sheet-top').exists('a top sheet is still open');
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user