akanjs 3.3.0-rc.17 → 3.3.0-rc.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "akanjs",
3
- "version": "3.3.0-rc.17",
3
+ "version": "3.3.0-rc.18",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -0,0 +1,6 @@
1
+ import { type Location } from "akanjs/client";
2
+ export declare class NativeSplash {
3
+ #private;
4
+ static readonly drawTimeoutMs = 4000;
5
+ static hideOnceDrawn(location: Location): () => void;
6
+ }
@@ -4,6 +4,7 @@ export type FrameSlotBucket = "active" | "pending";
4
4
  export type FrameSlotMapByBucket = Record<FrameSlotBucket, FrameSlotMap>;
5
5
  export declare const PENDING_FRAME_READY_TIMEOUT_MS = 80;
6
6
  export declare const PENDING_FRAME_READY_MAX_TIMEOUT_MS = 120;
7
+ export declare const STACK_TRANSITION_DURATION_MS = 350;
7
8
  export declare const KEYBOARD_SHOW_ANIMATION_DURATION_MS = 420;
8
9
  export declare const KEYBOARD_HIDE_ANIMATION_DURATION_MS = 90;
9
10
  export declare const KEYBOARD_SHOW_ANIMATION_EASING = "cubic-bezier(0.16, 1, 0.3, 1)";
package/ui/System/CSR.tsx CHANGED
@@ -26,6 +26,7 @@ import {
26
26
  useState,
27
27
  } from "react";
28
28
  import { createPortal } from "react-dom";
29
+ import { NativeSplash } from "../../webkit/nativeSplash";
29
30
  import { NativeUpdates } from "../../webkit/nativeUpdates";
30
31
  import { RenderLayer } from "../../webkit/RenderLayer";
31
32
  import { animated } from "../animated";
@@ -435,6 +436,10 @@ const CSRPageContainer = ({ entry, prefix, layoutStyle }: CSRPageContainerProps)
435
436
  useEffect(() => {
436
437
  if (pageType === "current") NativeUpdates.confirm();
437
438
  }, [pageType]);
439
+ useEffect(
440
+ () => (pageType === "current" ? NativeSplash.hideOnceDrawn(location) : undefined),
441
+ [pageType, location.entryId],
442
+ );
438
443
 
439
444
  const [pageContainers, setPageContainers] = useState(() => document.getElementById("pageContainers"));
440
445
  useLayoutEffect(() => {
@@ -0,0 +1,30 @@
1
+ "use client";
2
+ import { debugFrame, type Location } from "akanjs/client";
3
+ import { isNativeShell } from "akanjs/client/native";
4
+ import { splashScreen } from "akanjs/client/native/splash-screen";
5
+ import { CsrPageReadiness } from "./csrPageReadiness";
6
+
7
+ export class NativeSplash {
8
+ static readonly drawTimeoutMs = 4_000;
9
+ static #hidden = false;
10
+
11
+ static hideOnceDrawn(location: Location) {
12
+ if (NativeSplash.#hidden || !isNativeShell() || !splashScreen.isSupported("hide")) return () => undefined;
13
+ const startedAt = Date.now();
14
+ let frame = 0;
15
+ const isDrawn = () =>
16
+ !CsrPageReadiness.drawsLater(location) ||
17
+ CsrPageReadiness.isDrawn(location.entryId) ||
18
+ Date.now() - startedAt >= NativeSplash.drawTimeoutMs;
19
+ const hide = () => {
20
+ NativeSplash.#hidden = true;
21
+ void splashScreen.hide().catch((error: unknown) => debugFrame("splash.hide.failed", { error: String(error) }));
22
+ };
23
+
24
+ const check = () => {
25
+ frame = requestAnimationFrame(isDrawn() ? hide : check);
26
+ };
27
+ frame = requestAnimationFrame(check);
28
+ return () => cancelAnimationFrame(frame);
29
+ }
30
+ }
@@ -136,12 +136,16 @@ const commitWhenFrameReady = ({
136
136
  const waitUntilReady = () => {
137
137
  if (pendingNavigation.current !== intent) return;
138
138
  const elapsedMs = Date.now() - intent.createdAt;
139
- const ready = isPendingFrameReady({
139
+ const isFrameReady = isPendingFrameReady({
140
140
  path: toLocation.pathRoute.path,
141
141
  pendingFrameSlots: latestPendingFrameSlots.current,
142
142
  elapsedMs,
143
143
  });
144
- if (ready) {
144
+ const isDrawn =
145
+ !CsrPageReadiness.drawsLater(toLocation) ||
146
+ CsrPageReadiness.isDrawn(toLocation.entryId) ||
147
+ elapsedMs >= PAGE_DRAWN_TIMEOUT_MS;
148
+ if (isFrameReady && isDrawn) {
145
149
  void commitNavigation(elapsedMs >= PENDING_FRAME_READY_TIMEOUT_MS);
146
150
  return;
147
151
  }
@@ -11,10 +11,13 @@ import {
11
11
  type UseCsrTransition,
12
12
  } from "akanjs/client";
13
13
  import { clamp } from "akanjs/common";
14
- import { useCallback, useEffect, useMemo, useRef } from "react";
14
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react";
15
+ import { STACK_TRANSITION_DURATION_MS } from "./useFrameRuntime";
15
16
 
16
17
  const linearEasing = (t: number) => t;
17
18
 
19
+ const stackEasing = (t: number) => 1 - (1 - t) ** 4;
20
+
18
21
  const getBottomInsetTop = (clientHeight: number, pageState: PathRoute["pageState"]) =>
19
22
  clientHeight - pageState.bottomInset - pageState.bottomSafeArea;
20
23
 
@@ -154,7 +157,8 @@ const usePlayOnForward = (
154
157
  { history, location }: RouteState,
155
158
  config: { duration: number; easing?: (t: number) => number },
156
159
  ) => {
157
- useEffect(() => {
160
+
161
+ useLayoutEffect(() => {
158
162
  if (history.current.type === "forward") {
159
163
  void transUnit.start(transUnitRange[0], { immediate: true });
160
164
  void transUnit.start(transUnitRange[1], { config });
@@ -390,7 +394,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
390
394
  };
391
395
  }, [transUnitRange]);
392
396
  useEffect(() => unlockPageScroll, [unlockPageScroll]);
393
- usePlayOnForward(spring, routeState, { duration: 150 });
397
+ usePlayOnForward(spring, routeState, { duration: STACK_TRANSITION_DURATION_MS, easing: stackEasing });
394
398
 
395
399
  const pageBind = useDrag(
396
400
  ({ first, last, movement: [mx, my], velocity: [vx], direction: [dx], initial: [ix], cancel }) => {
@@ -28,6 +28,7 @@ export type FrameSlotBucket = "active" | "pending";
28
28
  export type FrameSlotMapByBucket = Record<FrameSlotBucket, FrameSlotMap>;
29
29
  export const PENDING_FRAME_READY_TIMEOUT_MS = 80;
30
30
  export const PENDING_FRAME_READY_MAX_TIMEOUT_MS = 120;
31
+ export const STACK_TRANSITION_DURATION_MS = 350;
31
32
  export const KEYBOARD_SHOW_ANIMATION_DURATION_MS = 420;
32
33
  export const KEYBOARD_HIDE_ANIMATION_DURATION_MS = 90;
33
34
  export const KEYBOARD_SHOW_ANIMATION_EASING = "cubic-bezier(0.16, 1, 0.3, 1)";
@@ -561,7 +562,8 @@ export function createFrameSnapshot({
561
562
  const getTransitionDuration = (type: TransitionType) => {
562
563
  if (typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)")?.matches) return 1;
563
564
  if (type === "bottomUp" || type === "scaleOut") return 220;
564
- if (type === "fade" || type === "stack") return 150;
565
+ if (type === "stack") return STACK_TRANSITION_DURATION_MS;
566
+ if (type === "fade") return 150;
565
567
  return 0;
566
568
  };
567
569