mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-03 15:22:22 -08:00
fix(mobile): stop pinned list sheet from jittering in height (#1509)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> fix jitter from mobile sheet #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
This commit is contained in:
1 file changed
+21
-3
@@ -1,5 +1,5 @@
|
||||
import type { MouseEventHandler, ReactNode } from 'react';
|
||||
import { forwardRef, useCallback, useMemo, useRef } from 'react';
|
||||
import { forwardRef, useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
||||
import type { MatrixEvent, Room, RoomPinnedEventsEventContent } from '$types/matrix-sdk';
|
||||
import {
|
||||
Box,
|
||||
@@ -210,6 +210,24 @@ export const RoomPinMenu = forwardRef<HTMLDivElement, RoomPinMenuProps>(
|
||||
overscan: 4,
|
||||
});
|
||||
|
||||
// Rows re-measure as dynamic content lands (decrypts, lazy media, replies),
|
||||
// nudging the total size back and forth across the sheet's max height. The
|
||||
// sheet sizes itself off this list, so latch the largest size seen for the
|
||||
// current set of pins. Structural changes rebase the latch so removals do
|
||||
// not leave stale empty space.
|
||||
const totalSize = virtualizer.getTotalSize();
|
||||
const pinListKey = JSON.stringify(sortedPinnedEvent);
|
||||
const [latchedSize, setLatchedSize] = useState({ pinListKey, size: 0 });
|
||||
useLayoutEffect(() => {
|
||||
setLatchedSize((prev) => {
|
||||
if (prev.pinListKey !== pinListKey) return { pinListKey, size: totalSize };
|
||||
if (totalSize <= prev.size) return prev;
|
||||
return { pinListKey, size: totalSize };
|
||||
});
|
||||
}, [pinListKey, totalSize]);
|
||||
const currentLatchedSize = latchedSize.pinListKey === pinListKey ? latchedSize.size : totalSize;
|
||||
const mobileMaxHeight = 'calc(85vh - 4rem)';
|
||||
|
||||
const renderMatrixEvent = useRoomMessagePreviewRenderer(room);
|
||||
|
||||
const handleOpen = (roomId: string, eventId: string) => {
|
||||
@@ -238,9 +256,9 @@ export const RoomPinMenu = forwardRef<HTMLDivElement, RoomPinMenuProps>(
|
||||
hideTrack
|
||||
visibility="Hover"
|
||||
style={{
|
||||
minHeight: 0,
|
||||
minHeight: isMobile ? `min(${currentLatchedSize}px, ${mobileMaxHeight})` : 0,
|
||||
flex: isMobile ? '0 1 auto' : 1,
|
||||
maxHeight: isMobile ? 'calc(85vh - 4rem)' : undefined,
|
||||
maxHeight: isMobile ? mobileMaxHeight : undefined,
|
||||
overflowY: 'auto',
|
||||
touchAction: 'pan-y',
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user