fix: Fix glitchy iOS media attachment drag interactions (#35057)

This commit is contained in:
diondiondion 2025-06-16 17:37:04 +02:00 committed by GitHub
commit 69f298731e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 51 additions and 38 deletions

View file

@ -22,10 +22,11 @@ import { useAppDispatch, useAppSelector } from 'mastodon/store';
export const Upload: React.FC<{ export const Upload: React.FC<{
id: string; id: string;
dragging?: boolean; dragging?: boolean;
draggable?: boolean;
overlay?: boolean; overlay?: boolean;
tall?: boolean; tall?: boolean;
wide?: boolean; wide?: boolean;
}> = ({ id, dragging, overlay, tall, wide }) => { }> = ({ id, dragging, draggable = true, overlay, tall, wide }) => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const media = useAppSelector((state) => const media = useAppSelector((state) =>
( (
@ -71,6 +72,7 @@ export const Upload: React.FC<{
<div <div
className={classNames('compose-form__upload media-gallery__item', { className={classNames('compose-form__upload media-gallery__item', {
dragging, dragging,
draggable,
overlay, overlay,
'media-gallery__item--tall': tall, 'media-gallery__item--tall': tall,
'media-gallery__item--wide': wide, 'media-gallery__item--wide': wide,

View file

@ -116,6 +116,10 @@ export const UploadForm: React.FC = () => {
[dispatch, setActiveId], [dispatch, setActiveId],
); );
const handleDragCancel = useCallback(() => {
setActiveId(null);
}, [setActiveId]);
const accessibility: { const accessibility: {
screenReaderInstructions: ScreenReaderInstructions; screenReaderInstructions: ScreenReaderInstructions;
announcements: Announcements; announcements: Announcements;
@ -158,11 +162,22 @@ export const UploadForm: React.FC = () => {
<div <div
className={`compose-form__uploads media-gallery media-gallery--layout-${mediaIds.size}`} className={`compose-form__uploads media-gallery media-gallery--layout-${mediaIds.size}`}
> >
{mediaIds.size === 1 ? (
<Upload
id={mediaIds.first()}
dragging={false}
draggable={false}
tall
wide
/>
) : (
<DndContext <DndContext
sensors={sensors} sensors={sensors}
collisionDetection={closestCenter} collisionDetection={closestCenter}
onDragStart={handleDragStart} onDragStart={handleDragStart}
onDragEnd={handleDragEnd} onDragEnd={handleDragEnd}
onDragCancel={handleDragCancel}
onDragAbort={handleDragCancel}
accessibility={accessibility} accessibility={accessibility}
> >
<SortableContext <SortableContext
@ -174,7 +189,9 @@ export const UploadForm: React.FC = () => {
key={id} key={id}
id={id} id={id}
dragging={id === activeId} dragging={id === activeId}
tall={mediaIds.size < 3 || (mediaIds.size === 3 && idx === 0)} tall={
mediaIds.size < 3 || (mediaIds.size === 3 && idx === 0)
}
wide={mediaIds.size === 1} wide={mediaIds.size === 1}
/> />
))} ))}
@ -184,6 +201,7 @@ export const UploadForm: React.FC = () => {
{activeId ? <Upload id={activeId as string} overlay /> : null} {activeId ? <Upload id={activeId as string} overlay /> : null}
</DragOverlay> </DragOverlay>
</DndContext> </DndContext>
)}
</div> </div>
)} )}
</> </>

View file

@ -708,7 +708,12 @@ body > [data-popper-placement] {
&__upload { &__upload {
position: relative; position: relative;
&.draggable {
will-change: transform, opacity;
touch-action: none;
cursor: grab; cursor: grab;
}
&.dragging { &.dragging {
opacity: 0; opacity: 0;
@ -720,18 +725,6 @@ body > [data-popper-placement] {
pointer-events: none; pointer-events: none;
} }
&__drag-handle {
position: absolute;
top: 50%;
inset-inline-start: 0;
transform: translateY(-50%);
color: $white;
background: transparent;
border: 0;
padding: 8px 3px;
cursor: grab;
}
&__actions { &__actions {
display: flex; display: flex;
align-items: flex-start; align-items: flex-start;