Fix detail issues in the stacked mobile bottom drawers
- Place details header now keeps the same top gap as the standard 56px drawer header, so the place name is not crammed against the drag handle. - Read the sheet inset untracked in the map's pin/center helpers so updateSelectedPin no longer re-runs on every drag frame. This stops the selected marker from jittering while a drawer is dragged. - Re-center the selected place in the resized visible area when a drawer settles at a new detent, and pan it clear of the sheet on a same-size settle (restores the auto-pan that untracking removed). - Commit the sheet's hidden position with the transform transition disabled so the entrance animates from fully hidden and slides up, instead of shrinking down from the top. - Add acceptance tests for the header gap, the per-frame pin recompute, and the settle recenter/pan behaviour.
This commit is contained in:
5 files changed
+219
-14
No files matched your search
+42
-13
@@ -1,5 +1,6 @@
|
||||
import Component from '@glimmer/component';
|
||||
import { service } from '@ember/service';
|
||||
import { untrack } from '@glimmer/validator';
|
||||
import { modifier } from 'ember-modifier';
|
||||
import 'ol/ol.css';
|
||||
import OlMap from 'ol/Map.js';
|
||||
@@ -43,6 +44,7 @@ export default class MapComponent extends Component {
|
||||
crosshairOverlay;
|
||||
ignoreNextMapClick = false;
|
||||
lastSheetSnapSeq;
|
||||
lastSnapInsetPx;
|
||||
|
||||
setupMap = modifier((element) => {
|
||||
if (this.mapInstance) return;
|
||||
@@ -720,8 +722,11 @@ export default class MapComponent extends Component {
|
||||
];
|
||||
|
||||
// Mobile: the bottom sheet covers `sheetInsetPx` pixels from the bottom.
|
||||
// Read untracked: this runs from updateSelectedPin, and tracking the inset
|
||||
// would re-run that modifier (restarting the pin drop-in and re-targeting
|
||||
// the view) on every drag frame.
|
||||
if (size[0] <= 768) {
|
||||
const inset = this.mapUi.sheetInsetPx;
|
||||
const inset = untrack(() => this.mapUi.sheetInsetPx);
|
||||
const visibleHeight = Math.max(size[1] - inset, 1);
|
||||
const topPadding = visibleHeight * 0.15;
|
||||
const bottomPadding = inset + visibleHeight * 0.15;
|
||||
@@ -788,7 +793,7 @@ export default class MapComponent extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
animateToSmartCenter(coords, zoom = null) {
|
||||
animateToSmartCenter(coords, zoom = null, duration = 1000) {
|
||||
if (!this.mapInstance) return;
|
||||
|
||||
const size = this.mapInstance.getSize();
|
||||
@@ -807,7 +812,9 @@ export default class MapComponent extends Component {
|
||||
// until the sheet publishes its height, which is fine — it just centers.
|
||||
if (size[0] <= 768) {
|
||||
const height = size[1];
|
||||
const inset = this.mapUi.sheetInsetPx;
|
||||
// Untracked: see zoomToBbox. The caller reads the latest value at call
|
||||
// time, so the settle-time recenter still sees the settled inset.
|
||||
const inset = untrack(() => this.mapUi.sheetInsetPx);
|
||||
const headerEl = document.querySelector('.app-header');
|
||||
const headerHeight = headerEl ? headerEl.offsetHeight : 60;
|
||||
|
||||
@@ -851,7 +858,7 @@ export default class MapComponent extends Component {
|
||||
|
||||
const animationOptions = {
|
||||
center: targetCenter,
|
||||
duration: 1000,
|
||||
duration,
|
||||
easing: (t) => t * (2 - t), // Ease-out
|
||||
};
|
||||
|
||||
@@ -886,7 +893,9 @@ export default class MapComponent extends Component {
|
||||
// there, even before the sheet has published its inset.
|
||||
if (size[0] <= 768) {
|
||||
const height = size[1];
|
||||
const inset = this.mapUi.sheetInsetPx;
|
||||
// Untracked: see zoomToBbox. The caller reads the latest value at call
|
||||
// time, so the settle-time pan still sees the settled inset.
|
||||
const inset = untrack(() => this.mapUi.sheetInsetPx);
|
||||
const visibleHeight = height - inset;
|
||||
|
||||
// If obscured by the bottom sheet
|
||||
@@ -1013,19 +1022,39 @@ export default class MapComponent extends Component {
|
||||
|
||||
// Keep the CSS `--sheet-inset` custom property on the map container in sync
|
||||
// with the mobile bottom sheet. The crosshair (a child of the map container)
|
||||
// reads it via CSS. When a drag settles (snapSeq changes) we pan the selected
|
||||
// pin back into the visible area, but never per drag frame.
|
||||
// reads it via CSS. When a drag settles (snapSeq changes) we re-center the
|
||||
// selected pin in the resized visible area, or pan it clear of the sheet when
|
||||
// the detent did not change, but never per drag frame.
|
||||
syncSheetInset = modifier((element, [inset, snapSeq]) => {
|
||||
element.style.setProperty('--sheet-inset', `${inset || 0}px`);
|
||||
|
||||
const isInitialRun = this.lastSheetSnapSeq === undefined;
|
||||
if (!isInitialRun && snapSeq !== this.lastSheetSnapSeq) {
|
||||
const place = this.mapUi.selectedPlace;
|
||||
if (place && place.lat && place.lon) {
|
||||
this.panIfObscured(fromLonLat([place.lon, place.lat]));
|
||||
}
|
||||
}
|
||||
const settled = !isInitialRun && snapSeq !== this.lastSheetSnapSeq;
|
||||
this.lastSheetSnapSeq = snapSeq;
|
||||
if (!settled) return;
|
||||
|
||||
const currentInset = inset || 0;
|
||||
const changed =
|
||||
this.lastSnapInsetPx !== undefined &&
|
||||
Math.abs(currentInset - this.lastSnapInsetPx) > 1;
|
||||
this.lastSnapInsetPx = currentInset;
|
||||
|
||||
const place = this.mapUi.selectedPlace;
|
||||
if (!place || !place.lat || !place.lon) return;
|
||||
const coords = fromLonLat([place.lon, place.lat]);
|
||||
|
||||
if (changed) {
|
||||
// A resize: re-center the place in the visible area above the sheet,
|
||||
// matching the 300ms sheet transition.
|
||||
this.animateToSmartCenter(coords, null, 300);
|
||||
} else {
|
||||
// A settle that kept the same detent (including the first one, where
|
||||
// there is no previous inset to compare against): only pan if the marker
|
||||
// ended up hidden behind the sheet or the header. This is the safety net
|
||||
// that updateSelectedPin used to provide per frame before the inset reads
|
||||
// were untracked.
|
||||
this.panIfObscured(coords);
|
||||
}
|
||||
});
|
||||
|
||||
decodeVectorTileOsmFeature(feature) {
|
||||
|
||||
@@ -405,10 +405,20 @@ export default class BottomSheetModifier extends Modifier {
|
||||
|
||||
// Start fully hidden, then slide to the detent on the next frame so the
|
||||
// transform transition animates the entrance.
|
||||
//
|
||||
// The transition is disabled while the hidden offset is committed: measure()
|
||||
// forced a style/layout flush (topGap reads getBoundingClientRect) while
|
||||
// --sheet-offset was still unset, so the pre-change style is translateY(0)
|
||||
// (fully expanded). Without this, the entrance would animate 0 -> detent and
|
||||
// look like the sheet shrinking down from the top instead of sliding up.
|
||||
this.element.classList.add('sheet-entering');
|
||||
this.currentOffset = this.sheetHeight;
|
||||
this.element.style.setProperty('--sheet-offset', `${this.sheetHeight}px`);
|
||||
this.syncAtMaxClass();
|
||||
this.queueInset(0);
|
||||
// Commit the hidden position as the transition's before-change style.
|
||||
void this.element.offsetHeight;
|
||||
this.element.classList.remove('sheet-entering');
|
||||
|
||||
requestAnimationFrame(() => {
|
||||
if (!this.active || this.destroyed) return;
|
||||
|
||||
+13
-1
@@ -1620,6 +1620,14 @@ button.create-place {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
/* Set by the modifier while it commits the sheet's initial hidden position.
|
||||
With the transition off, the entrance then animates from fully hidden
|
||||
instead of from the pre-measure offset of 0 (which looked like the sheet
|
||||
shrinking down from the top). */
|
||||
.sidebar.sheet-entering {
|
||||
transition: none;
|
||||
}
|
||||
|
||||
/* Injected by app/modifiers/bottom-sheet.js as the first child of the sheet.
|
||||
Keep the gap above the bar, but tighten the gap toward the content. */
|
||||
.sheet-handle {
|
||||
@@ -2624,7 +2632,11 @@ button.create-place {
|
||||
@media (width <= 768px) {
|
||||
.sidebar-header-place {
|
||||
height: auto;
|
||||
padding: 0.5rem 1rem 0.25rem;
|
||||
|
||||
/* Match the top gap of the standard 56px header, whose title is vertically
|
||||
centered (~1rem above it), so the place name is not crammed against the
|
||||
drag handle. */
|
||||
padding: 1rem 1rem 0.25rem;
|
||||
}
|
||||
|
||||
.sidebar-header-place .sidebar-header-title {
|
||||
|
||||
@@ -3,12 +3,14 @@ import {
|
||||
visit,
|
||||
click,
|
||||
currentURL,
|
||||
settled,
|
||||
triggerEvent,
|
||||
waitFor,
|
||||
waitUntil,
|
||||
} from '@ember/test-helpers';
|
||||
import { setupApplicationTest } from 'marco/tests/helpers';
|
||||
import { computeDetentLayout } from 'marco/utils/sheet-detents';
|
||||
import MapComponent from 'marco/components/map';
|
||||
import Service from '@ember/service';
|
||||
import sinon from 'sinon';
|
||||
|
||||
@@ -599,4 +601,116 @@ module('Acceptance | bottom sheet', function (hooks) {
|
||||
matchMediaStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('resizing the sheet does not recompute the selected pin per frame', async function (assert) {
|
||||
const matchMediaStub = installMobileMatchMedia();
|
||||
// The matchMedia stub makes the app think it is on a phone, but the map
|
||||
// still sizes itself from its container. Narrow it so the map takes its
|
||||
// mobile branch, which is the one that reads the sheet inset.
|
||||
const style = document.createElement('style');
|
||||
style.textContent = '.map-container { width: 400px; }';
|
||||
document.head.appendChild(style);
|
||||
try {
|
||||
const mapUi = this.owner.lookup('service:map-ui');
|
||||
|
||||
await visit('/search?lat=1&lon=1');
|
||||
await click('.place-item');
|
||||
await waitUntil(() => mapUi.sheetDetent === 'medium');
|
||||
await waitUntil(() => mapUi.sheetInsetPx > 0);
|
||||
|
||||
// updateSelectedPin restarts the pin's drop-in animation (remove/force
|
||||
// reflow/add the `active` class) every time it re-runs. Watch the pin's
|
||||
// class so a per-frame re-run is detectable without depending on geometry.
|
||||
const pin = document.querySelector('.selected-pin-container');
|
||||
assert.ok(pin, 'the selected pin is rendered');
|
||||
assert.true(pin.classList.contains('active'), 'the pin is active');
|
||||
let classMutations = 0;
|
||||
const observer = new MutationObserver((records) => {
|
||||
classMutations += records.length;
|
||||
});
|
||||
observer.observe(pin, { attributes: true, attributeFilter: ['class'] });
|
||||
|
||||
// Simulate the per-frame covered-height writes a drag makes.
|
||||
for (const inset of [500, 700, 850]) {
|
||||
mapUi.sheetInsetPx = inset;
|
||||
await settled();
|
||||
}
|
||||
classMutations += observer.takeRecords().length;
|
||||
observer.disconnect();
|
||||
|
||||
assert.strictEqual(
|
||||
classMutations,
|
||||
0,
|
||||
'the selected pin is not recomputed while the sheet is resized'
|
||||
);
|
||||
} finally {
|
||||
style.remove();
|
||||
matchMediaStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('settling the sheet at a new size recenters the selected place', async function (assert) {
|
||||
const matchMediaStub = installMobileMatchMedia();
|
||||
const handleStub = sinon.stub(
|
||||
MapComponent.prototype,
|
||||
'handlePinVisibility'
|
||||
);
|
||||
const centerStub = sinon.stub(
|
||||
MapComponent.prototype,
|
||||
'animateToSmartCenter'
|
||||
);
|
||||
const panStub = sinon.stub(MapComponent.prototype, 'panIfObscured');
|
||||
try {
|
||||
const mapUi = this.owner.lookup('service:map-ui');
|
||||
|
||||
await visit('/search?lat=1&lon=1');
|
||||
await click('.place-item');
|
||||
await waitUntil(() => mapUi.sheetDetent === 'medium');
|
||||
await waitUntil(() => mapUi.sheetInsetPx > 0);
|
||||
|
||||
handleStub.resetHistory();
|
||||
centerStub.resetHistory();
|
||||
panStub.resetHistory();
|
||||
|
||||
// The modifier publishes the new covered height and bumps the snap
|
||||
// sequence together when a drag settles.
|
||||
mapUi.sheetInsetPx = mapUi.sheetInsetPx + 140;
|
||||
mapUi.sheetSnapSeq = mapUi.sheetSnapSeq + 1;
|
||||
await settled();
|
||||
|
||||
assert.strictEqual(
|
||||
handleStub.callCount,
|
||||
0,
|
||||
'settling does not recompute the selected pin'
|
||||
);
|
||||
assert.true(
|
||||
centerStub.called,
|
||||
'the selected place is re-centered after the sheet settles at a new size'
|
||||
);
|
||||
assert.false(
|
||||
panStub.called,
|
||||
'a resize re-centers instead of only panning'
|
||||
);
|
||||
|
||||
// A settle that keeps the same detent must fall back to the obscured-pin
|
||||
// safety net instead of re-centering.
|
||||
centerStub.resetHistory();
|
||||
panStub.resetHistory();
|
||||
mapUi.sheetSnapSeq = mapUi.sheetSnapSeq + 1;
|
||||
await settled();
|
||||
assert.false(
|
||||
centerStub.called,
|
||||
'a same-size settle does not re-center the place'
|
||||
);
|
||||
assert.true(
|
||||
panStub.called,
|
||||
'a same-size settle still pans the marker if it is hidden'
|
||||
);
|
||||
} finally {
|
||||
panStub.restore();
|
||||
centerStub.restore();
|
||||
handleStub.restore();
|
||||
matchMediaStub.restore();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -207,6 +207,46 @@ module('Acceptance | drawer header', function (hooks) {
|
||||
}
|
||||
});
|
||||
|
||||
test('place details header keeps the same top gap as a standard drawer header', async function (assert) {
|
||||
const matchMediaStub = installMobileMatchMedia();
|
||||
try {
|
||||
await visit('/search?lat=1&lon=1');
|
||||
await waitUntil(() =>
|
||||
document.querySelector('.sheet-top .sidebar-header-title')
|
||||
);
|
||||
|
||||
const searchHeader = document.querySelector('.sheet-top .sidebar-header');
|
||||
const searchTitle = searchHeader.querySelector('.sidebar-header-title');
|
||||
const searchGap =
|
||||
searchTitle.getBoundingClientRect().top -
|
||||
searchHeader.getBoundingClientRect().top;
|
||||
|
||||
await click('.place-item');
|
||||
await waitUntil(() =>
|
||||
document.querySelector(
|
||||
'.sheet-top .sidebar-header-place .sidebar-header-title'
|
||||
)
|
||||
);
|
||||
|
||||
const placeHeader = document.querySelector(
|
||||
'.sheet-top .sidebar-header-place'
|
||||
);
|
||||
const placeTitle = placeHeader.querySelector('.sidebar-header-title');
|
||||
const placeGap =
|
||||
placeTitle.getBoundingClientRect().top -
|
||||
placeHeader.getBoundingClientRect().top;
|
||||
|
||||
// Measured relative to the header, so the entrance transition on the
|
||||
// sheet itself does not affect the comparison.
|
||||
assert.true(
|
||||
Math.abs(placeGap - searchGap) <= 3,
|
||||
`place header top gap (${placeGap.toFixed(1)}px) matches the standard header (${searchGap.toFixed(1)}px)`
|
||||
);
|
||||
} finally {
|
||||
matchMediaStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
test('desktop keeps the back button and centered title', async function (assert) {
|
||||
await visit('/menu');
|
||||
await clickSavedPlaces();
|
||||
|
||||
Reference in new issue
Block a user