Adjustments to fix swipe to reply formatting
This commit is contained in:
1 parent
16874b07e1
commit
a9737604d4
3 files changed
+105
-109
No files matched your search
@@ -8,14 +8,10 @@ import { RightSwipeAction, settingsAtom } from '../state/settings';
|
||||
|
||||
export function SwipeableMessageWrapper({
|
||||
children,
|
||||
onReply,
|
||||
messageId,
|
||||
itemIndex
|
||||
onReply
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
onReply: () => void;
|
||||
messageId: string;
|
||||
itemIndex: number;
|
||||
}) {
|
||||
const settings = useAtomValue(settingsAtom);
|
||||
const x = useMotionValue(0);
|
||||
@@ -38,7 +34,6 @@ export function SwipeableMessageWrapper({
|
||||
setIsReady(mx < -50);
|
||||
} else {
|
||||
if (mx < -50) {
|
||||
if ('vibrate' in navigator) navigator.vibrate(10);
|
||||
onReply();
|
||||
}
|
||||
x.set(0);
|
||||
@@ -48,23 +43,16 @@ export function SwipeableMessageWrapper({
|
||||
axis: 'x',
|
||||
bounds: { right: 0 },
|
||||
rubberband: true,
|
||||
filterTaps: true,
|
||||
pointer: { capture: true }
|
||||
filterTaps: true
|
||||
});
|
||||
|
||||
if (!settings.mobileGestures || !mobileOrTablet()) {
|
||||
return (
|
||||
<div data-message-id={messageId} data-message-item={itemIndex}>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
if (!isSwipeToReplyEnabled) {
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
{...bind()}
|
||||
data-message-id={messageId}
|
||||
data-message-item={itemIndex}
|
||||
style={{ position: 'relative', touchAction: 'pan-y' }}
|
||||
>
|
||||
<div style={{
|
||||
@@ -89,12 +77,7 @@ export function SwipeableMessageWrapper({
|
||||
</motion.div>
|
||||
</div>
|
||||
|
||||
<motion.div style={{
|
||||
x: springX,
|
||||
background: 'var(--sable-surface-container)',
|
||||
position: 'relative',
|
||||
zIndex: 1
|
||||
}}>
|
||||
<motion.div style={{ x: springX, position: 'relative', zIndex: 1 }}>
|
||||
{children}
|
||||
</motion.div>
|
||||
</div>
|
||||
|
||||
@@ -106,7 +106,6 @@ import { useSpaceOptionally } from '../../hooks/useSpace';
|
||||
import { useRoomCreators } from '../../hooks/useRoomCreators';
|
||||
import { useRoomPermissions } from '../../hooks/useRoomPermissions';
|
||||
import { useGetMemberPowerTag } from '../../hooks/useMemberPowerTag';
|
||||
import { SwipeableMessageWrapper } from '../../components/SwipeableMessageWrapper';
|
||||
|
||||
const TimelineFloat = as<'div', css.TimelineFloatVariants>(
|
||||
({ position, className, ...props }, ref) => (
|
||||
@@ -1045,79 +1044,73 @@ export function RoomTimeline({ room, eventId, roomInputRef, editor }: RoomTimeli
|
||||
getMemberDisplayName(room, senderId, nicknames) ?? getMxIdLocalPart(senderId) ?? senderId;
|
||||
|
||||
return (
|
||||
<SwipeableMessageWrapper
|
||||
messageId={mEventId}
|
||||
itemIndex={item}
|
||||
onReply={() => triggerReply(mEventId)}
|
||||
>
|
||||
<Message
|
||||
key={mEvent.getId()}
|
||||
data-message-item={item}
|
||||
data-message-id={mEventId}
|
||||
room={room}
|
||||
mEvent={mEvent}
|
||||
messageSpacing={messageSpacing}
|
||||
messageLayout={messageLayout}
|
||||
collapse={collapse}
|
||||
highlight={highlighted}
|
||||
edit={editId === mEventId}
|
||||
canDelete={canRedact || (canDeleteOwn && mEvent.getSender() === mx.getUserId())}
|
||||
canSendReaction={canSendReaction}
|
||||
canPinEvent={canPinEvent}
|
||||
imagePackRooms={imagePackRooms}
|
||||
relations={hasReactions ? reactionRelations : undefined}
|
||||
onUserClick={handleUserClick}
|
||||
onUsernameClick={handleUsernameClick}
|
||||
onReplyClick={handleReplyClick}
|
||||
onReactionToggle={handleReactionToggle}
|
||||
onEditId={handleEdit}
|
||||
reply={
|
||||
replyEventId && (
|
||||
<Reply
|
||||
room={room}
|
||||
timelineSet={timelineSet}
|
||||
replyEventId={replyEventId}
|
||||
threadRootId={threadRootId}
|
||||
onClick={handleOpenReply}
|
||||
/>
|
||||
)
|
||||
}
|
||||
reactions={
|
||||
reactionRelations && (
|
||||
<Reactions
|
||||
style={{ marginTop: config.space.S200 }}
|
||||
room={room}
|
||||
relations={reactionRelations}
|
||||
mEventId={mEventId}
|
||||
canSendReaction={canSendReaction}
|
||||
onReactionToggle={handleReactionToggle}
|
||||
/>
|
||||
)
|
||||
}
|
||||
hideReadReceipts={hideActivity}
|
||||
showDeveloperTools={showDeveloperTools}
|
||||
memberPowerTag={getMemberPowerTag(senderId)}
|
||||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
>
|
||||
{mEvent.isRedacted() ? (
|
||||
<RedactedContent reason={mEvent.getUnsigned().redacted_because?.content.reason} />
|
||||
) : (
|
||||
<RenderMessageContent
|
||||
displayName={senderDisplayName}
|
||||
msgType={mEvent.getContent().msgtype ?? ''}
|
||||
ts={mEvent.getTs()}
|
||||
edited={!!editedEvent}
|
||||
getContent={getContent}
|
||||
mediaAutoLoad={mediaAutoLoad}
|
||||
urlPreview={showUrlPreview}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
outlineAttachment={messageLayout === MessageLayout.Bubble}
|
||||
<Message
|
||||
key={mEvent.getId()}
|
||||
data-message-item={item}
|
||||
data-message-id={mEventId}
|
||||
room={room}
|
||||
mEvent={mEvent}
|
||||
messageSpacing={messageSpacing}
|
||||
messageLayout={messageLayout}
|
||||
collapse={collapse}
|
||||
highlight={highlighted}
|
||||
edit={editId === mEventId}
|
||||
canDelete={canRedact || (canDeleteOwn && mEvent.getSender() === mx.getUserId())}
|
||||
canSendReaction={canSendReaction}
|
||||
canPinEvent={canPinEvent}
|
||||
imagePackRooms={imagePackRooms}
|
||||
relations={hasReactions ? reactionRelations : undefined}
|
||||
onUserClick={handleUserClick}
|
||||
onUsernameClick={handleUsernameClick}
|
||||
onReplyClick={handleReplyClick}
|
||||
onReactionToggle={handleReactionToggle}
|
||||
onEditId={handleEdit}
|
||||
reply={
|
||||
replyEventId && (
|
||||
<Reply
|
||||
room={room}
|
||||
timelineSet={timelineSet}
|
||||
replyEventId={replyEventId}
|
||||
threadRootId={threadRootId}
|
||||
onClick={handleOpenReply}
|
||||
/>
|
||||
)}
|
||||
</Message>
|
||||
</SwipeableMessageWrapper>
|
||||
)
|
||||
}
|
||||
reactions={
|
||||
reactionRelations && (
|
||||
<Reactions
|
||||
style={{ marginTop: config.space.S200 }}
|
||||
room={room}
|
||||
relations={reactionRelations}
|
||||
mEventId={mEventId}
|
||||
canSendReaction={canSendReaction}
|
||||
onReactionToggle={handleReactionToggle}
|
||||
/>
|
||||
)
|
||||
}
|
||||
hideReadReceipts={hideActivity}
|
||||
showDeveloperTools={showDeveloperTools}
|
||||
memberPowerTag={getMemberPowerTag(senderId)}
|
||||
hour24Clock={hour24Clock}
|
||||
dateFormatString={dateFormatString}
|
||||
>
|
||||
{mEvent.isRedacted() ? (
|
||||
<RedactedContent reason={mEvent.getUnsigned().redacted_because?.content.reason} />
|
||||
) : (
|
||||
<RenderMessageContent
|
||||
displayName={senderDisplayName}
|
||||
msgType={mEvent.getContent().msgtype ?? ''}
|
||||
ts={mEvent.getTs()}
|
||||
edited={!!editedEvent}
|
||||
getContent={getContent}
|
||||
mediaAutoLoad={mediaAutoLoad}
|
||||
urlPreview={showUrlPreview}
|
||||
htmlReactParserOptions={htmlReactParserOptions}
|
||||
linkifyOpts={linkifyOpts}
|
||||
outlineAttachment={messageLayout === MessageLayout.Bubble}
|
||||
/>
|
||||
)}
|
||||
</Message>
|
||||
);
|
||||
},
|
||||
[MessageEvent.RoomMessageEncrypted]: (mEventId, mEvent, item, timelineSet, collapse) => {
|
||||
|
||||
@@ -83,6 +83,7 @@ import colorMXID from '../../../../util/colorMXID';
|
||||
import { getPowerTagIconSrc } from '../../../hooks/useMemberPowerTag';
|
||||
import { AccountDataEvent } from '../../../../types/matrix/accountData';
|
||||
import { useSableCosmetics } from '../../../hooks/useSableCosmetics';
|
||||
import { SwipeableMessageWrapper } from '../../../components/SwipeableMessageWrapper';
|
||||
|
||||
export type ReactionHandler = (keyOrMxc: string, shortcode: string) => void;
|
||||
|
||||
@@ -879,6 +880,16 @@ export const Message = as<'div', MessageProps>(
|
||||
}, 100);
|
||||
};
|
||||
|
||||
const handleSwipeReply = () => {
|
||||
const mockEvent = {
|
||||
currentTarget: {
|
||||
getAttribute: (attr: string) => (attr === 'data-event-id' ? mEvent.getId() : null),
|
||||
},
|
||||
} as unknown as React.MouseEvent<HTMLButtonElement>;
|
||||
|
||||
onReplyClick(mockEvent);
|
||||
};
|
||||
|
||||
const isThreadedMessage = mEvent.threadRootId !== undefined;
|
||||
|
||||
return (
|
||||
@@ -1194,22 +1205,31 @@ export const Message = as<'div', MessageProps>(
|
||||
</div>
|
||||
)}
|
||||
{messageLayout === MessageLayout.Compact && (
|
||||
<CompactLayout before={headerJSX} onContextMenu={handleContextMenu}>
|
||||
{msgContentJSX}
|
||||
</CompactLayout>
|
||||
)}
|
||||
<SwipeableMessageWrapper onReply={handleSwipeReply}>
|
||||
<CompactLayout before={headerJSX} onContextMenu={handleContextMenu}>
|
||||
{msgContentJSX}
|
||||
</CompactLayout>
|
||||
</SwipeableMessageWrapper>
|
||||
)
|
||||
}
|
||||
{messageLayout === MessageLayout.Bubble && (
|
||||
<BubbleLayout before={avatarJSX} header={headerJSX} onContextMenu={handleContextMenu}>
|
||||
{msgContentJSX}
|
||||
</BubbleLayout>
|
||||
<SwipeableMessageWrapper onReply={handleSwipeReply}>
|
||||
<BubbleLayout before={avatarJSX} header={headerJSX} onContextMenu={handleContextMenu}>
|
||||
{msgContentJSX}
|
||||
</BubbleLayout>
|
||||
</SwipeableMessageWrapper>
|
||||
)}
|
||||
{messageLayout !== MessageLayout.Compact && messageLayout !== MessageLayout.Bubble && (
|
||||
<ModernLayout before={avatarJSX} onContextMenu={handleContextMenu}>
|
||||
{headerJSX}
|
||||
{msgContentJSX}
|
||||
</ModernLayout>
|
||||
)}
|
||||
</MessageBase>
|
||||
{
|
||||
messageLayout !== MessageLayout.Compact && messageLayout !== MessageLayout.Bubble && (
|
||||
<SwipeableMessageWrapper onReply={handleSwipeReply}>
|
||||
<ModernLayout before={avatarJSX} onContextMenu={handleContextMenu}>
|
||||
{headerJSX}
|
||||
{msgContentJSX}
|
||||
</ModernLayout>
|
||||
</SwipeableMessageWrapper>
|
||||
)
|
||||
}
|
||||
</MessageBase >
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user