mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 00:06:35 +00:00
Revert "Restore scroll position when using back navigation in dashboard" (#24795)
Revert "Restore scroll position when using back navigation in dashboard (#24777)" This reverts commit 9cfcd21a93dd50d61fb64039ce7bec973c721806.
This commit is contained in:
parent
a9823f30e3
commit
899288ae43
@ -76,9 +76,9 @@ import { getLovelaceStrategy } from "./strategies/get-strategy";
|
|||||||
import { isLegacyStrategyConfig } from "./strategies/legacy-strategy";
|
import { isLegacyStrategyConfig } from "./strategies/legacy-strategy";
|
||||||
import type { Lovelace } from "./types";
|
import type { Lovelace } from "./types";
|
||||||
import "./views/hui-view";
|
import "./views/hui-view";
|
||||||
|
import "./views/hui-view-container";
|
||||||
import type { HUIView } from "./views/hui-view";
|
import type { HUIView } from "./views/hui-view";
|
||||||
import "./views/hui-view-background";
|
import "./views/hui-view-background";
|
||||||
import "./views/hui-view-container";
|
|
||||||
|
|
||||||
@customElement("hui-root")
|
@customElement("hui-root")
|
||||||
class HUIRoot extends LitElement {
|
class HUIRoot extends LitElement {
|
||||||
@ -99,8 +99,6 @@ class HUIRoot extends LitElement {
|
|||||||
|
|
||||||
private _viewCache?: Record<string, HUIView>;
|
private _viewCache?: Record<string, HUIView>;
|
||||||
|
|
||||||
private _viewScrollPositions: Record<string, number> = {};
|
|
||||||
|
|
||||||
private _debouncedConfigChanged: () => void;
|
private _debouncedConfigChanged: () => void;
|
||||||
|
|
||||||
private _conversation = memoizeOne((_components) =>
|
private _conversation = memoizeOne((_components) =>
|
||||||
@ -112,7 +110,7 @@ class HUIRoot extends LitElement {
|
|||||||
// The view can trigger a re-render when it knows that certain
|
// The view can trigger a re-render when it knows that certain
|
||||||
// web components have been loaded.
|
// web components have been loaded.
|
||||||
this._debouncedConfigChanged = debounce(
|
this._debouncedConfigChanged = debounce(
|
||||||
() => this._selectView(this._curView, true, false),
|
() => this._selectView(this._curView, true),
|
||||||
100,
|
100,
|
||||||
false
|
false
|
||||||
);
|
);
|
||||||
@ -527,22 +525,13 @@ class HUIRoot extends LitElement {
|
|||||||
window.addEventListener("scroll", this._handleWindowScroll, {
|
window.addEventListener("scroll", this._handleWindowScroll, {
|
||||||
passive: true,
|
passive: true,
|
||||||
});
|
});
|
||||||
window.addEventListener("popstate", this._handlePopState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public disconnectedCallback(): void {
|
public disconnectedCallback(): void {
|
||||||
super.disconnectedCallback();
|
super.disconnectedCallback();
|
||||||
window.removeEventListener("scroll", this._handleWindowScroll);
|
window.removeEventListener("scroll", this._handleWindowScroll);
|
||||||
window.removeEventListener("popstate", this._handlePopState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _restoreScroll = false;
|
|
||||||
|
|
||||||
private _handlePopState = () => {
|
|
||||||
// If we navigated back, we want to restore the scroll position.
|
|
||||||
this._restoreScroll = true;
|
|
||||||
};
|
|
||||||
|
|
||||||
protected updated(changedProperties: PropertyValues): void {
|
protected updated(changedProperties: PropertyValues): void {
|
||||||
super.updated(changedProperties);
|
super.updated(changedProperties);
|
||||||
|
|
||||||
@ -583,6 +572,9 @@ class HUIRoot extends LitElement {
|
|||||||
}
|
}
|
||||||
newSelectView = index;
|
newSelectView = index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Will allow to override history scroll restoration when using back button
|
||||||
|
setTimeout(() => scrollTo({ behavior: "auto", top: 0 }), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changedProperties.has("lovelace")) {
|
if (changedProperties.has("lovelace")) {
|
||||||
@ -621,10 +613,7 @@ class HUIRoot extends LitElement {
|
|||||||
newSelectView = this._curView;
|
newSelectView = this._curView;
|
||||||
}
|
}
|
||||||
// Will allow for ripples to start rendering
|
// Will allow for ripples to start rendering
|
||||||
afterNextRender(() => {
|
afterNextRender(() => this._selectView(newSelectView, force));
|
||||||
this._selectView(newSelectView, force, this._restoreScroll);
|
|
||||||
this._restoreScroll = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -932,26 +921,17 @@ class HUIRoot extends LitElement {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _selectView(
|
private _selectView(viewIndex: HUIRoot["_curView"], force: boolean): void {
|
||||||
viewIndex: HUIRoot["_curView"],
|
|
||||||
force: boolean,
|
|
||||||
restoreScroll: boolean
|
|
||||||
): void {
|
|
||||||
if (!force && this._curView === viewIndex) {
|
if (!force && this._curView === viewIndex) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._curView != null) {
|
|
||||||
this._viewScrollPositions[this._curView] = window.scrollY;
|
|
||||||
}
|
|
||||||
|
|
||||||
viewIndex = viewIndex === undefined ? 0 : viewIndex;
|
viewIndex = viewIndex === undefined ? 0 : viewIndex;
|
||||||
|
|
||||||
this._curView = viewIndex;
|
this._curView = viewIndex;
|
||||||
|
|
||||||
if (force) {
|
if (force) {
|
||||||
this._viewCache = {};
|
this._viewCache = {};
|
||||||
this._viewScrollPositions = {};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recreate a new element to clear the applied themes.
|
// Recreate a new element to clear the applied themes.
|
||||||
@ -983,15 +963,10 @@ class HUIRoot extends LitElement {
|
|||||||
|
|
||||||
if (!force && this._viewCache![viewIndex]) {
|
if (!force && this._viewCache![viewIndex]) {
|
||||||
view = this._viewCache![viewIndex];
|
view = this._viewCache![viewIndex];
|
||||||
const position = restoreScroll
|
|
||||||
? this._viewScrollPositions[viewIndex] || 0
|
|
||||||
: 0;
|
|
||||||
setTimeout(() => scrollTo({ behavior: "auto", top: position }), 0);
|
|
||||||
} else {
|
} else {
|
||||||
view = document.createElement("hui-view");
|
view = document.createElement("hui-view");
|
||||||
view.index = viewIndex;
|
view.index = viewIndex;
|
||||||
this._viewCache![viewIndex] = view;
|
this._viewCache![viewIndex] = view;
|
||||||
setTimeout(() => scrollTo({ behavior: "auto", top: 0 }), 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
view.lovelace = this.lovelace;
|
view.lovelace = this.lovelace;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user