mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-25 19:41:17 -08:00
fix: scrolling, closing, and animations in bottom sheets (#1404)
<!-- 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. --> Fixes scrolling not working, not playing animations on close, and the x button not closing in mobile bottom sheets. #### 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: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] 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:
4 files changed
+60
-8
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import React, { useRef, useState, useEffect } from 'react';
|
||||
import React, { createContext, useCallback, useContext, useRef, useState, useEffect } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { Box } from 'folds';
|
||||
import * as css from '$features/room/message/styles.css';
|
||||
@@ -18,12 +18,20 @@ interface MobileSwipeDownModalProps {
|
||||
requestClose: () => void;
|
||||
}
|
||||
|
||||
const MobileSheetCloseContext = createContext<(() => void) | null>(null);
|
||||
|
||||
export function useMobileSheetClose() {
|
||||
return useContext(MobileSheetCloseContext);
|
||||
}
|
||||
|
||||
export function MobileSwipeDownModal({ children, requestClose }: MobileSwipeDownModalProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const touchStartY = useRef<number | null>(null);
|
||||
const touchYDiff = useRef(0);
|
||||
const startTime = useRef(0);
|
||||
const [mounted, setMounted] = useState(false);
|
||||
const [closing, setClosing] = useState(false);
|
||||
const closingRef = useRef(false);
|
||||
const resetAnimationRef = useRef<Animation>();
|
||||
const { shouldReduceMotion } = useMobileSheetAnimation();
|
||||
|
||||
@@ -31,8 +39,30 @@ export function MobileSwipeDownModal({ children, requestClose }: MobileSwipeDown
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
const closeWithAnimation = useCallback(() => {
|
||||
if (closingRef.current) return;
|
||||
closingRef.current = true;
|
||||
setClosing(true);
|
||||
|
||||
const container = containerRef.current;
|
||||
if (!container) {
|
||||
requestClose();
|
||||
return;
|
||||
}
|
||||
|
||||
container.getAnimations().forEach((animation) => animation.cancel());
|
||||
const animation = container.animate(
|
||||
[{ transform: 'translate3d(0, 0, 0)' }, { transform: 'translate3d(0, 100%, 0)' }],
|
||||
{
|
||||
...getMobileSheetTiming(shouldReduceMotion),
|
||||
duration: shouldReduceMotion ? 0 : 140,
|
||||
}
|
||||
);
|
||||
animation.addEventListener('finish', requestClose, { once: true });
|
||||
}, [requestClose, shouldReduceMotion]);
|
||||
|
||||
// Android back closes the overlay instead of navigating away.
|
||||
useDismissOnBack(requestClose);
|
||||
useDismissOnBack(closeWithAnimation);
|
||||
|
||||
const handleTouchStart = (e: React.TouchEvent) => {
|
||||
touchStartY.current = e.touches[0]?.clientY ?? null;
|
||||
@@ -61,7 +91,7 @@ export function MobileSwipeDownModal({ children, requestClose }: MobileSwipeDown
|
||||
touchYDiff.current > 100 ||
|
||||
(endTime - startTime.current < 600 && touchYDiff.current > 20)
|
||||
) {
|
||||
requestClose();
|
||||
closeWithAnimation();
|
||||
} else {
|
||||
const currentOffset = touchYDiff.current;
|
||||
touchYDiff.current = 0;
|
||||
@@ -104,7 +134,8 @@ export function MobileSwipeDownModal({ children, requestClose }: MobileSwipeDown
|
||||
<Box
|
||||
className={css.MessageMobileOptionsWrapped}
|
||||
data-gestures="ignore"
|
||||
onClick={requestClose}
|
||||
style={closing ? { opacity: 0, transition: 'opacity 100ms ease-out' } : undefined}
|
||||
onClick={closeWithAnimation}
|
||||
onTouchStart={(e: React.TouchEvent) => e.stopPropagation()}
|
||||
onTouchMove={(e: React.TouchEvent) => e.stopPropagation()}
|
||||
onTouchEnd={(e: React.TouchEvent) => e.stopPropagation()}
|
||||
@@ -115,7 +146,9 @@ export function MobileSwipeDownModal({ children, requestClose }: MobileSwipeDown
|
||||
style={shouldReduceMotion ? { animation: 'none' } : undefined}
|
||||
onClick={(e: React.MouseEvent) => e.stopPropagation()}
|
||||
>
|
||||
{children(dragHandleJSX, dragHandlers)}
|
||||
<MobileSheetCloseContext.Provider value={closeWithAnimation}>
|
||||
{children(dragHandleJSX, dragHandlers)}
|
||||
</MobileSheetCloseContext.Provider>
|
||||
</Box>
|
||||
</Box>,
|
||||
document.body
|
||||
|
||||
@@ -54,7 +54,8 @@ export function ResponsiveMenu({
|
||||
fallbackFocus: () => document.body,
|
||||
returnFocusOnDeactivate,
|
||||
onDeactivate: requestClose,
|
||||
clickOutsideDeactivates: true,
|
||||
clickOutsideDeactivates: !isMobile,
|
||||
allowOutsideClick: isMobile,
|
||||
isKeyForward,
|
||||
isKeyBackward,
|
||||
escapeDeactivates: stopPropagation,
|
||||
|
||||
@@ -116,6 +116,7 @@ export const MessageMobileDragHandle = style({
|
||||
paddingTop: '6px',
|
||||
justifyContent: 'center',
|
||||
zIndex: 10,
|
||||
pointerEvents: 'none',
|
||||
});
|
||||
|
||||
export const MessageMobileDragIndicator = style({
|
||||
@@ -124,6 +125,7 @@ export const MessageMobileDragIndicator = style({
|
||||
borderRadius: '2px',
|
||||
backgroundColor: color.SurfaceVariant.OnContainer,
|
||||
opacity: 0.5,
|
||||
pointerEvents: 'auto',
|
||||
});
|
||||
|
||||
export const BubbleAvatarBase = style({
|
||||
|
||||
@@ -39,6 +39,8 @@ import type { PinReadMarker } from '$features/room/RoomViewHeader';
|
||||
import * as css from './RoomPinMenu.css';
|
||||
import { CustomAccountDataEvent } from '$types/matrix/accountData';
|
||||
import { EventType } from '$types/matrix-sdk';
|
||||
import { ScreenSize, useScreenSizeOptionally } from '$hooks/useScreenSize';
|
||||
import { useMobileSheetClose } from '$components/MobileSwipeDownModal';
|
||||
|
||||
const log = createLogger('RoomPinMenu');
|
||||
|
||||
@@ -172,6 +174,8 @@ type RoomPinMenuProps = {
|
||||
|
||||
export const RoomPinMenu = forwardRef<HTMLDivElement, RoomPinMenuProps>(
|
||||
({ room, requestClose, currentHash }, ref) => {
|
||||
const isMobile = useScreenSizeOptionally() === ScreenSize.Mobile;
|
||||
const mobileSheetClose = useMobileSheetClose();
|
||||
const mx = useMatrixClient();
|
||||
const userId = mx.getUserId()!;
|
||||
const powerLevels = usePowerLevelsContext();
|
||||
@@ -221,13 +225,25 @@ export const RoomPinMenu = forwardRef<HTMLDivElement, RoomPinMenuProps>(
|
||||
<Text size="H5">Pinned Messages</Text>
|
||||
</Box>
|
||||
<Box shrink="No">
|
||||
<IconButton size="300" onClick={requestClose} radii="300">
|
||||
<IconButton size="300" onClick={mobileSheetClose ?? requestClose} radii="300">
|
||||
{composerIcon(X)}
|
||||
</IconButton>
|
||||
</Box>
|
||||
</Header>
|
||||
<Box grow="Yes">
|
||||
<Scroll ref={scrollRef} size="300" hideTrack visibility="Hover">
|
||||
<Scroll
|
||||
ref={scrollRef}
|
||||
size="300"
|
||||
hideTrack
|
||||
visibility="Hover"
|
||||
style={{
|
||||
minHeight: 0,
|
||||
flex: isMobile ? '0 1 auto' : 1,
|
||||
maxHeight: isMobile ? 'calc(85vh - 4rem)' : undefined,
|
||||
overflowY: 'auto',
|
||||
touchAction: 'pan-y',
|
||||
}}
|
||||
>
|
||||
<Box className={css.PinMenuContent} direction="Column" gap="100">
|
||||
{sortedPinnedEvent.length > 0 ? (
|
||||
<div
|
||||
|
||||
Reference in new issue
Block a user