@onekeyfe/react-native-native-overlay 6.8.0-alpha.514 → 6.8.0-alpha.539

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.
Files changed (79) hide show
  1. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayHost.kt +37 -5
  2. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPackage.kt +1 -1
  3. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastCardView.kt +869 -0
  4. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastSpec.kt +327 -0
  5. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterView.kt +574 -0
  6. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterViewManager.kt +54 -0
  7. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayAccessibilityIsolationTest.kt +172 -0
  8. package/docs/SPEC.md +172 -11
  9. package/ios/NativeOverlayContainerView.swift +20 -4
  10. package/ios/NativeOverlayToastCardView.swift +572 -0
  11. package/ios/NativeOverlayToastSpec.swift +356 -0
  12. package/ios/NativeOverlayToasterView.swift +519 -0
  13. package/ios/RCTNativeOverlayToasterComponentView.h +11 -0
  14. package/ios/RCTNativeOverlayToasterComponentView.mm +85 -0
  15. package/lib/module/NativeOverlayToasterNativeComponent.ts +24 -0
  16. package/lib/module/OverlayStore.js +20 -3
  17. package/lib/module/OverlayStore.js.map +1 -1
  18. package/lib/module/OverlayView.web.js +9 -18
  19. package/lib/module/OverlayView.web.js.map +1 -1
  20. package/lib/module/index.js +2 -0
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/toast/OverlayToastHost.js +42 -0
  23. package/lib/module/toast/OverlayToastHost.js.map +1 -0
  24. package/lib/module/toast/OverlayToastHost.web.js +32 -0
  25. package/lib/module/toast/OverlayToastHost.web.js.map +1 -0
  26. package/lib/module/toast/OverlayToastStore.js +217 -0
  27. package/lib/module/toast/OverlayToastStore.js.map +1 -0
  28. package/lib/module/toast/toastBridge.js +65 -0
  29. package/lib/module/toast/toastBridge.js.map +1 -0
  30. package/lib/module/toast/toastDomContent.web.js +298 -0
  31. package/lib/module/toast/toastDomContent.web.js.map +1 -0
  32. package/lib/module/toast/toastDomRenderer.web.js +695 -0
  33. package/lib/module/toast/toastDomRenderer.web.js.map +1 -0
  34. package/lib/module/toast/toastStyles.web.js +97 -0
  35. package/lib/module/toast/toastStyles.web.js.map +1 -0
  36. package/lib/module/toast/types.js +2 -0
  37. package/lib/module/toast/types.js.map +1 -0
  38. package/lib/module/web/overlayLayers.js +82 -0
  39. package/lib/module/web/overlayLayers.js.map +1 -1
  40. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts +19 -0
  41. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts.map +1 -0
  42. package/lib/typescript/src/OverlayStore.d.ts +8 -1
  43. package/lib/typescript/src/OverlayStore.d.ts.map +1 -1
  44. package/lib/typescript/src/OverlayView.web.d.ts.map +1 -1
  45. package/lib/typescript/src/index.d.ts +4 -0
  46. package/lib/typescript/src/index.d.ts.map +1 -1
  47. package/lib/typescript/src/toast/OverlayToastHost.d.ts +6 -0
  48. package/lib/typescript/src/toast/OverlayToastHost.d.ts.map +1 -0
  49. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts +6 -0
  50. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts.map +1 -0
  51. package/lib/typescript/src/toast/OverlayToastStore.d.ts +47 -0
  52. package/lib/typescript/src/toast/OverlayToastStore.d.ts.map +1 -0
  53. package/lib/typescript/src/toast/toastBridge.d.ts +11 -0
  54. package/lib/typescript/src/toast/toastBridge.d.ts.map +1 -0
  55. package/lib/typescript/src/toast/toastDomContent.web.d.ts +15 -0
  56. package/lib/typescript/src/toast/toastDomContent.web.d.ts.map +1 -0
  57. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts +8 -0
  58. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts.map +1 -0
  59. package/lib/typescript/src/toast/toastStyles.web.d.ts +2 -0
  60. package/lib/typescript/src/toast/toastStyles.web.d.ts.map +1 -0
  61. package/lib/typescript/src/toast/types.d.ts +240 -0
  62. package/lib/typescript/src/toast/types.d.ts.map +1 -0
  63. package/lib/typescript/src/web/overlayLayers.d.ts +2 -0
  64. package/lib/typescript/src/web/overlayLayers.d.ts.map +1 -1
  65. package/package.json +3 -2
  66. package/react-native.config.js +1 -0
  67. package/src/NativeOverlayToasterNativeComponent.ts +24 -0
  68. package/src/OverlayStore.ts +35 -4
  69. package/src/OverlayView.web.tsx +10 -11
  70. package/src/index.ts +23 -0
  71. package/src/toast/OverlayToastHost.tsx +62 -0
  72. package/src/toast/OverlayToastHost.web.tsx +29 -0
  73. package/src/toast/OverlayToastStore.ts +254 -0
  74. package/src/toast/toastBridge.ts +62 -0
  75. package/src/toast/toastDomContent.web.ts +351 -0
  76. package/src/toast/toastDomRenderer.web.ts +856 -0
  77. package/src/toast/toastStyles.web.ts +97 -0
  78. package/src/toast/types.ts +251 -0
  79. package/src/web/overlayLayers.ts +114 -0
@@ -0,0 +1,97 @@
1
+ /* cspell:ignore Neue Noto */
2
+ // The web toaster chrome. These declarations replicate sonner@1.4.41's
3
+ // default stylesheet (the renderer this replaces) one for one: same custom
4
+ // properties, same values, same transitions and breakpoints, so the migration
5
+ // is visually a no-op. Attribute names are ours so nothing else can target the
6
+ // old library's nodes.
7
+ const STYLE_ID = 'onekey-overlay-toast-styles';
8
+
9
+ const CSS = `
10
+ :where(html[dir="ltr"]),:where([data-onekey-toast-toaster][dir="ltr"]){--toast-close-button-start:0;--toast-close-button-end:unset;--toast-close-button-transform:translate(-35%, -35%)}
11
+ :where(html[dir="rtl"]),:where([data-onekey-toast-toaster][dir="rtl"]){--toast-close-button-start:unset;--toast-close-button-end:0;--toast-close-button-transform:translate(35%, -35%)}
12
+ :where([data-onekey-toast-toaster]){position:fixed;width:var(--width);font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol,Noto Color Emoji;--gray1:hsl(0, 0%, 99%);--gray2:hsl(0, 0%, 97.3%);--gray3:hsl(0, 0%, 95.1%);--gray4:hsl(0, 0%, 93%);--gray5:hsl(0, 0%, 90.9%);--gray6:hsl(0, 0%, 88.7%);--gray7:hsl(0, 0%, 85.8%);--gray8:hsl(0, 0%, 78%);--gray9:hsl(0, 0%, 56.1%);--gray10:hsl(0, 0%, 52.3%);--gray11:hsl(0, 0%, 43.5%);--gray12:hsl(0, 0%, 9%);--border-radius:8px;box-sizing:border-box;padding:0;margin:0;list-style:none;outline:none;z-index:0}
13
+ :where([data-onekey-toast-toaster][data-x-position="right"]){right:max(var(--offset),env(safe-area-inset-right))}
14
+ :where([data-onekey-toast-toaster][data-x-position="left"]){left:max(var(--offset),env(safe-area-inset-left))}
15
+ :where([data-onekey-toast-toaster][data-x-position="center"]){left:50%;transform:translate(-50%)}
16
+ :where([data-onekey-toast-toaster][data-y-position="top"]){top:max(var(--offset),env(safe-area-inset-top))}
17
+ :where([data-onekey-toast-toaster][data-y-position="bottom"]){bottom:max(var(--offset),env(safe-area-inset-bottom))}
18
+ :where([data-onekey-toast]){--y:translateY(100%);--lift-amount:calc(var(--lift) * var(--gap));z-index:var(--z-index);position:absolute;opacity:0;transform:var(--y);filter:blur(0);touch-action:none;transition:transform .4s,opacity .4s,height .4s,box-shadow .2s;box-sizing:border-box;outline:none;overflow-wrap:anywhere}
19
+ :where([data-onekey-toast][data-styled="true"]){padding:16px;background:var(--normal-bg);border:1px solid var(--normal-border);color:var(--normal-text);border-radius:var(--border-radius);box-shadow:0 4px 12px #0000001a;width:var(--width);font-size:13px;display:flex;align-items:center;gap:6px}
20
+ :where([data-onekey-toast]:focus-visible){box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}
21
+ :where([data-onekey-toast][data-y-position="top"]){top:0;--y:translateY(-100%);--lift:1;--lift-amount:calc(1 * var(--gap))}
22
+ :where([data-onekey-toast][data-y-position="bottom"]){bottom:0;--y:translateY(100%);--lift:-1;--lift-amount:calc(var(--lift) * var(--gap))}
23
+ :where([data-onekey-toast]) :where([data-close-button]){position:absolute;left:var(--toast-close-button-start);right:var(--toast-close-button-end);top:0;height:20px;width:20px;display:flex;justify-content:center;align-items:center;padding:0;background:var(--gray1);color:var(--gray12);border:1px solid var(--gray4);transform:var(--toast-close-button-transform);border-radius:50%;cursor:pointer;z-index:1;transition:opacity .1s,background .2s,border-color .2s}
24
+ :where([data-onekey-toast]) :where([data-close-button]):focus-visible{box-shadow:0 4px 12px #0000001a,0 0 0 2px #0003}
25
+ :where([data-onekey-toast]):hover :where([data-close-button]):hover{background:var(--gray2);border-color:var(--gray5)}
26
+ :where([data-onekey-toast][data-swiping="true"]):before{content:"";position:absolute;left:0;right:0;height:100%;z-index:-1}
27
+ :where([data-onekey-toast][data-y-position="top"][data-swiping="true"]):before{bottom:50%;transform:scaleY(3) translateY(50%)}
28
+ :where([data-onekey-toast][data-y-position="bottom"][data-swiping="true"]):before{top:50%;transform:scaleY(3) translateY(-50%)}
29
+ :where([data-onekey-toast][data-swiping="false"][data-removed="true"]):before{content:"";position:absolute;inset:0;transform:scaleY(2)}
30
+ :where([data-onekey-toast]):after{content:"";position:absolute;left:0;height:calc(var(--gap) + 1px);bottom:100%;width:100%}
31
+ :where([data-onekey-toast][data-mounted="true"]){--y:translateY(0);opacity:1}
32
+ :where([data-onekey-toast][data-expanded="false"][data-front="false"]){--scale: var(--toasts-before) * .05 + 1;--y:translateY(calc(var(--lift-amount) * var(--toasts-before))) scale(calc(-1 * var(--scale)));height:var(--front-toast-height)}
33
+ :where([data-onekey-toast])>*{transition:opacity .4s}
34
+ :where([data-onekey-toast][data-expanded="false"][data-front="false"][data-styled="true"])>*{opacity:0}
35
+ :where([data-onekey-toast][data-visible="false"]){opacity:0;pointer-events:none}
36
+ :where([data-onekey-toast][data-mounted="true"][data-expanded="true"]){--y:translateY(calc(var(--lift) * var(--offset)));height:var(--initial-height)}
37
+ :where([data-onekey-toast][data-removed="true"][data-front="true"][data-swipe-out="false"]){--y:translateY(calc(var(--lift) * -100%));opacity:0}
38
+ :where([data-onekey-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="true"]){--y:translateY(calc(var(--lift) * var(--offset) + var(--lift) * -100%));opacity:0}
39
+ :where([data-onekey-toast][data-removed="true"][data-front="false"][data-swipe-out="false"][data-expanded="false"]){--y:translateY(40%);opacity:0;transition:transform .5s,opacity .2s}
40
+ :where([data-onekey-toast][data-removed="true"][data-front="false"]):before{height:calc(var(--initial-height) + 20%)}
41
+ [data-onekey-toast][data-swiping="true"]{transform:var(--y) translateY(var(--swipe-amount,0px));transition:none}
42
+ [data-onekey-toast][data-swipe-out="true"][data-y-position="bottom"],[data-onekey-toast][data-swipe-out="true"][data-y-position="top"]{animation:onekey-toast-swipe-out .2s ease-out forwards}
43
+ @keyframes onekey-toast-swipe-out{0%{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount)));opacity:1}to{transform:translateY(calc(var(--lift) * var(--offset) + var(--swipe-amount) + var(--lift) * -100%));opacity:0}}
44
+ @media (max-width:600px){[data-onekey-toast-toaster]{position:fixed;--mobile-offset:16px;right:var(--mobile-offset);left:var(--mobile-offset);width:100%}[data-onekey-toast-toaster] [data-onekey-toast]{left:0;right:0;width:calc(100% - var(--mobile-offset) * 2)}[data-onekey-toast-toaster][data-x-position="left"]{left:var(--mobile-offset)}[data-onekey-toast-toaster][data-y-position="bottom"]{bottom:20px}[data-onekey-toast-toaster][data-y-position="top"]{top:20px}[data-onekey-toast-toaster][data-x-position="center"]{left:var(--mobile-offset);right:var(--mobile-offset);transform:none}}
45
+ [data-onekey-toast-toaster][data-theme="light"]{--normal-bg:#fff;--normal-border:var(--gray4);--normal-text:var(--gray12);--success-bg:hsl(143, 85%, 96%);--success-border:hsl(145, 92%, 91%);--success-text:hsl(140, 100%, 27%);--info-bg:hsl(208, 100%, 97%);--info-border:hsl(221, 91%, 91%);--info-text:hsl(210, 92%, 45%);--warning-bg:hsl(49, 100%, 97%);--warning-border:hsl(49, 91%, 91%);--warning-text:hsl(31, 92%, 45%);--error-bg:hsl(359, 100%, 97%);--error-border:hsl(359, 100%, 94%);--error-text:hsl(360, 100%, 45%)}
46
+ [data-onekey-toast-toaster][data-theme="light"] [data-onekey-toast][data-invert="true"]{--normal-bg:#000;--normal-border:hsl(0, 0%, 20%);--normal-text:var(--gray1)}
47
+ [data-onekey-toast-toaster][data-theme="dark"] [data-onekey-toast][data-invert="true"]{--normal-bg:#fff;--normal-border:var(--gray3);--normal-text:var(--gray12)}
48
+ [data-onekey-toast-toaster][data-theme="dark"]{--normal-bg:#000;--normal-border:hsl(0, 0%, 20%);--normal-text:var(--gray1);--success-bg:hsl(150, 100%, 6%);--success-border:hsl(147, 100%, 12%);--success-text:hsl(150, 86%, 65%);--info-bg:hsl(215, 100%, 6%);--info-border:hsl(223, 100%, 12%);--info-text:hsl(216, 87%, 65%);--warning-bg:hsl(64, 100%, 6%);--warning-border:hsl(60, 100%, 12%);--warning-text:hsl(46, 87%, 65%);--error-bg:hsl(358, 76%, 10%);--error-border:hsl(357, 89%, 16%);--error-text:hsl(358, 100%, 81%)}
49
+ [data-rich-colors="true"] [data-onekey-toast][data-type="success"],[data-rich-colors="true"] [data-onekey-toast][data-type="success"] [data-close-button]{background:var(--success-bg);border-color:var(--success-border);color:var(--success-text)}
50
+ [data-rich-colors="true"] [data-onekey-toast][data-type="info"],[data-rich-colors="true"] [data-onekey-toast][data-type="info"] [data-close-button]{background:var(--info-bg);border-color:var(--info-border);color:var(--info-text)}
51
+ [data-rich-colors="true"] [data-onekey-toast][data-type="warning"],[data-rich-colors="true"] [data-onekey-toast][data-type="warning"] [data-close-button]{background:var(--warning-bg);border-color:var(--warning-border);color:var(--warning-text)}
52
+ [data-rich-colors="true"] [data-onekey-toast][data-type="error"],[data-rich-colors="true"] [data-onekey-toast][data-type="error"] [data-close-button]{background:var(--error-bg);border-color:var(--error-border);color:var(--error-text)}
53
+ @media (prefers-reduced-motion){[data-onekey-toast],[data-onekey-toast]>*{transition:none!important;animation:none!important}}
54
+
55
+ [data-onekey-toast-section]{pointer-events:bounding-box}
56
+ [data-okt-root]{display:flex;flex-direction:column;align-items:stretch;flex:1 1 auto;min-width:0;min-height:0;position:relative;box-sizing:border-box;max-height:var(--okt-max-height,none);overflow:hidden}
57
+ [data-okt-row]{display:flex;flex-direction:row;align-items:stretch;flex-shrink:0;min-width:0;min-height:0;position:relative;box-sizing:border-box}
58
+ [data-okt-col]{display:flex;flex-direction:column;align-items:stretch;flex:1 1 auto;min-width:0;min-height:0;position:relative;box-sizing:border-box}
59
+ [data-okt-icon-box]{display:flex;flex-direction:column;align-items:stretch;flex-shrink:0;position:relative;box-sizing:border-box}
60
+ [data-okt-icon]{display:block;flex-shrink:0}
61
+ [data-okt-badge]{display:flex;flex-direction:row;align-items:center;justify-content:center;flex-shrink:0;border-radius:9999px;box-sizing:border-box}
62
+ [data-okt-paragraphs]{display:flex;flex-direction:column;align-items:stretch;flex-shrink:0;min-width:0;position:relative;box-sizing:border-box}
63
+ [data-okt-text]{display:inline;box-sizing:border-box;margin:0;padding:0;word-wrap:break-word;overflow-wrap:break-word;white-space:pre-wrap;text-transform:none;user-select:none;-webkit-user-select:none}
64
+ [data-okt-paragraphs]>[data-okt-text],[data-okt-col]>[data-okt-text]{display:block}
65
+ [data-okt-text][data-okt-selectable]{user-select:auto;-webkit-user-select:auto}
66
+ [data-okt-text][data-okt-clamp]{display:-webkit-box;-webkit-box-orient:vertical;overflow:hidden;flex-shrink:1}
67
+ [data-okt-link]{cursor:pointer;text-decoration-line:underline}
68
+ [data-okt-link]:hover{background-color:var(--okt-link-hover,transparent)}
69
+ [data-okt-link]:active{background-color:var(--okt-link-active,transparent)}
70
+ [data-okt-actions]{display:flex;flex-direction:row;flex-shrink:0;gap:8px;box-sizing:border-box}
71
+ [data-okt-action]{display:flex;flex-direction:row;align-items:center;justify-content:center;flex-shrink:0;box-sizing:border-box;margin:0;border:0 solid rgba(170,170,170,0);cursor:default;font:inherit;font-variant-numeric:normal;white-space:pre-wrap;outline:none;appearance:none;-webkit-appearance:none;background-color:var(--okt-action-bg);transition:none}
72
+ [data-okt-action]:hover{background-color:var(--okt-action-hover,var(--okt-action-bg))}
73
+ [data-okt-action]:active{background-color:var(--okt-action-active,var(--okt-action-bg))}
74
+ [data-okt-action]:focus-visible{outline:2px solid var(--okt-action-ring,transparent);outline-offset:2px}
75
+ [data-okt-action]:disabled{background-color:var(--okt-action-bg)}
76
+ [data-okt-image]{display:block;flex-shrink:0;object-fit:cover}
77
+ [data-okt-spinner]{display:block;flex-shrink:0;animation:onekey-toast-spin .75s linear infinite}
78
+ @keyframes onekey-toast-spin{0%{transform:rotate(0deg)}to{transform:rotate(360deg)}}
79
+ [data-okt-pressable]{cursor:pointer}
80
+ @media (prefers-reduced-motion){[data-okt-spinner]{animation:none!important}}
81
+ `;
82
+
83
+ let injected = false;
84
+
85
+ export function ensureOverlayToastStyles() {
86
+ if (injected || typeof document === 'undefined') {
87
+ return;
88
+ }
89
+ injected = true;
90
+ if (document.getElementById(STYLE_ID)) {
91
+ return;
92
+ }
93
+ const style = document.createElement('style');
94
+ style.id = STYLE_ID;
95
+ style.appendChild(document.createTextNode(CSS));
96
+ (document.head ?? document.documentElement).appendChild(style);
97
+ }
@@ -0,0 +1,251 @@
1
+ /**
2
+ * The message-toast contract. A toast is plain data: the platform draws the
3
+ * card (DOM on web, UIKit on iOS, Android views on Android) and owns its
4
+ * stacking, timers, gestures and motion. Nothing here is a React node.
5
+ *
6
+ * Every colour is a resolved CSS colour string and every length is in points
7
+ * (CSS px on web), so the package carries no design tokens of its own.
8
+ */
9
+
10
+ /** Where a toast group is anchored. */
11
+ export type IOverlayToastPosition =
12
+ | 'top-left'
13
+ | 'top-center'
14
+ | 'top-right'
15
+ | 'bottom-left'
16
+ | 'bottom-center'
17
+ | 'bottom-right';
18
+
19
+ /** Why a toast left. `programmatic` is a caller's `dismiss`. */
20
+ export type IOverlayToastDismissReason =
21
+ | 'timeout'
22
+ | 'swipe'
23
+ | 'close'
24
+ | 'programmatic';
25
+
26
+ export type IOverlayToastFontWeight = '400' | '500' | '600' | '700';
27
+
28
+ /** One inline run of a paragraph. Unset fields inherit the paragraph. */
29
+ export interface IOverlayToastTextRun {
30
+ text: string;
31
+ color?: string;
32
+ fontWeight?: IOverlayToastFontWeight;
33
+ fontSize?: number;
34
+ underline?: boolean;
35
+ /**
36
+ * Makes the run tappable. The value is opaque to the platform and comes
37
+ * back through `onLink`.
38
+ */
39
+ link?: string;
40
+ }
41
+
42
+ export interface IOverlayToastText {
43
+ /** Paragraphs, each laid out as its own block. */
44
+ paragraphs: IOverlayToastTextRun[][];
45
+ color: string;
46
+ fontSize: number;
47
+ lineHeight: number;
48
+ fontWeight: IOverlayToastFontWeight;
49
+ letterSpacing?: number;
50
+ /** A CSS font-family list on web, a font family name on native. */
51
+ fontFamily?: string;
52
+ /**
53
+ * Native: the font name for each weight, for a typeface that ships one
54
+ * face per weight. A weight listed here selects that face.
55
+ */
56
+ fontFaces?: Partial<Record<IOverlayToastFontWeight, string>>;
57
+ /** Equal-width digits. */
58
+ tabularNumbers?: boolean;
59
+ /** Web: let the text be selected. Off by default. */
60
+ selectable?: boolean;
61
+ /** Clamp per paragraph; unset means no clamp. */
62
+ numberOfLines?: number;
63
+ /** Web: background of a link run under the pointer and while pressed. */
64
+ linkHoverColor?: string;
65
+ linkPressedColor?: string;
66
+ }
67
+
68
+ export type IOverlayToastIcon =
69
+ | {
70
+ kind: 'icon';
71
+ /** Icon name for the native icon registry. */
72
+ name: string;
73
+ /** Target of an SVG `<use>`; web draws this with `currentColor`. */
74
+ href?: string;
75
+ color: string;
76
+ size: number;
77
+ }
78
+ | { kind: 'spinner'; color: string; size: number }
79
+ | { kind: 'image'; uri: string; size: number; borderRadius?: number };
80
+
81
+ export interface IOverlayToastAction {
82
+ /** Opaque id reported through `onAction`. */
83
+ id: string;
84
+ label: string;
85
+ disabled?: boolean;
86
+ testID?: string;
87
+ /** Drawn before the label. */
88
+ icon?: IOverlayToastIcon;
89
+ /** Space between the icon and the label. */
90
+ iconGap?: number;
91
+ color: string;
92
+ backgroundColor: string;
93
+ hoverBackgroundColor?: string;
94
+ pressedBackgroundColor?: string;
95
+ focusRingColor?: string;
96
+ fontSize: number;
97
+ lineHeight: number;
98
+ fontWeight: IOverlayToastFontWeight;
99
+ fontFamily?: string;
100
+ /** Native: the font name for each weight. */
101
+ fontFaces?: Partial<Record<IOverlayToastFontWeight, string>>;
102
+ paddingHorizontal: number;
103
+ paddingVertical: number;
104
+ /** Outer margins; negative values pull the button over its neighbours. */
105
+ marginHorizontal?: number;
106
+ marginVertical?: number;
107
+ /** A transparent border that only adds to the button's size. */
108
+ borderWidth?: number;
109
+ borderRadius: number;
110
+ /** Opacity while `disabled`. */
111
+ disabledOpacity?: number;
112
+ }
113
+
114
+ interface IOverlayToastBase {
115
+ /** Stable id. Showing an id that is on screen updates that toast. */
116
+ id: string;
117
+ /** Auto-dismiss delay in ms. `Infinity` keeps it until dismissed. */
118
+ duration: number;
119
+ /** Defaults to the toaster's position. */
120
+ position?: IOverlayToastPosition;
121
+ testID?: string;
122
+ }
123
+
124
+ /**
125
+ * Status icon, title, message and an optional action row:
126
+ *
127
+ * ```
128
+ * [icon] title
129
+ * message
130
+ * [action] [action]
131
+ * ```
132
+ */
133
+ export interface IOverlayMessageToast extends IOverlayToastBase {
134
+ layout: 'message';
135
+ icon?: IOverlayToastIcon;
136
+ title?: IOverlayToastText;
137
+ message?: IOverlayToastText;
138
+ actions?: IOverlayToastAction[];
139
+ actionsAlign?: 'left' | 'right';
140
+ }
141
+
142
+ /**
143
+ * A pressable notification row:
144
+ *
145
+ * ```
146
+ * (badge) title [image]
147
+ * message
148
+ * ```
149
+ */
150
+ export interface IOverlayNotificationToast extends IOverlayToastBase {
151
+ layout: 'notification';
152
+ /** Drawn centred inside a round badge. */
153
+ icon: IOverlayToastIcon;
154
+ badgeColor: string;
155
+ badgeSize: number;
156
+ title?: IOverlayToastText;
157
+ message?: IOverlayToastText;
158
+ /** Trailing thumbnail. */
159
+ image?: { uri: string; size: number; borderRadius?: number };
160
+ actions?: IOverlayToastAction[];
161
+ actionsAlign?: 'left' | 'right';
162
+ /** Report presses on the row through `onPress`. */
163
+ pressable?: boolean;
164
+ }
165
+
166
+ export type IOverlayToastSpec =
167
+ | IOverlayMessageToast
168
+ | IOverlayNotificationToast;
169
+
170
+ export interface IOverlayToastHandlers {
171
+ /** The toast started leaving. */
172
+ onDismiss?: (reason: IOverlayToastDismissReason) => void;
173
+ /** The exit animation finished and the card is gone. */
174
+ onClose?: (reason: IOverlayToastDismissReason) => void;
175
+ onAction?: (actionId: string) => void;
176
+ onLink?: (link: string) => void;
177
+ onPress?: () => void;
178
+ }
179
+
180
+ /** Toaster-wide settings. Every field has a platform default. */
181
+ export interface IOverlayToasterConfig {
182
+ position?: IOverlayToastPosition;
183
+ /** Web chrome follows this; native reads `cardColor`. */
184
+ theme?: 'light' | 'dark';
185
+ /** Native card surface. */
186
+ cardColor?: string;
187
+ /**
188
+ * Native: the width of the card's content box. The card adds its own
189
+ * padding around it.
190
+ */
191
+ contentWidth?: number;
192
+ /** Native: the tallest a card's content may grow. */
193
+ contentMaxHeight?: number;
194
+ /** Web: the tallest a card's content may grow. */
195
+ webContentMaxHeight?: number;
196
+ /**
197
+ * Bottom edge, in window points, of something hanging from the top of the
198
+ * window where top toasts land. Top toasts rest under it. 0 clears it.
199
+ */
200
+ topObstruction?: number;
201
+ /** Air between the obstruction and the first toast under it. */
202
+ topObstructionGap?: number;
203
+ /** Room a toast keeps above the usable area's bottom edge. */
204
+ topObstructionRoom?: number;
205
+ /** Follow the system reduced-motion setting. Defaults to true. */
206
+ respectReducedMotion?: boolean;
207
+ /** Web: accessible label of the close button. */
208
+ closeButtonLabel?: string;
209
+ testID?: string;
210
+ }
211
+
212
+ export interface IOverlayToastHandle {
213
+ id: string;
214
+ dismiss: () => void;
215
+ }
216
+
217
+ /** What a platform renderer receives: the active toasts, newest first. */
218
+ export interface IOverlayToastItem {
219
+ spec: IOverlayToastSpec;
220
+ /** False once a caller dismissed it; the renderer plays the exit. */
221
+ visible: boolean;
222
+ /** Bumped whenever the spec changes, so the card is redrawn. */
223
+ revision: number;
224
+ /** Bumped by `show` only: a new generation restarts the toast's lifetime. */
225
+ generation: number;
226
+ }
227
+
228
+ export type IOverlayToastEvent =
229
+ | {
230
+ id: string;
231
+ generation?: number;
232
+ type: 'dismiss';
233
+ reason: IOverlayToastDismissReason;
234
+ }
235
+ | {
236
+ id: string;
237
+ generation?: number;
238
+ type: 'close';
239
+ reason: IOverlayToastDismissReason;
240
+ }
241
+ | { id: string; generation?: number; type: 'action'; actionId: string }
242
+ | { id: string; generation?: number; type: 'link'; link: string }
243
+ | { id: string; generation?: number; type: 'press' };
244
+
245
+ export interface IOverlayToastRenderer {
246
+ sync: (
247
+ items: readonly IOverlayToastItem[],
248
+ config: IOverlayToasterConfig
249
+ ) => void;
250
+ destroy: () => void;
251
+ }
@@ -48,6 +48,88 @@ function setInert(element: HTMLElement | null | undefined, inert: boolean) {
48
48
 
49
49
  // Elements outside a page host made inert for a blocking page overlay.
50
50
  let pageInertElements = new Set<HTMLElement>();
51
+ let topBlockingElement: HTMLElement | undefined;
52
+
53
+ interface IFocusRestoreTarget {
54
+ element: HTMLElement | SVGElement;
55
+ ownerId?: string;
56
+ fallback?: IFocusRestoreTarget;
57
+ }
58
+
59
+ const previousFocusByEntry = new WeakMap<HTMLElement, IFocusRestoreTarget>();
60
+
61
+ export function focusOverlayEntry(entry: HTMLElement) {
62
+ const { activeElement, body } = entry.ownerDocument;
63
+ if (!entry.isConnected || entry.contains(activeElement)) return;
64
+
65
+ const owner = activeElement?.closest<HTMLElement>(`[${ENTRY_ATTRIBUTE}]`);
66
+ const ownerId = owner?.getAttribute(ENTRY_ATTRIBUTE) || undefined;
67
+ const fallback = owner ? previousFocusByEntry.get(owner) : undefined;
68
+ entry.focus({ preventScroll: true });
69
+ if (
70
+ !entry.contains(entry.ownerDocument.activeElement) ||
71
+ activeElement === body ||
72
+ !(
73
+ activeElement instanceof HTMLElement ||
74
+ activeElement instanceof SVGElement
75
+ )
76
+ ) {
77
+ return;
78
+ }
79
+
80
+ // Focus moving between overlays must preserve an opener already recorded.
81
+ if (owner && previousFocusByEntry.has(entry)) return;
82
+
83
+ if (ownerId && overlayStore.getEntry(ownerId)?.phase !== 'active') {
84
+ if (fallback) previousFocusByEntry.set(entry, fallback);
85
+ return;
86
+ }
87
+ previousFocusByEntry.set(entry, {
88
+ element: activeElement,
89
+ ownerId,
90
+ fallback,
91
+ });
92
+ }
93
+
94
+ export function restoreOverlayEntryFocus(entry: HTMLElement) {
95
+ let target = previousFocusByEntry.get(entry);
96
+ previousFocusByEntry.delete(entry);
97
+ if (!entry.isConnected) return;
98
+
99
+ const { activeElement, body } = entry.ownerDocument;
100
+ if (
101
+ activeElement &&
102
+ activeElement !== body &&
103
+ !entry.contains(activeElement)
104
+ ) {
105
+ return;
106
+ }
107
+
108
+ // An exit can finish before the next blocker takes focus on the next frame.
109
+ const nextBlocker = topBlockingElement;
110
+ if (
111
+ target &&
112
+ nextBlocker?.isConnected &&
113
+ nextBlocker !== entry &&
114
+ !previousFocusByEntry.has(nextBlocker)
115
+ ) {
116
+ previousFocusByEntry.set(nextBlocker, target);
117
+ }
118
+
119
+ // Keep the opener chain available even when a lower dialog unmounts first.
120
+ for (; target; target = target.fallback) {
121
+ const { element, ownerId } = target;
122
+ if (
123
+ !element.isConnected ||
124
+ entry.contains(element) ||
125
+ (ownerId && overlayStore.getEntry(ownerId)?.phase !== 'active')
126
+ ) {
127
+ continue;
128
+ }
129
+ element.focus({ preventScroll: true });
130
+ if (entry.ownerDocument.activeElement !== activeElement) return;
131
+ }
132
+ }
51
133
 
52
134
  /**
53
135
  * A page host lives inside the app root, so a blocking page overlay cannot
@@ -70,6 +152,12 @@ function siblingsOutside(host: HTMLElement, root: HTMLElement) {
70
152
  }
71
153
 
72
154
  function inertEntriesBelow(container: ParentNode, top?: IOverlayEntry) {
155
+ const toastSection = container.querySelector<HTMLElement>(
156
+ '[data-onekey-toast-section]'
157
+ );
158
+ if (toastSection) {
159
+ setInert(toastSection, !!top);
160
+ }
73
161
  container
74
162
  .querySelectorAll<HTMLElement>(`[${ENTRY_ATTRIBUTE}]`)
75
163
  .forEach((node) => {
@@ -110,6 +198,10 @@ export function syncOverlayInert() {
110
198
  pageInertElements = nextPageInert;
111
199
 
112
200
  for (const [hostKey, host] of pageHosts) {
201
+ setInert(
202
+ host,
203
+ nextPageInert.has(host) || !overlayStore.isPageHostFocused(hostKey)
204
+ );
113
205
  inertEntriesBelow(
114
206
  host,
115
207
  top?.scope === 'page' && top.hostKey === hostKey ? top : undefined
@@ -127,6 +219,22 @@ export function syncOverlayInert() {
127
219
  top?.scope === 'global' && level === top.level ? top : undefined
128
220
  );
129
221
  }
222
+
223
+ const topHost =
224
+ top?.scope === 'global' ? layerRoots.get(top.level) : pageHost;
225
+ const topElement =
226
+ top &&
227
+ topHost?.querySelector<HTMLElement>(
228
+ `[${ENTRY_ATTRIBUTE}][data-stack-order="${top.seq}"]`
229
+ );
230
+ const blocker = topElement && !topElement.inert ? topElement : undefined;
231
+ if (blocker === topBlockingElement) return;
232
+ topBlockingElement = blocker;
233
+ if (!blocker || blocker.contains(document.activeElement)) return;
234
+ // Wait for the React commit before focusing a newly interactive dialog.
235
+ requestAnimationFrame(() => {
236
+ if (topBlockingElement === blocker) focusOverlayEntry(blocker);
237
+ });
130
238
  }
131
239
 
132
240
  function onKeyDown(event: KeyboardEvent) {
@@ -150,6 +258,9 @@ function installOverlayWebManager() {
150
258
  return;
151
259
  }
152
260
  installed = true;
261
+ overlayStore.setPageHostAvailabilityCheck(
262
+ (hostKey) => getOverlayPageHost(hostKey)?.isConnected === true
263
+ );
153
264
  overlayStore.subscribe(syncOverlayInert);
154
265
  document.addEventListener('keydown', onKeyDown, true);
155
266
  }
@@ -160,6 +271,7 @@ export function getOverlayLayerRoot(level: IOverlayLevel): HTMLDivElement {
160
271
  if (!root || !root.isConnected) {
161
272
  root = createLayerRoot(level);
162
273
  layerRoots.set(level, root);
274
+ syncOverlayInert();
163
275
  }
164
276
  return root;
165
277
  }
@@ -187,10 +299,12 @@ export function registerOverlayPageHost(
187
299
  ): () => void {
188
300
  installOverlayWebManager();
189
301
  pageHosts.set(hostKey, element);
302
+ syncOverlayInert();
190
303
  pageHostListeners.get(hostKey)?.forEach((listener) => listener());
191
304
  return () => {
192
305
  if (pageHosts.get(hostKey) === element) {
193
306
  pageHosts.delete(hostKey);
307
+ syncOverlayInert();
194
308
  pageHostListeners.get(hostKey)?.forEach((listener) => listener());
195
309
  }
196
310
  };