@astryxdesign/lab 0.7.17-canary.g5a3fd39 → 0.7.17-canary.g5cf5d69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/NavigationStack/NavigationStack.d.ts +2 -1
- package/dist/NavigationStack/NavigationStack.d.ts.map +1 -1
- package/dist/NavigationStack/NavigationStack.js +78 -19
- package/package.json +5 -5
- package/src/CircularProgress/__tests__/CircularProgressMotion.a11y.chromium.spec.ts +31 -16
- package/src/NavigationStack/NavigationStack.doc.mjs +1 -1
- package/src/NavigationStack/NavigationStack.test.tsx +52 -0
- package/src/NavigationStack/NavigationStack.tsx +96 -17
- package/src/NavigationStack/__tests__/NavigationStack.interaction.browser.spec.ts +121 -1
|
@@ -133,7 +133,8 @@ export declare namespace NavigationScreen {
|
|
|
133
133
|
* pointer.
|
|
134
134
|
*
|
|
135
135
|
* Accessibility: covered screens are `inert`. A push moves focus to the new
|
|
136
|
-
* screen's title
|
|
136
|
+
* screen's title, unless focus is already in that screen; a pop returns it
|
|
137
|
+
* to the control that pushed the screen.
|
|
137
138
|
* The back button is a real button named by the screen it returns to.
|
|
138
139
|
*/
|
|
139
140
|
export declare function NavigationStack<T>({ root, path, onPathChange, renderScreen, getKey, isInteractivePopEnabled, label, 'data-testid': testId, }: NavigationStackProps<T>): import("react").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NavigationStack.d.ts","sourceRoot":"","sources":["../../src/NavigationStack/NavigationStack.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAQL,KAAK,YAAY,EACjB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AA0Cf,MAAM,WAAW,qBAAqB;IACpC,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IACtC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,2CAA2C;IAC3C,IAAI,EAAE,YAAY,CAAC,qBAAqB,CAAC,CAAC;IAC1C,gEAAgE;IAChE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACvB,0EAA0E;IAC1E,YAAY,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IAClC,qDAAqD;IACrD,YAAY,EAAE,CACZ,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,MAAM,KACV,YAAY,CAAC,qBAAqB,CAAC,CAAC;IACzC;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAC;IACtD,iDAAiD;IACjD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC7C;;;OAGG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE;QAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAAC,KAAK,IAAI,CAAC;IAC9D,gDAAgD;IAChD,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;CACf;AAQD,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,OAAO,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAMvE;
|
|
1
|
+
{"version":3,"file":"NavigationStack.d.ts","sourceRoot":"","sources":["../../src/NavigationStack/NavigationStack.tsx"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAQL,KAAK,YAAY,EACjB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AA0Cf,MAAM,WAAW,qBAAqB;IACpC,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,iEAAiE;IACjE,UAAU,CAAC,EAAE,SAAS,CAAC;IACvB;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IACtC,mDAAmD;IACnD,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,2CAA2C;IAC3C,IAAI,EAAE,YAAY,CAAC,qBAAqB,CAAC,CAAC;IAC1C,gEAAgE;IAChE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACvB,0EAA0E;IAC1E,YAAY,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,IAAI,CAAC;IAClC,qDAAqD;IACrD,YAAY,EAAE,CACZ,KAAK,EAAE,CAAC,EACR,KAAK,EAAE,MAAM,KACV,YAAY,CAAC,qBAAqB,CAAC,CAAC;IACzC;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAAC;IACtD,iDAAiD;IACjD,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC7C;;;OAGG;IACH,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE;QAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;KAAC,KAAK,IAAI,CAAC;IAC9D,gDAAgD;IAChD,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,6BAA6B;IAC7B,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;CACf;AAQD,8DAA8D;AAC9D,wBAAgB,kBAAkB,CAAC,CAAC,GAAG,OAAO,KAAK,kBAAkB,CAAC,CAAC,CAAC,CAMvE;AAujBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,qBAAqB,GAAG,SAAS,CAIzE;yBAJe,gBAAgB;;;AAgGhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,EACjC,IAAI,EACJ,IAAI,EACJ,YAAY,EACZ,YAAY,EACZ,MAAM,EACN,uBAA8B,EAC9B,KAAK,EACL,aAAa,EAAE,MAAM,GACtB,EAAE,oBAAoB,CAAC,CAAC,CAAC,+BAi7BzB;yBA17Be,eAAe"}
|
|
@@ -231,10 +231,10 @@ function CardLayer({
|
|
|
231
231
|
inert: isCovered || undefined,
|
|
232
232
|
...{
|
|
233
233
|
0: {
|
|
234
|
-
className: "x10l6tqk x10a8y8t xb3r6kr x1eiddq6"
|
|
234
|
+
className: "x10l6tqk x10a8y8t xc8icb0 xb3r6kr x1eiddq6"
|
|
235
235
|
},
|
|
236
236
|
1: {
|
|
237
|
-
className: "x10l6tqk x10a8y8t xb3r6kr x1eiddq6 xdps06"
|
|
237
|
+
className: "x10l6tqk x10a8y8t xc8icb0 xb3r6kr x1eiddq6 xdps06"
|
|
238
238
|
}
|
|
239
239
|
}[!!isHidden << 0],
|
|
240
240
|
children: [/*#__PURE__*/_jsxs("div", {
|
|
@@ -456,6 +456,42 @@ function writingDirection(element) {
|
|
|
456
456
|
return isRtlElement(element) ? 'rtl' : 'ltr';
|
|
457
457
|
}
|
|
458
458
|
|
|
459
|
+
/** When a transition's animations start, as the animator's call options. */
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* The clock of a transition. A finger's release keeps its release time, so
|
|
463
|
+
* the spring continues from the frame the finger left. A transition from rest
|
|
464
|
+
* leaves its start to the animator. The browser's commit then dates it. So a
|
|
465
|
+
* heavy commit or a later listener's block delays the motion. It never skips
|
|
466
|
+
* ahead. In an input event's own task (a tap on a row, a key), the motion
|
|
467
|
+
* starts at the first frame after that task.
|
|
468
|
+
*/
|
|
469
|
+
function transitionClock(releasedAt, isInputTask) {
|
|
470
|
+
if (releasedAt != null) {
|
|
471
|
+
return {
|
|
472
|
+
at: releasedAt
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
return isInputTask ? {
|
|
476
|
+
start: 'next-frame'
|
|
477
|
+
} : {};
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/** The pointer, key and touch events a person's press dispatches. */
|
|
481
|
+
const INPUT_EVENT_TYPES = new Set(['click', 'pointerdown', 'pointerup', 'mousedown', 'mouseup', 'touchstart', 'touchend', 'keydown', 'keyup']);
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* The page is dispatching an input event (a pointer, a key, a touch) now.
|
|
485
|
+
* The fallback for a push the app starts outside the stack's own handlers.
|
|
486
|
+
*/
|
|
487
|
+
function isDispatchingInput(view) {
|
|
488
|
+
if (view == null) {
|
|
489
|
+
return false;
|
|
490
|
+
}
|
|
491
|
+
const event = Reflect.get(view, 'event');
|
|
492
|
+
return event instanceof view.Event && INPUT_EVENT_TYPES.has(event.type);
|
|
493
|
+
}
|
|
494
|
+
|
|
459
495
|
/**
|
|
460
496
|
* A push/pop navigator: UINavigationController's transitions, back button
|
|
461
497
|
* and back swipes, on the compositor.
|
|
@@ -506,7 +542,8 @@ function writingDirection(element) {
|
|
|
506
542
|
* pointer.
|
|
507
543
|
*
|
|
508
544
|
* Accessibility: covered screens are `inert`. A push moves focus to the new
|
|
509
|
-
* screen's title
|
|
545
|
+
* screen's title, unless focus is already in that screen; a pop returns it
|
|
546
|
+
* to the control that pushed the screen.
|
|
510
547
|
* The back button is a real button named by the screen it returns to.
|
|
511
548
|
*/
|
|
512
549
|
export function NavigationStack({
|
|
@@ -650,9 +687,12 @@ export function NavigationStack({
|
|
|
650
687
|
// ---------------------------------------------------------------------------
|
|
651
688
|
|
|
652
689
|
const runningRef = useRef(null);
|
|
653
|
-
// The clock the last transition's screens run on (their start
|
|
654
|
-
//
|
|
655
|
-
const startedRef = useRef(
|
|
690
|
+
// The clock the last transition's screens run on (their start), so the
|
|
691
|
+
// back chevron keeps time with them.
|
|
692
|
+
const startedRef = useRef({});
|
|
693
|
+
// A click or key press in the stack is being handled in this task
|
|
694
|
+
// (rememberActivation).
|
|
695
|
+
const inputTaskRef = useRef(false);
|
|
656
696
|
// A pop's focus return, waiting for the commit that drops the leaving
|
|
657
697
|
// screen (until then every screen is `inert` and cannot take focus).
|
|
658
698
|
const pendingFocusRef = useRef(null);
|
|
@@ -774,13 +814,15 @@ export function NavigationStack({
|
|
|
774
814
|
/**
|
|
775
815
|
* Springs the layers to progress `to`. `dp` is the progress velocity to
|
|
776
816
|
* start from (omit it to keep the velocity the layers have on screen).
|
|
817
|
+
* `releasedAt` is a finger's release time; without it the springs start on
|
|
818
|
+
* the animator's clock (transitionClock).
|
|
777
819
|
*/
|
|
778
|
-
const animateProgress = useCallback((to, top, under, spring, dp, release, underBar,
|
|
820
|
+
const animateProgress = useCallback((to, top, under, spring, dp, release, underBar, releasedAt) => {
|
|
779
821
|
const width = cardsRef.current?.clientWidth ?? 0;
|
|
780
822
|
const direction = writingDirection(containerRef.current);
|
|
781
823
|
const values = layersAt(to, width, direction);
|
|
782
824
|
const velocity = dp == null ? null : layerVelocities(dp, width, direction);
|
|
783
|
-
const
|
|
825
|
+
const clock = transitionClock(releasedAt, inputTaskRef.current || isDispatchingInput(containerRef.current?.ownerDocument.defaultView));
|
|
784
826
|
const topLayers = layersOf(top);
|
|
785
827
|
const underLayers = layersOf(under);
|
|
786
828
|
const handles = [];
|
|
@@ -796,11 +838,11 @@ export function NavigationStack({
|
|
|
796
838
|
x: velocity.topX
|
|
797
839
|
} : undefined
|
|
798
840
|
}, {
|
|
799
|
-
|
|
841
|
+
...clock,
|
|
800
842
|
touchRelease: release,
|
|
801
843
|
crossfadeAs: to === 0 ? 'entrance' : 'exit'
|
|
802
844
|
}));
|
|
803
|
-
startedRef.current =
|
|
845
|
+
startedRef.current = clock;
|
|
804
846
|
}
|
|
805
847
|
// The bars move with their cards (each screen's bar is part of it in
|
|
806
848
|
// UIKit): the incoming one covers the outgoing title.
|
|
@@ -813,7 +855,7 @@ export function NavigationStack({
|
|
|
813
855
|
x: velocity.topX
|
|
814
856
|
} : undefined
|
|
815
857
|
}, {
|
|
816
|
-
|
|
858
|
+
...clock,
|
|
817
859
|
touchRelease: release
|
|
818
860
|
}));
|
|
819
861
|
}
|
|
@@ -826,7 +868,7 @@ export function NavigationStack({
|
|
|
826
868
|
x: velocity.underX
|
|
827
869
|
} : undefined
|
|
828
870
|
}, {
|
|
829
|
-
|
|
871
|
+
...clock,
|
|
830
872
|
touchRelease: release
|
|
831
873
|
}));
|
|
832
874
|
}
|
|
@@ -839,7 +881,7 @@ export function NavigationStack({
|
|
|
839
881
|
x: velocity.underX
|
|
840
882
|
} : undefined
|
|
841
883
|
}, {
|
|
842
|
-
|
|
884
|
+
...clock,
|
|
843
885
|
touchRelease: release,
|
|
844
886
|
crossfadeAs: to === 1 ? 'entrance' : 'exit'
|
|
845
887
|
}));
|
|
@@ -871,7 +913,7 @@ export function NavigationStack({
|
|
|
871
913
|
x: clipVelocity
|
|
872
914
|
}
|
|
873
915
|
}, {
|
|
874
|
-
|
|
916
|
+
...clock,
|
|
875
917
|
touchRelease: release
|
|
876
918
|
}), underLayers.barClipContent.animate({
|
|
877
919
|
x: -clipTo
|
|
@@ -881,7 +923,7 @@ export function NavigationStack({
|
|
|
881
923
|
x: -clipVelocity
|
|
882
924
|
}
|
|
883
925
|
}, {
|
|
884
|
-
|
|
926
|
+
...clock,
|
|
885
927
|
touchRelease: release
|
|
886
928
|
}));
|
|
887
929
|
}
|
|
@@ -912,7 +954,7 @@ export function NavigationStack({
|
|
|
912
954
|
opacity: velocity.dim
|
|
913
955
|
} : undefined
|
|
914
956
|
}, {
|
|
915
|
-
|
|
957
|
+
...clock,
|
|
916
958
|
touchRelease: release
|
|
917
959
|
}));
|
|
918
960
|
}
|
|
@@ -962,7 +1004,7 @@ export function NavigationStack({
|
|
|
962
1004
|
velocity: t => t < delayS ? 0 : fade.velocity(t - delayS)
|
|
963
1005
|
}
|
|
964
1006
|
}, {
|
|
965
|
-
|
|
1007
|
+
...startedRef.current,
|
|
966
1008
|
touchRelease: release
|
|
967
1009
|
});
|
|
968
1010
|
}, [view.models, backControl.animator, backChevron.animator]);
|
|
@@ -1017,6 +1059,15 @@ export function NavigationStack({
|
|
|
1017
1059
|
if (container == null || !isFocusLost(container)) {
|
|
1018
1060
|
return;
|
|
1019
1061
|
}
|
|
1062
|
+
// Nor from the screen now on top: focus a person moved into it before
|
|
1063
|
+
// the transition settled (a tap on its field mid-push) stays there.
|
|
1064
|
+
const target = revealed ?? key;
|
|
1065
|
+
const active = container.ownerDocument.activeElement;
|
|
1066
|
+
// This stack's own cards only: a stack nested in a screen has cards too.
|
|
1067
|
+
const topCard = [...(cardsRef.current?.children ?? [])].find(card => card.getAttribute('data-navigation-screen') === target);
|
|
1068
|
+
if (topCard != null && active != null && topCard.contains(active)) {
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1020
1071
|
// The moved focus shows its ring by the last input, as Core's overlays
|
|
1021
1072
|
// do. After a key it shows; after a tap it does not.
|
|
1022
1073
|
const modality = readModality();
|
|
@@ -1037,7 +1088,6 @@ export function NavigationStack({
|
|
|
1037
1088
|
}
|
|
1038
1089
|
// Else the screen now on top (the one pushed, or the one revealed): its
|
|
1039
1090
|
// visible title, the large title while it shows, else the bar's.
|
|
1040
|
-
const target = revealed ?? key;
|
|
1041
1091
|
const layers = layersOf(target);
|
|
1042
1092
|
const large = layers?.largeTitleElement;
|
|
1043
1093
|
const title = large != null && large.isConnected && !collapsedRef.current.has(target) ? large : layers?.titleElement;
|
|
@@ -1119,7 +1169,7 @@ export function NavigationStack({
|
|
|
1119
1169
|
if (!wasRunning) {
|
|
1120
1170
|
setProgress(0, top, under, 'ride');
|
|
1121
1171
|
}
|
|
1122
|
-
promise = animateProgress(1, top, under, springs.navigationPop, wasRunning ? undefined : programmaticVelocity('pop'), false, 'ride'
|
|
1172
|
+
promise = animateProgress(1, top, under, springs.navigationPop, wasRunning ? undefined : programmaticVelocity('pop'), false, 'ride');
|
|
1123
1173
|
fadeBack('pop', under);
|
|
1124
1174
|
}
|
|
1125
1175
|
void promise.then(finished => {
|
|
@@ -1217,6 +1267,15 @@ export function NavigationStack({
|
|
|
1217
1267
|
// from the container's own capture handlers. A press on a control's label or
|
|
1218
1268
|
// icon remembers the control itself.
|
|
1219
1269
|
const rememberActivation = useCallback(event => {
|
|
1270
|
+
// A transition this click or key starts runs in its task: React commits
|
|
1271
|
+
// it before the task ends, and the next task clears the mark. A click
|
|
1272
|
+
// from script commits after window.event is restored. The mark still
|
|
1273
|
+
// sees that task.
|
|
1274
|
+
inputTaskRef.current = true;
|
|
1275
|
+
const view = containerRef.current?.ownerDocument.defaultView;
|
|
1276
|
+
view?.setTimeout(() => {
|
|
1277
|
+
inputTaskRef.current = false;
|
|
1278
|
+
}, 0);
|
|
1220
1279
|
const {
|
|
1221
1280
|
target
|
|
1222
1281
|
} = event;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astryxdesign/lab",
|
|
3
|
-
"version": "0.7.17-canary.
|
|
3
|
+
"version": "0.7.17-canary.g5cf5d69",
|
|
4
4
|
"description": "Experimental Astryx components — published to npm only under the @canary dist-tag for early testing; never released as a stable (latest) version.",
|
|
5
5
|
"author": "Meta Open Source",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@stylexjs/stylex": ">=0.10.0",
|
|
52
|
-
"@astryxdesign/core": "0.7.17-canary.
|
|
52
|
+
"@astryxdesign/core": "0.7.17-canary.g5cf5d69",
|
|
53
53
|
"react": ">=19.0.0",
|
|
54
54
|
"react-dom": ">=19.0.0"
|
|
55
55
|
},
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"d3-shape": "^3.2.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@astryxdesign/a11y-spec": "0.7.17-canary.
|
|
63
|
-
"@astryxdesign/cli": "0.7.17-canary.
|
|
64
|
-
"@astryxdesign/interaction-harness": "0.7.17-canary.
|
|
62
|
+
"@astryxdesign/a11y-spec": "0.7.17-canary.g5cf5d69",
|
|
63
|
+
"@astryxdesign/cli": "0.7.17-canary.g5cf5d69",
|
|
64
|
+
"@astryxdesign/interaction-harness": "0.7.17-canary.g5cf5d69",
|
|
65
65
|
"@babel/cli": "^7.29.7",
|
|
66
66
|
"@babel/core": "^7.29.7",
|
|
67
67
|
"@babel/preset-react": "^7.29.7",
|
|
@@ -26,10 +26,12 @@ import {
|
|
|
26
26
|
type StaticServer,
|
|
27
27
|
} from '@astryxdesign/a11y-spec/storybook';
|
|
28
28
|
import {
|
|
29
|
+
armHold,
|
|
29
30
|
busyWindowProof,
|
|
30
31
|
CONTROL_RGB,
|
|
31
32
|
countBetween,
|
|
32
33
|
inPresentationOrder,
|
|
34
|
+
releaseAnimations,
|
|
33
35
|
startBusyControl,
|
|
34
36
|
traceRendering,
|
|
35
37
|
trackMarker,
|
|
@@ -424,31 +426,44 @@ test('a value change lays out and paints nothing per frame', async ({page}) => {
|
|
|
424
426
|
document.querySelector('.astryx-circular-progress-fill') as HTMLElement
|
|
425
427
|
).style.setProperty('--duration-medium', '3000ms'),
|
|
426
428
|
);
|
|
427
|
-
//
|
|
428
|
-
//
|
|
429
|
-
|
|
429
|
+
// Hold the fill before the story renders. Test-process delays must not
|
|
430
|
+
// consume the change before its judged second starts.
|
|
431
|
+
const fill = page.locator('.astryx-circular-progress-fill');
|
|
432
|
+
const hold = await armHold(page, fill, {
|
|
433
|
+
count: 4,
|
|
434
|
+
judges: {
|
|
435
|
+
target: fill.locator(':scope > span').last(),
|
|
436
|
+
property: 'transform',
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
await setArgs(page, {value: 80});
|
|
440
|
+
expect(await hold.held()).toHaveLength(4);
|
|
430
441
|
let from = 0;
|
|
431
442
|
let to = 0;
|
|
432
443
|
let moving = false;
|
|
433
444
|
const trace = await traceRendering(page, async () => {
|
|
434
|
-
await
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
445
|
+
[from, to, moving] = await fill.evaluate(async element => {
|
|
446
|
+
const animations = element.getAnimations({subtree: true});
|
|
447
|
+
for (const animation of animations) {
|
|
448
|
+
animation.currentTime = 200;
|
|
449
|
+
animation.play();
|
|
450
|
+
}
|
|
451
|
+
await Promise.all(animations.map(animation => animation.ready));
|
|
438
452
|
await new Promise(resolve =>
|
|
439
453
|
requestAnimationFrame(() => requestAnimationFrame(resolve)),
|
|
440
454
|
);
|
|
441
|
-
|
|
455
|
+
const start = performance.timeOrigin + performance.now();
|
|
456
|
+
// Keep both marks and the running-state read in the page's task queue.
|
|
457
|
+
// A delayed response to the test cannot move the read past the end.
|
|
458
|
+
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
459
|
+
return [
|
|
460
|
+
start,
|
|
461
|
+
performance.timeOrigin + performance.now(),
|
|
462
|
+
animations.some(animation => animation.playState === 'running'),
|
|
463
|
+
] as const;
|
|
442
464
|
});
|
|
443
|
-
await page.waitForTimeout(1000);
|
|
444
|
-
[to, moving] = await page.evaluate(
|
|
445
|
-
() =>
|
|
446
|
-
[
|
|
447
|
-
performance.timeOrigin + performance.now(),
|
|
448
|
-
document.getAnimations().some(a => a.playState === 'running'),
|
|
449
|
-
] as const,
|
|
450
|
-
);
|
|
451
465
|
});
|
|
466
|
+
await releaseAnimations(page, {finish: true});
|
|
452
467
|
const counts = countBetween(trace, from, to);
|
|
453
468
|
// A full second of the change: nothing lays out or paints. A
|
|
454
469
|
// stroke-dashoffset transition repainted every frame (36 paints in 410 ms).
|
|
@@ -25,7 +25,7 @@ export const docs = {
|
|
|
25
25
|
name: 'NavigationStack',
|
|
26
26
|
displayName: 'Navigation Stack',
|
|
27
27
|
description:
|
|
28
|
-
"The navigator. You own the path: pass the entries pushed on the root screen and update them in onPathChange. The stack renders the root screen and one screen per entry, the top one last, keeps covered screens and their scroll positions alive, and makes them inert. The bar shows the top screen's title, its end content and a round Back button with a chevron, named by the screen it returns to. A push moves focus to the new screen's title; a pop returns it to the control that pushed the screen. Under a finger the bar paints no background and no hairline, as iOS 26's does. Once a screen's content has moved 10px under the bar, a veil of the body colour fades in at the top of that screen. Each screen keeps its own veil through a push, a pop or a back swipe. With a mouse the bar keeps its surface and hairline.",
|
|
28
|
+
"The navigator. You own the path: pass the entries pushed on the root screen and update them in onPathChange. The stack renders the root screen and one screen per entry, the top one last, keeps covered screens and their scroll positions alive, and makes them inert. The bar shows the top screen's title, its end content and a round Back button with a chevron, named by the screen it returns to. A push moves focus to the new screen's title, unless focus is already in that screen; a pop returns it to the control that pushed the screen. Under a finger the bar paints no background and no hairline, as iOS 26's does. Once a screen's content has moved 10px under the bar, a veil of the body colour fades in at the top of that screen. Each screen keeps its own veil through a push, a pop or a back swipe. With a mouse the bar keeps its surface and hairline.",
|
|
29
29
|
props: [
|
|
30
30
|
{
|
|
31
31
|
name: 'root',
|
|
@@ -109,6 +109,16 @@ describe('NavigationStack', () => {
|
|
|
109
109
|
expect(screen.getByRole('button', {name: 'General'})).toBeInTheDocument();
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
+
// A card is a stacking context at rest, as it is during a transition (a
|
|
113
|
+
// transform makes one), so screen content with any z-index stays under the
|
|
114
|
+
// bar, whose z-index is 1.
|
|
115
|
+
it("gives every card isolation: 'isolate' at rest", () => {
|
|
116
|
+
render(<Harness initial={['General']} />);
|
|
117
|
+
for (const title of ['Settings', 'General']) {
|
|
118
|
+
expect(getComputedStyle(screenCard(title)!).isolation).toBe('isolate');
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
112
122
|
it('pushes a screen: its title shows, Back reads the previous title, the root is covered', async () => {
|
|
113
123
|
render(<Harness />);
|
|
114
124
|
fireEvent.click(screen.getByRole('button', {name: 'General'}));
|
|
@@ -156,6 +166,48 @@ describe('NavigationStack', () => {
|
|
|
156
166
|
await waitFor(() => expect(general).toHaveFocus(), {timeout: 3000});
|
|
157
167
|
});
|
|
158
168
|
|
|
169
|
+
it('keeps focus a person moved into the new screen before the push settles', async () => {
|
|
170
|
+
function Composer() {
|
|
171
|
+
return <input aria-label="Message" />;
|
|
172
|
+
}
|
|
173
|
+
function ComposerHarness() {
|
|
174
|
+
const [path, setPath] = useState<string[]>([]);
|
|
175
|
+
return (
|
|
176
|
+
<NavigationStack
|
|
177
|
+
label="Settings"
|
|
178
|
+
root={
|
|
179
|
+
<NavigationScreen title="Settings">
|
|
180
|
+
<button type="button" onClick={() => setPath(['Compose'])}>
|
|
181
|
+
Compose
|
|
182
|
+
</button>
|
|
183
|
+
</NavigationScreen>
|
|
184
|
+
}
|
|
185
|
+
path={path}
|
|
186
|
+
onPathChange={setPath}
|
|
187
|
+
getKey={entry => entry}
|
|
188
|
+
renderScreen={entry => (
|
|
189
|
+
<NavigationScreen title={entry}>
|
|
190
|
+
<Composer />
|
|
191
|
+
</NavigationScreen>
|
|
192
|
+
)}
|
|
193
|
+
/>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
render(<ComposerHarness />);
|
|
197
|
+
const compose = screen.getByRole('button', {name: 'Compose'});
|
|
198
|
+
compose.focus();
|
|
199
|
+
fireEvent.click(compose);
|
|
200
|
+
// Mid-push, the person moves focus into the new screen, as a tap on its
|
|
201
|
+
// composer does.
|
|
202
|
+
const field = screen.getByRole('textbox', {name: 'Message'});
|
|
203
|
+
field.focus();
|
|
204
|
+
expect(field).toHaveFocus();
|
|
205
|
+
// Wait past the push's settle (well under a second in jsdom); the bar
|
|
206
|
+
// title must not take focus from the field then.
|
|
207
|
+
await new Promise(resolve => setTimeout(resolve, 1200));
|
|
208
|
+
expect(field).toHaveFocus();
|
|
209
|
+
});
|
|
210
|
+
|
|
159
211
|
it('labels Back with the previous screen’s backTitle when it has one', () => {
|
|
160
212
|
render(<Harness initial={['General']} backTitle="All settings" />);
|
|
161
213
|
expect(screen.getByRole('button', {name: 'All settings'})).toHaveAttribute(
|
|
@@ -308,9 +308,12 @@ const styles = stylex.create({
|
|
|
308
308
|
position: 'absolute',
|
|
309
309
|
inset: 0,
|
|
310
310
|
},
|
|
311
|
+
// Each card is a stacking context at rest, as a transform makes it during a
|
|
312
|
+
// transition. So screen content with any z-index stays under the bar.
|
|
311
313
|
card: {
|
|
312
314
|
position: 'absolute',
|
|
313
315
|
inset: 0,
|
|
316
|
+
isolation: 'isolate',
|
|
314
317
|
overflow: 'hidden',
|
|
315
318
|
backgroundColor: colorVars['--color-background-body'],
|
|
316
319
|
},
|
|
@@ -763,6 +766,54 @@ function writingDirection(element: HTMLElement | null): 'ltr' | 'rtl' {
|
|
|
763
766
|
return isRtlElement(element) ? 'rtl' : 'ltr';
|
|
764
767
|
}
|
|
765
768
|
|
|
769
|
+
/** When a transition's animations start, as the animator's call options. */
|
|
770
|
+
type TransitionClock = {at?: number; start?: 'next-frame'};
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* The clock of a transition. A finger's release keeps its release time, so
|
|
774
|
+
* the spring continues from the frame the finger left. A transition from rest
|
|
775
|
+
* leaves its start to the animator. The browser's commit then dates it. So a
|
|
776
|
+
* heavy commit or a later listener's block delays the motion. It never skips
|
|
777
|
+
* ahead. In an input event's own task (a tap on a row, a key), the motion
|
|
778
|
+
* starts at the first frame after that task.
|
|
779
|
+
*/
|
|
780
|
+
function transitionClock(
|
|
781
|
+
releasedAt: number | undefined,
|
|
782
|
+
isInputTask: boolean,
|
|
783
|
+
): TransitionClock {
|
|
784
|
+
if (releasedAt != null) {
|
|
785
|
+
return {at: releasedAt};
|
|
786
|
+
}
|
|
787
|
+
return isInputTask ? {start: 'next-frame'} : {};
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
/** The pointer, key and touch events a person's press dispatches. */
|
|
791
|
+
const INPUT_EVENT_TYPES: ReadonlySet<string> = new Set([
|
|
792
|
+
'click',
|
|
793
|
+
'pointerdown',
|
|
794
|
+
'pointerup',
|
|
795
|
+
'mousedown',
|
|
796
|
+
'mouseup',
|
|
797
|
+
'touchstart',
|
|
798
|
+
'touchend',
|
|
799
|
+
'keydown',
|
|
800
|
+
'keyup',
|
|
801
|
+
]);
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* The page is dispatching an input event (a pointer, a key, a touch) now.
|
|
805
|
+
* The fallback for a push the app starts outside the stack's own handlers.
|
|
806
|
+
*/
|
|
807
|
+
function isDispatchingInput(
|
|
808
|
+
view: (Window & typeof globalThis) | null | undefined,
|
|
809
|
+
): boolean {
|
|
810
|
+
if (view == null) {
|
|
811
|
+
return false;
|
|
812
|
+
}
|
|
813
|
+
const event: unknown = Reflect.get(view, 'event');
|
|
814
|
+
return event instanceof view.Event && INPUT_EVENT_TYPES.has(event.type);
|
|
815
|
+
}
|
|
816
|
+
|
|
766
817
|
/**
|
|
767
818
|
* A push/pop navigator: UINavigationController's transitions, back button
|
|
768
819
|
* and back swipes, on the compositor.
|
|
@@ -813,7 +864,8 @@ function writingDirection(element: HTMLElement | null): 'ltr' | 'rtl' {
|
|
|
813
864
|
* pointer.
|
|
814
865
|
*
|
|
815
866
|
* Accessibility: covered screens are `inert`. A push moves focus to the new
|
|
816
|
-
* screen's title
|
|
867
|
+
* screen's title, unless focus is already in that screen; a pop returns it
|
|
868
|
+
* to the control that pushed the screen.
|
|
817
869
|
* The back button is a real button named by the screen it returns to.
|
|
818
870
|
*/
|
|
819
871
|
export function NavigationStack<T>({
|
|
@@ -963,9 +1015,12 @@ export function NavigationStack<T>({
|
|
|
963
1015
|
// ---------------------------------------------------------------------------
|
|
964
1016
|
|
|
965
1017
|
const runningRef = useRef<{id: number; done: boolean} | null>(null);
|
|
966
|
-
// The clock the last transition's screens run on (their start
|
|
967
|
-
//
|
|
968
|
-
const startedRef = useRef(
|
|
1018
|
+
// The clock the last transition's screens run on (their start), so the
|
|
1019
|
+
// back chevron keeps time with them.
|
|
1020
|
+
const startedRef = useRef<TransitionClock>({});
|
|
1021
|
+
// A click or key press in the stack is being handled in this task
|
|
1022
|
+
// (rememberActivation).
|
|
1023
|
+
const inputTaskRef = useRef(false);
|
|
969
1024
|
// A pop's focus return, waiting for the commit that drops the leaving
|
|
970
1025
|
// screen (until then every screen is `inert` and cannot take focus).
|
|
971
1026
|
const pendingFocusRef = useRef<{popped: string; revealed: string} | null>(
|
|
@@ -1101,6 +1156,8 @@ export function NavigationStack<T>({
|
|
|
1101
1156
|
/**
|
|
1102
1157
|
* Springs the layers to progress `to`. `dp` is the progress velocity to
|
|
1103
1158
|
* start from (omit it to keep the velocity the layers have on screen).
|
|
1159
|
+
* `releasedAt` is a finger's release time; without it the springs start on
|
|
1160
|
+
* the animator's clock (transitionClock).
|
|
1104
1161
|
*/
|
|
1105
1162
|
const animateProgress = useCallback(
|
|
1106
1163
|
(
|
|
@@ -1111,14 +1168,18 @@ export function NavigationStack<T>({
|
|
|
1111
1168
|
dp: number | undefined,
|
|
1112
1169
|
release: boolean,
|
|
1113
1170
|
underBar: 'rest' | 'ride',
|
|
1114
|
-
|
|
1171
|
+
releasedAt?: number,
|
|
1115
1172
|
): Promise<boolean> => {
|
|
1116
1173
|
const width = cardsRef.current?.clientWidth ?? 0;
|
|
1117
1174
|
const direction = writingDirection(containerRef.current);
|
|
1118
1175
|
const values = layersAt(to, width, direction);
|
|
1119
1176
|
const velocity =
|
|
1120
1177
|
dp == null ? null : layerVelocities(dp, width, direction);
|
|
1121
|
-
const
|
|
1178
|
+
const clock = transitionClock(
|
|
1179
|
+
releasedAt,
|
|
1180
|
+
inputTaskRef.current ||
|
|
1181
|
+
isDispatchingInput(containerRef.current?.ownerDocument.defaultView),
|
|
1182
|
+
);
|
|
1122
1183
|
const topLayers = layersOf(top);
|
|
1123
1184
|
const underLayers = layersOf(under);
|
|
1124
1185
|
const handles = [];
|
|
@@ -1131,13 +1192,13 @@ export function NavigationStack<T>({
|
|
|
1131
1192
|
{x: values.topX},
|
|
1132
1193
|
{spring, velocity: velocity ? {x: velocity.topX} : undefined},
|
|
1133
1194
|
{
|
|
1134
|
-
|
|
1195
|
+
...clock,
|
|
1135
1196
|
touchRelease: release,
|
|
1136
1197
|
crossfadeAs: to === 0 ? 'entrance' : 'exit',
|
|
1137
1198
|
},
|
|
1138
1199
|
),
|
|
1139
1200
|
);
|
|
1140
|
-
startedRef.current =
|
|
1201
|
+
startedRef.current = clock;
|
|
1141
1202
|
}
|
|
1142
1203
|
// The bars move with their cards (each screen's bar is part of it in
|
|
1143
1204
|
// UIKit): the incoming one covers the outgoing title.
|
|
@@ -1146,7 +1207,7 @@ export function NavigationStack<T>({
|
|
|
1146
1207
|
topLayers.bar.animate(
|
|
1147
1208
|
{x: values.topX},
|
|
1148
1209
|
{spring, velocity: velocity ? {x: velocity.topX} : undefined},
|
|
1149
|
-
{
|
|
1210
|
+
{...clock, touchRelease: release},
|
|
1150
1211
|
),
|
|
1151
1212
|
);
|
|
1152
1213
|
}
|
|
@@ -1155,7 +1216,7 @@ export function NavigationStack<T>({
|
|
|
1155
1216
|
underLayers.bar.animate(
|
|
1156
1217
|
{x: values.underX},
|
|
1157
1218
|
{spring, velocity: velocity ? {x: velocity.underX} : undefined},
|
|
1158
|
-
{
|
|
1219
|
+
{...clock, touchRelease: release},
|
|
1159
1220
|
),
|
|
1160
1221
|
);
|
|
1161
1222
|
}
|
|
@@ -1165,7 +1226,7 @@ export function NavigationStack<T>({
|
|
|
1165
1226
|
{x: values.underX},
|
|
1166
1227
|
{spring, velocity: velocity ? {x: velocity.underX} : undefined},
|
|
1167
1228
|
{
|
|
1168
|
-
|
|
1229
|
+
...clock,
|
|
1169
1230
|
touchRelease: release,
|
|
1170
1231
|
crossfadeAs: to === 1 ? 'entrance' : 'exit',
|
|
1171
1232
|
},
|
|
@@ -1205,7 +1266,7 @@ export function NavigationStack<T>({
|
|
|
1205
1266
|
spring,
|
|
1206
1267
|
velocity: clipVelocity == null ? undefined : {x: clipVelocity},
|
|
1207
1268
|
},
|
|
1208
|
-
{
|
|
1269
|
+
{...clock, touchRelease: release},
|
|
1209
1270
|
),
|
|
1210
1271
|
underLayers.barClipContent.animate(
|
|
1211
1272
|
{x: -clipTo},
|
|
@@ -1213,7 +1274,7 @@ export function NavigationStack<T>({
|
|
|
1213
1274
|
spring,
|
|
1214
1275
|
velocity: clipVelocity == null ? undefined : {x: -clipVelocity},
|
|
1215
1276
|
},
|
|
1216
|
-
{
|
|
1277
|
+
{...clock, touchRelease: release},
|
|
1217
1278
|
),
|
|
1218
1279
|
);
|
|
1219
1280
|
}
|
|
@@ -1239,7 +1300,7 @@ export function NavigationStack<T>({
|
|
|
1239
1300
|
spring,
|
|
1240
1301
|
velocity: velocity ? {opacity: velocity.dim} : undefined,
|
|
1241
1302
|
},
|
|
1242
|
-
{
|
|
1303
|
+
{...clock, touchRelease: release},
|
|
1243
1304
|
),
|
|
1244
1305
|
);
|
|
1245
1306
|
}
|
|
@@ -1294,7 +1355,7 @@ export function NavigationStack<T>({
|
|
|
1294
1355
|
velocity: t => (t < delayS ? 0 : fade.velocity(t - delayS)),
|
|
1295
1356
|
},
|
|
1296
1357
|
},
|
|
1297
|
-
{
|
|
1358
|
+
{...startedRef.current, touchRelease: release},
|
|
1298
1359
|
);
|
|
1299
1360
|
},
|
|
1300
1361
|
[view.models, backControl.animator, backChevron.animator],
|
|
@@ -1337,6 +1398,17 @@ export function NavigationStack<T>({
|
|
|
1337
1398
|
if (container == null || !isFocusLost(container)) {
|
|
1338
1399
|
return;
|
|
1339
1400
|
}
|
|
1401
|
+
// Nor from the screen now on top: focus a person moved into it before
|
|
1402
|
+
// the transition settled (a tap on its field mid-push) stays there.
|
|
1403
|
+
const target = revealed ?? key;
|
|
1404
|
+
const active = container.ownerDocument.activeElement;
|
|
1405
|
+
// This stack's own cards only: a stack nested in a screen has cards too.
|
|
1406
|
+
const topCard = [...(cardsRef.current?.children ?? [])].find(
|
|
1407
|
+
card => card.getAttribute('data-navigation-screen') === target,
|
|
1408
|
+
);
|
|
1409
|
+
if (topCard != null && active != null && topCard.contains(active)) {
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1340
1412
|
// The moved focus shows its ring by the last input, as Core's overlays
|
|
1341
1413
|
// do. After a key it shows; after a tap it does not.
|
|
1342
1414
|
const modality = readModality();
|
|
@@ -1356,7 +1428,6 @@ export function NavigationStack<T>({
|
|
|
1356
1428
|
}
|
|
1357
1429
|
// Else the screen now on top (the one pushed, or the one revealed): its
|
|
1358
1430
|
// visible title, the large title while it shows, else the bar's.
|
|
1359
|
-
const target = revealed ?? key;
|
|
1360
1431
|
const layers = layersOf(target);
|
|
1361
1432
|
const large = layers?.largeTitleElement;
|
|
1362
1433
|
const title =
|
|
@@ -1449,7 +1520,6 @@ export function NavigationStack<T>({
|
|
|
1449
1520
|
wasRunning ? undefined : programmaticVelocity('pop'),
|
|
1450
1521
|
false,
|
|
1451
1522
|
'ride',
|
|
1452
|
-
at,
|
|
1453
1523
|
);
|
|
1454
1524
|
fadeBack('pop', under);
|
|
1455
1525
|
}
|
|
@@ -1558,6 +1628,15 @@ export function NavigationStack<T>({
|
|
|
1558
1628
|
// from the container's own capture handlers. A press on a control's label or
|
|
1559
1629
|
// icon remembers the control itself.
|
|
1560
1630
|
const rememberActivation = useCallback((event: SyntheticEvent) => {
|
|
1631
|
+
// A transition this click or key starts runs in its task: React commits
|
|
1632
|
+
// it before the task ends, and the next task clears the mark. A click
|
|
1633
|
+
// from script commits after window.event is restored. The mark still
|
|
1634
|
+
// sees that task.
|
|
1635
|
+
inputTaskRef.current = true;
|
|
1636
|
+
const view = containerRef.current?.ownerDocument.defaultView;
|
|
1637
|
+
view?.setTimeout(() => {
|
|
1638
|
+
inputTaskRef.current = false;
|
|
1639
|
+
}, 0);
|
|
1561
1640
|
const {target} = event;
|
|
1562
1641
|
if (isElement(target)) {
|
|
1563
1642
|
// The scroller is focusable while it overflows, but it is not a
|
|
@@ -105,7 +105,13 @@ async function newFinePage(browser: Browser) {
|
|
|
105
105
|
*/
|
|
106
106
|
async function openStack(
|
|
107
107
|
page: Page,
|
|
108
|
-
story:
|
|
108
|
+
story:
|
|
109
|
+
| 'settings'
|
|
110
|
+
| 'pushed'
|
|
111
|
+
| 'carousel'
|
|
112
|
+
| 'declines-pops'
|
|
113
|
+
| 'large-title'
|
|
114
|
+
| 'raised-content',
|
|
109
115
|
{
|
|
110
116
|
standalone = false,
|
|
111
117
|
pointer = 'touch',
|
|
@@ -1150,6 +1156,68 @@ function blockDuringPush(page: Page, ms: number) {
|
|
|
1150
1156
|
});
|
|
1151
1157
|
}
|
|
1152
1158
|
|
|
1159
|
+
test('a push whose commit blocks the main thread starts from its first frame', async ({
|
|
1160
|
+
page,
|
|
1161
|
+
}) => {
|
|
1162
|
+
// A heavy screen blocks the main thread in the task that pushes it (here
|
|
1163
|
+
// for 300 ms, right after the stack mounts it). The push starts when that
|
|
1164
|
+
// task ends, so its first frames show it near where it starts. Dated
|
|
1165
|
+
// before the block, it would show almost all of its travel at once. The
|
|
1166
|
+
// check reads the time since the block with the position, because an
|
|
1167
|
+
// engine's first frames after a long task can take far longer than 16 ms.
|
|
1168
|
+
const {driver, width} = await openStack(page, 'settings');
|
|
1169
|
+
await page.evaluate(() => {
|
|
1170
|
+
const observer = new MutationObserver(() => {
|
|
1171
|
+
if (
|
|
1172
|
+
document.querySelector('[data-navigation-screen="screen-General"]') ==
|
|
1173
|
+
null
|
|
1174
|
+
) {
|
|
1175
|
+
return;
|
|
1176
|
+
}
|
|
1177
|
+
observer.disconnect();
|
|
1178
|
+
const until = performance.now() + 300;
|
|
1179
|
+
while (performance.now() < until) {
|
|
1180
|
+
// Hold the main thread, as a heavy commit does.
|
|
1181
|
+
}
|
|
1182
|
+
(window as Window & {blockEnd?: number}).blockEnd = performance.now();
|
|
1183
|
+
});
|
|
1184
|
+
observer.observe(document.body, {childList: true, subtree: true});
|
|
1185
|
+
});
|
|
1186
|
+
await driver.tap(await rowCenter(page, 'General'));
|
|
1187
|
+
// The second frame after the block, and how long after the block it ran.
|
|
1188
|
+
const {x, sinceBlock} = await page.evaluate(
|
|
1189
|
+
() =>
|
|
1190
|
+
new Promise<{x: number; sinceBlock: number}>(resolve => {
|
|
1191
|
+
requestAnimationFrame(() =>
|
|
1192
|
+
requestAnimationFrame(() => {
|
|
1193
|
+
const pushed = document.querySelector(
|
|
1194
|
+
'[data-navigation-screen="screen-General"]',
|
|
1195
|
+
);
|
|
1196
|
+
const value =
|
|
1197
|
+
pushed == null ? 'none' : getComputedStyle(pushed).translate;
|
|
1198
|
+
const blockEnd =
|
|
1199
|
+
(window as Window & {blockEnd?: number}).blockEnd ?? 0;
|
|
1200
|
+
resolve({
|
|
1201
|
+
x: value === 'none' ? 0 : parseFloat(value),
|
|
1202
|
+
sinceBlock: performance.now() - blockEnd,
|
|
1203
|
+
});
|
|
1204
|
+
}),
|
|
1205
|
+
);
|
|
1206
|
+
}),
|
|
1207
|
+
);
|
|
1208
|
+
// The push spring from the trailing edge (OMEGA, starting at
|
|
1209
|
+
// PUSH_VELOCITY): about 70 % of the width is still to travel after 33 ms.
|
|
1210
|
+
// The share left `ms` into the push:
|
|
1211
|
+
const leftAt = (ms: number) => {
|
|
1212
|
+
const s = ms / 1000;
|
|
1213
|
+
return (1 + (OMEGA - PUSH_VELOCITY) * s) * Math.exp(-OMEGA * s);
|
|
1214
|
+
};
|
|
1215
|
+
// Started at the block's end, at least half of what the spring leaves at
|
|
1216
|
+
// that time is still to travel. Dated before the 300 ms block, almost none
|
|
1217
|
+
// would be.
|
|
1218
|
+
expect(Math.abs(x) / width).toBeGreaterThan(0.5 * leftAt(sinceBlock));
|
|
1219
|
+
});
|
|
1220
|
+
|
|
1153
1221
|
test('a push keeps advancing every frame while the main thread is blocked', async ({
|
|
1154
1222
|
page,
|
|
1155
1223
|
browserName,
|
|
@@ -1501,6 +1569,58 @@ test('under a finger, a pop that reveals a screen two levels down leaves its bar
|
|
|
1501
1569
|
expect(await readCut(page, 'screen-General')).toEqual({shown: 1});
|
|
1502
1570
|
});
|
|
1503
1571
|
|
|
1572
|
+
for (const pointer of ['touch', 'mouse'] as const) {
|
|
1573
|
+
test(`screen content with z-index 2 stays under the bar's title and Back (${pointer})`, async ({
|
|
1574
|
+
page,
|
|
1575
|
+
browser,
|
|
1576
|
+
}) => {
|
|
1577
|
+
// A mouse page reads a fine pointer only in its own context.
|
|
1578
|
+
const {context, page: target} =
|
|
1579
|
+
pointer === 'mouse' ? await newFinePage(browser) : {context: null, page};
|
|
1580
|
+
try {
|
|
1581
|
+
await openStack(target, 'raised-content', {pointer});
|
|
1582
|
+
await expect(target.getByTestId('raised-content')).toBeVisible();
|
|
1583
|
+
// At rest, after the animator lets go of `will-change` (it holds it
|
|
1584
|
+
// briefly after the last motion, and that alone makes a stacking
|
|
1585
|
+
// context), so only the card's own isolation keeps the content under.
|
|
1586
|
+
await expect
|
|
1587
|
+
.poll(() =>
|
|
1588
|
+
target.evaluate(() =>
|
|
1589
|
+
[...document.querySelectorAll('[data-navigation-screen]')].every(
|
|
1590
|
+
screen => getComputedStyle(screen).willChange === 'auto',
|
|
1591
|
+
),
|
|
1592
|
+
),
|
|
1593
|
+
)
|
|
1594
|
+
.toBe(true);
|
|
1595
|
+
const hits = await target.evaluate(() => {
|
|
1596
|
+
const at = (element: Element | null) => {
|
|
1597
|
+
const box = element?.getBoundingClientRect();
|
|
1598
|
+
if (element == null || box == null) {
|
|
1599
|
+
return null;
|
|
1600
|
+
}
|
|
1601
|
+
const hit = document.elementFromPoint(
|
|
1602
|
+
box.left + box.width / 2,
|
|
1603
|
+
box.top + box.height / 2,
|
|
1604
|
+
);
|
|
1605
|
+
return hit != null && element.contains(hit);
|
|
1606
|
+
};
|
|
1607
|
+
const title = [...document.querySelectorAll('h2')].find(
|
|
1608
|
+
h => h.closest('[inert]') == null,
|
|
1609
|
+
);
|
|
1610
|
+
return {
|
|
1611
|
+
title: at(title ?? null),
|
|
1612
|
+
back: at(document.querySelector('[data-navigation-back]')),
|
|
1613
|
+
};
|
|
1614
|
+
});
|
|
1615
|
+
expect(hits).toEqual({title: true, back: true});
|
|
1616
|
+
await target.locator('[data-navigation-back]').click();
|
|
1617
|
+
await expect(card(target, 'screen-General')).toHaveCount(0);
|
|
1618
|
+
} finally {
|
|
1619
|
+
await context?.close();
|
|
1620
|
+
}
|
|
1621
|
+
});
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1504
1624
|
test('under a finger, Back reveals the covered bar whole', async ({page}) => {
|
|
1505
1625
|
const {driver} = await openStack(page, 'settings');
|
|
1506
1626
|
await driver.tap(await rowCenter(page, 'General'));
|