Skip to content

Commit a139edb

Browse files
committed
feat: introduce new design for long message ctx menus
1 parent 7835c8a commit a139edb

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

package/src/contexts/overlayContext/MessageOverlayHostLayer.tsx

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
} from '../../state-store';
2424

2525
const DURATION = 300;
26-
2726
export const MessageOverlayHostLayer = () => {
2827
const { id, closing } = useOverlayController();
2928
const insets = useSafeAreaInsets();
@@ -89,19 +88,42 @@ export const MessageOverlayHostLayer = () => {
8988
opacity: backdrop.value,
9089
}));
9190

92-
const shiftY = useDerivedValue(() => {
91+
const messageShiftY = useDerivedValue(() => {
9392
if (!messageH.value || !topH.value || !bottomH.value) return 0;
9493

9594
const anchorY = messageH.value.y;
9695
const msgH = messageH.value.h;
97-
9896
const minTop = minY + topH.value.h;
99-
const maxTop = maxY - (msgH + bottomH.value.h);
97+
const maxTopWithBottom = maxY - (msgH + bottomH.value.h);
98+
const maxTopWithoutBottom = maxY - msgH;
99+
const maxTop = minTop <= maxTopWithBottom ? maxTopWithBottom : maxTopWithoutBottom;
100+
const solvedTop = clamp(anchorY, minTop, Math.max(minTop, maxTop));
100101

101-
const solvedTop = clamp(anchorY, minTop, maxTop);
102102
return solvedTop - anchorY;
103103
});
104104

105+
const bottomShiftY = useDerivedValue(() => {
106+
if (!messageH.value || !topH.value || !bottomH.value) return 0;
107+
108+
const anchorMessageTop = messageH.value.y;
109+
const msgH = messageH.value.h;
110+
const minMessageTop = minY + topH.value.h;
111+
const maxMessageTopWithBottom = maxY - (msgH + bottomH.value.h);
112+
const maxMessageTopWithoutBottom = maxY - msgH;
113+
const maxMessageTop =
114+
minMessageTop <= maxMessageTopWithBottom
115+
? maxMessageTopWithBottom
116+
: maxMessageTopWithoutBottom;
117+
const solvedMessageTop = clamp(
118+
anchorMessageTop,
119+
minMessageTop,
120+
Math.max(minMessageTop, maxMessageTop),
121+
);
122+
123+
const solvedBottomTop = Math.min(solvedMessageTop + msgH, maxY - bottomH.value.h);
124+
return solvedBottomTop - bottomH.value.y;
125+
});
126+
105127
const viewportH = useSharedValue(screenH);
106128
useEffect(() => {
107129
viewportH.value = screenH;
@@ -171,7 +193,7 @@ export const MessageOverlayHostLayer = () => {
171193
});
172194

173195
const topItemTranslateStyle = useAnimatedStyle(() => {
174-
const target = isActive ? (closing ? closeCorrectionY.value : shiftY.value) : 0;
196+
const target = isActive ? (closing ? closeCorrectionY.value : messageShiftY.value) : 0;
175197
return {
176198
transform: [
177199
{ scale: backdrop.value },
@@ -192,7 +214,7 @@ export const MessageOverlayHostLayer = () => {
192214
});
193215

194216
const bottomItemTranslateStyle = useAnimatedStyle(() => {
195-
const target = isActive ? (closing ? closeCorrectionY.value : shiftY.value) : 0;
217+
const target = isActive ? (closing ? closeCorrectionY.value : bottomShiftY.value) : 0;
196218
return {
197219
transform: [
198220
{ scale: backdrop.value },
@@ -213,7 +235,7 @@ export const MessageOverlayHostLayer = () => {
213235
});
214236

215237
const hostTranslateStyle = useAnimatedStyle(() => {
216-
const target = isActive ? (closing ? closeCorrectionY.value : shiftY.value) : 0;
238+
const target = isActive ? (closing ? closeCorrectionY.value : messageShiftY.value) : 0;
217239

218240
return {
219241
transform: [
@@ -236,14 +258,15 @@ export const MessageOverlayHostLayer = () => {
236258
const x = t.x;
237259
const y = t.y;
238260

239-
const yShift = shiftY.value; // overlay shift
261+
const messageYShift = messageShiftY.value; // overlay shift for top + message
262+
const bottomYShift = bottomShiftY.value; // overlay shift for bottom
240263
const yParent = scrollY.value; // parent content
241264

242265
const top = topH.value;
243266
if (top) {
244267
// top rectangle's final screen Y
245-
// base layout Y + overlay shift (shiftY) + parent scroll transform (scrollY)
246-
const topY = top.y + yParent + yShift;
268+
// base layout Y + overlay shift + parent scroll transform
269+
const topY = top.y + yParent + messageYShift;
247270
if (x >= top.x && x <= top.x + top.w && y >= topY && y <= topY + top.h) {
248271
state.fail();
249272
return;
@@ -253,8 +276,8 @@ export const MessageOverlayHostLayer = () => {
253276
const bot = bottomH.value;
254277
if (bot) {
255278
// bottom rectangle's final screen Y
256-
// base layout Y + overlay shift (shiftY) + parent scroll transform (scrollY)
257-
const botY = bot.y + yParent + yShift;
279+
// base layout Y + overlay shift + parent scroll transform
280+
const botY = bot.y + yParent + bottomYShift;
258281
if (x >= bot.x && x <= bot.x + bot.w && y >= botY && y <= botY + bot.h) {
259282
state.fail();
260283
return;

0 commit comments

Comments
 (0)