akanjs 3.3.0-rc.21 → 3.3.0-rc.23

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.21",
3
+ "version": "3.3.0-rc.23",
4
4
  "sourceType": "module",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -34,6 +34,8 @@ export declare class NativeNavigation {
34
34
  openDeepLink(url: string): void;
35
35
  openPushLink(url: unknown): void;
36
36
  back(): void;
37
+ /** The frame's word that a move was sent back to the page on screen before it showed, as a refusing guard does. */
38
+ static turnedBack(): void;
37
39
  static isMacBackKey({ key, metaKey, altKey, ctrlKey, shiftKey, }: Pick<KeyboardEvent, "key" | "metaKey" | "altKey" | "ctrlKey" | "shiftKey">): boolean;
38
40
  }
39
41
  export {};
@@ -27,6 +27,9 @@ interface NativeNavigationOptions {
27
27
 
28
28
  /** A native shell's deep links, push taps and Android back button, for the CSR frame that owns the history. */
29
29
  export class NativeNavigation {
30
+
31
+ static #fallingBack: { navigation: NativeNavigation; path: string; navigations: number; redirects: number } | null =
32
+ null;
30
33
  #mountedAt = Date.now();
31
34
  #handled: { href: string; handledAt: number } | null = null;
32
35
  #didResetStack = false;
@@ -95,6 +98,7 @@ export class NativeNavigation {
95
98
  * is history, or the index is still to come. Otherwise the system takes it and shows its own back-to-home animation.
96
99
  */
97
100
  syncBack(force = false) {
101
+ this.#leaveIfSentBack();
98
102
  if (!isNativeApp() || !app.isSupported("setBackEnabled")) return;
99
103
  const backState = this.options.backState();
100
104
  const enabled =
@@ -155,6 +159,31 @@ export class NativeNavigation {
155
159
  return;
156
160
  }
157
161
  clientRouter.backOrFallback(window.__AKAN_MOBILE_TARGET__?.indexPath ?? "/", { scrollToTop: false });
162
+ NativeNavigation.#fallingBack = {
163
+ navigation: this,
164
+ path: backState.path,
165
+ navigations: clientRouter.navigationCount(),
166
+ redirects: clientRouter.redirectCount(),
167
+ };
168
+ }
169
+
170
+ /** The frame's word that a move was sent back to the page on screen before it showed, as a refusing guard does. */
171
+ static turnedBack() {
172
+ const fallingBack = NativeNavigation.#fallingBack;
173
+ if (fallingBack) fallingBack.navigation.#leaveIfSentBack();
174
+ }
175
+
176
+ #leaveIfSentBack() {
177
+ const fallingBack = NativeNavigation.#fallingBack;
178
+ if (fallingBack?.navigation !== this) return;
179
+ const redirects = clientRouter.redirectCount() - fallingBack.redirects;
180
+ if (clientRouter.navigationCount() - fallingBack.navigations !== redirects) {
181
+ NativeNavigation.#fallingBack = null;
182
+ return;
183
+ }
184
+ if (!redirects || this.options.historyIdx() > 0 || this.options.backState().path !== fallingBack.path) return;
185
+ NativeNavigation.#fallingBack = null;
186
+ void app.exit().catch(() => undefined);
158
187
  }
159
188
 
160
189
  #leavesApp(path: string) {
@@ -405,7 +405,9 @@ const useStackSlide = (
405
405
  }, [transUnitRange]);
406
406
  useLayoutEffect(() => {
407
407
  cancelSlide();
408
- if (history.current.type !== "forward" || CsrSlide.isCalm) {
408
+
409
+ const isStack = frameRef.current.pageState.transition === "stack";
410
+ if (history.current.type !== "forward" || CsrSlide.isCalm || !isStack) {
409
411
  void transUnit.start(transUnitRange[1], { immediate: true });
410
412
  return;
411
413
  }
@@ -18,6 +18,7 @@ import {
18
18
  import { isNativeApp, openExternalUrl } from "akanjs/client/native";
19
19
  import { useCallback, useMemo, useState } from "react";
20
20
  import { CsrRefresh } from "./csrRefresh";
21
+ import { NativeNavigation } from "./nativeNavigation";
21
22
  import { useCsrKeyboard } from "./useCsrKeyboard";
22
23
  import { type CsrLocationState, useCsrLocationState } from "./useCsrLocationState";
23
24
  import { type CsrNavigation, useCsrNavigation } from "./useCsrNavigation";
@@ -66,6 +67,7 @@ const useCsrRouter = ({
66
67
 
67
68
  const cancelled: NavigationIntent | null = cancelPendingNavigation();
68
69
  if (location.href === href) {
70
+ if (cancelled) NativeNavigation.turnedBack();
69
71
  if (!pageContentRef.current) return;
70
72
  pageContentRef.current.scrollTop = getScrollTop(location);
71
73
  return;