drawnui-react 0.1.0-preview.8 → 1.0.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/README.md +229 -22
- package/SKIPPED.md +38 -29
- package/dist/controls/AnimatedFramesRenderer.d.ts +9 -0
- package/dist/controls/AnimatedFramesRenderer.js +18 -1
- package/dist/controls/DrawnGame.d.ts +44 -0
- package/dist/controls/DrawnGame.js +82 -0
- package/dist/controls/GridStructure.d.ts +25 -3
- package/dist/controls/GridStructure.js +81 -5
- package/dist/controls/SkiaBackdrop.d.ts +8 -2
- package/dist/controls/SkiaBackdrop.js +42 -14
- package/dist/controls/SkiaButton.d.ts +17 -3
- package/dist/controls/SkiaButton.js +26 -8
- package/dist/controls/SkiaCarousel.d.ts +22 -3
- package/dist/controls/SkiaCarousel.js +85 -9
- package/dist/controls/SkiaCheckbox.d.ts +0 -1
- package/dist/controls/SkiaCheckbox.js +2 -7
- package/dist/controls/SkiaDrawer.d.ts +15 -0
- package/dist/controls/SkiaDrawer.js +42 -7
- package/dist/controls/SkiaEditor.d.ts +51 -2
- package/dist/controls/SkiaEditor.js +292 -58
- package/dist/controls/SkiaGif.d.ts +7 -0
- package/dist/controls/SkiaGif.js +25 -4
- package/dist/controls/SkiaImage.d.ts +10 -0
- package/dist/controls/SkiaImage.js +80 -19
- package/dist/controls/SkiaLabel.d.ts +200 -11
- package/dist/controls/SkiaLabel.js +925 -93
- package/dist/controls/SkiaLabelFps.d.ts +12 -0
- package/dist/controls/SkiaLabelFps.js +35 -0
- package/dist/controls/SkiaLayout.d.ts +89 -9
- package/dist/controls/SkiaLayout.js +397 -23
- package/dist/controls/SkiaLottie.js +5 -3
- package/dist/controls/SkiaProgress.d.ts +2 -1
- package/dist/controls/SkiaProgress.js +8 -5
- package/dist/controls/SkiaRadioButton.d.ts +2 -0
- package/dist/controls/SkiaRadioButton.js +16 -4
- package/dist/controls/SkiaRichLabel.d.ts +1 -1
- package/dist/controls/SkiaRichLabel.js +11 -1
- package/dist/controls/SkiaScroll.d.ts +86 -7
- package/dist/controls/SkiaScroll.js +361 -40
- package/dist/controls/SkiaScrollBar.d.ts +27 -0
- package/dist/controls/SkiaScrollBar.js +51 -2
- package/dist/controls/SkiaShaderCarousel.d.ts +11 -1
- package/dist/controls/SkiaShaderCarousel.js +27 -5
- package/dist/controls/SkiaShape.d.ts +15 -2
- package/dist/controls/SkiaShape.js +57 -10
- package/dist/controls/SkiaShell.d.ts +282 -0
- package/dist/controls/SkiaShell.js +972 -0
- package/dist/controls/SkiaSlider.d.ts +20 -2
- package/dist/controls/SkiaSlider.js +61 -7
- package/dist/controls/SkiaSprite.d.ts +4 -0
- package/dist/controls/SkiaSprite.js +27 -11
- package/dist/controls/SkiaSvg.d.ts +4 -0
- package/dist/controls/SkiaSvg.js +28 -4
- package/dist/controls/SkiaSwitch.d.ts +0 -1
- package/dist/controls/SkiaSwitch.js +4 -8
- package/dist/controls/SkiaToggle.d.ts +25 -5
- package/dist/controls/SkiaToggle.js +58 -5
- package/dist/controls/SnappingLayout.d.ts +12 -1
- package/dist/controls/SnappingLayout.js +21 -2
- package/dist/controls/TooltipStyle.d.ts +52 -0
- package/dist/controls/TooltipStyle.js +88 -0
- package/dist/core/Accessibility.d.ts +162 -11
- package/dist/core/Accessibility.js +882 -22
- package/dist/core/Animators.d.ts +37 -1
- package/dist/core/Animators.js +102 -9
- package/dist/core/Canvas.d.ts +307 -8
- package/dist/core/Canvas.js +1202 -66
- package/dist/core/ControlStyle.d.ts +2 -0
- package/dist/core/ControlStyle.js +2 -0
- package/dist/core/DesignerActions.d.ts +32 -0
- package/dist/core/DesignerActions.js +68 -0
- package/dist/core/Easing.d.ts +12 -1
- package/dist/core/Easing.js +25 -1
- package/dist/core/Gestures.d.ts +86 -2
- package/dist/core/Gestures.js +184 -4
- package/dist/core/Hover.d.ts +51 -0
- package/dist/core/Hover.js +140 -0
- package/dist/core/ImageEffects.d.ts +2 -0
- package/dist/core/ImageEffects.js +2 -0
- package/dist/core/KeyboardManager.d.ts +40 -0
- package/dist/core/KeyboardManager.js +98 -8
- package/dist/core/PopupWindows.d.ts +94 -0
- package/dist/core/PopupWindows.js +207 -0
- package/dist/core/Props.d.ts +11 -0
- package/dist/core/Props.js +44 -0
- package/dist/core/ScrollAnimators.d.ts +6 -0
- package/dist/core/ScrollAnimators.js +16 -1
- package/dist/core/Shaping.d.ts +40 -0
- package/dist/core/Shaping.js +224 -0
- package/dist/core/SkiaControl.d.ts +306 -13
- package/dist/core/SkiaControl.js +681 -75
- package/dist/core/SkiaEffect.d.ts +29 -1
- package/dist/core/SkiaEffect.js +78 -16
- package/dist/core/SkiaImageManager.d.ts +101 -18
- package/dist/core/SkiaImageManager.js +318 -63
- package/dist/core/Styles.js +7 -1
- package/dist/core/Super.d.ts +33 -2
- package/dist/core/Super.js +58 -12
- package/dist/core/TextInputProxy.d.ts +31 -1
- package/dist/core/TextInputProxy.js +97 -15
- package/dist/core/Tooltips.d.ts +71 -0
- package/dist/core/Tooltips.js +205 -0
- package/dist/core/Types.d.ts +11 -1
- package/dist/core/Types.js +32 -1
- package/dist/core/ViewsAdapter.d.ts +7 -2
- package/dist/core/ViewsAdapter.js +10 -3
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/react/SkiaShell.d.ts +8 -74
- package/dist/react/SkiaShell.js +163 -475
- package/dist/react/index.d.ts +48 -4
- package/dist/react/index.js +210 -43
- package/dist/react/reconciler.d.ts +32 -0
- package/dist/react/reconciler.js +71 -40
- package/dist/vite/index.d.ts +9 -0
- package/dist/vite/index.js +36 -3
- package/package.json +103 -5
package/dist/react/SkiaShell.js
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, forwardRef,
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/** "name?a=1&b=2" -> name + arguments (query values are strings). */
|
|
8
|
-
export function SplitRoute(route) {
|
|
9
|
-
const q = route.indexOf("?");
|
|
10
|
-
if (q < 0)
|
|
11
|
-
return { name: route, args: {} };
|
|
12
|
-
const args = {};
|
|
13
|
-
new URLSearchParams(route.slice(q + 1)).forEach((v, k) => { args[k] = v; });
|
|
14
|
-
return { name: route.slice(0, q), args };
|
|
15
|
-
}
|
|
16
|
-
/** name + arguments -> "name?a=1" (only string / number / boolean values travel in the route, the rest stays in memory). */
|
|
17
|
-
export function BuildRoute(name, args) {
|
|
18
|
-
if (!args)
|
|
19
|
-
return name;
|
|
20
|
-
const p = new URLSearchParams();
|
|
21
|
-
for (const [k, v] of Object.entries(args))
|
|
22
|
-
if (typeof v === "string" || typeof v === "number" || typeof v === "boolean")
|
|
23
|
-
p.set(k, String(v));
|
|
24
|
-
const q = p.toString();
|
|
25
|
-
return q ? `${name}?${q}` : name;
|
|
26
|
-
}
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, forwardRef, useContext, useImperativeHandle, useLayoutEffect, useMemo, useReducer, useRef, useState } from "react";
|
|
3
|
+
import { SkiaShell as SkiaShellControl, SplitRoute } from "../controls/SkiaShell";
|
|
4
|
+
import { Registry, createDrawnPortal } from "./reconciler";
|
|
5
|
+
// the shell itself lives in the engine ("drawnui-react/core" SkiaShell); these are its types and helpers
|
|
6
|
+
export { BuildRoute, ShellDefaults, SplitRoute } from "../controls/SkiaShell";
|
|
27
7
|
const ShellContext = createContext(null);
|
|
28
8
|
/** Navigation for pages and buttons rendered inside a SkiaShell. */
|
|
29
9
|
export function useShell() {
|
|
@@ -32,462 +12,170 @@ export function useShell() {
|
|
|
32
12
|
throw new Error("DrawnUi: useShell() must be used inside <SkiaShell>");
|
|
33
13
|
return shell;
|
|
34
14
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
15
|
+
let nextPortalKey = 1;
|
|
16
|
+
/**
|
|
17
|
+
* JSX shown by the engine shell: a portal into the room the shell made for it (a page's body, a popup's center, a
|
|
18
|
+
* modal's drawer, a toast, a tab container). Its top-level controls go straight into that control, as JSX children of
|
|
19
|
+
* it would, so the content keeps the contexts of the tree around `<SkiaShell>` and lays out exactly as before.
|
|
20
|
+
*/
|
|
21
|
+
class PortalHost {
|
|
22
|
+
render;
|
|
23
|
+
bridge;
|
|
24
|
+
fixed;
|
|
25
|
+
key = `p${nextPortalKey++}`;
|
|
26
|
+
parent;
|
|
27
|
+
children = [];
|
|
28
|
+
detached = false;
|
|
29
|
+
committed = false;
|
|
30
|
+
onCommitted = [];
|
|
31
|
+
/**
|
|
32
|
+
* @param render the JSX, read on every render of the `<SkiaShell>` element (pages follow the latest Routes)
|
|
33
|
+
* @param fixed rendered by the element whether attached or not (the root, the tab roots)
|
|
34
|
+
*/
|
|
35
|
+
constructor(render, bridge, fixed = false) {
|
|
36
|
+
this.render = render;
|
|
37
|
+
this.bridge = bridge;
|
|
38
|
+
this.fixed = fixed;
|
|
39
|
+
}
|
|
40
|
+
AttachTo(parent) {
|
|
41
|
+
this.parent = parent;
|
|
42
|
+
this.detached = false;
|
|
43
|
+
for (const c of this.children)
|
|
44
|
+
parent.InsertChild(c);
|
|
45
|
+
if (!this.fixed && !this.bridge.attached.has(this)) {
|
|
46
|
+
this.bridge.attached.add(this);
|
|
47
|
+
this.bridge.changed();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
Detach() {
|
|
51
|
+
if (this.detached)
|
|
52
|
+
return;
|
|
53
|
+
this.detached = true;
|
|
54
|
+
const p = this.parent;
|
|
55
|
+
this.parent = undefined;
|
|
56
|
+
// the controls leave the shell now; React disposes them when it unmounts the portal
|
|
57
|
+
if (p)
|
|
58
|
+
for (const c of this.children)
|
|
59
|
+
if (c.Parent === p)
|
|
60
|
+
p.RemoveSubView(c);
|
|
61
|
+
if (this.bridge.attached.delete(this))
|
|
62
|
+
this.bridge.changed();
|
|
63
|
+
}
|
|
64
|
+
Ready() {
|
|
65
|
+
if (this.committed)
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
return new Promise((r) => this.onCommitted.push(r));
|
|
68
|
+
}
|
|
69
|
+
/** The portal's first commit: its controls are in place. */
|
|
70
|
+
Committed() {
|
|
71
|
+
if (this.committed)
|
|
72
|
+
return;
|
|
73
|
+
this.committed = true;
|
|
74
|
+
for (const r of this.onCommitted.splice(0))
|
|
75
|
+
r();
|
|
76
|
+
}
|
|
77
|
+
// ---- DrawnContainer: React places the portal's top-level controls ----
|
|
78
|
+
appendChild(child) {
|
|
79
|
+
const i = this.children.indexOf(child);
|
|
80
|
+
if (i >= 0)
|
|
81
|
+
this.children.splice(i, 1);
|
|
82
|
+
this.children.push(child);
|
|
83
|
+
this.parent?.InsertChild(child);
|
|
72
84
|
}
|
|
85
|
+
insertBefore(child, before) {
|
|
86
|
+
const i = this.children.indexOf(child);
|
|
87
|
+
if (i >= 0)
|
|
88
|
+
this.children.splice(i, 1);
|
|
89
|
+
const at = this.children.indexOf(before);
|
|
90
|
+
this.children.splice(at < 0 ? this.children.length : at, 0, child);
|
|
91
|
+
this.parent?.InsertChild(child, before);
|
|
92
|
+
}
|
|
93
|
+
removeChild(child) {
|
|
94
|
+
const i = this.children.indexOf(child);
|
|
95
|
+
if (i >= 0)
|
|
96
|
+
this.children.splice(i, 1);
|
|
97
|
+
if (this.parent && child.Parent === this.parent)
|
|
98
|
+
this.parent.RemoveSubView(child);
|
|
99
|
+
}
|
|
100
|
+
clear() { for (const c of [...this.children])
|
|
101
|
+
this.removeChild(c); }
|
|
102
|
+
}
|
|
103
|
+
/** Marks its portal committed (a layout effect runs after the portal's controls were placed). */
|
|
104
|
+
function Committed({ host }) {
|
|
105
|
+
useLayoutEffect(() => host.Committed(), [host]);
|
|
106
|
+
return null;
|
|
73
107
|
}
|
|
74
|
-
|
|
75
|
-
|
|
108
|
+
/** The engine shell as the `<SkiaShell>` element hosts it: tells the element when to re-render, takes its tab roots. */
|
|
109
|
+
class ShellHost extends SkiaShellControl {
|
|
110
|
+
bridge;
|
|
111
|
+
set Bridge(b) { this.bridge = b; if (b)
|
|
112
|
+
b.core = this; }
|
|
113
|
+
get Bridge() { return this.bridge; }
|
|
114
|
+
OnChanged() { this.bridge?.changed(); }
|
|
115
|
+
CreateTabRoot(index) { return this.bridge?.tabHosts[index] ?? super.CreateTabRoot(index); }
|
|
76
116
|
}
|
|
77
|
-
|
|
117
|
+
Registry.SkiaShellHost = ShellHost;
|
|
118
|
+
const ShellHostTag = "SkiaShellHost";
|
|
78
119
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* backdrop, scale + fade, tap outside to close), modals (full-screen SkiaDrawer from the bottom, optionally
|
|
82
|
-
*
|
|
83
|
-
*
|
|
120
|
+
* DrawnUi SkiaShell for React: the engine SkiaShell ("drawnui-react/core") with JSX content. A root page (or tabs) plus
|
|
121
|
+
* per-tab stacks of routed pages with a nav bar (pages slide in/out like SkiaViewSwitcher), popups (blurred + dimmed
|
|
122
|
+
* backdrop, scale + fade, tap outside to close), modals (full-screen SkiaDrawer from the bottom, optionally draggable),
|
|
123
|
+
* toasts (bottom banner, slide + fade, auto close). Pages live in the URL hash and the browser back button behaves like
|
|
124
|
+
* C# GoBack (popup, then modal, then page). Navigation via ref or useShell().
|
|
84
125
|
*/
|
|
85
126
|
export const SkiaShell = forwardRef(function SkiaShell({ Routes, children, NavBarHeight = 56, NavBarColor = "#212529", Titles, PagesAnimationSpeed = 200, PageBackgroundColor = "#212529", Tabs, TabBarHeight = 56, TabBarColor = "#212529", UseBrowserHistory = true, AnimateTabs = false, TabsAnimationSpeed = 150, Navigating, Navigated, RouteChanged, Insets }, ref) {
|
|
86
127
|
const hasTabs = !!Tabs && Tabs.length > 0;
|
|
87
|
-
const [
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
const
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
/** A programmatic close of something that has a history entry goes through history.back(), so the URL stays in sync. */
|
|
136
|
-
const backThroughHistory = useCallback((kind) => {
|
|
137
|
-
if (!historyOn || history.current[history.current.length - 1] !== kind)
|
|
138
|
-
return false;
|
|
139
|
-
window.history.back();
|
|
140
|
-
return true;
|
|
141
|
-
}, [historyOn]);
|
|
142
|
-
// ---- pages ----
|
|
143
|
-
const slideOut = useCallback(async (current, animated) => {
|
|
144
|
-
const ctrl = pageCtrls.current.get(current);
|
|
145
|
-
if (animated && ctrl) {
|
|
146
|
-
setLeaving(current);
|
|
147
|
-
await AnimateWithTimeout(ctrl.TranslateToAsync(CanvasWidthPts(ctrl), 0, PagesAnimationSpeed), PagesAnimationSpeed + 500);
|
|
148
|
-
setLeaving(null);
|
|
149
|
-
}
|
|
150
|
-
}, [PagesAnimationSpeed]);
|
|
151
|
-
/** Pops the top page; false when Navigating cancelled it (C# NavigationSource.Pop). */
|
|
152
|
-
const popPage = useCallback(async (animated) => {
|
|
153
|
-
const s = live.current.stack;
|
|
154
|
-
const current = s[s.length - 1];
|
|
155
|
-
if (!current)
|
|
156
|
-
return false;
|
|
157
|
-
const below = s[s.length - 2] ?? "";
|
|
158
|
-
if (!canNavigate(below, "Pop", pageCtrls.current.get(current), pageCtrls.current.get(current)))
|
|
159
|
-
return false;
|
|
160
|
-
await slideOut(current, animated);
|
|
161
|
-
setStack((x) => x.slice(0, -1));
|
|
162
|
-
argsInMemory.current.delete(current);
|
|
163
|
-
navigated(below, "Pop", pageCtrls.current.get(below));
|
|
164
|
-
return true;
|
|
165
|
-
}, [slideOut, setStack, canNavigate, navigated]);
|
|
166
|
-
const GoToAsync = useCallback(async (r, animated = true, args) => {
|
|
167
|
-
const { name, args: fromRoute } = SplitRoute(r);
|
|
168
|
-
if (!Routes[name])
|
|
169
|
-
throw new Error(`DrawnUi: route '${name}' is not registered in SkiaShell.Routes`);
|
|
170
|
-
const full = BuildRoute(name, { ...fromRoute, ...args });
|
|
171
|
-
if (!canNavigate(full, "Push", undefined, pageCtrls.current.get(live.current.stack[live.current.stack.length - 1] ?? "")))
|
|
172
|
-
return;
|
|
173
|
-
if (args)
|
|
174
|
-
argsInMemory.current.set(full, { ...fromRoute, ...args });
|
|
175
|
-
const next = [...live.current.stack, full];
|
|
176
|
-
setStack(() => next);
|
|
177
|
-
pushHistory("page", next);
|
|
178
|
-
if (animated) {
|
|
179
|
-
setTransitions((t) => t + 1);
|
|
180
|
-
await new Promise((res) => setTimeout(res, PagesAnimationSpeed + 50));
|
|
181
|
-
setTransitions((t) => t - 1);
|
|
182
|
-
}
|
|
183
|
-
navigated(full, "Push", await WaitFor(() => pageCtrls.current.get(full)));
|
|
184
|
-
}, [Routes, PagesAnimationSpeed, setStack, pushHistory, canNavigate, navigated]);
|
|
185
|
-
// ---- popups ----
|
|
186
|
-
const closePopupNow = useCallback(async (p, animated) => {
|
|
187
|
-
if (p.closing)
|
|
188
|
-
return false;
|
|
189
|
-
if (!canNavigate(live.current.stack[live.current.stack.length - 1] ?? "", "Pop", p.content, p.content))
|
|
190
|
-
return false;
|
|
191
|
-
p.closing = true;
|
|
192
|
-
if (animated && p.animated !== false && p.ctrl && p.content) {
|
|
193
|
-
await AnimateWithTimeout(Promise.all([p.ctrl.FadeToAsync(0, ShellDefaults.PopupsAnimationSpeed), p.content.ScaleToAsync(0, 0, ShellDefaults.PopupsAnimationSpeed)]));
|
|
194
|
-
}
|
|
195
|
-
setPopups((list) => list.filter((x) => x !== p));
|
|
196
|
-
navigated(live.current.stack[live.current.stack.length - 1] ?? "", "Pop");
|
|
197
|
-
return true;
|
|
198
|
-
}, [canNavigate, navigated]);
|
|
199
|
-
const closePopup = useCallback(async (p, animated) => {
|
|
200
|
-
if (p.closing)
|
|
201
|
-
return;
|
|
202
|
-
if (p.history && backThroughHistory("popup")) {
|
|
203
|
-
p.history = false;
|
|
204
|
-
return;
|
|
205
|
-
} // popstate closes it
|
|
206
|
-
await closePopupNow(p, animated);
|
|
207
|
-
}, [backThroughHistory, closePopupNow]);
|
|
208
|
-
const OpenPopupAsync = useCallback(async (content, options) => {
|
|
209
|
-
const animated = options?.animated ?? true;
|
|
210
|
-
if (!canNavigate(live.current.stack[live.current.stack.length - 1] ?? "", "Push"))
|
|
211
|
-
return;
|
|
212
|
-
const entry = { id: nextId.current++, node: null, animated };
|
|
213
|
-
const closeWhenBackgroundTapped = options?.closeWhenBackgroundTapped ?? true;
|
|
214
|
-
const showOverlay = options?.showOverlay ?? true;
|
|
215
|
-
const overlay = options?.backgroundColor ?? ShellDefaults.PopupBackgroundColor;
|
|
216
|
-
entry.node = (_jsxs(SkiaLayer, { VerticalOptions: "Fill", HorizontalOptions: "Fill", ZIndex: ShellDefaults.ZIndexPopups + entry.id, BlockGesturesBelow: true, Opacity: animated ? 0.1 : 1, ref: (c) => { if (c)
|
|
217
|
-
entry.ctrl = c; }, Tapped: (_, e) => {
|
|
218
|
-
// C# PopupWrapper: a tap outside the content closes it
|
|
219
|
-
const c = entry.content;
|
|
220
|
-
const l = e.ProcessingInfo.MappedLocation, o = e.ProcessingInfo.ChildOffset;
|
|
221
|
-
if (closeWhenBackgroundTapped && c && !c.HitIsInside(l.X + o.X, l.Y + o.Y))
|
|
222
|
-
void closePopup(entry, animated);
|
|
223
|
-
}, children: [showOverlay && _jsx(SkiaBackdrop, { Blur: ShellDefaults.PopupsBackgroundBlur, BackgroundColor: overlay, InputTransparent: true }), _jsx(SkiaLayer, { HorizontalOptions: "Center", VerticalOptions: "Center", Scale: animated ? 0.5 : 1, ref: (c) => { if (c)
|
|
224
|
-
entry.content = c; }, children: content })] }, entry.id));
|
|
225
|
-
setPopups((list) => [...list, entry]);
|
|
226
|
-
entry.history = true;
|
|
227
|
-
pushHistory("popup", live.current.stack);
|
|
228
|
-
await WaitFor(() => entry.ctrl && entry.content); // mounted after the React commit
|
|
229
|
-
if (animated && entry.ctrl && entry.content)
|
|
230
|
-
await AnimateWithTimeout(Promise.all([entry.ctrl.FadeToAsync(1, ShellDefaults.PopupsAnimationSpeed), entry.content.ScaleToAsync(1, 1, ShellDefaults.PopupsAnimationSpeed)]));
|
|
231
|
-
navigated(live.current.stack[live.current.stack.length - 1] ?? "", "Push", entry.content);
|
|
232
|
-
}, [closePopup, pushHistory, canNavigate, navigated]);
|
|
233
|
-
const ClosePopupAsync = useCallback(async (animated = true) => { const list = live.current.popups; const top = list[list.length - 1]; if (top)
|
|
234
|
-
await closePopup(top, animated); }, [closePopup]);
|
|
235
|
-
const CloseAllPopups = useCallback(async () => { for (const p of [...live.current.popups].reverse())
|
|
236
|
-
await closePopup(p, false); }, [closePopup]);
|
|
237
|
-
// ---- modals ----
|
|
238
|
-
const removeModal = useCallback((m) => setModals((list) => list.filter((x) => x !== m)), []);
|
|
239
|
-
const popModalNow = useCallback(async (top, animated) => {
|
|
240
|
-
if (top.closing)
|
|
241
|
-
return false;
|
|
242
|
-
if (!canNavigate(live.current.stack[live.current.stack.length - 1] ?? "", "Pop", top.drawer, top.drawer))
|
|
243
|
-
return false;
|
|
244
|
-
top.closing = true;
|
|
245
|
-
if (top.drawer && top.drawer.IsOpen) {
|
|
246
|
-
top.drawer.Animated = animated;
|
|
247
|
-
const done = new Promise((r) => { const prev = top.drawer.StateTransitionComplete; top.drawer.StateTransitionComplete = (d, o) => { prev?.(d, o); if (!o)
|
|
248
|
-
r(); }; });
|
|
249
|
-
top.drawer.IsOpen = false;
|
|
250
|
-
if (animated)
|
|
251
|
-
await AnimateWithTimeout(done);
|
|
252
|
-
}
|
|
253
|
-
removeModal(top);
|
|
254
|
-
navigated(live.current.stack[live.current.stack.length - 1] ?? "", "Pop");
|
|
255
|
-
return true;
|
|
256
|
-
}, [removeModal, canNavigate, navigated]);
|
|
257
|
-
const PushModalAsync = useCallback(async (content, options) => {
|
|
258
|
-
const animated = options?.animated ?? true;
|
|
259
|
-
if (!canNavigate(live.current.stack[live.current.stack.length - 1] ?? "", "Push"))
|
|
260
|
-
return;
|
|
261
|
-
const entry = { id: nextId.current++, node: null };
|
|
262
|
-
const overlay = (options?.freezeBackground ?? true) ? ShellDefaults.PopupBackgroundColor : undefined;
|
|
263
|
-
let opened = () => { };
|
|
264
|
-
const openedPromise = new Promise((r) => { opened = r; });
|
|
265
|
-
// the user closed it (drag down / IsOpen = false): leave through history when it owns an entry, else remove
|
|
266
|
-
const userClosed = () => { if (entry.closing)
|
|
267
|
-
return; if (entry.history && backThroughHistory("modal"))
|
|
268
|
-
entry.history = false;
|
|
269
|
-
else {
|
|
270
|
-
entry.closing = true;
|
|
271
|
-
removeModal(entry);
|
|
272
|
-
} };
|
|
273
|
-
entry.node = (_jsxs(SkiaLayer, { VerticalOptions: "Fill", HorizontalOptions: "Fill", ZIndex: ShellDefaults.ZIndexModals + entry.id, BlockGesturesBelow: true, children: [overlay && _jsx(SkiaBackdrop, { Blur: ShellDefaults.PopupsBackgroundBlur, BackgroundColor: overlay, InputTransparent: true }), _jsx(SkiaDrawer, { ref: (d) => { if (d)
|
|
274
|
-
entry.drawer = d; }, Direction: "FromBottom", HeaderSize: 0, HorizontalOptions: "Fill", VerticalOptions: "Fill", RespondsToGestures: options?.useGestures ?? false, Animated: animated, Bounces: false, BlockGesturesBelow: true, StateTransitionComplete: (d, isOpen) => { if (isOpen)
|
|
275
|
-
opened();
|
|
276
|
-
else if (!d.IsOpen)
|
|
277
|
-
userClosed(); }, IsOpenChanged: (_, isOpen) => { if (!isOpen && !animated)
|
|
278
|
-
userClosed(); }, children: content })] }, entry.id));
|
|
279
|
-
setModals((list) => [...list, entry]);
|
|
280
|
-
entry.history = true;
|
|
281
|
-
pushHistory("modal", live.current.stack);
|
|
282
|
-
const drawer = await WaitFor(() => entry.drawer);
|
|
283
|
-
await WaitFor(() => drawer && drawer.DrawingRect.Height > 0); // first draw: the drawer measured its travel
|
|
284
|
-
if (drawer) {
|
|
285
|
-
drawer.IsOpen = true;
|
|
286
|
-
if (!animated)
|
|
287
|
-
opened();
|
|
288
|
-
}
|
|
289
|
-
await AnimateWithTimeout(openedPromise);
|
|
290
|
-
navigated(live.current.stack[live.current.stack.length - 1] ?? "", "Push", drawer);
|
|
291
|
-
}, [removeModal, pushHistory, backThroughHistory, canNavigate, navigated]);
|
|
292
|
-
const PopModalAsync = useCallback(async (animated = true) => {
|
|
293
|
-
const list = live.current.modals;
|
|
294
|
-
const top = list[list.length - 1];
|
|
295
|
-
if (!top || top.closing)
|
|
296
|
-
return;
|
|
297
|
-
if (top.history && backThroughHistory("modal")) {
|
|
298
|
-
top.history = false;
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
await popModalNow(top, animated);
|
|
302
|
-
}, [popModalNow, backThroughHistory]);
|
|
303
|
-
// ---- toasts ----
|
|
304
|
-
const closeToast = useCallback(async (t, animated) => {
|
|
305
|
-
if (t.closing)
|
|
306
|
-
return;
|
|
307
|
-
t.closing = true;
|
|
308
|
-
const c = t.ctrl;
|
|
309
|
-
if (animated && c)
|
|
310
|
-
await AnimateWithTimeout(Promise.all([c.TranslateToAsync(0, c.DrawingRect.Height / c.RenderingScale, 250), c.FadeToAsync(0, 250)]));
|
|
311
|
-
setToasts((list) => list.filter((x) => x !== t));
|
|
312
|
-
}, []);
|
|
313
|
-
const toastsRef = useRef([]);
|
|
314
|
-
toastsRef.current = toasts;
|
|
315
|
-
const CloseAllToasts = useCallback(async () => { await Promise.all(toastsRef.current.map((t) => closeToast(t, false))); }, [closeToast]);
|
|
316
|
-
const ShowToast = useCallback((content, msShowTime = 4000) => {
|
|
317
|
-
void (async () => {
|
|
318
|
-
await CloseAllToasts();
|
|
319
|
-
const entry = { id: nextId.current++, node: null };
|
|
320
|
-
const body = typeof content === "string"
|
|
321
|
-
? _jsx(SkiaRichLabel, { Text: content, TextColor: ShellDefaults.ToastTextColor, FontFamily: ShellDefaults.ToastTextFont || undefined, FontSize: ShellDefaults.ToastTextSize, Margin: new Thickness(ShellDefaults.ToastTextMargins), HorizontalOptions: "Fill" })
|
|
322
|
-
: content;
|
|
323
|
-
entry.node = (_jsx(SkiaLayer, { HorizontalOptions: "Fill", VerticalOptions: "End", ZIndex: ShellDefaults.ZIndexToasts + entry.id, BackgroundColor: ShellDefaults.ToastBackgroundColor, BlockGesturesBelow: true, UseCache: "Operations", Opacity: 0, ref: (c) => { if (c)
|
|
324
|
-
entry.ctrl = c; }, children: _jsx(SkiaLayer, { HorizontalOptions: "Fill", children: body }) }, entry.id));
|
|
325
|
-
setToasts((list) => [...list, entry]);
|
|
326
|
-
const c = await WaitFor(() => entry.ctrl);
|
|
327
|
-
await WaitFor(() => c && c.DrawingRect.Height > 0); // laid out: height known
|
|
328
|
-
if (c) {
|
|
329
|
-
c.TranslationY = c.DrawingRect.Height / c.RenderingScale;
|
|
330
|
-
void c.TranslateToAsync(0, 0, 300);
|
|
331
|
-
void c.FadeToAsync(1, 300);
|
|
332
|
-
}
|
|
333
|
-
setTimeout(() => void closeToast(entry, true), msShowTime);
|
|
334
|
-
})();
|
|
335
|
-
}, [CloseAllToasts, closeToast]);
|
|
336
|
-
// ---- back (C# GoBackDefault order) ----
|
|
337
|
-
const GoBackAsync = useCallback(async (animated = true) => {
|
|
338
|
-
const { popups: ps, modals: ms, stack: s } = live.current;
|
|
339
|
-
if (ps.length) {
|
|
340
|
-
await closePopup(ps[ps.length - 1], animated);
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
if (ms.length) {
|
|
344
|
-
await PopModalAsync(animated);
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
if (!s.length)
|
|
348
|
-
return;
|
|
349
|
-
if (backThroughHistory("page")) {
|
|
350
|
-
await WaitFor(() => live.current.stack.length < s.length, PagesAnimationSpeed + 800);
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
await popPage(animated);
|
|
354
|
-
}, [closePopup, PopModalAsync, backThroughHistory, popPage, PagesAnimationSpeed]);
|
|
355
|
-
const PopToRootAsync = useCallback(async () => {
|
|
356
|
-
setLeaving(null);
|
|
357
|
-
if (historyOn) {
|
|
358
|
-
const pages = history.current.filter((k) => k === "page").length;
|
|
359
|
-
history.current = history.current.filter((k) => k !== "page");
|
|
360
|
-
if (pages)
|
|
361
|
-
window.history.replaceState({ [HISTORY_KEY]: history.current.length }, "", hashFor([]));
|
|
362
|
-
}
|
|
363
|
-
setStacks((all) => all.map(() => []));
|
|
364
|
-
}, [historyOn]);
|
|
365
|
-
const PopTabToRootAsync = useCallback(async () => { setLeaving(null); setStack(() => []); }, [setStack]);
|
|
366
|
-
const SelectTabAsync = useCallback(async (index) => {
|
|
367
|
-
if (!hasTabs)
|
|
368
|
-
return;
|
|
369
|
-
const to = Math.max(0, Math.min(Tabs.length - 1, index));
|
|
370
|
-
const from = live.current.selectedTab;
|
|
371
|
-
setLeaving(null);
|
|
372
|
-
if (to === from)
|
|
373
|
-
return;
|
|
374
|
-
if (!AnimateTabs) {
|
|
375
|
-
setSelectedTab(to);
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
// C# SelectRightTab / SelectLeftTab: the new root slides in from 0.75 width with a fade, the old one slides out
|
|
379
|
-
const dir = to > from ? 1 : -1;
|
|
380
|
-
setTabTransition({ from, dir });
|
|
381
|
-
setSelectedTab(to);
|
|
382
|
-
const next = await WaitFor(() => tabRoots.current.get(to));
|
|
383
|
-
const prev = tabRoots.current.get(from);
|
|
384
|
-
if (next) {
|
|
385
|
-
const w = CanvasWidthPts(next);
|
|
386
|
-
await AnimateWithTimeout(Promise.all([
|
|
387
|
-
next.TranslateToAsync(0, 0, TabsAnimationSpeed, TabsEasing),
|
|
388
|
-
next.FadeToAsync(1, TabsAnimationSpeed, Easing.Linear),
|
|
389
|
-
prev ? prev.TranslateToAsync(-dir * w, 0, TabsAnimationSpeed, TabsEasing) : Promise.resolve(),
|
|
390
|
-
]), TabsAnimationSpeed + 500);
|
|
391
|
-
}
|
|
392
|
-
setTabTransition(null);
|
|
393
|
-
}, [hasTabs, Tabs, AnimateTabs, TabsAnimationSpeed]);
|
|
394
|
-
// popstate: the browser popped OUR last entry (back) — or moved forward to a hash we can rebuild
|
|
395
|
-
useEffect(() => {
|
|
396
|
-
if (!historyOn)
|
|
397
|
-
return;
|
|
398
|
-
const parseHash = () => window.location.hash.replace(/^#\/?/, "").split("/").filter(Boolean).map(decodeURIComponent).filter((r) => !!Routes[RouteName(r)]);
|
|
399
|
-
// initial deep link
|
|
400
|
-
const initial = parseHash();
|
|
401
|
-
if (initial.length) {
|
|
402
|
-
setStacks((all) => { const next = all.slice(); next[live.current.selectedTab] = initial; return next; });
|
|
403
|
-
history.current = initial.map(() => "page");
|
|
404
|
-
window.history.replaceState({ [HISTORY_KEY]: history.current.length }, "", hashFor(initial));
|
|
405
|
-
}
|
|
406
|
-
const onPop = () => {
|
|
407
|
-
const depth = window.history.state?.[HISTORY_KEY] ?? 0;
|
|
408
|
-
if (depth < history.current.length) {
|
|
409
|
-
// back: unwind our entries down to depth
|
|
410
|
-
void (async () => {
|
|
411
|
-
while (history.current.length > depth) {
|
|
412
|
-
const kind = history.current.pop();
|
|
413
|
-
const { popups: ps, modals: ms } = live.current;
|
|
414
|
-
let done = true;
|
|
415
|
-
if (kind === "popup") {
|
|
416
|
-
const top = ps[ps.length - 1];
|
|
417
|
-
if (top) {
|
|
418
|
-
top.history = false;
|
|
419
|
-
done = await closePopupNow(top, true);
|
|
420
|
-
if (!done)
|
|
421
|
-
top.history = true;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
else if (kind === "modal") {
|
|
425
|
-
const top = ms[ms.length - 1];
|
|
426
|
-
if (top) {
|
|
427
|
-
top.history = false;
|
|
428
|
-
done = await popModalNow(top, true);
|
|
429
|
-
if (!done)
|
|
430
|
-
top.history = true;
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
else if (kind === "page")
|
|
434
|
-
done = await popPage(true);
|
|
435
|
-
if (!done && kind) { // Navigating cancelled: put the browser entry back
|
|
436
|
-
history.current.push(kind);
|
|
437
|
-
window.history.pushState({ [HISTORY_KEY]: history.current.length }, "", kind === "page" ? hashFor(live.current.stack) : undefined);
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
})();
|
|
442
|
-
}
|
|
443
|
-
else {
|
|
444
|
-
// forward (depth grew), or the same depth with another hash = a plain <a href="#/route"> link or a typed hash:
|
|
445
|
-
// the hash names the pages, rebuild the stack without animation (overlays cannot be restored)
|
|
446
|
-
const target = parseHash();
|
|
447
|
-
if (depth === history.current.length && target.join("/") === live.current.stack.join("/"))
|
|
448
|
-
return;
|
|
449
|
-
history.current = target.map(() => "page");
|
|
450
|
-
window.history.replaceState({ [HISTORY_KEY]: history.current.length }, "", hashFor(target));
|
|
451
|
-
setStacks((all) => { const next = all.slice(); next[live.current.selectedTab] = target; return next; });
|
|
452
|
-
}
|
|
128
|
+
const [, rerender] = useReducer((x) => x + 1, 0);
|
|
129
|
+
const [bridge] = useState(() => ({
|
|
130
|
+
tabHosts: [], attached: new Set(), unmounted: false,
|
|
131
|
+
changed() { if (!this.unmounted)
|
|
132
|
+
rerender(); },
|
|
133
|
+
}));
|
|
134
|
+
useLayoutEffect(() => { bridge.unmounted = false; return () => { bridge.unmounted = true; }; }, [bridge]);
|
|
135
|
+
const routes = useRef(Routes);
|
|
136
|
+
routes.current = Routes;
|
|
137
|
+
const RenderRoute = (name, args) => routes.current[name]?.(args) ?? null;
|
|
138
|
+
// the engine asks for a page: a portal host that renders the route's JSX
|
|
139
|
+
const engineRoutes = useMemo(() => Object.fromEntries(Object.keys(Routes).map((name) => [name, (args) => new PortalHost(() => RenderRoute(name, args), bridge)])), [Routes, bridge]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
140
|
+
const [rootHost] = useState(() => new PortalHost(() => null, bridge, true));
|
|
141
|
+
rootHost.render = () => children;
|
|
142
|
+
const tabsKey = hasTabs ? Tabs.map((t) => t.route).join("\n") : "";
|
|
143
|
+
bridge.tabHosts = useMemo(() => (hasTabs ? Tabs.map((t) => new PortalHost(() => null, bridge, true)) : []), [tabsKey, bridge]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
144
|
+
if (hasTabs)
|
|
145
|
+
bridge.tabHosts.forEach((h, i) => { const { name, args } = SplitRoute(Tabs[i]?.route ?? ""); h.render = () => RenderRoute(name, args); });
|
|
146
|
+
const host = (content) => new PortalHost(() => content, bridge);
|
|
147
|
+
const core = () => {
|
|
148
|
+
if (!bridge.core)
|
|
149
|
+
throw new Error("DrawnUi: SkiaShell is not mounted yet");
|
|
150
|
+
return bridge.core;
|
|
151
|
+
};
|
|
152
|
+
const version = bridge.core?.NavVersion ?? 0;
|
|
153
|
+
const nav = useMemo(() => {
|
|
154
|
+
const s = bridge.core;
|
|
155
|
+
return {
|
|
156
|
+
GoToAsync: (r, animated, args) => core().GoToAsync(r, animated, args),
|
|
157
|
+
GoBackAsync: (animated) => core().GoBackAsync(animated),
|
|
158
|
+
PopToRootAsync: () => core().PopToRootAsync(),
|
|
159
|
+
NavigationStack: s ? s.NavigationStack : [],
|
|
160
|
+
CanGoBack: s ? s.CanGoBack : false,
|
|
161
|
+
Route: s ? s.Route : "",
|
|
162
|
+
Arguments: s ? s.Arguments : {},
|
|
163
|
+
OpenPopupAsync: (content, options) => core().OpenPopupAsync(host(content), options),
|
|
164
|
+
ClosePopupAsync: (animated) => core().ClosePopupAsync(animated),
|
|
165
|
+
CloseAllPopups: () => core().CloseAllPopups(),
|
|
166
|
+
PushModalAsync: (content, options) => core().PushModalAsync(host(content), options),
|
|
167
|
+
PopModalAsync: (animated) => core().PopModalAsync(animated),
|
|
168
|
+
ShowToast: (content, ms) => core().ShowToast(typeof content === "string" ? content : host(content), ms),
|
|
169
|
+
CloseAllToasts: () => core().CloseAllToasts(),
|
|
170
|
+
PopupsCount: s ? s.PopupsCount : 0,
|
|
171
|
+
ModalsCount: s ? s.ModalsCount : 0,
|
|
172
|
+
ToastsCount: s ? s.ToastsCount : 0,
|
|
173
|
+
SelectedTab: s ? s.SelectedTab : 0,
|
|
174
|
+
SelectTabAsync: (index) => core().SelectTabAsync(index),
|
|
175
|
+
PopTabToRootAsync: () => core().PopTabToRootAsync(),
|
|
453
176
|
};
|
|
454
|
-
|
|
455
|
-
return () => window.removeEventListener("popstate", onPop);
|
|
456
|
-
}, [historyOn, Routes, closePopupNow, popModalNow, popPage]);
|
|
457
|
-
const nav = useMemo(() => ({
|
|
458
|
-
GoToAsync, GoBackAsync, PopToRootAsync, NavigationStack: stack, CanGoBack: stack.length > 0 || popups.length > 0 || modals.length > 0, Route: route, Arguments: { ...SplitRoute(route).args, ...argsInMemory.current.get(route) },
|
|
459
|
-
OpenPopupAsync, ClosePopupAsync, CloseAllPopups, PushModalAsync, PopModalAsync, ShowToast, CloseAllToasts,
|
|
460
|
-
PopupsCount: popups.length, ModalsCount: modals.length, ToastsCount: toasts.length,
|
|
461
|
-
SelectedTab: selectedTab, SelectTabAsync, PopTabToRootAsync,
|
|
462
|
-
}), [GoToAsync, GoBackAsync, PopToRootAsync, stack, route, OpenPopupAsync, ClosePopupAsync, CloseAllPopups, PushModalAsync, PopModalAsync, ShowToast, CloseAllToasts, popups.length, modals.length, toasts.length, selectedTab, SelectTabAsync, PopTabToRootAsync]);
|
|
177
|
+
}, [version, bridge]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
463
178
|
useImperativeHandle(ref, () => nav, [nav]);
|
|
464
|
-
const
|
|
465
|
-
|
|
466
|
-
const transitioning = transitions > 0 || leaving !== null;
|
|
467
|
-
const rootBottom = hasTabs ? TabBarHeight + insets.Bottom : 0;
|
|
468
|
-
const navTop = NavBarHeight + insets.Top;
|
|
469
|
-
const rootNode = hasTabs ? RenderRoute(Tabs[selectedTab]?.route ?? "") : children;
|
|
470
|
-
const entering = tabTransition ? { TranslationX: tabTransition.dir * 0.75 * (typeof window !== "undefined" ? window.innerWidth : 0), Opacity: 0.001, ZIndex: 1 } : {};
|
|
471
|
-
return (_jsx(ShellContext.Provider, { value: nav, children: _jsxs(SkiaLayer, { VerticalOptions: "Fill", children: [tabTransition && (_jsx(SkiaLayer, { VerticalOptions: "Fill", Margin: new Thickness(0, 0, 0, rootBottom), ZIndex: 0, BackgroundColor: PageBackgroundColor, ref: (c) => { if (c)
|
|
472
|
-
tabRoots.current.set(tabTransition.from, c); }, children: RenderRoute(Tabs[tabTransition.from]?.route ?? "") }, `tab-leaving-${tabTransition.from}`)), _jsx(SkiaLayer, { VerticalOptions: "Fill", Margin: new Thickness(0, 0, 0, rootBottom), IsVisible: visiblePages.length === 0 || transitioning, BackgroundColor: hasTabs ? PageBackgroundColor : undefined, ...entering, ref: (c) => { if (c)
|
|
473
|
-
tabRoots.current.set(selectedTab, c); }, children: rootNode }, hasTabs ? `tab-${selectedTab}` : "root"), visiblePages.map((r, i) => (_jsxs(PageHost, { route: r, speed: PagesAnimationSpeed, visible: r === topRoute || transitioning, background: PageBackgroundColor, bottom: rootBottom, register: (c) => { if (c)
|
|
474
|
-
pageCtrls.current.set(r, c);
|
|
475
|
-
else
|
|
476
|
-
pageCtrls.current.delete(r); }, children: [_jsx(SkiaLayer, { VerticalOptions: "Fill", Margin: new Thickness(0, navTop, 0, 0), children: RenderRoute(r) }), _jsxs(SkiaLayer, { HeightRequest: navTop, BackgroundColor: NavBarColor, Padding: new Thickness(0, insets.Top, 0, 0), children: [_jsx(SkiaButton, { Text: "\u2039 Back", BackgroundColor: "#00000000", TextColor: "#6EA8FE", FontSize: 16, VerticalOptions: "Center", Margin: new Thickness(8, 0), ApplyEffect: "Ripple", Tapped: () => void GoBackAsync(), AccessibilityRole: "button", AccessibilityLabel: "Back" }), _jsx(SkiaLabel, { Text: Titles?.[RouteName(r)] ?? RouteName(r), FontSize: 18, FontFamily: "FontTextBold", TextColor: Colors.White, HorizontalOptions: "Fill", HorizontalTextAlignment: "Center", VerticalOptions: "Center", MaxLines: 1, Margin: new Thickness(96, 0), AccessibilityRole: "heading" }), _jsx(SkiaButton, { Text: "Home", BackgroundColor: "#00000000", TextColor: "#6EA8FE", FontSize: 16, HorizontalOptions: "End", VerticalOptions: "Center", Margin: new Thickness(0, 0, 8, 0), ApplyEffect: "Ripple", Tapped: () => void PopToRootAsync(), AccessibilityRole: "button", AccessibilityLabel: "Home" }), _jsx(SkiaLayer, { HeightRequest: 1, VerticalOptions: "End", BackgroundColor: "#343A40" })] })] }, `${selectedTab}:${r}#${i}`))), hasTabs && (_jsxs(SkiaLayer, { HeightRequest: TabBarHeight + insets.Bottom, VerticalOptions: "End", BackgroundColor: TabBarColor, ZIndex: ShellDefaults.ZIndexModals - 1, BlockGesturesBelow: true, Padding: new Thickness(0, 0, 0, insets.Bottom), children: [_jsx(SkiaLayer, { HeightRequest: 1, BackgroundColor: "#343A40" }), _jsx(SkiaGrid, { ColumnDefinitions: Tabs.map(() => "*").join(","), HorizontalOptions: "Fill", VerticalOptions: "Fill", children: Tabs.map((t, i) => (_jsxs(SkiaLayer, { Column: i, HorizontalOptions: "Fill", VerticalOptions: "Fill", AnimationTapped: "Ripple", Tapped: () => void SelectTabAsync(i), AccessibilityRole: "button", AccessibilityLabel: t.title, children: [_jsx(SkiaLabel, { Text: t.title, FontSize: 13, FontFamily: i === selectedTab ? "FontTextBold" : undefined, TextColor: i === selectedTab ? ShellDefaults.TabSelectedColor : ShellDefaults.TabColor, HorizontalOptions: "Center", VerticalOptions: "Center", AccessibilityRole: "presentation" }), i === selectedTab && _jsx(SkiaShape, { Type: "Rectangle", HeightRequest: 3, WidthRequest: 36, CornerRadius: 2, BackgroundColor: ShellDefaults.TabSelectedColor, HorizontalOptions: "Center", VerticalOptions: "End" })] }, t.route))) })] })), modals.map((m) => m.node), popups.map((p) => p.node), toasts.map((t) => t.node)] }) }));
|
|
179
|
+
const portal = (h) => createDrawnPortal(_jsxs(_Fragment, { children: [h.render(), _jsx(Committed, { host: h })] }), h, h.key);
|
|
180
|
+
return (_jsx(ShellContext.Provider, { value: nav, children: _jsxs(ShellHostTag, { Bridge: bridge, VerticalOptions: "Fill", Routes: engineRoutes, Titles: Titles, NavBarHeight: NavBarHeight, NavBarColor: NavBarColor, PagesAnimationSpeed: PagesAnimationSpeed, PageBackgroundColor: PageBackgroundColor, TabBarHeight: TabBarHeight, TabBarColor: TabBarColor, UseBrowserHistory: UseBrowserHistory, AnimateTabs: AnimateTabs, TabsAnimationSpeed: TabsAnimationSpeed, Navigating: Navigating, Navigated: Navigated, RouteChanged: RouteChanged, Insets: Insets, Tabs: Tabs, RootContent: rootHost, children: [hasTabs ? bridge.tabHosts.map(portal) : portal(rootHost), [...bridge.attached].map(portal)] }) }));
|
|
477
181
|
});
|
|
478
|
-
/** A pushed page: slides in from the right on mount (C# SkiaViewSwitcher PushView), covers what is below. */
|
|
479
|
-
function PageHost({ route, speed, visible, background, bottom, register, children }) {
|
|
480
|
-
const ctrl = useRef(null);
|
|
481
|
-
useEffect(() => {
|
|
482
|
-
const c = ctrl.current;
|
|
483
|
-
if (!c)
|
|
484
|
-
return;
|
|
485
|
-
register(c);
|
|
486
|
-
if (speed > 0) {
|
|
487
|
-
c.TranslationX = CanvasWidthPts(c);
|
|
488
|
-
void c.TranslateToAsync(0, 0, speed);
|
|
489
|
-
}
|
|
490
|
-
return () => register(null);
|
|
491
|
-
}, [route]); // eslint-disable-line react-hooks/exhaustive-deps
|
|
492
|
-
return (_jsx(SkiaLayer, { ref: (c) => { ctrl.current = c; }, VerticalOptions: "Fill", HorizontalOptions: "Fill", Margin: new Thickness(0, 0, 0, bottom), BackgroundColor: background, IsVisible: visible, BlockGesturesBelow: true, children: children }));
|
|
493
|
-
}
|