akanjs 3.3.0-rc.3 → 3.3.0-rc.5
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/CHANGELOG.md +8 -0
- package/client/csrTypes.ts +11 -0
- package/client/device.ts +13 -1
- package/client/frameConfig.ts +24 -3
- package/client/index.ts +1 -0
- package/package.json +1 -1
- package/types/client/csrTypes.d.ts +14 -0
- package/types/client/device.d.ts +3 -0
- package/types/client/index.d.ts +1 -1
- package/types/ui/System/Common.d.ts +1 -1
- package/types/vendor/@akanjs/native/packages/core/src/boot.d.ts +5 -0
- package/types/webkit/index.d.ts +1 -1
- package/types/webkit/useCsrKeyboard.d.ts +2 -1
- package/types/webkit/useFrameRuntime.d.ts +4 -1
- package/types/webkit/useVisualViewportFrame.d.ts +2 -0
- package/ui/Dialog/Modal.tsx +16 -2
- package/ui/KeyboardAvoiding.tsx +2 -1
- package/ui/Layout/FrameSlotPortal.tsx +10 -3
- package/ui/System/CSR.tsx +21 -8
- package/ui/System/Common.tsx +8 -2
- package/ui/System/SSR.tsx +3 -2
- package/vendor/@akanjs/native/CHANGELOG.md +9 -0
- package/vendor/@akanjs/native/native/ios/Sources/AkanNativeViewController.swift +21 -2
- package/vendor/@akanjs/native/packages/core/src/boot.ts +6 -0
- package/webkit/index.ts +1 -1
- package/webkit/useCsrKeyboard.ts +27 -1
- package/webkit/useCsrTransitions.ts +27 -9
- package/webkit/useCsrValues.ts +8 -2
- package/webkit/useFrameRuntime.ts +48 -4
- package/webkit/useVisualViewportFrame.tsx +26 -0
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,14 @@
|
|
|
8
8
|
|
|
9
9
|
The key defaults to false, so existing apps are unchanged. The api report lists one new optional `AkanNativeIosConfig` property; no upgrade step is needed.
|
|
10
10
|
|
|
11
|
+
- 3032627: An iOS app's page now meets the keyboard the way a native screen does: its content ends at the keys and moves with them, and a header stays where it is. In keyboard mode "none" (what akan apps ship) WKWebView still met the keyboard on its own, insetting its scroll view and panning the whole page until the focused field cleared the keys, so the header went off screen, the page showed under the status bar, and whatever the frame did for the keyboard came on top of the pan. The iOS shell now takes the keyboard notifications away from WKWebView in "none", as Capacitor's Keyboard plugin does, and tells the page through `__AKAN_NATIVE__.keyboardAvoidance = "page"`. Under such a shell the frame ends every page's content at the keys (not only a page with a keyboard accessory), drops the bottom safe area and inset the keys cover, animates on the duration the shell reports with UIKit's keyboard curve (`IOS_KEYBOARD_ANIMATION_EASING`), and scrolls a field the keys cover back into view; a dialog ends at the keys too, `useVisualViewportFrame` reports the keys from the shell, `KeyboardAvoiding` steps aside, and `--akan-keyboard-duration` / `--akan-keyboard-easing` plus `data-akan-keyboard` (while the keys are up) on the root let a page move its own parts with the keys. A page under an older shell, which still pans, keeps today's behavior.
|
|
12
|
+
|
|
13
|
+
The api report lists additions only: `Device.keyboardAnimationMs`, `Device.keyboardHeight` and `Device.subscribeKeyboard`, the optional `KeyboardFrameState.avoidsContent` and `isPageKeyboardAvoidance` from `akanjs/webkit`; no upgrade step is needed. An iOS app gets the new behavior once it is built with this shell; a page that lifted its own composer by the keyboard's height under the old pan should drop that lift.
|
|
14
|
+
|
|
15
|
+
- 4040f2d: `overlay: true` (or `"top"` / `"bottom"`) in a route's `.config()` lays the page under that side's safe area and inset instead of below them, so a translucent bar (a frosted tab bar, a glass header) has the page's content scrolling beneath it. On an overlaid side the page's padding is 0, `--akan-overlay-top` / `--akan-overlay-bottom` carry the chrome's height for the page's scrollers to pad by, the top inset's container stops painting the background, and the safe area strip is transparent and lets touches through unless the route sets its color. Until now every bar sat over a reserved band of plain background, so a backdrop blur had nothing to show.
|
|
16
|
+
|
|
17
|
+
The key defaults to off, so existing pages are unchanged. The api report lists the new `PageOverlayConfig` type and one new optional property on `PageConfig` and on `CsrState`; no upgrade step is needed.
|
|
18
|
+
|
|
11
19
|
### Patch Changes
|
|
12
20
|
|
|
13
21
|
- c44d068: A coding agent reads less to build its first app: the `akanjs` README keeps the path to a first app and links the rest on akanjs.com (17 KB to 7 KB), the `akan-page` and `akan-service` skills ship the API reference one section at a time with every entry named in the skill's index (`Link` now lists the anchor attributes it takes and `Link.Back`, `Link.Close` and `Link.Lang`), the `akan-page` skill holds what a first page looks up while `pageRule` keeps the deeper contract, and each rule is stated once across AGENTS.md, the path rules and the skills. Run `akan agent install` in a workspace to pick up the new files.
|
package/client/csrTypes.ts
CHANGED
|
@@ -19,6 +19,8 @@ export type PageSafeAreaConfig =
|
|
|
19
19
|
bottom?: boolean;
|
|
20
20
|
android?: "auto" | "edge-to-edge" | "none";
|
|
21
21
|
};
|
|
22
|
+
/** The sides whose chrome the page runs under instead of below. */
|
|
23
|
+
export type PageOverlayConfig = boolean | "top" | "bottom";
|
|
22
24
|
/** `"stream"` flushes the shell (`Loading` included) then streams; a redirect in suspended content becomes a client one.
|
|
23
25
|
* `"block"` buffers the whole document, so an error in slow content can still render a clean error page. */
|
|
24
26
|
export type SsrRenderMode = "stream" | "block";
|
|
@@ -34,6 +36,12 @@ export interface PageConfig {
|
|
|
34
36
|
topInset?: number | boolean | ResponsiveInset;
|
|
35
37
|
/** Bottom chrome reservation in px, or px per breakpoint. Use true for the default 48px reservation. */
|
|
36
38
|
bottomInset?: number | boolean | ResponsiveInset;
|
|
39
|
+
/**
|
|
40
|
+
* Lays the page under its top or bottom chrome (safe area and inset) instead of below it, so a translucent bar has
|
|
41
|
+
* content scrolling beneath it. The page pads its own scrollers by `--akan-overlay-top` / `--akan-overlay-bottom`,
|
|
42
|
+
* and an overlaid side's safe area defaults to transparent.
|
|
43
|
+
*/
|
|
44
|
+
overlay?: PageOverlayConfig;
|
|
37
45
|
gesture?: boolean;
|
|
38
46
|
cache?: boolean;
|
|
39
47
|
/** Initial full-document SSR strategy. Defaults to `"stream"`. */
|
|
@@ -64,6 +72,7 @@ export interface CsrState {
|
|
|
64
72
|
responsiveInset?: { top: ResponsiveInset; bottom: ResponsiveInset };
|
|
65
73
|
/** Web only: the sides whose safe area `env(safe-area-inset-*)` measures, since a browser tells script nothing. */
|
|
66
74
|
safeAreaEnv?: { top: boolean; bottom: boolean };
|
|
75
|
+
overlay?: { top: boolean; bottom: boolean };
|
|
67
76
|
gesture: boolean;
|
|
68
77
|
cache: boolean;
|
|
69
78
|
ssr: SsrRenderMode;
|
|
@@ -437,6 +446,8 @@ export interface KeyboardFrameState {
|
|
|
437
446
|
source?: "native" | "visualViewport" | "fallback";
|
|
438
447
|
animationDuration?: number;
|
|
439
448
|
animationEasing?: string;
|
|
449
|
+
/** The page's content ends at the keyboard, as UIKit's keyboard layout guide does: an iOS shell no longer pans. */
|
|
450
|
+
avoidsContent?: boolean;
|
|
440
451
|
}
|
|
441
452
|
export interface FrameContentViewportState {
|
|
442
453
|
top: number;
|
package/client/device.ts
CHANGED
|
@@ -151,6 +151,9 @@ export class Device {
|
|
|
151
151
|
topSafeArea: number;
|
|
152
152
|
bottomSafeArea: number;
|
|
153
153
|
isMobile = isMobileDevice();
|
|
154
|
+
keyboardAnimationMs = 0;
|
|
155
|
+
keyboardHeight = 0;
|
|
156
|
+
#keyboardSubscribers = new Set<(height: number) => void>();
|
|
154
157
|
#native: NativeControls | null;
|
|
155
158
|
#stopKeyboardListeners: (() => void)[] = [];
|
|
156
159
|
#pageContentRef: RefObject<HTMLDivElement | null> | null = null;
|
|
@@ -176,16 +179,25 @@ export class Device {
|
|
|
176
179
|
debugFrame("keyboard.event", { event, height, previousHeight: currentHeight });
|
|
177
180
|
if (currentHeight === height) return;
|
|
178
181
|
currentHeight = height;
|
|
182
|
+
this.keyboardHeight = height;
|
|
179
183
|
onKeyboardChanged(height);
|
|
184
|
+
for (const subscriber of this.#keyboardSubscribers) subscriber(height);
|
|
180
185
|
};
|
|
181
186
|
this.#stopKeyboardListeners.push(
|
|
182
187
|
...(["willShow", "didShow", "willHide", "didHide"] as const).map((event) =>
|
|
183
|
-
keyboard.listen(event, ({ height }) => {
|
|
188
|
+
keyboard.listen(event, ({ height, duration }) => {
|
|
189
|
+
if (duration > 0) this.keyboardAnimationMs = duration;
|
|
184
190
|
emitKeyboardHeight(event, height);
|
|
185
191
|
}),
|
|
186
192
|
),
|
|
187
193
|
);
|
|
188
194
|
}
|
|
195
|
+
subscribeKeyboard(onKeyboardChanged: (height: number) => void) {
|
|
196
|
+
this.#keyboardSubscribers.add(onKeyboardChanged);
|
|
197
|
+
return () => {
|
|
198
|
+
this.#keyboardSubscribers.delete(onKeyboardChanged);
|
|
199
|
+
};
|
|
200
|
+
}
|
|
189
201
|
unlistenKeyboardChanged() {
|
|
190
202
|
for (const stop of this.#stopKeyboardListeners.splice(0)) stop();
|
|
191
203
|
}
|
package/client/frameConfig.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { isRecord, trimSlashes } from "akanjs/common";
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
PageConfig,
|
|
4
|
+
PageOverlayConfig,
|
|
5
|
+
PageSafeAreaConfig,
|
|
6
|
+
PageState,
|
|
7
|
+
ResponsiveInset,
|
|
8
|
+
SsrRenderMode,
|
|
9
|
+
} from "./csrTypes";
|
|
3
10
|
import { transitionTypes } from "./transitionTypes";
|
|
4
11
|
|
|
5
12
|
export type DevicePlatform = "ios" | "android" | "web" | (string & {});
|
|
@@ -38,6 +45,7 @@ const pageConfigKeys = new Set<keyof PageConfig>([
|
|
|
38
45
|
"safeArea",
|
|
39
46
|
"topInset",
|
|
40
47
|
"bottomInset",
|
|
48
|
+
"overlay",
|
|
41
49
|
"gesture",
|
|
42
50
|
"cache",
|
|
43
51
|
"ssr",
|
|
@@ -78,6 +86,9 @@ export const validatePageConfig = (routeKey: string, config?: PageConfig) => {
|
|
|
78
86
|
`[route-convention] pageConfig.${key} in ${routeKey} must be a boolean, a non-negative px number, or { base, sm?, md?, lg?, xl?, "2xl"? } of them.`,
|
|
79
87
|
);
|
|
80
88
|
}
|
|
89
|
+
const { overlay } = pageConfig;
|
|
90
|
+
if (overlay !== undefined && typeof overlay !== "boolean" && overlay !== "top" && overlay !== "bottom")
|
|
91
|
+
throw new Error(`[route-convention] pageConfig.overlay in ${routeKey} must be a boolean, "top" or "bottom".`);
|
|
81
92
|
validateSafeAreaConfig(routeKey, pageConfig.safeArea);
|
|
82
93
|
};
|
|
83
94
|
|
|
@@ -199,6 +210,7 @@ export const resolvePageState = ({
|
|
|
199
210
|
const transition = config.transition ?? "none";
|
|
200
211
|
const responsive = isResponsiveInset(config.topInset) || isResponsiveInset(config.bottomInset);
|
|
201
212
|
const safeAreaEnv = platform === "web" ? resolveSafeAreaEnv(config.safeArea) : undefined;
|
|
213
|
+
const overlay = resolveOverlay(config.overlay);
|
|
202
214
|
return {
|
|
203
215
|
transition,
|
|
204
216
|
topSafeArea: safeArea.top,
|
|
@@ -216,6 +228,7 @@ export const resolvePageState = ({
|
|
|
216
228
|
}
|
|
217
229
|
: {}),
|
|
218
230
|
...(safeAreaEnv ? { safeAreaEnv } : {}),
|
|
231
|
+
...(overlay ? { overlay } : {}),
|
|
219
232
|
gesture: explicitKeys.gesture
|
|
220
233
|
? (config.gesture ?? false)
|
|
221
234
|
: transition === "none"
|
|
@@ -223,11 +236,19 @@ export const resolvePageState = ({
|
|
|
223
236
|
: (config.gesture ?? false),
|
|
224
237
|
cache: config.cache ?? false,
|
|
225
238
|
ssr: config.ssr ?? "stream",
|
|
226
|
-
topSafeAreaColor: config.topSafeAreaColor ?? defaultPageState.topSafeAreaColor,
|
|
227
|
-
bottomSafeAreaColor:
|
|
239
|
+
topSafeAreaColor: config.topSafeAreaColor ?? (overlay?.top ? "transparent" : defaultPageState.topSafeAreaColor),
|
|
240
|
+
bottomSafeAreaColor:
|
|
241
|
+
config.bottomSafeAreaColor ?? (overlay?.bottom ? "transparent" : defaultPageState.bottomSafeAreaColor),
|
|
228
242
|
};
|
|
229
243
|
};
|
|
230
244
|
|
|
245
|
+
const resolveOverlay = (overlay?: PageOverlayConfig): { top: boolean; bottom: boolean } | undefined => {
|
|
246
|
+
if (overlay === true) return { top: true, bottom: true };
|
|
247
|
+
if (overlay === "top") return { top: true, bottom: false };
|
|
248
|
+
if (overlay === "bottom") return { top: false, bottom: true };
|
|
249
|
+
return undefined;
|
|
250
|
+
};
|
|
251
|
+
|
|
231
252
|
const resolveInset = (inset: PageConfig["topInset"]): number => {
|
|
232
253
|
if (inset === true) return DEFAULT_BOOLEAN_INSET;
|
|
233
254
|
if (inset === false || inset === undefined) return 0;
|
package/client/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -12,6 +12,8 @@ export type PageSafeAreaConfig = boolean | "top" | "bottom" | {
|
|
|
12
12
|
bottom?: boolean;
|
|
13
13
|
android?: "auto" | "edge-to-edge" | "none";
|
|
14
14
|
};
|
|
15
|
+
/** The sides whose chrome the page runs under instead of below. */
|
|
16
|
+
export type PageOverlayConfig = boolean | "top" | "bottom";
|
|
15
17
|
/** `"stream"` flushes the shell (`Loading` included) then streams; a redirect in suspended content becomes a client one.
|
|
16
18
|
* `"block"` buffers the whole document, so an error in slow content can still render a clean error page. */
|
|
17
19
|
export type SsrRenderMode = "stream" | "block";
|
|
@@ -28,6 +30,12 @@ export interface PageConfig {
|
|
|
28
30
|
topInset?: number | boolean | ResponsiveInset;
|
|
29
31
|
/** Bottom chrome reservation in px, or px per breakpoint. Use true for the default 48px reservation. */
|
|
30
32
|
bottomInset?: number | boolean | ResponsiveInset;
|
|
33
|
+
/**
|
|
34
|
+
* Lays the page under its top or bottom chrome (safe area and inset) instead of below it, so a translucent bar has
|
|
35
|
+
* content scrolling beneath it. The page pads its own scrollers by `--akan-overlay-top` / `--akan-overlay-bottom`,
|
|
36
|
+
* and an overlaid side's safe area defaults to transparent.
|
|
37
|
+
*/
|
|
38
|
+
overlay?: PageOverlayConfig;
|
|
31
39
|
gesture?: boolean;
|
|
32
40
|
cache?: boolean;
|
|
33
41
|
/** Initial full-document SSR strategy. Defaults to `"stream"`. */
|
|
@@ -63,6 +71,10 @@ export interface CsrState {
|
|
|
63
71
|
top: boolean;
|
|
64
72
|
bottom: boolean;
|
|
65
73
|
};
|
|
74
|
+
overlay?: {
|
|
75
|
+
top: boolean;
|
|
76
|
+
bottom: boolean;
|
|
77
|
+
};
|
|
66
78
|
gesture: boolean;
|
|
67
79
|
cache: boolean;
|
|
68
80
|
ssr: SsrRenderMode;
|
|
@@ -421,6 +433,8 @@ export interface KeyboardFrameState {
|
|
|
421
433
|
source?: "native" | "visualViewport" | "fallback";
|
|
422
434
|
animationDuration?: number;
|
|
423
435
|
animationEasing?: string;
|
|
436
|
+
/** The page's content ends at the keyboard, as UIKit's keyboard layout guide does: an iOS shell no longer pans. */
|
|
437
|
+
avoidsContent?: boolean;
|
|
424
438
|
}
|
|
425
439
|
export interface FrameContentViewportState {
|
|
426
440
|
top: number;
|
package/types/client/device.d.ts
CHANGED
|
@@ -27,10 +27,13 @@ export declare class Device {
|
|
|
27
27
|
topSafeArea: number;
|
|
28
28
|
bottomSafeArea: number;
|
|
29
29
|
isMobile: boolean;
|
|
30
|
+
keyboardAnimationMs: number;
|
|
31
|
+
keyboardHeight: number;
|
|
30
32
|
constructor({ lang, info, topSafeArea, bottomSafeArea, native }: DeviceInitOption);
|
|
31
33
|
setPageContentRef(pageContentRef: RefObject<HTMLDivElement | null>): void;
|
|
32
34
|
hideKeyboard(): Promise<void>;
|
|
33
35
|
listenKeyboardChanged(onKeyboardChanged: (height: number) => void): void;
|
|
36
|
+
subscribeKeyboard(onKeyboardChanged: (height: number) => void): () => void;
|
|
34
37
|
unlistenKeyboardChanged(): void;
|
|
35
38
|
vibrate(type?: "light" | "medium" | "heavy" | number): Promise<void>;
|
|
36
39
|
getScrollTop(): number;
|
package/types/client/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { cn, colorTokens, radiusTokens } from "./cn.d.ts";
|
|
|
3
3
|
export { authTokenKey, cookieJar, cookies, type GetOption, getAccount, getAuthToken, getCookie, getHeader, getSessionClaims, getStoredAuthToken, headers, initAuth, removeCookie, resetAuth, setAuth, setCookie, } from "./cookie.d.ts";
|
|
4
4
|
export { createFont, Inter, Nanum_Gothic_Coding, Noto_Sans_KR, Roboto } from "./createFont.d.ts";
|
|
5
5
|
export { CsrLocation, csrLocation } from "./csrLocation.d.ts";
|
|
6
|
-
export { type AkanHeadSnapshotNode, type AkanHeadSnapshotV1, type AnimatedDivProps, type ContainerTransition, type CsrContextType, type CsrNavigationKind, type CsrNavigationPhase, type CsrPageType, type CsrStackAccount, type CsrStackEntry, type CsrState, type CsrTransitionStyles, csrContext, DEFAULT_BOTTOM_INSET, DEFAULT_TOP_INSET, type FrameContentViewportState, type FrameLayer, type FrameLayerZIndex, type FrameLayoutState, type FramePlatformProfile, type FrameSlotBucket, type FrameSlotRegistration, type FrameSlotRole, type FrameSlotScope, type FrameSlotType, type FrameSnapshot, type FrameViewportState, type GenerateHead, type Head, type HeadProps, type History, type KeyboardAccessoryFrameState, type KeyboardFrameState, type LayoutErrorProps, type LayoutErrorRender, type LayoutFallbackRoute, type LayoutLoadingProps, type LayoutLoadingRender, type LayoutModule, type LayoutNotFoundProps, type LayoutNotFoundRender, type LayoutProps, type LayoutRender, type Location, type LocationState, type NavigationIntent, type PageActivity, type PageActivityState, type PageConfig, type PageLoadingProps, type PageLoadingRender, type PageModule, type PageProps, type PageRender, type PageSafeAreaConfig, type PageState, type PageTransition, type PathContextType, type PathRoute, pageActivityContext, pathContext, type ResolvedHead, type ResolveHead, type ResolveHeadResult, type ResponsiveInset, type Route, type RouteGuard, type RouteGuardProps, type RouteGuide, type RouteModule, type RouteRender, type RouterProps, type RouteState, type RouteViewport, type SafeAreaTransition, type SsrRenderMode, type TransitionAction, type TransitionActionContext, type TransitionPlan, type TransitionStyle, type UseCsrTransition, useCsr, usePathCtx, type WebAppManifest, type WebAppManifestIcon, } from "./csrTypes.d.ts";
|
|
6
|
+
export { type AkanHeadSnapshotNode, type AkanHeadSnapshotV1, type AnimatedDivProps, type ContainerTransition, type CsrContextType, type CsrNavigationKind, type CsrNavigationPhase, type CsrPageType, type CsrStackAccount, type CsrStackEntry, type CsrState, type CsrTransitionStyles, csrContext, DEFAULT_BOTTOM_INSET, DEFAULT_TOP_INSET, type FrameContentViewportState, type FrameLayer, type FrameLayerZIndex, type FrameLayoutState, type FramePlatformProfile, type FrameSlotBucket, type FrameSlotRegistration, type FrameSlotRole, type FrameSlotScope, type FrameSlotType, type FrameSnapshot, type FrameViewportState, type GenerateHead, type Head, type HeadProps, type History, type KeyboardAccessoryFrameState, type KeyboardFrameState, type LayoutErrorProps, type LayoutErrorRender, type LayoutFallbackRoute, type LayoutLoadingProps, type LayoutLoadingRender, type LayoutModule, type LayoutNotFoundProps, type LayoutNotFoundRender, type LayoutProps, type LayoutRender, type Location, type LocationState, type NavigationIntent, type PageActivity, type PageActivityState, type PageConfig, type PageLoadingProps, type PageLoadingRender, type PageModule, type PageOverlayConfig, type PageProps, type PageRender, type PageSafeAreaConfig, type PageState, type PageTransition, type PathContextType, type PathRoute, pageActivityContext, pathContext, type ResolvedHead, type ResolveHead, type ResolveHeadResult, type ResponsiveInset, type Route, type RouteGuard, type RouteGuardProps, type RouteGuide, type RouteModule, type RouteRender, type RouterProps, type RouteState, type RouteViewport, type SafeAreaTransition, type SsrRenderMode, type TransitionAction, type TransitionActionContext, type TransitionPlan, type TransitionStyle, type UseCsrTransition, useCsr, usePathCtx, type WebAppManifest, type WebAppManifestIcon, } from "./csrTypes.d.ts";
|
|
7
7
|
export { Toast } from "./decorators.d.ts";
|
|
8
8
|
export { Device, debugFrame, isMobileDevice, isNativeTarget } from "./device.d.ts";
|
|
9
9
|
export { breakpointQuery, type DevicePlatform, defaultPageState, getExplicitPageConfigKeys, type InsetBreakpoint, insetAt, insetBreakpoints, insetsByBreakpoint, isResponsiveInset, mergePageConfigs, type ResolvePageStateOptions, readCssSafeAreaInsets, resolvePageState, type SafeAreaInsets, type TailwindBreakpoint, validatePageConfig, } from "./frameConfig.d.ts";
|
|
@@ -32,7 +32,7 @@ export declare function ManifestLink({ manifest, basePath }: {
|
|
|
32
32
|
basePath?: string | null;
|
|
33
33
|
}): import("react").JSX.Element | null;
|
|
34
34
|
export declare function createManifestDataUrl(manifest: WebAppManifest): string;
|
|
35
|
-
export type AkanFrameCssVarName = "--akan-top-safe-area" | "--akan-bottom-safe-area" | "--akan-top-inset" | "--akan-bottom-inset" | "--akan-page-padding-top" | "--akan-page-padding-bottom" | "--akan-content-height" | `--akan-${"top" | "bottom"}-inset-visibility` | `--akan-${"top" | "bottom"}-inset-${InsetBreakpoint}` | `--akan-${"top" | "bottom"}-inset-visibility-${InsetBreakpoint}`;
|
|
35
|
+
export type AkanFrameCssVarName = "--akan-top-safe-area" | "--akan-bottom-safe-area" | "--akan-top-inset" | "--akan-bottom-inset" | "--akan-page-padding-top" | "--akan-page-padding-bottom" | "--akan-overlay-top" | "--akan-overlay-bottom" | "--akan-content-height" | `--akan-${"top" | "bottom"}-inset-visibility` | `--akan-${"top" | "bottom"}-inset-${InsetBreakpoint}` | `--akan-${"top" | "bottom"}-inset-visibility-${InsetBreakpoint}`;
|
|
36
36
|
export type AkanFrameCssVars = CSSProperties & {
|
|
37
37
|
[name in AkanFrameCssVarName]?: string;
|
|
38
38
|
};
|
|
@@ -50,6 +50,11 @@ export interface AkanNativeBoot {
|
|
|
50
50
|
/** Native hosts: the page's engine (wkwebview, webview2, webkitgtk, android-webview) and its version. */
|
|
51
51
|
engine?: string;
|
|
52
52
|
engineVersion?: string;
|
|
53
|
+
/**
|
|
54
|
+
* iOS: "page" when the shell took the WebView's own keyboard avoidance away (keyboard mode "none"), so nothing
|
|
55
|
+
* pans the page to a focused field and the page lays itself out from the keyboard plugin's events.
|
|
56
|
+
*/
|
|
57
|
+
keyboardAvoidance?: "page";
|
|
53
58
|
}
|
|
54
59
|
/** The global object. init.js fills the boot fields, @akanjs/native/core adds `receive`. */
|
|
55
60
|
export interface AkanNativeGlobal extends Partial<AkanNativeBoot> {
|
package/types/webkit/index.d.ts
CHANGED
|
@@ -24,4 +24,4 @@ export { usePageTool } from "./usePageTool.d.ts";
|
|
|
24
24
|
export type { ScreenScopeItem } from "./useScreenScope.d.ts";
|
|
25
25
|
export { useScreenScope } from "./useScreenScope.d.ts";
|
|
26
26
|
export { useThrottle } from "./useThrottle.d.ts";
|
|
27
|
-
export { useVisualViewportFrame, type VisualViewportFrame } from "./useVisualViewportFrame.d.ts";
|
|
27
|
+
export { isPageKeyboardAvoidance, useVisualViewportFrame, type VisualViewportFrame } from "./useVisualViewportFrame.d.ts";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type KeyboardFrameState } from "akanjs/client";
|
|
1
2
|
import type { CsrLocationState } from "./useCsrLocationState.d.ts";
|
|
2
3
|
import type { CsrRefs } from "./useCsrRefs.d.ts";
|
|
3
4
|
import { type useFrameSlots, type useFrameViewport } from "./useFrameRuntime.d.ts";
|
|
@@ -13,7 +14,7 @@ export declare const useCsrKeyboard: ({ viewport, updateViewport, frameSlots, ph
|
|
|
13
14
|
platformProfile: import("akanjs/client").FramePlatformProfile;
|
|
14
15
|
accessoryHeight: number;
|
|
15
16
|
shouldAnchorContentBottom: boolean;
|
|
16
|
-
keyboardFrame:
|
|
17
|
+
keyboardFrame: KeyboardFrameState;
|
|
17
18
|
keyboardLayout: Pick<import("akanjs/client").FrameLayoutState, "keyboardAccessory" | "contentViewport">;
|
|
18
19
|
};
|
|
19
20
|
export type CsrKeyboard = ReturnType<typeof useCsrKeyboard>;
|
|
@@ -8,6 +8,7 @@ export declare const KEYBOARD_SHOW_ANIMATION_DURATION_MS = 420;
|
|
|
8
8
|
export declare const KEYBOARD_HIDE_ANIMATION_DURATION_MS = 90;
|
|
9
9
|
export declare const KEYBOARD_SHOW_ANIMATION_EASING = "cubic-bezier(0.16, 1, 0.3, 1)";
|
|
10
10
|
export declare const KEYBOARD_HIDE_ANIMATION_EASING = "cubic-bezier(0.7, 0, 0.84, 0)";
|
|
11
|
+
export declare const IOS_KEYBOARD_ANIMATION_EASING = "cubic-bezier(0.38, 0.7, 0.125, 1)";
|
|
11
12
|
export declare const FRAME_Z_INDEX: {
|
|
12
13
|
readonly page: 10;
|
|
13
14
|
readonly previousPage: 0;
|
|
@@ -43,13 +44,15 @@ export declare function getKeyboardAccessorySlots(path: string, frameSlots: Fram
|
|
|
43
44
|
export declare function resolveKeyboardAccessoryHeight(path: string, frameSlots: FrameSlotMap): number;
|
|
44
45
|
export declare function hasKeyboardStickySlot(path: string, frameSlots: FrameSlotMap): boolean;
|
|
45
46
|
export declare function hasBottomAnchoredKeyboardSlot(path: string, frameSlots: FrameSlotMap): boolean;
|
|
46
|
-
export declare function resolveKeyboardFrame({ keyboardHeight, visualViewportKeyboardHeight, platformProfile, sticky, freeze, }: {
|
|
47
|
+
export declare function resolveKeyboardFrame({ keyboardHeight, visualViewportKeyboardHeight, platformProfile, sticky, freeze, pageAvoidsKeyboard, nativeAnimationDuration, }: {
|
|
47
48
|
keyboardHeight: number;
|
|
48
49
|
bottomSafeArea: number;
|
|
49
50
|
visualViewportKeyboardHeight: number;
|
|
50
51
|
platformProfile: FramePlatformProfile;
|
|
51
52
|
sticky: boolean;
|
|
52
53
|
freeze?: boolean;
|
|
54
|
+
pageAvoidsKeyboard?: boolean;
|
|
55
|
+
nativeAnimationDuration?: number;
|
|
53
56
|
}): KeyboardFrameState;
|
|
54
57
|
export declare function resolveKeyboardLayout({ viewport, keyboard, accessoryHeight, bottomSafeArea, }: {
|
|
55
58
|
viewport: FrameLayoutState["viewport"];
|
|
@@ -5,6 +5,8 @@ export interface VisualViewportFrame {
|
|
|
5
5
|
height: number;
|
|
6
6
|
offsetTop: number;
|
|
7
7
|
}
|
|
8
|
+
/** Whether the iOS shell left the keyboard to the page; an older shell still pans to the field, so the page must not. */
|
|
9
|
+
export declare const isPageKeyboardAvoidance: () => boolean;
|
|
8
10
|
/**
|
|
9
11
|
* The visible part of the page while the on-screen keyboard is up, on the web. Only `visualViewport` reports the
|
|
10
12
|
* keyboard: `dvh` tracks the browser's own chrome, and iOS pans the visual viewport to the field instead of shrinking
|
package/ui/Dialog/Modal.tsx
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { cn, usePage } from "akanjs/client";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
isPageKeyboardAvoidance,
|
|
5
|
+
useBodyScrollLock,
|
|
6
|
+
useEscapeKey,
|
|
7
|
+
usePageActivity,
|
|
8
|
+
useVisualViewportFrame,
|
|
9
|
+
} from "akanjs/webkit";
|
|
4
10
|
import { type ReactNode, useCallback, useContext, useEffect, useId, useRef, useState } from "react";
|
|
5
11
|
import { createPortal } from "react-dom";
|
|
6
12
|
import { BiX } from "react-icons/bi";
|
|
@@ -47,6 +53,14 @@ export const Modal = ({
|
|
|
47
53
|
const [root, setRoot] = useState<HTMLDivElement | null>(null);
|
|
48
54
|
const [dragY, setDragY] = useState(0);
|
|
49
55
|
const surface = modalSurfaceOf(presentation, placement);
|
|
56
|
+
|
|
57
|
+
const { keyboardHeight } = useVisualViewportFrame();
|
|
58
|
+
const keyboardInset = isPageKeyboardAvoidance()
|
|
59
|
+
? {
|
|
60
|
+
paddingBottom: keyboardHeight,
|
|
61
|
+
transition: "padding-bottom var(--akan-keyboard-duration, 0ms) var(--akan-keyboard-easing, ease)",
|
|
62
|
+
}
|
|
63
|
+
: null;
|
|
50
64
|
|
|
51
65
|
const requestClose = useCallback(() => {
|
|
52
66
|
if (confirmClose && !window.confirm(l("base.confirmClose"))) return;
|
|
@@ -98,7 +112,7 @@ export const Modal = ({
|
|
|
98
112
|
{...overlayLayerProps}
|
|
99
113
|
ref={setRoot}
|
|
100
114
|
className={cn("fixed inset-0 flex bg-black/40", surface.root)}
|
|
101
|
-
style={{ zIndex: overlayZ.modal, visibility: isCurrentPage ? undefined : "hidden" }}
|
|
115
|
+
style={{ zIndex: overlayZ.modal, visibility: isCurrentPage ? undefined : "hidden", ...keyboardInset }}
|
|
102
116
|
onClick={(event) => {
|
|
103
117
|
if (event.target !== event.currentTarget) return;
|
|
104
118
|
requestClose();
|
package/ui/KeyboardAvoiding.tsx
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { useSpring } from "@react-spring/web";
|
|
3
3
|
import { useCsr } from "akanjs/client";
|
|
4
4
|
import { st } from "akanjs/store";
|
|
5
|
+
import { isPageKeyboardAvoidance } from "akanjs/webkit";
|
|
5
6
|
import { type ReactNode, useEffect, useRef } from "react";
|
|
6
7
|
import { animated } from "./animated";
|
|
7
8
|
|
|
@@ -28,7 +29,7 @@ export const KeyboardAvoiding = ({ children, className }: KeyboardAvoidingProps)
|
|
|
28
29
|
const test = async () => {
|
|
29
30
|
if (!pageContentRef.current) return;
|
|
30
31
|
|
|
31
|
-
const newHeight = keyboardHeight ? keyboardHeight - pageState.bottomSafeArea : 0;
|
|
32
|
+
const newHeight = keyboardHeight && !isPageKeyboardAvoidance() ? keyboardHeight - pageState.bottomSafeArea : 0;
|
|
32
33
|
|
|
33
34
|
await onChange(newHeight);
|
|
34
35
|
|
|
@@ -41,10 +41,11 @@ const moveInto = (parent: HTMLElement, node: HTMLElement) => {
|
|
|
41
41
|
|
|
42
42
|
interface SsrFrameSlotProps {
|
|
43
43
|
slot: FrameSlotName;
|
|
44
|
+
isOverlaid: boolean;
|
|
44
45
|
children: ReactNode;
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
const SsrFrameSlot = ({ slot, children }: SsrFrameSlotProps) => {
|
|
48
|
+
const SsrFrameSlot = ({ slot, isOverlaid, children }: SsrFrameSlotProps) => {
|
|
48
49
|
const boxRef = useRef<HTMLDivElement>(null);
|
|
49
50
|
const contentRef = useRef<HTMLDivElement>(null);
|
|
50
51
|
useLayoutEffect(() => {
|
|
@@ -61,7 +62,7 @@ const SsrFrameSlot = ({ slot, children }: SsrFrameSlotProps) => {
|
|
|
61
62
|
<div
|
|
62
63
|
ref={boxRef}
|
|
63
64
|
data-akan-frame-fallback={slot}
|
|
64
|
-
className={cn(frameSlotContainerClassNames[slot], "z-10 empty:hidden")}
|
|
65
|
+
className={cn(frameSlotContainerClassNames[slot], "z-10 empty:hidden", isOverlaid && "bg-transparent")}
|
|
65
66
|
style={frameSlotStyles[slot]}
|
|
66
67
|
>
|
|
67
68
|
<div ref={contentRef} className={frameSlotContentClassNames[slot]}>
|
|
@@ -78,7 +79,13 @@ interface FrameSlotPortalProps {
|
|
|
78
79
|
}
|
|
79
80
|
export const FrameSlotPortal = ({ slot, children }: FrameSlotPortalProps) => {
|
|
80
81
|
const pathCtx = usePathCtx();
|
|
81
|
-
|
|
82
|
+
const overlay = pathCtx.location?.pathRoute?.pageState?.overlay;
|
|
83
|
+
if (getEnv().renderMode !== "csr")
|
|
84
|
+
return (
|
|
85
|
+
<SsrFrameSlot slot={slot} isOverlaid={slot === "topInset" && !!overlay?.top}>
|
|
86
|
+
{children}
|
|
87
|
+
</SsrFrameSlot>
|
|
88
|
+
);
|
|
82
89
|
|
|
83
90
|
const path = pathCtx.location?.pathRoute?.path;
|
|
84
91
|
return <Portal id={path ? `${slot}Content-${pathCtx.pageKey ?? path}` : `${slot}Content`}>{children}</Portal>;
|
package/ui/System/CSR.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
debugFrame,
|
|
9
9
|
getPathInfo,
|
|
10
10
|
type PageActivity,
|
|
11
|
+
type PageState,
|
|
11
12
|
type ReactFont,
|
|
12
13
|
router,
|
|
13
14
|
useCsr,
|
|
@@ -101,6 +102,21 @@ const CSRProvider = ({
|
|
|
101
102
|
};
|
|
102
103
|
CSR.Provider = CSRProvider;
|
|
103
104
|
|
|
105
|
+
const chromeClassNamesOf = (overlay?: PageState["overlay"]) => ({
|
|
106
|
+
topSafeArea: cn(
|
|
107
|
+
"akan-frame-chrome fixed inset-x-0 top-0 max-w-screen bg-background",
|
|
108
|
+
overlay?.top && "pointer-events-none",
|
|
109
|
+
),
|
|
110
|
+
topInset: cn(
|
|
111
|
+
"akan-frame-chrome fixed inset-x-0 isolate max-w-screen overflow-hidden bg-background",
|
|
112
|
+
overlay?.top && "bg-transparent",
|
|
113
|
+
),
|
|
114
|
+
bottomSafeArea: cn(
|
|
115
|
+
"akan-frame-chrome fixed inset-x-0 max-w-screen bg-background",
|
|
116
|
+
overlay?.bottom && "pointer-events-none",
|
|
117
|
+
),
|
|
118
|
+
});
|
|
119
|
+
|
|
104
120
|
interface CSRWrapperProps {
|
|
105
121
|
className?: string;
|
|
106
122
|
appName: string;
|
|
@@ -137,7 +153,8 @@ const CSRWrapper = ({
|
|
|
137
153
|
stackEntries,
|
|
138
154
|
} = useCsr();
|
|
139
155
|
const csrLoaded = st.use.csrLoaded({ agent: false });
|
|
140
|
-
const { router: reactRouter, history } = useCsr();
|
|
156
|
+
const { router: reactRouter, history, location } = useCsr();
|
|
157
|
+
const chrome = chromeClassNamesOf(location?.pathRoute?.pageState?.overlay);
|
|
141
158
|
useEffect(() => {
|
|
142
159
|
debugFrame("csrWrapper.mount", { appName, layoutStyle, pathCount: pathRoutes.length });
|
|
143
160
|
if (layoutStyle === "mobile") {
|
|
@@ -197,15 +214,11 @@ const CSRWrapper = ({
|
|
|
197
214
|
: null}
|
|
198
215
|
<TopChromeLayer
|
|
199
216
|
id="topSafeArea"
|
|
200
|
-
className={
|
|
217
|
+
className={chrome.topSafeArea}
|
|
201
218
|
layerRef={topSafeAreaRef}
|
|
202
219
|
style={topSafeArea?.containerStyle}
|
|
203
220
|
/>
|
|
204
|
-
<TopChromeLayer
|
|
205
|
-
id="topInsetContainer"
|
|
206
|
-
className={cn("akan-frame-chrome fixed inset-x-0 isolate max-w-screen overflow-hidden bg-background")}
|
|
207
|
-
style={topInset?.containerStyle}
|
|
208
|
-
>
|
|
221
|
+
<TopChromeLayer id="topInsetContainer" className={chrome.topInset} style={topInset?.containerStyle}>
|
|
209
222
|
<CSRFrameSlotTargets slot="topInset" />
|
|
210
223
|
</TopChromeLayer>
|
|
211
224
|
<TopChromeLayer
|
|
@@ -245,7 +258,7 @@ const CSRWrapper = ({
|
|
|
245
258
|
</KeyboardLayer>
|
|
246
259
|
<BottomChromeLayer
|
|
247
260
|
id="bottomSafeArea"
|
|
248
|
-
className=
|
|
261
|
+
className={chrome.bottomSafeArea}
|
|
249
262
|
layerRef={bottomSafeAreaRef}
|
|
250
263
|
style={bottomSafeArea?.containerStyle}
|
|
251
264
|
/>
|
package/ui/System/Common.tsx
CHANGED
|
@@ -61,6 +61,8 @@ export type AkanFrameCssVarName =
|
|
|
61
61
|
| "--akan-bottom-inset"
|
|
62
62
|
| "--akan-page-padding-top"
|
|
63
63
|
| "--akan-page-padding-bottom"
|
|
64
|
+
| "--akan-overlay-top"
|
|
65
|
+
| "--akan-overlay-bottom"
|
|
64
66
|
| "--akan-content-height"
|
|
65
67
|
| `--akan-${"top" | "bottom"}-inset-visibility`
|
|
66
68
|
| `--akan-${"top" | "bottom"}-inset-${InsetBreakpoint}`
|
|
@@ -83,11 +85,15 @@ export const isResponsiveFrame = (pageState: PageState, { cssResolved }: { cssRe
|
|
|
83
85
|
*/
|
|
84
86
|
export function getFrameCssVars(pageState: PageState, { cssResolved }: { cssResolved: boolean }): AkanFrameCssVars {
|
|
85
87
|
const safeAreaEnv = cssResolved ? pageState.safeAreaEnv : undefined;
|
|
88
|
+
const topChrome = "calc(var(--akan-top-safe-area) + var(--akan-top-inset))";
|
|
89
|
+
const bottomChrome = "calc(var(--akan-bottom-safe-area) + var(--akan-bottom-inset))";
|
|
86
90
|
const vars: AkanFrameCssVars = {
|
|
87
91
|
"--akan-top-safe-area": safeAreaEnv?.top ? "env(safe-area-inset-top, 0px)" : px(pageState.topSafeArea),
|
|
88
92
|
"--akan-bottom-safe-area": safeAreaEnv?.bottom ? "env(safe-area-inset-bottom, 0px)" : px(pageState.bottomSafeArea),
|
|
89
|
-
"--akan-page-padding-top":
|
|
90
|
-
"--akan-page-padding-bottom":
|
|
93
|
+
"--akan-page-padding-top": pageState.overlay?.top ? "0px" : topChrome,
|
|
94
|
+
"--akan-page-padding-bottom": pageState.overlay?.bottom ? "0px" : bottomChrome,
|
|
95
|
+
"--akan-overlay-top": pageState.overlay?.top ? topChrome : "0px",
|
|
96
|
+
"--akan-overlay-bottom": pageState.overlay?.bottom ? bottomChrome : "0px",
|
|
91
97
|
"--akan-content-height":
|
|
92
98
|
"calc(var(--akan-viewport-height, 100dvh) - var(--akan-page-padding-top) - var(--akan-page-padding-bottom))",
|
|
93
99
|
};
|
package/ui/System/SSR.tsx
CHANGED
|
@@ -185,7 +185,7 @@ const SSRWrapper = ({
|
|
|
185
185
|
<div
|
|
186
186
|
key="top-safe-area"
|
|
187
187
|
id="topSafeArea"
|
|
188
|
-
className={cn("fixed inset-x-0 top-0 bg-background")}
|
|
188
|
+
className={cn("fixed inset-x-0 top-0 bg-background", pageState.overlay?.top && "pointer-events-none")}
|
|
189
189
|
style={topSafeAreaStyle}
|
|
190
190
|
/>
|
|
191
191
|
<div key="page-containers" id="pageContainers" className={cn("isolate")}>
|
|
@@ -210,6 +210,7 @@ const SSRWrapper = ({
|
|
|
210
210
|
frameSlotContainerClassNames.topInset,
|
|
211
211
|
layoutStyle === "mobile" && "left-1/2 w-full max-w-[600px] -translate-x-1/2",
|
|
212
212
|
layoutStyle === "web" && "w-full",
|
|
213
|
+
pageState.overlay?.top && "bg-transparent",
|
|
213
214
|
)}
|
|
214
215
|
style={frameSlotStyles.topInset}
|
|
215
216
|
>
|
|
@@ -253,7 +254,7 @@ const SSRWrapper = ({
|
|
|
253
254
|
<div
|
|
254
255
|
key="bottom-safe-area"
|
|
255
256
|
id="bottomSafeArea"
|
|
256
|
-
className="fixed inset-x-0 bg-background"
|
|
257
|
+
className={cn("fixed inset-x-0 bg-background", pageState.overlay?.bottom && "pointer-events-none")}
|
|
257
258
|
style={bottomSafeAreaStyle}
|
|
258
259
|
/>
|
|
259
260
|
</ClientPathWrapper>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @akanjs/native
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3032627: An iOS app's page now meets the keyboard the way a native screen does: its content ends at the keys and moves with them, and a header stays where it is. In keyboard mode "none" (what akan apps ship) WKWebView still met the keyboard on its own, insetting its scroll view and panning the whole page until the focused field cleared the keys, so the header went off screen, the page showed under the status bar, and whatever the frame did for the keyboard came on top of the pan. The iOS shell now takes the keyboard notifications away from WKWebView in "none", as Capacitor's Keyboard plugin does, and tells the page through `__AKAN_NATIVE__.keyboardAvoidance = "page"`. Under such a shell the frame ends every page's content at the keys (not only a page with a keyboard accessory), drops the bottom safe area and inset the keys cover, animates on the duration the shell reports with UIKit's keyboard curve (`IOS_KEYBOARD_ANIMATION_EASING`), and scrolls a field the keys cover back into view; a dialog ends at the keys too, `useVisualViewportFrame` reports the keys from the shell, `KeyboardAvoiding` steps aside, and `--akan-keyboard-duration` / `--akan-keyboard-easing` plus `data-akan-keyboard` (while the keys are up) on the root let a page move its own parts with the keys. A page under an older shell, which still pans, keeps today's behavior.
|
|
8
|
+
|
|
9
|
+
The api report lists additions only: `Device.keyboardAnimationMs`, `Device.keyboardHeight` and `Device.subscribeKeyboard`, the optional `KeyboardFrameState.avoidsContent` and `isPageKeyboardAvoidance` from `akanjs/webkit`; no upgrade step is needed. An iOS app gets the new behavior once it is built with this shell; a page that lifted its own composer by the keyboard's height under the old pan should drop that lift.
|
|
@@ -85,6 +85,7 @@ final class AkanNativeViewController: UIViewController, WKNavigationDelegate, WK
|
|
|
85
85
|
webView.navigationDelegate = self
|
|
86
86
|
webView.uiDelegate = self
|
|
87
87
|
self.webView = webView
|
|
88
|
+
if !keyboardResizes { detachWebKitKeyboardAvoidance() }
|
|
88
89
|
|
|
89
90
|
bridge.webView = webView
|
|
90
91
|
bridge.viewController = self
|
|
@@ -121,7 +122,24 @@ final class AkanNativeViewController: UIViewController, WKNavigationDelegate, WK
|
|
|
121
122
|
/// Keyboard mode (O6-1, keyboard.setResizeMode): true ("resize", the default) shortens the web view
|
|
122
123
|
/// by the keyboard; false ("none") lets the keyboard cover the page.
|
|
123
124
|
var keyboardResizes = true {
|
|
124
|
-
didSet {
|
|
125
|
+
didSet {
|
|
126
|
+
if !keyboardResizes { detachWebKitKeyboardAvoidance() }
|
|
127
|
+
applyKeyboard(duration: 0, options: [])
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/// WKWebView meets the keyboard on its own: it insets its scroll view and pans the whole page until the focused
|
|
132
|
+
/// field clears the keys, taking a fixed header off screen. In "none" the page lays itself out from the keyboard
|
|
133
|
+
/// plugin's events instead (`__AKAN_NATIVE__.keyboardAvoidance`), so the shell takes those notifications away from
|
|
134
|
+
/// WebKit, as Capacitor's Keyboard plugin does. Never undone: in "resize" the keys never cover the web view.
|
|
135
|
+
private func detachWebKitKeyboardAvoidance() {
|
|
136
|
+
guard let webView else { return }
|
|
137
|
+
let names: [Notification.Name] = [
|
|
138
|
+
UIResponder.keyboardWillShowNotification, UIResponder.keyboardDidShowNotification,
|
|
139
|
+
UIResponder.keyboardWillHideNotification, UIResponder.keyboardDidHideNotification,
|
|
140
|
+
UIResponder.keyboardWillChangeFrameNotification, UIResponder.keyboardDidChangeFrameNotification,
|
|
141
|
+
]
|
|
142
|
+
for name in names { NotificationCenter.default.removeObserver(webView, name: name, object: nil) }
|
|
125
143
|
}
|
|
126
144
|
|
|
127
145
|
/// How much of this view the keyboard covers, in points: its end frame converted from the screen
|
|
@@ -276,8 +294,9 @@ final class AkanNativeViewController: UIViewController, WKNavigationDelegate, WK
|
|
|
276
294
|
}
|
|
277
295
|
// The shell's origin and engine: one value every origin comparison uses (`__AKAN_NATIVE__.origin`).
|
|
278
296
|
let engine = "window.__AKAN_NATIVE__.origin=\"app://localhost\";window.__AKAN_NATIVE__.engine=\"wkwebview\";window.__AKAN_NATIVE__.engineVersion=\"\(UIDevice.current.systemVersion)\";\n"
|
|
297
|
+
let keyboard = keyboardResizes ? "" : "window.__AKAN_NATIVE__.keyboardAvoidance=\"page\";\n"
|
|
279
298
|
// A new document starts with the current safe area (N14); later changes are pushed.
|
|
280
|
-
return Data((Self.initPrefix + boot + "," + env + Self.initSuffix + engine + Self.cssInsets(cssInsets)).utf8)
|
|
299
|
+
return Data((Self.initPrefix + boot + "," + env + Self.initSuffix + engine + keyboard + Self.cssInsets(cssInsets)).utf8)
|
|
281
300
|
}
|
|
282
301
|
|
|
283
302
|
/// The safe area the page's --akan-native-safe-area-* variables hold (N14), in CSS px.
|
|
@@ -49,6 +49,11 @@ export interface AkanNativeBoot {
|
|
|
49
49
|
/** Native hosts: the page's engine (wkwebview, webview2, webkitgtk, android-webview) and its version. */
|
|
50
50
|
engine?: string;
|
|
51
51
|
engineVersion?: string;
|
|
52
|
+
/**
|
|
53
|
+
* iOS: "page" when the shell took the WebView's own keyboard avoidance away (keyboard mode "none"), so nothing
|
|
54
|
+
* pans the page to a focused field and the page lays itself out from the keyboard plugin's events.
|
|
55
|
+
*/
|
|
56
|
+
keyboardAvoidance?: "page";
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
/** The global object. init.js fills the boot fields, @akanjs/native/core adds `receive`. */
|
|
@@ -93,5 +98,6 @@ export function readBoot(): AkanNativeBoot {
|
|
|
93
98
|
: {}),
|
|
94
99
|
...(typeof g.engine === "string" ? { engine: g.engine } : {}),
|
|
95
100
|
...(typeof g.engineVersion === "string" ? { engineVersion: g.engineVersion } : {}),
|
|
101
|
+
...(g.keyboardAvoidance === "page" ? { keyboardAvoidance: "page" as const } : {}),
|
|
96
102
|
};
|
|
97
103
|
}
|
package/webkit/index.ts
CHANGED
|
@@ -24,4 +24,4 @@ export { usePageTool } from "./usePageTool";
|
|
|
24
24
|
export type { ScreenScopeItem } from "./useScreenScope";
|
|
25
25
|
export { useScreenScope } from "./useScreenScope";
|
|
26
26
|
export { useThrottle } from "./useThrottle";
|
|
27
|
-
export { useVisualViewportFrame, type VisualViewportFrame } from "./useVisualViewportFrame";
|
|
27
|
+
export { isPageKeyboardAvoidance, useVisualViewportFrame, type VisualViewportFrame } from "./useVisualViewportFrame";
|
package/webkit/useCsrKeyboard.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { debugFrame } from "akanjs/client";
|
|
2
|
+
import { debugFrame, type KeyboardFrameState } from "akanjs/client";
|
|
3
3
|
import { useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
4
4
|
import type { CsrLocationState } from "./useCsrLocationState";
|
|
5
5
|
import type { CsrRefs } from "./useCsrRefs";
|
|
@@ -148,8 +148,34 @@ export const useCsrKeyboard = ({
|
|
|
148
148
|
keyboardFrame.sticky,
|
|
149
149
|
keyboardLayout.contentViewport.height,
|
|
150
150
|
]);
|
|
151
|
+
useKeyboardRoot(keyboardFrame);
|
|
152
|
+
useRevealCoveredField(pageContentRef, keyboardFrame);
|
|
151
153
|
useFrameRuntimeResync({ updateViewport });
|
|
152
154
|
return { platformProfile, accessoryHeight, shouldAnchorContentBottom, keyboardFrame, keyboardLayout };
|
|
153
155
|
};
|
|
154
156
|
|
|
155
157
|
export type CsrKeyboard = ReturnType<typeof useCsrKeyboard>;
|
|
158
|
+
|
|
159
|
+
const useKeyboardRoot = (keyboardFrame: KeyboardFrameState) => {
|
|
160
|
+
useLayoutEffect(() => {
|
|
161
|
+
const root = document.documentElement;
|
|
162
|
+
root.style.setProperty("--akan-keyboard-duration", `${keyboardFrame.animationDuration ?? 0}ms`);
|
|
163
|
+
root.style.setProperty("--akan-keyboard-easing", keyboardFrame.animationEasing ?? "ease");
|
|
164
|
+
root.toggleAttribute("data-akan-keyboard", keyboardFrame.visible);
|
|
165
|
+
}, [keyboardFrame.animationDuration, keyboardFrame.animationEasing, keyboardFrame.visible]);
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
const useRevealCoveredField = (pageContentRef: CsrRefs["pageContentRef"], keyboardFrame: KeyboardFrameState) => {
|
|
169
|
+
useEffect(() => {
|
|
170
|
+
const element = pageContentRef.current;
|
|
171
|
+
if (!element || !keyboardFrame.avoidsContent || !keyboardFrame.visible) return;
|
|
172
|
+
const timer = window.setTimeout(() => {
|
|
173
|
+
const field = document.activeElement;
|
|
174
|
+
if (!(field instanceof HTMLElement) || !element.contains(field)) return;
|
|
175
|
+
const rect = field.getBoundingClientRect();
|
|
176
|
+
if (rect.bottom > element.getBoundingClientRect().bottom || rect.top < 0)
|
|
177
|
+
field.scrollIntoView({ block: "nearest", behavior: "smooth" });
|
|
178
|
+
}, keyboardFrame.animationDuration ?? 0);
|
|
179
|
+
return () => window.clearTimeout(timer);
|
|
180
|
+
}, [pageContentRef, keyboardFrame.avoidsContent, keyboardFrame.visible, keyboardFrame.animationDuration]);
|
|
181
|
+
};
|
|
@@ -42,21 +42,39 @@ const tween = (progress: Progress, from: number, to: number) => progress.to([0,
|
|
|
42
42
|
const fadeIn = (progress: Progress) => ({ opacity: progress.to((value) => value) });
|
|
43
43
|
const fadeOut = (progress: Progress) => ({ opacity: progress.to((value) => 1 - value) });
|
|
44
44
|
|
|
45
|
+
const isKeyboardOverContent = ({ keyboard }: RouteState["frameLayout"]) =>
|
|
46
|
+
!!keyboard.avoidsContent && keyboard.visible && !keyboard.sticky;
|
|
47
|
+
|
|
48
|
+
const chromePadding = (pageState: FramePageState, top: number, bottom: number) => ({
|
|
49
|
+
paddingTop: pageState.overlay?.top ? 0 : top,
|
|
50
|
+
paddingBottom: pageState.overlay?.bottom ? 0 : bottom,
|
|
51
|
+
"--akan-overlay-top": `${pageState.overlay?.top ? top : 0}px`,
|
|
52
|
+
"--akan-overlay-bottom": `${pageState.overlay?.bottom ? bottom : 0}px`,
|
|
53
|
+
});
|
|
54
|
+
|
|
45
55
|
const pageContentStyle = ({ frameLayout }: RouteState, pageState: FramePageState) => ({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
pageState.
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
56
|
+
...chromePadding(
|
|
57
|
+
pageState,
|
|
58
|
+
pageState.topSafeArea + pageState.topInset,
|
|
59
|
+
isKeyboardOverContent(frameLayout)
|
|
60
|
+
? 0
|
|
61
|
+
: Math.max(
|
|
62
|
+
pageState.bottomSafeArea,
|
|
63
|
+
pageState.bottomInset +
|
|
64
|
+
pageState.bottomSafeArea -
|
|
65
|
+
(frameLayout.keyboard.sticky ? frameLayout.keyboardAccessory.height : 0),
|
|
66
|
+
),
|
|
52
67
|
),
|
|
53
68
|
height: frameLayout.contentViewport.height,
|
|
54
69
|
"--akan-content-height": `${frameLayout.contentViewport.height}px`,
|
|
55
70
|
});
|
|
56
71
|
|
|
57
72
|
const prevPageContentStyle = (clientHeight: number, prevPageState: FramePageState) => ({
|
|
58
|
-
|
|
59
|
-
|
|
73
|
+
...chromePadding(
|
|
74
|
+
prevPageState,
|
|
75
|
+
prevPageState.topSafeArea + prevPageState.topInset,
|
|
76
|
+
prevPageState.bottomInset + prevPageState.bottomSafeArea,
|
|
77
|
+
),
|
|
60
78
|
height: clientHeight,
|
|
61
79
|
});
|
|
62
80
|
|
|
@@ -167,7 +185,7 @@ const useNoneTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
167
185
|
},
|
|
168
186
|
prevPage: {
|
|
169
187
|
containerStyle: {
|
|
170
|
-
paddingTop: prevPageState.topSafeArea + prevPageState.topInset,
|
|
188
|
+
paddingTop: prevPageState.overlay?.top ? 0 : prevPageState.topSafeArea + prevPageState.topInset,
|
|
171
189
|
},
|
|
172
190
|
contentStyle: { opacity: 0 },
|
|
173
191
|
},
|
package/webkit/useCsrValues.ts
CHANGED
|
@@ -224,14 +224,20 @@ export const useCsrValues = (rootRouteGuide: RouteGuide, pathRoutes: PathRoute[]
|
|
|
224
224
|
const useCsrTransitionMap = useCsrTransitions(routeState);
|
|
225
225
|
|
|
226
226
|
const contentResizeStyle = useMemo(() => {
|
|
227
|
-
if (!shouldAnchorContentBottom || !keyboardFrame.sticky) return null;
|
|
227
|
+
if (!keyboardFrame.avoidsContent && (!shouldAnchorContentBottom || !keyboardFrame.sticky)) return null;
|
|
228
228
|
const duration = keyboardFrame.animationDuration ?? 420;
|
|
229
229
|
const easing = keyboardFrame.animationEasing ?? "cubic-bezier(0.16, 1, 0.3, 1)";
|
|
230
230
|
return {
|
|
231
231
|
transition: `height ${duration}ms ${easing}, padding-bottom ${duration}ms ${easing}`,
|
|
232
232
|
willChange: "height, padding-bottom",
|
|
233
233
|
};
|
|
234
|
-
}, [
|
|
234
|
+
}, [
|
|
235
|
+
shouldAnchorContentBottom,
|
|
236
|
+
keyboardFrame.sticky,
|
|
237
|
+
keyboardFrame.avoidsContent,
|
|
238
|
+
keyboardFrame.animationDuration,
|
|
239
|
+
keyboardFrame.animationEasing,
|
|
240
|
+
]);
|
|
235
241
|
const csrTransition = useCsrTransitionMap[resolvedLocation.pathRoute.pageState.transition];
|
|
236
242
|
const page: PageTransition | null =
|
|
237
243
|
contentResizeStyle && csrTransition.page
|
|
@@ -20,6 +20,8 @@ import {
|
|
|
20
20
|
import { st } from "akanjs/store";
|
|
21
21
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
22
22
|
|
|
23
|
+
import { isPageKeyboardAvoidance } from "./useVisualViewportFrame";
|
|
24
|
+
|
|
23
25
|
export type FrameSlotMap = Record<string, Record<string, FrameSlotRegistration>>;
|
|
24
26
|
export type FrameSlotBucket = "active" | "pending";
|
|
25
27
|
export type FrameSlotMapByBucket = Record<FrameSlotBucket, FrameSlotMap>;
|
|
@@ -30,6 +32,8 @@ export const KEYBOARD_HIDE_ANIMATION_DURATION_MS = 90;
|
|
|
30
32
|
export const KEYBOARD_SHOW_ANIMATION_EASING = "cubic-bezier(0.16, 1, 0.3, 1)";
|
|
31
33
|
export const KEYBOARD_HIDE_ANIMATION_EASING = "cubic-bezier(0.7, 0, 0.84, 0)";
|
|
32
34
|
|
|
35
|
+
export const IOS_KEYBOARD_ANIMATION_EASING = "cubic-bezier(0.38, 0.7, 0.125, 1)";
|
|
36
|
+
|
|
33
37
|
export const FRAME_Z_INDEX = {
|
|
34
38
|
page: 10,
|
|
35
39
|
previousPage: 0,
|
|
@@ -158,6 +162,14 @@ const getCurrentPlatform = () => {
|
|
|
158
162
|
}
|
|
159
163
|
};
|
|
160
164
|
|
|
165
|
+
const keyboardAnimationMs = () => {
|
|
166
|
+
try {
|
|
167
|
+
return Device.getDevice().keyboardAnimationMs;
|
|
168
|
+
} catch {
|
|
169
|
+
return 0;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
161
173
|
export function getFramePlatformProfile(): FramePlatformProfile {
|
|
162
174
|
const platform = getCurrentPlatform();
|
|
163
175
|
if (platform === "ios") return "ios";
|
|
@@ -260,6 +272,8 @@ export function resolveKeyboardFrame({
|
|
|
260
272
|
platformProfile,
|
|
261
273
|
sticky,
|
|
262
274
|
freeze,
|
|
275
|
+
pageAvoidsKeyboard = false,
|
|
276
|
+
nativeAnimationDuration = 0,
|
|
263
277
|
}: {
|
|
264
278
|
keyboardHeight: number;
|
|
265
279
|
bottomSafeArea: number;
|
|
@@ -267,6 +281,8 @@ export function resolveKeyboardFrame({
|
|
|
267
281
|
platformProfile: FramePlatformProfile;
|
|
268
282
|
sticky: boolean;
|
|
269
283
|
freeze?: boolean;
|
|
284
|
+
pageAvoidsKeyboard?: boolean;
|
|
285
|
+
nativeAnimationDuration?: number;
|
|
270
286
|
}): KeyboardFrameState {
|
|
271
287
|
const useVisualViewportHeight = platformProfile === "android" && visualViewportKeyboardHeight > 0;
|
|
272
288
|
const visualFallbackHeight =
|
|
@@ -289,6 +305,8 @@ export function resolveKeyboardFrame({
|
|
|
289
305
|
: 0;
|
|
290
306
|
const offset = sticky && !freeze ? Math.max(0, effectiveKeyboardHeight - visualCompensation) : 0;
|
|
291
307
|
const isShowing = effectiveKeyboardHeight > 0 && !freeze;
|
|
308
|
+
const avoidsContent = platformProfile === "ios" && pageAvoidsKeyboard;
|
|
309
|
+
const followsKeyboard = avoidsContent && nativeAnimationDuration > 0;
|
|
292
310
|
return {
|
|
293
311
|
height: effectiveKeyboardHeight,
|
|
294
312
|
offset,
|
|
@@ -296,8 +314,17 @@ export function resolveKeyboardFrame({
|
|
|
296
314
|
sticky,
|
|
297
315
|
frozen: freeze,
|
|
298
316
|
source,
|
|
299
|
-
animationDuration:
|
|
300
|
-
|
|
317
|
+
animationDuration: followsKeyboard
|
|
318
|
+
? nativeAnimationDuration
|
|
319
|
+
: isShowing
|
|
320
|
+
? KEYBOARD_SHOW_ANIMATION_DURATION_MS
|
|
321
|
+
: KEYBOARD_HIDE_ANIMATION_DURATION_MS,
|
|
322
|
+
animationEasing: followsKeyboard
|
|
323
|
+
? IOS_KEYBOARD_ANIMATION_EASING
|
|
324
|
+
: isShowing
|
|
325
|
+
? KEYBOARD_SHOW_ANIMATION_EASING
|
|
326
|
+
: KEYBOARD_HIDE_ANIMATION_EASING,
|
|
327
|
+
avoidsContent,
|
|
301
328
|
};
|
|
302
329
|
}
|
|
303
330
|
|
|
@@ -324,7 +351,11 @@ export function resolveKeyboardLayout({
|
|
|
324
351
|
visible: keyboard.sticky && resolvedAccessoryHeight > 0,
|
|
325
352
|
slotHeight: accessoryHeight,
|
|
326
353
|
};
|
|
327
|
-
const contentBottom = keyboard.sticky
|
|
354
|
+
const contentBottom = keyboard.sticky
|
|
355
|
+
? keyboardAccessory.top
|
|
356
|
+
: keyboard.avoidsContent && keyboard.visible
|
|
357
|
+
? Math.max(0, viewport.height - keyboard.height)
|
|
358
|
+
: viewport.height;
|
|
328
359
|
if (keyboard.sticky && accessoryHeight <= 0) {
|
|
329
360
|
debugFrame("keyboard.accessoryLayout", {
|
|
330
361
|
reason: "missing-accessory-height",
|
|
@@ -357,6 +388,8 @@ export function useKeyboardFrame({
|
|
|
357
388
|
freeze?: boolean;
|
|
358
389
|
}) {
|
|
359
390
|
const keyboardHeight = st.use.keyboardHeight({ agent: false });
|
|
391
|
+
const pageAvoidsKeyboard = isPageKeyboardAvoidance();
|
|
392
|
+
const nativeAnimationDuration = keyboardAnimationMs();
|
|
360
393
|
const androidViewportKeyboardHeight =
|
|
361
394
|
platformProfile === "android" ? Math.max(0, Math.round(viewport.height - window.innerHeight)) : 0;
|
|
362
395
|
const visualViewportKeyboardHeight = Math.max(
|
|
@@ -374,8 +407,19 @@ export function useKeyboardFrame({
|
|
|
374
407
|
platformProfile,
|
|
375
408
|
sticky,
|
|
376
409
|
freeze,
|
|
410
|
+
pageAvoidsKeyboard,
|
|
411
|
+
nativeAnimationDuration,
|
|
377
412
|
}),
|
|
378
|
-
[
|
|
413
|
+
[
|
|
414
|
+
keyboardHeight,
|
|
415
|
+
bottomSafeArea,
|
|
416
|
+
visualViewportKeyboardHeight,
|
|
417
|
+
platformProfile,
|
|
418
|
+
sticky,
|
|
419
|
+
freeze,
|
|
420
|
+
pageAvoidsKeyboard,
|
|
421
|
+
nativeAnimationDuration,
|
|
422
|
+
],
|
|
379
423
|
);
|
|
380
424
|
}
|
|
381
425
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { Device } from "akanjs/client";
|
|
2
3
|
import { useEffect, useState } from "react";
|
|
3
4
|
|
|
4
5
|
export interface VisualViewportFrame {
|
|
@@ -9,6 +10,18 @@ export interface VisualViewportFrame {
|
|
|
9
10
|
offsetTop: number;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
/** Whether the iOS shell left the keyboard to the page; an older shell still pans to the field, so the page must not. */
|
|
14
|
+
export const isPageKeyboardAvoidance = () =>
|
|
15
|
+
(globalThis as { __AKAN_NATIVE__?: { keyboardAvoidance?: string } }).__AKAN_NATIVE__?.keyboardAvoidance === "page";
|
|
16
|
+
|
|
17
|
+
const currentDevice = () => {
|
|
18
|
+
try {
|
|
19
|
+
return Device.getDevice();
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
12
25
|
const closedFrame = (): VisualViewportFrame => ({
|
|
13
26
|
keyboardHeight: 0,
|
|
14
27
|
height: typeof window === "undefined" ? 0 : window.innerHeight,
|
|
@@ -23,6 +36,19 @@ const closedFrame = (): VisualViewportFrame => ({
|
|
|
23
36
|
export const useVisualViewportFrame = (): VisualViewportFrame => {
|
|
24
37
|
const [frame, setFrame] = useState<VisualViewportFrame>(closedFrame);
|
|
25
38
|
useEffect(() => {
|
|
39
|
+
|
|
40
|
+
if (isPageKeyboardAvoidance()) {
|
|
41
|
+
const device = currentDevice();
|
|
42
|
+
if (!device) return;
|
|
43
|
+
const apply = (keyboardHeight: number) =>
|
|
44
|
+
setFrame(
|
|
45
|
+
keyboardHeight > 0
|
|
46
|
+
? { keyboardHeight, height: window.innerHeight - keyboardHeight, offsetTop: 0 }
|
|
47
|
+
: closedFrame(),
|
|
48
|
+
);
|
|
49
|
+
apply(device.keyboardHeight);
|
|
50
|
+
return device.subscribeKeyboard(apply);
|
|
51
|
+
}
|
|
26
52
|
const viewport = window.visualViewport;
|
|
27
53
|
if (!viewport) return;
|
|
28
54
|
const measure = () => {
|