Browse Source

Fix pinned container scrollTop

master
morethanwords 4 years ago
parent
commit
c3b9cd8cf1
  1. 14
      src/components/chat/pinnedContainer.ts

14
src/components/chat/pinnedContainer.ts

@ -3,7 +3,7 @@ import appImManager from "../../lib/appManagers/appImManager";
import { cancelEvent } from "../../lib/utils"; import { cancelEvent } from "../../lib/utils";
import DivAndCaption from "../divAndCaption"; import DivAndCaption from "../divAndCaption";
const CLASSNAME_SHOWN_MAIN = 'is-pinned-message-shown'; const classNames: string[] = [];
const CLASSNAME_BASE = 'pinned-container'; const CLASSNAME_BASE = 'pinned-container';
const HEIGHT = 52; const HEIGHT = 52;
@ -17,6 +17,8 @@ export default class PinnedContainer {
prev(mid, title, subtitle); prev(mid, title, subtitle);
}; */ }; */
classNames.push(`is-pinned-${className}-shown`);
divAndCaption.container.classList.add(CLASSNAME_BASE, 'hide'); divAndCaption.container.classList.add(CLASSNAME_BASE, 'hide');
divAndCaption.title.classList.add(CLASSNAME_BASE + '-title'); divAndCaption.title.classList.add(CLASSNAME_BASE + '-title');
divAndCaption.subtitle.classList.add(CLASSNAME_BASE + '-subtitle'); divAndCaption.subtitle.classList.add(CLASSNAME_BASE + '-subtitle');
@ -45,11 +47,15 @@ export default class PinnedContainer {
return; return;
} }
const scrollTop = mediaSizes.isMobile ? appImManager.scrollable.scrollTop : undefined; const scrollTop = mediaSizes.isMobile /* && !appImManager.scrollable.isScrolledDown */ ? appImManager.scrollable.scrollTop : undefined;
this.divAndCaption.container.classList.toggle('hide', hide); this.divAndCaption.container.classList.toggle('hide', hide);
appImManager.topbar.classList.toggle(`is-pinned-${this.className}-shown`, !hide); const className = `is-pinned-${this.className}-shown`;
appImManager.topbar.classList.toggle(className, !hide);
if(scrollTop !== undefined && !appImManager.topbar.classList.contains(CLASSNAME_SHOWN_MAIN)) { const active = classNames.filter(className => appImManager.topbar.classList.contains(className));
const maxActive = hide ? 0 : 1;
if(scrollTop !== undefined && active.length <= maxActive) {
appImManager.scrollable.scrollTop = scrollTop + ((hide ? -1 : 1) * HEIGHT); appImManager.scrollable.scrollTop = scrollTop + ((hide ? -1 : 1) * HEIGHT);
} }
} }

Loading…
Cancel
Save