akanjs 3.3.0-rc.3 → 3.3.0-rc.4

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 CHANGED
@@ -8,6 +8,10 @@
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
+
11
15
  ### Patch Changes
12
16
 
13
17
  - 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.
@@ -437,6 +437,8 @@ export interface KeyboardFrameState {
437
437
  source?: "native" | "visualViewport" | "fallback";
438
438
  animationDuration?: number;
439
439
  animationEasing?: string;
440
+ /** The page's content ends at the keyboard, as UIKit's keyboard layout guide does: an iOS shell no longer pans. */
441
+ avoidsContent?: boolean;
440
442
  }
441
443
  export interface FrameContentViewportState {
442
444
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.3",
3
+ "version": "3.3.0-rc.4",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -421,6 +421,8 @@ export interface KeyboardFrameState {
421
421
  source?: "native" | "visualViewport" | "fallback";
422
422
  animationDuration?: number;
423
423
  animationEasing?: string;
424
+ /** The page's content ends at the keyboard, as UIKit's keyboard layout guide does: an iOS shell no longer pans. */
425
+ avoidsContent?: boolean;
424
426
  }
425
427
  export interface FrameContentViewportState {
426
428
  top: number;
@@ -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;
@@ -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> {
@@ -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: import("akanjs/client").KeyboardFrameState;
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
@@ -1,6 +1,12 @@
1
1
  "use client";
2
2
  import { cn, usePage } from "akanjs/client";
3
- import { useBodyScrollLock, useEscapeKey, usePageActivity } from "akanjs/webkit";
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();
@@ -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
 
@@ -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 { applyKeyboard(duration: 0, options: []) }
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";
@@ -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,14 +42,19 @@ 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
+
45
48
  const pageContentStyle = ({ frameLayout }: RouteState, pageState: FramePageState) => ({
46
49
  paddingTop: pageState.topSafeArea + pageState.topInset,
47
- paddingBottom: Math.max(
48
- pageState.bottomSafeArea,
49
- pageState.bottomInset +
50
- pageState.bottomSafeArea -
51
- (frameLayout.keyboard.sticky ? frameLayout.keyboardAccessory.height : 0),
52
- ),
50
+ paddingBottom: isKeyboardOverContent(frameLayout)
51
+ ? 0
52
+ : Math.max(
53
+ pageState.bottomSafeArea,
54
+ pageState.bottomInset +
55
+ pageState.bottomSafeArea -
56
+ (frameLayout.keyboard.sticky ? frameLayout.keyboardAccessory.height : 0),
57
+ ),
53
58
  height: frameLayout.contentViewport.height,
54
59
  "--akan-content-height": `${frameLayout.contentViewport.height}px`,
55
60
  });
@@ -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
- }, [shouldAnchorContentBottom, keyboardFrame.sticky, keyboardFrame.animationDuration, keyboardFrame.animationEasing]);
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: isShowing ? KEYBOARD_SHOW_ANIMATION_DURATION_MS : KEYBOARD_HIDE_ANIMATION_DURATION_MS,
300
- animationEasing: isShowing ? KEYBOARD_SHOW_ANIMATION_EASING : KEYBOARD_HIDE_ANIMATION_EASING,
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 ? keyboardAccessory.top : viewport.height;
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
- [keyboardHeight, bottomSafeArea, visualViewportKeyboardHeight, platformProfile, sticky, freeze],
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 = () => {