Skip to content

Commit 7105e4b

Browse files
committed
feat(ContextMenu): the menu's glass grows out of the finger as iOS 26's does
1 parent 0a9d5fd commit 7105e4b

14 files changed

Lines changed: 994 additions & 118 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@astryxdesign/core': patch
3+
'@astryxdesign/cli': patch
4+
---
5+
6+
[feat] Under a finger, on every touch device, when a held finger opens a ContextMenu, the menu now grows out of the finger as iOS 26's does. A small blob of its surface at the press point moves and grows into the menu, overshooting slightly, as it fades in, and the menu's content follows it in from a blur, clipped to it. The menu then wears its own surface again. Under Reduce Motion the menu cross-fades in where it is instead, in 200 ms: nothing moves, grows or blurs. The morph's springs and the size's delay are motion roles a theme can retune; `astryx docs motion` lists them.
7+
8+
@vjeux

‎packages/cli/assets/docs/motion.doc.mjs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ const calmTheme = defineTheme({
184184
headers: ['Role', 'CSS variable', 'Kind', 'Default'],
185185
rows: [
186186
// motion-roles:start (generated by scripts/generate-motion-roles.mjs)
187+
[
188+
'contextMenu.lift.morphSizeDelayMs',
189+
'--motion-context-menu-lift-morph-size-delay-ms',
190+
'duration',
191+
'8.5ms',
192+
],
193+
[
194+
'contextMenu.lift.morphSizeSpring',
195+
'--motion-context-menu-lift-morph-size-spring',
196+
'spring',
197+
'0.315s 0.23',
198+
],
187199
[
188200
'contextMenu.lift.morphSpring',
189201
'--motion-context-menu-lift-morph-spring',

‎packages/cli/test/__golden__/no-icon-set/docs-topics.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
"touch-motion",
202202
"best-practices"
203203
],
204-
"skeleton": "d5314896677a615d939c780dbed90105c655fa6d36395864f6d8fc7a60066785",
204+
"skeleton": "3ef83d0b5788b731e0f1cbb467998001da943fe4032be29f20be63d641000739",
205205
"mentions": []
206206
},
207207
"principles": {

‎packages/core/src/ContextMenu/ContextMenu.doc.mjs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const docs = {
159159
usage: {
160160
anatomy,
161161
description:
162-
'A right-click context menu that appears at the cursor position. Use to provide contextual actions for specific elements or regions without cluttering the UI with visible buttons. Under a finger, on every touch device, a held finger opens it with iOS timing: the trigger starts to grow at 150 ms, and the menu opens at 735 ms, or as soon as the finger lifts after 400 ms. A block trigger then lifts out of the page, as on iOS: a copy of it grows about 13% over a tinted backdrop, and the menu sits beside it, below when it fits and above otherwise.',
162+
'A right-click context menu that appears at the cursor position. Use to provide contextual actions for specific elements or regions without cluttering the UI with visible buttons. Under a finger, on every touch device, a held finger opens it with iOS timing: the trigger starts to grow at 150 ms, and the menu opens at 735 ms, or as soon as the finger lifts after 400 ms. A block trigger then lifts out of the page, as on iOS: a copy of it grows about 13% over a tinted backdrop, and the menu grows out of the finger to sit beside it, below when it fits and above otherwise.',
163163
bestPractices: [
164164
{
165165
guidance: true,
@@ -228,7 +228,7 @@ export const docs = {
228228
export const docsZh = {
229229
usage: {
230230
description:
231-
'右键点击时在光标位置出现的上下文菜单。用于为特定元素或区域提供上下文操作,而不使 UI 杂乱。在所有触摸设备上,按住手指即可打开,时序与 iOS 相同:150 毫秒时触发区域开始放大,735 毫秒时菜单打开;若手指在 400 毫秒后抬起,菜单在抬起时立即打开。随后块级触发区域会像 iOS 一样从页面中浮起:它的副本在着色背景上放大约 13%,菜单位于其旁边,空间足够时在下方,否则在上方。',
231+
'右键点击时在光标位置出现的上下文菜单。用于为特定元素或区域提供上下文操作,而不使 UI 杂乱。在所有触摸设备上,按住手指即可打开,时序与 iOS 相同:150 毫秒时触发区域开始放大,735 毫秒时菜单打开;若手指在 400 毫秒后抬起,菜单在抬起时立即打开。随后块级触发区域会像 iOS 一样从页面中浮起:它的副本在着色背景上放大约 13%,菜单从手指处展开并位于其旁边,空间足够时在下方,否则在上方。',
232232
bestPractices: [
233233
{guidance: true, description: '保持菜单项简洁和面向操作。'},
234234
{guidance: true, description: '有很多项时使用分组和分隔线。'},

‎packages/core/src/ContextMenu/ContextMenu.tsx‎

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ import {contextMenu} from '../motion/uikit';
9595
import {
9696
ContextMenuPressRecognizer,
9797
menuPlacement,
98-
playMenuEntrance,
9998
useContextMenuLift,
10099
useContextMenuPressFeedback,
101100
type ContextMenuLiftResult,
@@ -715,8 +714,7 @@ export function ContextMenu({
715714

716715
// Opens the menu beside a lifted preview: the cursor anchor becomes the
717716
// preview's box (in the trigger's coordinates; the trigger is back at its
718-
// size, under the preview), the layer places the menu against it, and the
719-
// menu's content enters from a blur.
717+
// size, under the preview), and the layer places the menu against it.
720718
const openLifted = useCallback(
721719
({source, lifted}: ContextMenuLiftResult) => {
722720
liftedBoxRef.current = lifted;
@@ -738,10 +736,6 @@ export function ContextMenu({
738736
? document.activeElement
739737
: triggerRef.current;
740738
layer.show();
741-
const menu = listRef.current?.closest<HTMLElement>('[popover]');
742-
if (menu != null) {
743-
playMenuEntrance(menu);
744-
}
745739
// A touch opened it: the menu itself takes the focus, so no row is lit
746740
// until the finger moves onto one (as openAtLocalPoint's touch path).
747741
requestAnimationFrame(() => {
@@ -794,27 +788,45 @@ export function ContextMenu({
794788
});
795789
const liftRef = useRef(liftPresentation);
796790
liftRef.current = liftPresentation;
797-
// A lift whose menu waits for its first side to render.
798-
const pendingLiftRef = useRef<ContextMenuLiftResult | null>(null);
791+
// A lift whose menu waits for its side to render, and the finger its glass
792+
// grows out of.
793+
const pendingLiftRef = useRef<{
794+
lifted: ContextMenuLiftResult;
795+
press: {x: number; y: number};
796+
isShown: boolean;
797+
} | null>(null);
799798
// The open lift's copy, in viewport coordinates.
800799
const liftedBoxRef = useRef<ContextMenuLiftResult['lifted'] | null>(null);
801800
const [liftPlacement, setLiftPlacement] = useState<MenuPlacement | null>(
802801
null,
803802
);
804803
// The lifted menu, once its first side (below) has rendered: show it,
805804
// measure it, and move it above before the frame paints if it does not fit
806-
// (a state update in a layout effect renders again before paint).
805+
// (a state update in a layout effect renders again before paint). Its glass
806+
// then grows out of the finger, from the side it settled on.
807807
useIsomorphicLayoutEffect(() => {
808-
const lifted = pendingLiftRef.current;
809-
if (lifted == null || liftPlacement == null) {
808+
const pending = pendingLiftRef.current;
809+
if (pending == null || liftPlacement == null) {
810810
return;
811811
}
812+
if (!pending.isShown) {
813+
pending.isShown = true;
814+
openLifted(pending.lifted);
815+
const menuHeight = listRef.current?.offsetHeight ?? 0;
816+
const placement = menuPlacement(
817+
pending.lifted.lifted,
818+
menuHeight,
819+
pending.lifted.viewport,
820+
);
821+
if (placement.side !== liftPlacement.side) {
822+
setLiftPlacement(placement);
823+
return;
824+
}
825+
}
812826
pendingLiftRef.current = null;
813-
openLifted(lifted);
814-
const menuHeight = listRef.current?.offsetHeight ?? 0;
815-
const placement = menuPlacement(lifted.lifted, menuHeight, lifted.viewport);
816-
if (placement.side !== liftPlacement.side) {
817-
setLiftPlacement(placement);
827+
const list = listRef.current;
828+
if (list != null) {
829+
liftRef.current.morphMenu(list, pending.press);
818830
}
819831
}, [liftPlacement, openLifted, listRef]);
820832
// The gesture hook follows the element behind the ref, so a `triggerAs`
@@ -846,9 +858,14 @@ export function ContextMenu({
846858
if (lifted != null) {
847859
pressFeedbackRef.current.end();
848860
// The menu's side depends on its height: it renders below first,
849-
// and the layout effect below shows it, measures it, and moves it
850-
// above before the frame paints if it does not fit.
851-
pendingLiftRef.current = lifted;
861+
// and the layout effect below shows it, measures it, moves it above
862+
// before the frame paints if it does not fit, and then grows its
863+
// glass out of the finger.
864+
pendingLiftRef.current = {
865+
lifted,
866+
press: recognizer.press ?? recognizer.location(),
867+
isShown: false,
868+
};
852869
setLiftPlacement(menuPlacement(lifted.lifted, 0, lifted.viewport));
853870
return;
854871
}

0 commit comments

Comments
 (0)