SHA256
Чат и обсуждения: шапка не уезжает за экран при открытой клавиатуре
В поиске по переписке после ввода текста шапка с «раньше/позже» уезжала за верхний край экрана, и переключать совпадения было нечем. Причина – scrollIntoView: он прокручивает не только ленту, но и все внешние контейнеры и видимую область браузера, а при открытой клавиатуре видимая область меньше экрана приложения. Теперь прокручивается только сама лента (общий scrollNodeIntoContainer в services/scroll-utils.js): поиск и «перейти к дате», переход к цитате, «к последнему», разделитель «Новые сообщения», а также переходы к ответу и к записи в обсуждениях и ленте канала.
This commit is contained in:
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
client.version=1.19.23
|
client.version=1.19.24
|
||||||
server.version=1.15.0
|
server.version=1.15.0
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@
|
|||||||
}());
|
}());
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
window.__SHINE_BUILD_HASH__ = '20261013123000';
|
window.__SHINE_BUILD_HASH__ = '20261013130000';
|
||||||
window.__SHINE_CLIENT_VERSION__ = '1.2.10';
|
window.__SHINE_CLIENT_VERSION__ = '1.2.10';
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import { loadProfileSnapshot } from '../services/user-profile-params.js';
|
|||||||
import { extractLoginFromBlockchainName, makeProfileRoute, makeShineChannelRoute, makeShineMessageRoute } from '../services/shine-routes.js';
|
import { extractLoginFromBlockchainName, makeProfileRoute, makeShineChannelRoute, makeShineMessageRoute } from '../services/shine-routes.js';
|
||||||
import { parsePublicationOrdinal, publicationAtOrdinal, ordinalForPublication } from '../services/channel-message-ordinals.js';
|
import { parsePublicationOrdinal, publicationAtOrdinal, ordinalForPublication } from '../services/channel-message-ordinals.js';
|
||||||
import { dropPageData, pageDataAge, readPageData, writePageData } from '../services/page-data-cache.js';
|
import { dropPageData, pageDataAge, readPageData, writePageData } from '../services/page-data-cache.js';
|
||||||
|
import { scrollNodeIntoContainer } from '../services/scroll-utils.js';
|
||||||
|
|
||||||
export const pageMeta = { id: 'channel-thread-view', title: 'Обсуждение', shellMode: { scrollbar: 'hidden', topFade: false, contentUnderTopbar: false, contentWidth: 'wide' } };
|
export const pageMeta = { id: 'channel-thread-view', title: 'Обсуждение', shellMode: { scrollbar: 'hidden', topFade: false, contentUnderTopbar: false, contentWidth: 'wide' } };
|
||||||
const MSG_SUBTYPE_TEXT_POST = 10;
|
const MSG_SUBTYPE_TEXT_POST = 10;
|
||||||
@@ -1355,7 +1356,7 @@ function applyPendingScroll(screen, routeKey, shouldContinue = () => true) {
|
|||||||
const cards = screen.querySelectorAll('.thread-block--replies [data-message-key]');
|
const cards = screen.querySelectorAll('.thread-block--replies [data-message-key]');
|
||||||
const last = cards[cards.length - 1];
|
const last = cards[cards.length - 1];
|
||||||
if (last) {
|
if (last) {
|
||||||
last.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
scrollNodeIntoContainer(last, { behavior: 'smooth' });
|
||||||
}
|
}
|
||||||
pendingThreadScroll.delete(routeKey);
|
pendingThreadScroll.delete(routeKey);
|
||||||
return;
|
return;
|
||||||
@@ -1363,7 +1364,7 @@ function applyPendingScroll(screen, routeKey, shouldContinue = () => true) {
|
|||||||
|
|
||||||
const node = screen.querySelector(`[data-message-key="${target}"]`);
|
const node = screen.querySelector(`[data-message-key="${target}"]`);
|
||||||
if (node) {
|
if (node) {
|
||||||
node.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
scrollNodeIntoContainer(node, { behavior: 'smooth' });
|
||||||
pendingThreadScroll.delete(routeKey);
|
pendingThreadScroll.delete(routeKey);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -1987,7 +1988,7 @@ export function render({ navigate, route, chrome }) {
|
|||||||
};
|
};
|
||||||
returnBtn.addEventListener('click', () => {
|
returnBtn.addEventListener('click', () => {
|
||||||
const el = listWrap.querySelector(`[data-message-key="${CSS.escape(returnKey)}"]`);
|
const el = listWrap.querySelector(`[data-message-key="${CSS.escape(returnKey)}"]`);
|
||||||
el?.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
scrollNodeIntoContainer(el, { behavior: 'smooth' });
|
||||||
highlight(el);
|
highlight(el);
|
||||||
returnBtn.hidden = true;
|
returnBtn.hidden = true;
|
||||||
});
|
});
|
||||||
@@ -1998,7 +1999,7 @@ export function render({ navigate, route, chrome }) {
|
|||||||
const el = listWrap.querySelector(`[data-message-key="${CSS.escape(key)}"]`);
|
const el = listWrap.querySelector(`[data-message-key="${CSS.escape(key)}"]`);
|
||||||
if (!el) return;
|
if (!el) return;
|
||||||
el.closest('.thread-replies')?.classList.add('is-expanded');
|
el.closest('.thread-replies')?.classList.add('is-expanded');
|
||||||
el.scrollIntoView({ block: 'center', behavior: 'smooth' });
|
scrollNodeIntoContainer(el, { behavior: 'smooth' });
|
||||||
highlight(el);
|
highlight(el);
|
||||||
returnKey = fromKey;
|
returnKey = fromKey;
|
||||||
returnBtn.hidden = false;
|
returnBtn.hidden = false;
|
||||||
@@ -2139,7 +2140,7 @@ export function render({ navigate, route, chrome }) {
|
|||||||
if (!hasPendingScroll && !Number.isFinite(restorePosition) && focusWrap) {
|
if (!hasPendingScroll && !Number.isFinite(restorePosition) && focusWrap) {
|
||||||
trackTimer(window.setTimeout(() => {
|
trackTimer(window.setTimeout(() => {
|
||||||
if (disposed || seq !== refreshSeq || !focusWrap.isConnected) return;
|
if (disposed || seq !== refreshSeq || !focusWrap.isConnected) return;
|
||||||
focusWrap.scrollIntoView({ behavior: 'auto', block: 'start' });
|
scrollNodeIntoContainer(focusWrap, { block: 'start' });
|
||||||
}, 20));
|
}, 20));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ import {
|
|||||||
import { parseDmTechBlocks } from '../services/dm-tech-blocks.js';
|
import { parseDmTechBlocks } from '../services/dm-tech-blocks.js';
|
||||||
import { dropPageData, readPageData, writePageData } from '../services/page-data-cache.js';
|
import { dropPageData, readPageData, writePageData } from '../services/page-data-cache.js';
|
||||||
import { sortedChannelPublications } from '../services/channel-message-ordinals.js';
|
import { sortedChannelPublications } from '../services/channel-message-ordinals.js';
|
||||||
|
import { scrollNodeIntoContainer } from '../services/scroll-utils.js';
|
||||||
|
|
||||||
export const pageMeta = { id: 'channel-view', title: 'Канал', shellMode: { scrollbar: 'hidden', topFade: false, contentUnderTopbar: false, contentWidth: 'wide' } };
|
export const pageMeta = { id: 'channel-view', title: 'Канал', shellMode: { scrollbar: 'hidden', topFade: false, contentUnderTopbar: false, contentWidth: 'wide' } };
|
||||||
const CHANNEL_TYPE_STORIES = 0;
|
const CHANNEL_TYPE_STORIES = 0;
|
||||||
@@ -1034,7 +1035,7 @@ function flashAndScrollToMessage(messageRef) {
|
|||||||
const target = cards.find((card) => card.dataset.messageKey === key);
|
const target = cards.find((card) => card.dataset.messageKey === key);
|
||||||
if (!target) return false;
|
if (!target) return false;
|
||||||
target.classList.remove('is-focus-flash');
|
target.classList.remove('is-focus-flash');
|
||||||
target.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
scrollNodeIntoContainer(target, { behavior: 'smooth' });
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
if (target.isConnected) target.classList.add('is-focus-flash');
|
if (target.isConnected) target.classList.add('is-focus-flash');
|
||||||
}, 60);
|
}, 60);
|
||||||
@@ -1602,9 +1603,7 @@ function renderDemoFallback(screen, navigate, error) {
|
|||||||
|
|
||||||
function scrollChannelToBottom(screen, smooth = true) {
|
function scrollChannelToBottom(screen, smooth = true) {
|
||||||
const feed = screen.querySelector('.channel-feed');
|
const feed = screen.querySelector('.channel-feed');
|
||||||
if (feed) {
|
if (feed) scrollNodeIntoContainer(feed, { block: 'end', behavior: smooth ? 'smooth' : 'auto' });
|
||||||
feed.scrollIntoView({ behavior: smooth ? 'smooth' : 'auto', block: 'end' });
|
|
||||||
}
|
|
||||||
const appScreen = document.getElementById('app-screen');
|
const appScreen = document.getElementById('app-screen');
|
||||||
if (appScreen) {
|
if (appScreen) {
|
||||||
appScreen.scrollTo({ top: appScreen.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });
|
appScreen.scrollTo({ top: appScreen.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });
|
||||||
@@ -1631,7 +1630,7 @@ function applyPendingScroll(screen, routeKey, forceBottom = false) {
|
|||||||
|
|
||||||
const element = screen.querySelector(`[data-message-key="${target}"]`);
|
const element = screen.querySelector(`[data-message-key="${target}"]`);
|
||||||
if (element) {
|
if (element) {
|
||||||
element.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
scrollNodeIntoContainer(element, { behavior: 'smooth' });
|
||||||
pendingScrollByRoute.delete(routeKey);
|
pendingScrollByRoute.delete(routeKey);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import {
|
|||||||
import { DM_CHAT_PREFS_EVENT, isDmChatMuted, isDmChatPinned, setDmChatPinned } from '../services/dm-chat-prefs.js';
|
import { DM_CHAT_PREFS_EVENT, isDmChatMuted, isDmChatPinned, setDmChatPinned } from '../services/dm-chat-prefs.js';
|
||||||
import { createDmMuteMenuItem } from '../components/dm-mute-menu.js';
|
import { createDmMuteMenuItem } from '../components/dm-mute-menu.js';
|
||||||
import { actionErrorText, mediaAccessErrorText } from '../services/ui-error-texts.js';
|
import { actionErrorText, mediaAccessErrorText } from '../services/ui-error-texts.js';
|
||||||
|
import { scrollNodeIntoContainer } from '../services/scroll-utils.js';
|
||||||
import { loadProfileSnapshot } from '../services/user-profile-params.js';
|
import { loadProfileSnapshot } from '../services/user-profile-params.js';
|
||||||
import { makeProfileLinksRoute, makeProfileRoute } from '../services/shine-routes.js';
|
import { makeProfileLinksRoute, makeProfileRoute } from '../services/shine-routes.js';
|
||||||
import { openHistoryLayer } from '../router.js';
|
import { openHistoryLayer } from '../router.js';
|
||||||
@@ -932,9 +933,7 @@ function scrollToLatestMessage(list) {
|
|||||||
const scrollContainer = findChatScrollContainer(list);
|
const scrollContainer = findChatScrollContainer(list);
|
||||||
const lastBubble = list.lastElementChild;
|
const lastBubble = list.lastElementChild;
|
||||||
const apply = () => {
|
const apply = () => {
|
||||||
if (lastBubble?.scrollIntoView) {
|
scrollNodeIntoContainer(lastBubble, { container: scrollContainer, block: 'end' });
|
||||||
lastBubble.scrollIntoView({ block: 'end', inline: 'nearest' });
|
|
||||||
}
|
|
||||||
scrollContainer.scrollTop = scrollContainer.scrollHeight;
|
scrollContainer.scrollTop = scrollContainer.scrollHeight;
|
||||||
};
|
};
|
||||||
apply();
|
apply();
|
||||||
@@ -1092,15 +1091,11 @@ function createDmVoiceAttachmentCard(attachment) {
|
|||||||
function scrollToLatestMessageSmart(list, { smoothIfNearBottom = false } = {}) {
|
function scrollToLatestMessageSmart(list, { smoothIfNearBottom = false } = {}) {
|
||||||
if (!list) return;
|
if (!list) return;
|
||||||
const scrollContainer = findChatScrollContainer(list);
|
const scrollContainer = findChatScrollContainer(list);
|
||||||
const lastBubble = list.lastElementChild;
|
|
||||||
const maxScrollTop = Math.max(0, scrollContainer.scrollHeight - scrollContainer.clientHeight);
|
const maxScrollTop = Math.max(0, scrollContainer.scrollHeight - scrollContainer.clientHeight);
|
||||||
const distanceToBottom = Math.max(0, maxScrollTop - scrollContainer.scrollTop);
|
const distanceToBottom = Math.max(0, maxScrollTop - scrollContainer.scrollTop);
|
||||||
const useSmooth = smoothIfNearBottom && distanceToBottom <= 180;
|
const useSmooth = smoothIfNearBottom && distanceToBottom <= 180;
|
||||||
|
|
||||||
const apply = (behavior = useSmooth ? 'smooth' : 'auto') => {
|
const apply = (behavior = useSmooth ? 'smooth' : 'auto') => {
|
||||||
if (lastBubble?.scrollIntoView) {
|
|
||||||
lastBubble.scrollIntoView({ block: 'end', inline: 'nearest', behavior });
|
|
||||||
}
|
|
||||||
if (behavior === 'smooth' && typeof scrollContainer.scrollTo === 'function') {
|
if (behavior === 'smooth' && typeof scrollContainer.scrollTo === 'function') {
|
||||||
scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, behavior: 'smooth' });
|
scrollContainer.scrollTo({ top: scrollContainer.scrollHeight, behavior: 'smooth' });
|
||||||
} else {
|
} else {
|
||||||
@@ -1119,9 +1114,7 @@ function scrollToUnreadSeparator(list) {
|
|||||||
if (!separator) return false;
|
if (!separator) return false;
|
||||||
const scrollContainer = findChatScrollContainer(list);
|
const scrollContainer = findChatScrollContainer(list);
|
||||||
const apply = () => {
|
const apply = () => {
|
||||||
if (separator?.scrollIntoView) {
|
scrollNodeIntoContainer(separator, { container: scrollContainer, block: 'start' });
|
||||||
separator.scrollIntoView({ block: 'start', inline: 'nearest' });
|
|
||||||
}
|
|
||||||
const bottomSlack = 72;
|
const bottomSlack = 72;
|
||||||
scrollContainer.scrollTop = Math.max(0, scrollContainer.scrollTop - bottomSlack);
|
scrollContainer.scrollTop = Math.max(0, scrollContainer.scrollTop - bottomSlack);
|
||||||
};
|
};
|
||||||
@@ -1273,9 +1266,7 @@ function renderLog(
|
|||||||
replyBox.addEventListener('click', (event) => {
|
replyBox.addEventListener('click', (event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
const targetNode = list.querySelector(`[data-base-key="${CSS.escape(String(replyTarget?.baseKey || ''))}"]`);
|
const targetNode = list.querySelector(`[data-base-key="${CSS.escape(String(replyTarget?.baseKey || ''))}"]`);
|
||||||
if (targetNode?.scrollIntoView) {
|
scrollNodeIntoContainer(targetNode, { container: findChatScrollContainer(list), block: 'center', behavior: 'smooth' });
|
||||||
targetNode.scrollIntoView({ block: 'center', inline: 'nearest', behavior: 'smooth' });
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
bubble.append(replyBox);
|
bubble.append(replyBox);
|
||||||
}
|
}
|
||||||
@@ -1691,7 +1682,7 @@ export function render({ navigate, route, chrome }) {
|
|||||||
if (!node) return;
|
if (!node) return;
|
||||||
stickToBottom = false;
|
stickToBottom = false;
|
||||||
const distance = Math.abs(node.getBoundingClientRect().top - wrap.getBoundingClientRect().top - wrap.clientHeight / 2);
|
const distance = Math.abs(node.getBoundingClientRect().top - wrap.getBoundingClientRect().top - wrap.clientHeight / 2);
|
||||||
node.scrollIntoView({ block, behavior: distance < wrap.clientHeight ? 'smooth' : 'auto' });
|
scrollNodeIntoContainer(node, { container: wrap, block, behavior: distance < wrap.clientHeight ? 'smooth' : 'auto' });
|
||||||
};
|
};
|
||||||
|
|
||||||
const findBubble = (messageKey) => (messageKey
|
const findBubble = (messageKey) => (messageKey
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// Прокрутить к элементу только его ленту (ближайший прокручиваемый контейнер).
|
||||||
|
// element.scrollIntoView двигает ещё и все внешние контейнеры и видимую область браузера:
|
||||||
|
// при открытой клавиатуре это уводило шапку за верхний край экрана – в поиске по переписке
|
||||||
|
// пропадали «раньше/позже», после ответа в обсуждении – заголовок.
|
||||||
|
|
||||||
|
function findScrollContainer(node) {
|
||||||
|
for (let el = node?.parentElement; el; el = el.parentElement) {
|
||||||
|
const { overflowY } = getComputedStyle(el);
|
||||||
|
if ((overflowY === 'auto' || overflowY === 'scroll') && el.scrollHeight > el.clientHeight) return el;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Element} node
|
||||||
|
* @param {{ container?: Element|null, block?: 'start'|'center'|'end', behavior?: 'auto'|'smooth' }} [opts]
|
||||||
|
*/
|
||||||
|
export function scrollNodeIntoContainer(node, { container = null, block = 'center', behavior = 'auto' } = {}) {
|
||||||
|
if (!node) return;
|
||||||
|
const host = container || findScrollContainer(node);
|
||||||
|
if (!host) return;
|
||||||
|
const hostRect = host.getBoundingClientRect();
|
||||||
|
const nodeRect = node.getBoundingClientRect();
|
||||||
|
let delta;
|
||||||
|
if (block === 'start') delta = nodeRect.top - hostRect.top;
|
||||||
|
else if (block === 'end') delta = nodeRect.bottom - hostRect.bottom;
|
||||||
|
else delta = nodeRect.top - hostRect.top - (host.clientHeight - nodeRect.height) / 2;
|
||||||
|
const top = Math.max(0, Math.min(host.scrollHeight - host.clientHeight, host.scrollTop + delta));
|
||||||
|
if (behavior === 'smooth' && typeof host.scrollTo === 'function') host.scrollTo({ top, behavior: 'smooth' });
|
||||||
|
else host.scrollTop = top;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user