shelving 1.328.3 → 1.329.1
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/docs/llms-full.txt +15 -15
- package/docs/react/SequenceTransitionOptions.md +0 -2
- package/docs/react/useSequenceTransition.md +0 -1
- package/docs/ui/AppLayout.md +10 -9
- package/docs/ui/BackSwipe.md +1 -1
- package/docs/ui/Navigation.md +1 -1
- package/docs/ui/NavigationSequence/back.md +1 -0
- package/docs/ui/NavigationSequence/forward.md +1 -0
- package/docs/ui/waitForKeyboard.md +1 -1
- package/package.json +1 -1
- package/react/useSequenceTransition.d.ts +0 -7
- package/react/useSequenceTransition.js +5 -17
- package/ui/layout/AppLayout.md +10 -9
- package/ui/layout/AppLayout.module.css +5 -2
- package/ui/router/BackSwipe.d.ts +1 -1
- package/ui/router/BackSwipe.js +11 -2
- package/ui/router/BackSwipe.ts +9 -2
- package/ui/router/Navigation.d.ts +1 -1
- package/ui/router/Navigation.js +1 -8
- package/ui/router/Navigation.tsx +1 -8
- package/ui/router/NavigationSequence.d.ts +4 -0
- package/ui/router/NavigationSequence.js +22 -0
- package/ui/router/NavigationSequence.tsx +23 -0
- package/ui/util/keyboard.d.ts +1 -1
- package/ui/util/keyboard.js +5 -2
- package/ui/util/keyboard.ts +4 -2
package/docs/llms-full.txt
CHANGED
|
@@ -12072,7 +12072,6 @@ Options for `useSequenceTransition()`.
|
|
|
12072
12072
|
readonly current: () => T;
|
|
12073
12073
|
readonly transition?: string | ((value: T) => string | null | undefined) | undefined;
|
|
12074
12074
|
readonly equal?: ((a: T, b: T) => boolean) | undefined;
|
|
12075
|
-
readonly wait?: ((value: T) => PromiseLike<void> | void) | undefined;
|
|
12076
12075
|
}
|
|
12077
12076
|
```
|
|
12078
12077
|
|
|
@@ -12083,7 +12082,6 @@ Options for `useSequenceTransition()`.
|
|
|
12083
12082
|
| `current` | `() => T` | Read the current value. - Called for the first render, and again when the subscription starts, to catch up on values sent before it started. Read only. |
|
|
12084
12083
|
| `transition` | `string \| ((value: T) => string \| null \| undefined) \| undefined` | Transition type for a value, or a fixed type for every value. - A value with a type is set inside `startTransition()` with that type, so a `<ViewTransition>` can animate it. - A value with no type (`undefined` or `null`) is set at once, with no transition. Read only. Optional. |
|
|
12085
12084
|
| `equal` | `((a: T, b: T) => boolean) \| undefined` | Is a new value the same as the shown value? A value that is the same is skipped, so it starts no second transition. Read only. Defaults to `Object.is`. |
|
|
12086
|
-
| `wait` | `((value: T) => PromiseLike<void> \| void) \| undefined` | Wait before a value with a transition type is set, for example until the on-screen keyboard is down. - Return a promise to wait for it, or nothing to set the value at once. - A newer value that arrives while it waits wins: the older value is never set. - Values with no transition type never wait. Read only. Optional. |
|
|
12087
12085
|
|
|
12088
12086
|
|
|
12089
12087
|
---
|
|
@@ -12146,7 +12144,6 @@ useSequenceTransition(sequence: AsyncIterable<T>, options: SequenceTransitionOpt
|
|
|
12146
12144
|
| `.current` | `() => T` | Read the current value. - Called for the first render, and again when the subscription starts, to catch up on values sent before it started. Read only. |
|
|
12147
12145
|
| `.transition` | `string \| ((value: T) => string \| null \| undefined) \| undefined` | Transition type for a value, or a fixed type for every value. - A value with a type is set inside `startTransition()` with that type, so a `<ViewTransition>` can animate it. - A value with no type (`undefined` or `null`) is set at once, with no transition. Read only. Optional. |
|
|
12148
12146
|
| `.equal` | `((a: T, b: T) => boolean) \| undefined` | Is a new value the same as the shown value? A value that is the same is skipped, so it starts no second transition. Read only. Defaults to `Object.is`. |
|
|
12149
|
-
| `.wait` | `((value: T) => PromiseLike<void> \| void) \| undefined` | Wait before a value with a transition type is set, for example until the on-screen keyboard is down. - Return a promise to wait for it, or nothing to set the value at once. - A newer value that arrives while it waits wins: the older value is never set. - Values with no transition type never wait. Read only. Optional. |
|
|
12150
12147
|
|
|
12151
12148
|
## Returns
|
|
12152
12149
|
|
|
@@ -31198,15 +31195,16 @@ function StackBar() {
|
|
|
31198
31195
|
|
|
31199
31196
|
## Styling
|
|
31200
31197
|
|
|
31201
|
-
| Variable
|
|
31202
|
-
|
|
|
31203
|
-
| `--app-layout-background`
|
|
31204
|
-
| `--app-layout-color`
|
|
31205
|
-
| `--app-layout-nav-background`
|
|
31206
|
-
| `--app-layout-nav-color`
|
|
31207
|
-
| `--app-layout-nav-border`
|
|
31208
|
-
| `--app-layout-nav-shadow`
|
|
31209
|
-
| `--app-layout-nav-
|
|
31198
|
+
| Variable | Styles | Default |
|
|
31199
|
+
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
|
|
31200
|
+
| `--app-layout-background` | Page background while the layout is mounted | `var(--tint-100)` (white) |
|
|
31201
|
+
| `--app-layout-color` | Text colour for the layout | `var(--tint-00)` (black) |
|
|
31202
|
+
| `--app-layout-nav-background` | Bar fill (also fills the home-bar area below it) | `var(--tint-100)` (white) |
|
|
31203
|
+
| `--app-layout-nav-color` | Bar text and icon colour | `var(--tint-00)` (black) |
|
|
31204
|
+
| `--app-layout-nav-border` | Line above the bar | `var(--stroke-normal) solid var(--tint-90)` |
|
|
31205
|
+
| `--app-layout-nav-shadow` | Shadow of the bar, for example a soft shadow above it | `none` |
|
|
31206
|
+
| `--app-layout-nav-transition-name` | View-transition name of the bar. Set it only for your own transition types (for example under `:root:active-view-transition-type(tab)`), so the bar stays above parts of a page that slide in their own layers | `none` |
|
|
31207
|
+
| `--app-layout-nav-item-width` | Largest width of one bar item | `6rem` |
|
|
31210
31208
|
|
|
31211
31209
|
The bar keeps its items clear of the home bar and the rounded screen corners with safe-area insets.
|
|
31212
31210
|
|
|
@@ -33570,7 +33568,7 @@ BackButton({ href, className, title = "Back", children = <LeftIcon />, ...props
|
|
|
33570
33568
|
Swipe from the left edge of the screen to go back one page in the current stack, by scrubbing the normal back slide.
|
|
33571
33569
|
|
|
33572
33570
|
- It renders nothing. Put it inside `<Navigation>`, next to the pages.
|
|
33573
|
-
- When the swipe starts, it publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
33571
|
+
- When the swipe starts, it lowers the on-screen keyboard (`waitForKeyboard()`), then publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
33574
33572
|
- On release it plays the slide to the end and calls `NavigationSequence.back()`, which publishes the same page again (skipped, so no second slide). Or it plays the slide back and publishes the page it started on again. A cancelled swipe never changes the URL.
|
|
33575
33573
|
- On the bottom page of a stack, or on a floating page, it does nothing, so it never goes back into another tab.
|
|
33576
33574
|
- It ignores touches in a `<nav>` and in dialogs.
|
|
@@ -33652,7 +33650,7 @@ Top-level navigation provider, with one stack of pages for each tab.
|
|
|
33652
33650
|
- Owns a single `NavigationSequence` made from the surrounding `<Meta>` url and root.
|
|
33653
33651
|
- Turns clicks on same-origin links into `NavigationSequence.forward()`, or `NavigationSequence.back()` for a link with `className="back"`, or `NavigationSequence.replace()` for a link with `className="replace"`. Clicks with a modifier key, or on links with `download` or a `target`, are left to the browser.
|
|
33654
33652
|
- Holds the page it shows in its own state, and publishes its `url`, `stack` and `ordinal` into `Meta`. Read the current page from `Meta`.
|
|
33655
|
-
-
|
|
33653
|
+
- Each move lowers the on-screen keyboard before it changes the history: see `NavigationSequence.forward()`.
|
|
33656
33654
|
- Takes each `NavigationEvent` with `useSequenceTransition()`. A move is set inside `startTransition()` with its `"forward"` or `"back"` type, so a `<Transition>` around the routes runs a view transition. A replace has no transition. An event for the page already shown is skipped.
|
|
33657
33655
|
- Uses the browser Navigation API. Without it (older browsers, server renders) there are no stacks and no transitions.
|
|
33658
33656
|
|
|
@@ -34215,6 +34213,7 @@ Go forward to a URL, as a link does.
|
|
|
34215
34213
|
- Else push the URL onto `stack`, one level deeper than its top page.
|
|
34216
34214
|
- The URL you are already on: replace it instead.
|
|
34217
34215
|
- A change of stack slides by tab order. Else it slides forward.
|
|
34216
|
+
- Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
34218
34217
|
|
|
34219
34218
|
## Signatures
|
|
34220
34219
|
|
|
@@ -34236,6 +34235,7 @@ Go back to a URL, as a back button does.
|
|
|
34236
34235
|
- Else push the URL in place of the top page of `stack`.
|
|
34237
34236
|
- It works when the app was opened at the current page, so a back button always has somewhere to go.
|
|
34238
34237
|
- If the browser refuses to go back with the Navigation API, it uses `history.back()`.
|
|
34238
|
+
- Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
34239
34239
|
|
|
34240
34240
|
## Signatures
|
|
34241
34241
|
|
|
@@ -39367,7 +39367,7 @@ if (isKeyboardOpen()) await waitForKeyboard();
|
|
|
39367
39367
|
Lower the on-screen keyboard, and wait until it is down.
|
|
39368
39368
|
- Blurs the focused text field, if there is one, so the keyboard starts to close.
|
|
39369
39369
|
- While the keyboard is open or closing (`isKeyboardOpen()`), it checks once each frame and goes on when the keyboard is
|
|
39370
|
-
down, or after half a second at most.
|
|
39370
|
+
down, or after half a second at most. It then waits one more frame, so the page paints at full height first.
|
|
39371
39371
|
- Returns nothing when there is nothing to wait for, so a caller can go on at once without a promise.
|
|
39372
39372
|
- Use it before a page slide: a keyboard that closes during a view transition resizes the page in the middle of it.
|
|
39373
39373
|
|
|
@@ -12,7 +12,6 @@ Options for `useSequenceTransition()`.
|
|
|
12
12
|
readonly current: () => T;
|
|
13
13
|
readonly transition?: string | ((value: T) => string | null | undefined) | undefined;
|
|
14
14
|
readonly equal?: ((a: T, b: T) => boolean) | undefined;
|
|
15
|
-
readonly wait?: ((value: T) => PromiseLike<void> | void) | undefined;
|
|
16
15
|
}
|
|
17
16
|
```
|
|
18
17
|
|
|
@@ -23,4 +22,3 @@ Options for `useSequenceTransition()`.
|
|
|
23
22
|
| `current` | `() => T` | Read the current value. - Called for the first render, and again when the subscription starts, to catch up on values sent before it started. Read only. |
|
|
24
23
|
| `transition` | `string \| ((value: T) => string \| null \| undefined) \| undefined` | Transition type for a value, or a fixed type for every value. - A value with a type is set inside `startTransition()` with that type, so a `<ViewTransition>` can animate it. - A value with no type (`undefined` or `null`) is set at once, with no transition. Read only. Optional. |
|
|
25
24
|
| `equal` | `((a: T, b: T) => boolean) \| undefined` | Is a new value the same as the shown value? A value that is the same is skipped, so it starts no second transition. Read only. Defaults to `Object.is`. |
|
|
26
|
-
| `wait` | `((value: T) => PromiseLike<void> \| void) \| undefined` | Wait before a value with a transition type is set, for example until the on-screen keyboard is down. - Return a promise to wait for it, or nothing to set the value at once. - A newer value that arrives while it waits wins: the older value is never set. - Values with no transition type never wait. Read only. Optional. |
|
|
@@ -56,7 +56,6 @@ useSequenceTransition(sequence: AsyncIterable<T>, options: SequenceTransitionOpt
|
|
|
56
56
|
| `.current` | `() => T` | Read the current value. - Called for the first render, and again when the subscription starts, to catch up on values sent before it started. Read only. |
|
|
57
57
|
| `.transition` | `string \| ((value: T) => string \| null \| undefined) \| undefined` | Transition type for a value, or a fixed type for every value. - A value with a type is set inside `startTransition()` with that type, so a `<ViewTransition>` can animate it. - A value with no type (`undefined` or `null`) is set at once, with no transition. Read only. Optional. |
|
|
58
58
|
| `.equal` | `((a: T, b: T) => boolean) \| undefined` | Is a new value the same as the shown value? A value that is the same is skipped, so it starts no second transition. Read only. Defaults to `Object.is`. |
|
|
59
|
-
| `.wait` | `((value: T) => PromiseLike<void> \| void) \| undefined` | Wait before a value with a transition type is set, for example until the on-screen keyboard is down. - Return a promise to wait for it, or nothing to set the value at once. - A newer value that arrives while it waits wins: the older value is never set. - Values with no transition type never wait. Read only. Optional. |
|
|
60
59
|
|
|
61
60
|
## Returns
|
|
62
61
|
|
package/docs/ui/AppLayout.md
CHANGED
|
@@ -59,15 +59,16 @@ function StackBar() {
|
|
|
59
59
|
|
|
60
60
|
## Styling
|
|
61
61
|
|
|
62
|
-
| Variable
|
|
63
|
-
|
|
|
64
|
-
| `--app-layout-background`
|
|
65
|
-
| `--app-layout-color`
|
|
66
|
-
| `--app-layout-nav-background`
|
|
67
|
-
| `--app-layout-nav-color`
|
|
68
|
-
| `--app-layout-nav-border`
|
|
69
|
-
| `--app-layout-nav-shadow`
|
|
70
|
-
| `--app-layout-nav-
|
|
62
|
+
| Variable | Styles | Default |
|
|
63
|
+
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
|
|
64
|
+
| `--app-layout-background` | Page background while the layout is mounted | `var(--tint-100)` (white) |
|
|
65
|
+
| `--app-layout-color` | Text colour for the layout | `var(--tint-00)` (black) |
|
|
66
|
+
| `--app-layout-nav-background` | Bar fill (also fills the home-bar area below it) | `var(--tint-100)` (white) |
|
|
67
|
+
| `--app-layout-nav-color` | Bar text and icon colour | `var(--tint-00)` (black) |
|
|
68
|
+
| `--app-layout-nav-border` | Line above the bar | `var(--stroke-normal) solid var(--tint-90)` |
|
|
69
|
+
| `--app-layout-nav-shadow` | Shadow of the bar, for example a soft shadow above it | `none` |
|
|
70
|
+
| `--app-layout-nav-transition-name` | View-transition name of the bar. Set it only for your own transition types (for example under `:root:active-view-transition-type(tab)`), so the bar stays above parts of a page that slide in their own layers | `none` |
|
|
71
|
+
| `--app-layout-nav-item-width` | Largest width of one bar item | `6rem` |
|
|
71
72
|
|
|
72
73
|
The bar keeps its items clear of the home bar and the rounded screen corners with safe-area insets.
|
|
73
74
|
|
package/docs/ui/BackSwipe.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Swipe from the left edge of the screen to go back one page in the current stack, by scrubbing the normal back slide.
|
|
7
7
|
|
|
8
8
|
- It renders nothing. Put it inside `<Navigation>`, next to the pages.
|
|
9
|
-
- When the swipe starts, it publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
9
|
+
- When the swipe starts, it lowers the on-screen keyboard (`waitForKeyboard()`), then publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
10
10
|
- On release it plays the slide to the end and calls `NavigationSequence.back()`, which publishes the same page again (skipped, so no second slide). Or it plays the slide back and publishes the page it started on again. A cancelled swipe never changes the URL.
|
|
11
11
|
- On the bottom page of a stack, or on a floating page, it does nothing, so it never goes back into another tab.
|
|
12
12
|
- It ignores touches in a `<nav>` and in dialogs.
|
package/docs/ui/Navigation.md
CHANGED
|
@@ -7,7 +7,7 @@ Top-level navigation provider, with one stack of pages for each tab.
|
|
|
7
7
|
- Owns a single `NavigationSequence` made from the surrounding `<Meta>` url and root.
|
|
8
8
|
- Turns clicks on same-origin links into `NavigationSequence.forward()`, or `NavigationSequence.back()` for a link with `className="back"`, or `NavigationSequence.replace()` for a link with `className="replace"`. Clicks with a modifier key, or on links with `download` or a `target`, are left to the browser.
|
|
9
9
|
- Holds the page it shows in its own state, and publishes its `url`, `stack` and `ordinal` into `Meta`. Read the current page from `Meta`.
|
|
10
|
-
-
|
|
10
|
+
- Each move lowers the on-screen keyboard before it changes the history: see `NavigationSequence.forward()`.
|
|
11
11
|
- Takes each `NavigationEvent` with `useSequenceTransition()`. A move is set inside `startTransition()` with its `"forward"` or `"back"` type, so a `<Transition>` around the routes runs a view transition. A replace has no transition. An event for the page already shown is skipped.
|
|
12
12
|
- Uses the browser Navigation API. Without it (older browsers, server renders) there are no stacks and no transitions.
|
|
13
13
|
|
|
@@ -9,6 +9,7 @@ Go back to a URL, as a back button does.
|
|
|
9
9
|
- Else push the URL in place of the top page of `stack`.
|
|
10
10
|
- It works when the app was opened at the current page, so a back button always has somewhere to go.
|
|
11
11
|
- If the browser refuses to go back with the Navigation API, it uses `history.back()`.
|
|
12
|
+
- Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
12
13
|
|
|
13
14
|
## Signatures
|
|
14
15
|
|
|
@@ -8,6 +8,7 @@ Go forward to a URL, as a link does.
|
|
|
8
8
|
- Else push the URL onto `stack`, one level deeper than its top page.
|
|
9
9
|
- The URL you are already on: replace it instead.
|
|
10
10
|
- A change of stack slides by tab order. Else it slides forward.
|
|
11
|
+
- Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
11
12
|
|
|
12
13
|
## Signatures
|
|
13
14
|
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Lower the on-screen keyboard, and wait until it is down.
|
|
7
7
|
- Blurs the focused text field, if there is one, so the keyboard starts to close.
|
|
8
8
|
- While the keyboard is open or closing (`isKeyboardOpen()`), it checks once each frame and goes on when the keyboard is
|
|
9
|
-
down, or after half a second at most.
|
|
9
|
+
down, or after half a second at most. It then waits one more frame, so the page paints at full height first.
|
|
10
10
|
- Returns nothing when there is nothing to wait for, so a caller can go on at once without a promise.
|
|
11
11
|
- Use it before a page slide: a keyboard that closes during a view transition resizes the page in the middle of it.
|
|
12
12
|
|
package/package.json
CHANGED
|
@@ -21,13 +21,6 @@ export interface SequenceTransitionOptions<T> {
|
|
|
21
21
|
* @default Object.is
|
|
22
22
|
*/
|
|
23
23
|
readonly equal?: ((a: T, b: T) => boolean) | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* Wait before a value with a transition type is set, for example until the on-screen keyboard is down.
|
|
26
|
-
* - Return a promise to wait for it, or nothing to set the value at once.
|
|
27
|
-
* - A newer value that arrives while it waits wins: the older value is never set.
|
|
28
|
-
* - Values with no transition type never wait.
|
|
29
|
-
*/
|
|
30
|
-
readonly wait?: ((value: T) => PromiseLike<void> | void) | undefined;
|
|
31
24
|
}
|
|
32
25
|
/**
|
|
33
26
|
* Subscribe to an async iterable, and set each value it yields inside a React transition.
|
|
@@ -22,30 +22,18 @@ export function useSequenceTransition(sequence, options) {
|
|
|
22
22
|
optionsRef.current = options;
|
|
23
23
|
const valueRef = useRef(value);
|
|
24
24
|
useEffect(() => {
|
|
25
|
-
// Counts the values, so a value that waited is set only when no newer value came in while it waited.
|
|
26
|
-
let count = 0;
|
|
27
25
|
const set = (next) => {
|
|
28
|
-
const { transition, equal = Object.is
|
|
26
|
+
const { transition, equal = Object.is } = optionsRef.current;
|
|
29
27
|
if (equal(valueRef.current, next))
|
|
30
28
|
return;
|
|
31
29
|
valueRef.current = next;
|
|
32
|
-
const n = ++count;
|
|
33
30
|
const type = typeof transition === "function" ? transition(next) : transition;
|
|
34
31
|
if (!type)
|
|
35
32
|
return setValue(next);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
addTransitionType(type);
|
|
41
|
-
setValue(next);
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
const waiting = wait?.(next);
|
|
45
|
-
if (waiting)
|
|
46
|
-
waiting.then(show, show);
|
|
47
|
-
else
|
|
48
|
-
show();
|
|
33
|
+
startTransition(() => {
|
|
34
|
+
addTransitionType(type);
|
|
35
|
+
setValue(next);
|
|
36
|
+
});
|
|
49
37
|
};
|
|
50
38
|
set(optionsRef.current.current());
|
|
51
39
|
return runSequence(sequence, set, setError);
|
package/ui/layout/AppLayout.md
CHANGED
|
@@ -51,15 +51,16 @@ function StackBar() {
|
|
|
51
51
|
|
|
52
52
|
## Styling
|
|
53
53
|
|
|
54
|
-
| Variable
|
|
55
|
-
|
|
|
56
|
-
| `--app-layout-background`
|
|
57
|
-
| `--app-layout-color`
|
|
58
|
-
| `--app-layout-nav-background`
|
|
59
|
-
| `--app-layout-nav-color`
|
|
60
|
-
| `--app-layout-nav-border`
|
|
61
|
-
| `--app-layout-nav-shadow`
|
|
62
|
-
| `--app-layout-nav-
|
|
54
|
+
| Variable | Styles | Default |
|
|
55
|
+
| ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
|
|
56
|
+
| `--app-layout-background` | Page background while the layout is mounted | `var(--tint-100)` (white) |
|
|
57
|
+
| `--app-layout-color` | Text colour for the layout | `var(--tint-00)` (black) |
|
|
58
|
+
| `--app-layout-nav-background` | Bar fill (also fills the home-bar area below it) | `var(--tint-100)` (white) |
|
|
59
|
+
| `--app-layout-nav-color` | Bar text and icon colour | `var(--tint-00)` (black) |
|
|
60
|
+
| `--app-layout-nav-border` | Line above the bar | `var(--stroke-normal) solid var(--tint-90)` |
|
|
61
|
+
| `--app-layout-nav-shadow` | Shadow of the bar, for example a soft shadow above it | `none` |
|
|
62
|
+
| `--app-layout-nav-transition-name` | View-transition name of the bar. Set it only for your own transition types (for example under `:root:active-view-transition-type(tab)`), so the bar stays above parts of a page that slide in their own layers | `none` |
|
|
63
|
+
| `--app-layout-nav-item-width` | Largest width of one bar item | `6rem` |
|
|
63
64
|
|
|
64
65
|
The bar keeps its items clear of the home bar and the rounded screen corners with safe-area insets.
|
|
65
66
|
|
|
@@ -81,8 +81,11 @@
|
|
|
81
81
|
color: var(--app-layout-nav-color, var(--tint-00));
|
|
82
82
|
box-shadow: var(--app-layout-nav-shadow, none);
|
|
83
83
|
|
|
84
|
-
/* No view-transition name of its own. Pages slide sideways in the content slot above it, so they never pass over it.
|
|
85
|
-
* A named bar would draw above everything else during any view transition, and jump over a dialog or notice that covers it.
|
|
84
|
+
/* No view-transition name of its own by default. Pages slide sideways in the content slot above it, so they never pass over it.
|
|
85
|
+
* A named bar would draw above everything else during any view transition, and jump over a dialog or notice that covers it.
|
|
86
|
+
* An app can name it for its own transitions only, for example parts of a page that slide in their own layers and would pass over it:
|
|
87
|
+
* `:root:active-view-transition-type(tab) { --app-layout-nav-transition-name: app-nav; }` */
|
|
88
|
+
view-transition-name: var(--app-layout-nav-transition-name, none);
|
|
86
89
|
|
|
87
90
|
/* Each item takes an equal share of the bar. */
|
|
88
91
|
> * {
|
package/ui/router/BackSwipe.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Swipe from the left edge of the screen to go back one page in the current stack, by scrubbing the normal back slide.
|
|
3
3
|
*
|
|
4
4
|
* - It renders nothing. Put it inside `<Navigation>`, next to the pages.
|
|
5
|
-
* - When the swipe starts, it publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
5
|
+
* - When the swipe starts, it lowers the on-screen keyboard (`waitForKeyboard()`), then publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
6
6
|
* - On release it plays the slide to the end and calls `NavigationSequence.back()`, which publishes the same page again (skipped, so no second slide). Or it plays the slide back and publishes the page it started on again. A cancelled swipe never changes the URL.
|
|
7
7
|
* - On the bottom page of a stack, or on a floating page, it does nothing, so it never goes back into another tab.
|
|
8
8
|
* - It ignores touches in a `<nav>` and in dialogs.
|
package/ui/router/BackSwipe.js
CHANGED
|
@@ -2,6 +2,7 @@ import { useRef } from "react";
|
|
|
2
2
|
import { requireURL } from "../../util/url.js";
|
|
3
3
|
import { requireMeta } from "../misc/MetaContext.js";
|
|
4
4
|
import { useSwipe } from "../transition/useSwipe.js";
|
|
5
|
+
import { waitForKeyboard } from "../util/keyboard.js";
|
|
5
6
|
import { requireNavigation } from "./NavigationContext.js";
|
|
6
7
|
/** How far from the left edge of the screen a swipe can start, in pixels. */
|
|
7
8
|
const _EDGE = 24;
|
|
@@ -9,7 +10,7 @@ const _EDGE = 24;
|
|
|
9
10
|
* Swipe from the left edge of the screen to go back one page in the current stack, by scrubbing the normal back slide.
|
|
10
11
|
*
|
|
11
12
|
* - It renders nothing. Put it inside `<Navigation>`, next to the pages.
|
|
12
|
-
* - When the swipe starts, it publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
13
|
+
* - When the swipe starts, it lowers the on-screen keyboard (`waitForKeyboard()`), then publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
13
14
|
* - On release it plays the slide to the end and calls `NavigationSequence.back()`, which publishes the same page again (skipped, so no second slide). Or it plays the slide back and publishes the page it started on again. A cancelled swipe never changes the URL.
|
|
14
15
|
* - On the bottom page of a stack, or on a floating page, it does nothing, so it never goes back into another tab.
|
|
15
16
|
* - It ignores touches in a `<nav>` and in dialogs.
|
|
@@ -36,7 +37,15 @@ export function BackSwipe() {
|
|
|
36
37
|
return false;
|
|
37
38
|
const parent = { url: requireURL(path, url), stack, ordinal: ordinal - 1, direction: "back" };
|
|
38
39
|
swipeRef.current = { from: { url, stack, ordinal }, parent };
|
|
39
|
-
|
|
40
|
+
// Lower the keyboard before the slide starts, so the page does not resize in the middle of it.
|
|
41
|
+
const waiting = waitForKeyboard();
|
|
42
|
+
if (waiting)
|
|
43
|
+
void waiting.then(() => {
|
|
44
|
+
if (swipeRef.current?.parent === parent)
|
|
45
|
+
void nav.publish(parent);
|
|
46
|
+
});
|
|
47
|
+
else
|
|
48
|
+
void nav.publish(parent);
|
|
40
49
|
},
|
|
41
50
|
cancel: () => {
|
|
42
51
|
const swipe = swipeRef.current;
|
package/ui/router/BackSwipe.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { useRef } from "react";
|
|
|
2
2
|
import { requireURL } from "../../util/url.js";
|
|
3
3
|
import { requireMeta } from "../misc/MetaContext.js";
|
|
4
4
|
import { useSwipe } from "../transition/useSwipe.js";
|
|
5
|
+
import { waitForKeyboard } from "../util/keyboard.js";
|
|
5
6
|
import { requireNavigation } from "./NavigationContext.js";
|
|
6
7
|
import type { NavigationEvent } from "./NavigationSequence.js";
|
|
7
8
|
|
|
@@ -12,7 +13,7 @@ const _EDGE = 24;
|
|
|
12
13
|
* Swipe from the left edge of the screen to go back one page in the current stack, by scrubbing the normal back slide.
|
|
13
14
|
*
|
|
14
15
|
* - It renders nothing. Put it inside `<Navigation>`, next to the pages.
|
|
15
|
-
* - When the swipe starts, it publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
16
|
+
* - When the swipe starts, it lowers the on-screen keyboard (`waitForKeyboard()`), then publishes the page below as a `"back"` event with `NavigationSequence.publish()`. History does not change. `<Navigation>` shows that page in a back transition, and `useSwipe()` scrubs it.
|
|
16
17
|
* - On release it plays the slide to the end and calls `NavigationSequence.back()`, which publishes the same page again (skipped, so no second slide). Or it plays the slide back and publishes the page it started on again. A cancelled swipe never changes the URL.
|
|
17
18
|
* - On the bottom page of a stack, or on a floating page, it does nothing, so it never goes back into another tab.
|
|
18
19
|
* - It ignores touches in a `<nav>` and in dialogs.
|
|
@@ -38,7 +39,13 @@ export function BackSwipe(): null {
|
|
|
38
39
|
if (!path) return false;
|
|
39
40
|
const parent: NavigationEvent = { url: requireURL(path, url), stack, ordinal: ordinal - 1, direction: "back" };
|
|
40
41
|
swipeRef.current = { from: { url, stack, ordinal }, parent };
|
|
41
|
-
|
|
42
|
+
// Lower the keyboard before the slide starts, so the page does not resize in the middle of it.
|
|
43
|
+
const waiting = waitForKeyboard();
|
|
44
|
+
if (waiting)
|
|
45
|
+
void waiting.then(() => {
|
|
46
|
+
if (swipeRef.current?.parent === parent) void nav.publish(parent);
|
|
47
|
+
});
|
|
48
|
+
else void nav.publish(parent);
|
|
42
49
|
},
|
|
43
50
|
cancel: () => {
|
|
44
51
|
const swipe = swipeRef.current;
|
|
@@ -27,7 +27,7 @@ export interface NavigationProps extends PossibleMeta, OptionalChildProps {
|
|
|
27
27
|
* - Owns a single `NavigationSequence` made from the surrounding `<Meta>` url and root.
|
|
28
28
|
* - Turns clicks on same-origin links into `NavigationSequence.forward()`, or `NavigationSequence.back()` for a link with `className="back"`, or `NavigationSequence.replace()` for a link with `className="replace"`. Clicks with a modifier key, or on links with `download` or a `target`, are left to the browser.
|
|
29
29
|
* - Holds the page it shows in its own state, and publishes its `url`, `stack` and `ordinal` into `Meta`. Read the current page from `Meta`.
|
|
30
|
-
* -
|
|
30
|
+
* - Each move lowers the on-screen keyboard before it changes the history: see `NavigationSequence.forward()`.
|
|
31
31
|
* - Takes each `NavigationEvent` with `useSequenceTransition()`. A move is set inside `startTransition()` with its `"forward"` or `"back"` type, so a `<Transition>` around the routes runs a view transition. A replace has no transition. An event for the page already shown is skipped.
|
|
32
32
|
* - Uses the browser Navigation API. Without it (older browsers, server renders) there are no stacks and no transitions.
|
|
33
33
|
*
|
package/ui/router/Navigation.js
CHANGED
|
@@ -4,7 +4,6 @@ import { useInstance } from "../../react/useInstance.js";
|
|
|
4
4
|
import { useSequenceTransition } from "../../react/useSequenceTransition.js";
|
|
5
5
|
import { MetaContext, requireMeta } from "../misc/MetaContext.js";
|
|
6
6
|
import { mergeMeta } from "../util/index.js";
|
|
7
|
-
import { waitForKeyboard } from "../util/keyboard.js";
|
|
8
7
|
import { NavigationContext } from "./NavigationContext.js";
|
|
9
8
|
import { NavigationSequence } from "./NavigationSequence.js";
|
|
10
9
|
/**
|
|
@@ -12,7 +11,7 @@ import { NavigationSequence } from "./NavigationSequence.js";
|
|
|
12
11
|
* - Owns a single `NavigationSequence` made from the surrounding `<Meta>` url and root.
|
|
13
12
|
* - Turns clicks on same-origin links into `NavigationSequence.forward()`, or `NavigationSequence.back()` for a link with `className="back"`, or `NavigationSequence.replace()` for a link with `className="replace"`. Clicks with a modifier key, or on links with `download` or a `target`, are left to the browser.
|
|
14
13
|
* - Holds the page it shows in its own state, and publishes its `url`, `stack` and `ordinal` into `Meta`. Read the current page from `Meta`.
|
|
15
|
-
* -
|
|
14
|
+
* - Each move lowers the on-screen keyboard before it changes the history: see `NavigationSequence.forward()`.
|
|
16
15
|
* - Takes each `NavigationEvent` with `useSequenceTransition()`. A move is set inside `startTransition()` with its `"forward"` or `"back"` type, so a `<Transition>` around the routes runs a view transition. A replace has no transition. An event for the page already shown is skipped.
|
|
17
16
|
* - Uses the browser Navigation API. Without it (older browsers, server renders) there are no stacks and no transitions.
|
|
18
17
|
*
|
|
@@ -29,7 +28,6 @@ export function Navigation({ children, stacks = [], ...meta }) {
|
|
|
29
28
|
current: () => nav.current(),
|
|
30
29
|
transition: _getDirection,
|
|
31
30
|
equal: _isSamePage,
|
|
32
|
-
wait: _waitForMove,
|
|
33
31
|
});
|
|
34
32
|
// Tell a waiting `NavigationSequence.publish()` that its page is committed.
|
|
35
33
|
useLayoutEffect(() => {
|
|
@@ -69,11 +67,6 @@ export function Navigation({ children, stacks = [], ...meta }) {
|
|
|
69
67
|
function _getDirection({ direction }) {
|
|
70
68
|
return direction;
|
|
71
69
|
}
|
|
72
|
-
/** Before a move slides, lower the on-screen keyboard and wait until it is down, so the page does not resize during the slide. */
|
|
73
|
-
function _waitForMove({ direction }) {
|
|
74
|
-
if (direction)
|
|
75
|
-
return waitForKeyboard();
|
|
76
|
-
}
|
|
77
70
|
function _isSamePage(a, b) {
|
|
78
71
|
return a.url.href === b.url.href && a.stack === b.stack && a.ordinal === b.ordinal;
|
|
79
72
|
}
|
package/ui/router/Navigation.tsx
CHANGED
|
@@ -4,7 +4,6 @@ import { useSequenceTransition } from "../../react/useSequenceTransition.js";
|
|
|
4
4
|
import type { AbsolutePath } from "../../util/path.js";
|
|
5
5
|
import { MetaContext, requireMeta } from "../misc/MetaContext.js";
|
|
6
6
|
import { mergeMeta, type PossibleMeta } from "../util/index.js";
|
|
7
|
-
import { waitForKeyboard } from "../util/keyboard.js";
|
|
8
7
|
import type { OptionalChildProps } from "../util/props.js";
|
|
9
8
|
import { NavigationContext } from "./NavigationContext.js";
|
|
10
9
|
import { type NavigationEvent, NavigationSequence } from "./NavigationSequence.js";
|
|
@@ -35,7 +34,7 @@ export interface NavigationProps extends PossibleMeta, OptionalChildProps {
|
|
|
35
34
|
* - Owns a single `NavigationSequence` made from the surrounding `<Meta>` url and root.
|
|
36
35
|
* - Turns clicks on same-origin links into `NavigationSequence.forward()`, or `NavigationSequence.back()` for a link with `className="back"`, or `NavigationSequence.replace()` for a link with `className="replace"`. Clicks with a modifier key, or on links with `download` or a `target`, are left to the browser.
|
|
37
36
|
* - Holds the page it shows in its own state, and publishes its `url`, `stack` and `ordinal` into `Meta`. Read the current page from `Meta`.
|
|
38
|
-
* -
|
|
37
|
+
* - Each move lowers the on-screen keyboard before it changes the history: see `NavigationSequence.forward()`.
|
|
39
38
|
* - Takes each `NavigationEvent` with `useSequenceTransition()`. A move is set inside `startTransition()` with its `"forward"` or `"back"` type, so a `<Transition>` around the routes runs a view transition. A replace has no transition. An event for the page already shown is skipped.
|
|
40
39
|
* - Uses the browser Navigation API. Without it (older browsers, server renders) there are no stacks and no transitions.
|
|
41
40
|
*
|
|
@@ -53,7 +52,6 @@ export function Navigation({ children, stacks = [], ...meta }: NavigationProps):
|
|
|
53
52
|
current: () => nav.current(),
|
|
54
53
|
transition: _getDirection,
|
|
55
54
|
equal: _isSamePage,
|
|
56
|
-
wait: _waitForMove,
|
|
57
55
|
});
|
|
58
56
|
|
|
59
57
|
// Tell a waiting `NavigationSequence.publish()` that its page is committed.
|
|
@@ -99,11 +97,6 @@ function _getDirection({ direction }: NavigationEvent): string | undefined {
|
|
|
99
97
|
return direction;
|
|
100
98
|
}
|
|
101
99
|
|
|
102
|
-
/** Before a move slides, lower the on-screen keyboard and wait until it is down, so the page does not resize during the slide. */
|
|
103
|
-
function _waitForMove({ direction }: NavigationEvent): Promise<void> | void {
|
|
104
|
-
if (direction) return waitForKeyboard();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
100
|
function _isSamePage(a: NavigationEvent, b: NavigationEvent): boolean {
|
|
108
101
|
return a.url.href === b.url.href && a.stack === b.stack && a.ordinal === b.ordinal;
|
|
109
102
|
}
|
|
@@ -143,6 +143,7 @@ export declare class NavigationSequence extends DeferredSequence<NavigationEvent
|
|
|
143
143
|
* - Else push the URL onto `stack`, one level deeper than its top page.
|
|
144
144
|
* - The URL you are already on: replace it instead.
|
|
145
145
|
* - A change of stack slides by tab order. Else it slides forward.
|
|
146
|
+
* - Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
146
147
|
*
|
|
147
148
|
* @param possible The destination URL, resolved against `base`.
|
|
148
149
|
* @param stack Root path of the stack to go to, or `null` for the floating stack. Defaults to the current stack.
|
|
@@ -151,6 +152,7 @@ export declare class NavigationSequence extends DeferredSequence<NavigationEvent
|
|
|
151
152
|
* @see https://shelving.cc/ui/NavigationSequence/forward
|
|
152
153
|
*/
|
|
153
154
|
forward(possible: PossibleURL, stack?: AbsolutePath | null): void;
|
|
155
|
+
private _forward;
|
|
154
156
|
/**
|
|
155
157
|
* Go back to a URL, as a back button does.
|
|
156
158
|
* - The URL is an earlier page in `stack`: go back to it. When it is the entry just before the current one, this goes back in the browser history. Else it pushes the URL again at that page's ordinal.
|
|
@@ -158,6 +160,7 @@ export declare class NavigationSequence extends DeferredSequence<NavigationEvent
|
|
|
158
160
|
* - Else push the URL in place of the top page of `stack`.
|
|
159
161
|
* - It works when the app was opened at the current page, so a back button always has somewhere to go.
|
|
160
162
|
* - If the browser refuses to go back with the Navigation API, it uses `history.back()`.
|
|
163
|
+
* - Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
161
164
|
*
|
|
162
165
|
* @param possible The destination URL, resolved against `base`.
|
|
163
166
|
* @param stack Root path of the stack to go back in, or `null` for the floating stack. Defaults to the current stack.
|
|
@@ -166,6 +169,7 @@ export declare class NavigationSequence extends DeferredSequence<NavigationEvent
|
|
|
166
169
|
* @see https://shelving.cc/ui/NavigationSequence/back
|
|
167
170
|
*/
|
|
168
171
|
back(possible: PossibleURL, stack?: AbsolutePath | null): void;
|
|
172
|
+
private _back;
|
|
169
173
|
/**
|
|
170
174
|
* Replace the current URL, with no transition.
|
|
171
175
|
* - The page stays in the same stack, at the same ordinal, so a cached page stays mounted.
|
|
@@ -2,6 +2,7 @@ import { DeferredSequence } from "../../sequence/DeferredSequence.js";
|
|
|
2
2
|
import { createDeferred } from "../../util/async.js";
|
|
3
3
|
import { BLACKHOLE } from "../../util/function.js";
|
|
4
4
|
import { getURL, matchURLPrefix, requireURL } from "../../util/url.js";
|
|
5
|
+
import { waitForKeyboard } from "../util/keyboard.js";
|
|
5
6
|
/**
|
|
6
7
|
* Sequence of navigation events that drives browser history and keeps a stack of pages for each tab.
|
|
7
8
|
*
|
|
@@ -180,6 +181,7 @@ export class NavigationSequence extends DeferredSequence {
|
|
|
180
181
|
* - Else push the URL onto `stack`, one level deeper than its top page.
|
|
181
182
|
* - The URL you are already on: replace it instead.
|
|
182
183
|
* - A change of stack slides by tab order. Else it slides forward.
|
|
184
|
+
* - Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
183
185
|
*
|
|
184
186
|
* @param possible The destination URL, resolved against `base`.
|
|
185
187
|
* @param stack Root path of the stack to go to, or `null` for the floating stack. Defaults to the current stack.
|
|
@@ -189,6 +191,9 @@ export class NavigationSequence extends DeferredSequence {
|
|
|
189
191
|
*/
|
|
190
192
|
forward(possible, stack = this._stack) {
|
|
191
193
|
const url = requireURL(possible, this.base, this.forward);
|
|
194
|
+
_afterKeyboard(() => this._forward(url, stack));
|
|
195
|
+
}
|
|
196
|
+
_forward(url, stack) {
|
|
192
197
|
if (!this._navigation) {
|
|
193
198
|
this._push(url, "forward");
|
|
194
199
|
return;
|
|
@@ -209,6 +214,7 @@ export class NavigationSequence extends DeferredSequence {
|
|
|
209
214
|
* - Else push the URL in place of the top page of `stack`.
|
|
210
215
|
* - It works when the app was opened at the current page, so a back button always has somewhere to go.
|
|
211
216
|
* - If the browser refuses to go back with the Navigation API, it uses `history.back()`.
|
|
217
|
+
* - Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
212
218
|
*
|
|
213
219
|
* @param possible The destination URL, resolved against `base`.
|
|
214
220
|
* @param stack Root path of the stack to go back in, or `null` for the floating stack. Defaults to the current stack.
|
|
@@ -218,6 +224,9 @@ export class NavigationSequence extends DeferredSequence {
|
|
|
218
224
|
*/
|
|
219
225
|
back(possible, stack = this._stack) {
|
|
220
226
|
const url = requireURL(possible, this.base, this.back);
|
|
227
|
+
_afterKeyboard(() => this._back(url, stack));
|
|
228
|
+
}
|
|
229
|
+
_back(url, stack) {
|
|
221
230
|
const navigation = this._navigation;
|
|
222
231
|
if (!navigation) {
|
|
223
232
|
this._push(url, "back");
|
|
@@ -371,6 +380,19 @@ export class NavigationSequence extends DeferredSequence {
|
|
|
371
380
|
return b > a ? "forward" : "back";
|
|
372
381
|
}
|
|
373
382
|
}
|
|
383
|
+
/**
|
|
384
|
+
* Lower the on-screen keyboard, then run `go`: at once when no keyboard is up, else when it is down (`waitForKeyboard()`).
|
|
385
|
+
* - Every move waits here, before the history changes, for two reasons:
|
|
386
|
+
* - iOS Safari takes the snapshot for its own back swipe when the history changes. With the keyboard up, that snapshot keeps the keyboard's empty space.
|
|
387
|
+
* - A keyboard that closes during a page slide resizes the page in the middle of the slide, and the slide's snapshot is too short.
|
|
388
|
+
*/
|
|
389
|
+
function _afterKeyboard(go) {
|
|
390
|
+
const waiting = waitForKeyboard();
|
|
391
|
+
if (waiting)
|
|
392
|
+
void waiting.then(go);
|
|
393
|
+
else
|
|
394
|
+
go();
|
|
395
|
+
}
|
|
374
396
|
/** Get the browser Navigation API, or `undefined` if it is missing or unusable (for example in a sandboxed frame). */
|
|
375
397
|
function _getNavigation() {
|
|
376
398
|
if (typeof navigation === "undefined" || typeof window === "undefined")
|
|
@@ -3,6 +3,7 @@ import { createDeferred } from "../../util/async.js";
|
|
|
3
3
|
import { BLACKHOLE } from "../../util/function.js";
|
|
4
4
|
import type { AbsolutePath } from "../../util/path.js";
|
|
5
5
|
import { getURL, type ImmutableURL, matchURLPrefix, type PossibleURL, requireURL } from "../../util/url.js";
|
|
6
|
+
import { waitForKeyboard } from "../util/keyboard.js";
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* State that `NavigationSequence` saves on each browser history entry.
|
|
@@ -247,6 +248,7 @@ export class NavigationSequence extends DeferredSequence<NavigationEvent> {
|
|
|
247
248
|
* - Else push the URL onto `stack`, one level deeper than its top page.
|
|
248
249
|
* - The URL you are already on: replace it instead.
|
|
249
250
|
* - A change of stack slides by tab order. Else it slides forward.
|
|
251
|
+
* - Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
250
252
|
*
|
|
251
253
|
* @param possible The destination URL, resolved against `base`.
|
|
252
254
|
* @param stack Root path of the stack to go to, or `null` for the floating stack. Defaults to the current stack.
|
|
@@ -256,6 +258,10 @@ export class NavigationSequence extends DeferredSequence<NavigationEvent> {
|
|
|
256
258
|
*/
|
|
257
259
|
forward(possible: PossibleURL, stack: AbsolutePath | null = this._stack): void {
|
|
258
260
|
const url = requireURL(possible, this.base, this.forward);
|
|
261
|
+
_afterKeyboard(() => this._forward(url, stack));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
private _forward(url: ImmutableURL, stack: AbsolutePath | null): void {
|
|
259
265
|
if (!this._navigation) {
|
|
260
266
|
this._push(url, "forward");
|
|
261
267
|
return;
|
|
@@ -277,6 +283,7 @@ export class NavigationSequence extends DeferredSequence<NavigationEvent> {
|
|
|
277
283
|
* - Else push the URL in place of the top page of `stack`.
|
|
278
284
|
* - It works when the app was opened at the current page, so a back button always has somewhere to go.
|
|
279
285
|
* - If the browser refuses to go back with the Navigation API, it uses `history.back()`.
|
|
286
|
+
* - Lowers the on-screen keyboard first (see `_afterKeyboard()`).
|
|
280
287
|
*
|
|
281
288
|
* @param possible The destination URL, resolved against `base`.
|
|
282
289
|
* @param stack Root path of the stack to go back in, or `null` for the floating stack. Defaults to the current stack.
|
|
@@ -286,6 +293,10 @@ export class NavigationSequence extends DeferredSequence<NavigationEvent> {
|
|
|
286
293
|
*/
|
|
287
294
|
back(possible: PossibleURL, stack: AbsolutePath | null = this._stack): void {
|
|
288
295
|
const url = requireURL(possible, this.base, this.back);
|
|
296
|
+
_afterKeyboard(() => this._back(url, stack));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
private _back(url: ImmutableURL, stack: AbsolutePath | null): void {
|
|
289
300
|
const navigation = this._navigation;
|
|
290
301
|
if (!navigation) {
|
|
291
302
|
this._push(url, "back");
|
|
@@ -438,6 +449,18 @@ export class NavigationSequence extends DeferredSequence<NavigationEvent> {
|
|
|
438
449
|
}
|
|
439
450
|
}
|
|
440
451
|
|
|
452
|
+
/**
|
|
453
|
+
* Lower the on-screen keyboard, then run `go`: at once when no keyboard is up, else when it is down (`waitForKeyboard()`).
|
|
454
|
+
* - Every move waits here, before the history changes, for two reasons:
|
|
455
|
+
* - iOS Safari takes the snapshot for its own back swipe when the history changes. With the keyboard up, that snapshot keeps the keyboard's empty space.
|
|
456
|
+
* - A keyboard that closes during a page slide resizes the page in the middle of the slide, and the slide's snapshot is too short.
|
|
457
|
+
*/
|
|
458
|
+
function _afterKeyboard(go: () => void): void {
|
|
459
|
+
const waiting = waitForKeyboard();
|
|
460
|
+
if (waiting) void waiting.then(go);
|
|
461
|
+
else go();
|
|
462
|
+
}
|
|
463
|
+
|
|
441
464
|
/** Get the browser Navigation API, or `undefined` if it is missing or unusable (for example in a sandboxed frame). */
|
|
442
465
|
function _getNavigation(): _Navigation | undefined {
|
|
443
466
|
if (typeof navigation === "undefined" || typeof window === "undefined") return;
|
package/ui/util/keyboard.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export declare function isKeyboardOpen(): boolean;
|
|
|
15
15
|
* Lower the on-screen keyboard, and wait until it is down.
|
|
16
16
|
* - Blurs the focused text field, if there is one, so the keyboard starts to close.
|
|
17
17
|
* - While the keyboard is open or closing (`isKeyboardOpen()`), it checks once each frame and goes on when the keyboard is
|
|
18
|
-
* down, or after half a second at most.
|
|
18
|
+
* down, or after half a second at most. It then waits one more frame, so the page paints at full height first.
|
|
19
19
|
* - Returns nothing when there is nothing to wait for, so a caller can go on at once without a promise.
|
|
20
20
|
* - Use it before a page slide: a keyboard that closes during a view transition resizes the page in the middle of it.
|
|
21
21
|
*
|
package/ui/util/keyboard.js
CHANGED
|
@@ -26,7 +26,7 @@ export function isKeyboardOpen() {
|
|
|
26
26
|
* Lower the on-screen keyboard, and wait until it is down.
|
|
27
27
|
* - Blurs the focused text field, if there is one, so the keyboard starts to close.
|
|
28
28
|
* - While the keyboard is open or closing (`isKeyboardOpen()`), it checks once each frame and goes on when the keyboard is
|
|
29
|
-
* down, or after half a second at most.
|
|
29
|
+
* down, or after half a second at most. It then waits one more frame, so the page paints at full height first.
|
|
30
30
|
* - Returns nothing when there is nothing to wait for, so a caller can go on at once without a promise.
|
|
31
31
|
* - Use it before a page slide: a keyboard that closes during a view transition resizes the page in the middle of it.
|
|
32
32
|
*
|
|
@@ -43,8 +43,9 @@ export function waitForKeyboard() {
|
|
|
43
43
|
return new Promise(resolve => {
|
|
44
44
|
const start = performance.now();
|
|
45
45
|
const check = (now) => {
|
|
46
|
+
// When the keyboard is down, wait one more frame so the page paints at full height before anything snapshots it.
|
|
46
47
|
if (now - start >= _MAX || !isKeyboardOpen())
|
|
47
|
-
return resolve();
|
|
48
|
+
return void requestAnimationFrame(() => resolve());
|
|
48
49
|
requestAnimationFrame(check);
|
|
49
50
|
};
|
|
50
51
|
requestAnimationFrame(check);
|
|
@@ -52,6 +53,8 @@ export function waitForKeyboard() {
|
|
|
52
53
|
}
|
|
53
54
|
/** Blur the focused element when it takes typed text (and so shows the on-screen keyboard). */
|
|
54
55
|
function _blurTextField() {
|
|
56
|
+
if (typeof document === "undefined")
|
|
57
|
+
return;
|
|
55
58
|
const el = document.activeElement;
|
|
56
59
|
if (el instanceof HTMLElement && _isTextField(el))
|
|
57
60
|
el.blur();
|
package/ui/util/keyboard.ts
CHANGED
|
@@ -27,7 +27,7 @@ export function isKeyboardOpen(): boolean {
|
|
|
27
27
|
* Lower the on-screen keyboard, and wait until it is down.
|
|
28
28
|
* - Blurs the focused text field, if there is one, so the keyboard starts to close.
|
|
29
29
|
* - While the keyboard is open or closing (`isKeyboardOpen()`), it checks once each frame and goes on when the keyboard is
|
|
30
|
-
* down, or after half a second at most.
|
|
30
|
+
* down, or after half a second at most. It then waits one more frame, so the page paints at full height first.
|
|
31
31
|
* - Returns nothing when there is nothing to wait for, so a caller can go on at once without a promise.
|
|
32
32
|
* - Use it before a page slide: a keyboard that closes during a view transition resizes the page in the middle of it.
|
|
33
33
|
*
|
|
@@ -42,7 +42,8 @@ export function waitForKeyboard(): Promise<void> | void {
|
|
|
42
42
|
return new Promise<void>(resolve => {
|
|
43
43
|
const start = performance.now();
|
|
44
44
|
const check = (now: number) => {
|
|
45
|
-
|
|
45
|
+
// When the keyboard is down, wait one more frame so the page paints at full height before anything snapshots it.
|
|
46
|
+
if (now - start >= _MAX || !isKeyboardOpen()) return void requestAnimationFrame(() => resolve());
|
|
46
47
|
requestAnimationFrame(check);
|
|
47
48
|
};
|
|
48
49
|
requestAnimationFrame(check);
|
|
@@ -51,6 +52,7 @@ export function waitForKeyboard(): Promise<void> | void {
|
|
|
51
52
|
|
|
52
53
|
/** Blur the focused element when it takes typed text (and so shows the on-screen keyboard). */
|
|
53
54
|
function _blurTextField(): void {
|
|
55
|
+
if (typeof document === "undefined") return;
|
|
54
56
|
const el = document.activeElement;
|
|
55
57
|
if (el instanceof HTMLElement && _isTextField(el)) el.blur();
|
|
56
58
|
}
|