@onekeyfe/react-native-native-overlay 6.7.0-alpha.475 → 6.8.0-11

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 (102) hide show
  1. package/README.md +119 -21
  2. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayEntryRootView.kt +60 -0
  3. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayHost.kt +37 -5
  4. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPackage.kt +1 -1
  5. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastCardView.kt +869 -0
  6. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastSpec.kt +327 -0
  7. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterView.kt +574 -0
  8. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterViewManager.kt +54 -0
  9. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayView.kt +12 -0
  10. package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayViewManager.kt +8 -0
  11. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayAccessibilityIsolationTest.kt +172 -0
  12. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayMotionTest.kt +42 -0
  13. package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlaySheetInsetTest.kt +78 -0
  14. package/docs/SPEC.md +324 -33
  15. package/ios/NativeOverlayContainerView.swift +6 -0
  16. package/ios/NativeOverlayToastCardView.swift +572 -0
  17. package/ios/NativeOverlayToastSpec.swift +356 -0
  18. package/ios/NativeOverlayToasterView.swift +519 -0
  19. package/ios/NativeOverlayWindowManager.swift +244 -7
  20. package/ios/RCTNativeOverlayToasterComponentView.h +11 -0
  21. package/ios/RCTNativeOverlayToasterComponentView.mm +85 -0
  22. package/lib/module/NativeOverlayNativeComponent.ts +13 -0
  23. package/lib/module/NativeOverlayToasterNativeComponent.ts +24 -0
  24. package/lib/module/OverlayView.js +7 -1
  25. package/lib/module/OverlayView.js.map +1 -1
  26. package/lib/module/animation/anchoredOrigin.js +26 -0
  27. package/lib/module/animation/anchoredOrigin.js.map +1 -0
  28. package/lib/module/animation/resolveAnimation.js +26 -4
  29. package/lib/module/animation/resolveAnimation.js.map +1 -1
  30. package/lib/module/index.js +3 -0
  31. package/lib/module/index.js.map +1 -1
  32. package/lib/module/toast/OverlayToastHost.js +42 -0
  33. package/lib/module/toast/OverlayToastHost.js.map +1 -0
  34. package/lib/module/toast/OverlayToastHost.web.js +32 -0
  35. package/lib/module/toast/OverlayToastHost.web.js.map +1 -0
  36. package/lib/module/toast/OverlayToastStore.js +217 -0
  37. package/lib/module/toast/OverlayToastStore.js.map +1 -0
  38. package/lib/module/toast/toastBridge.js +65 -0
  39. package/lib/module/toast/toastBridge.js.map +1 -0
  40. package/lib/module/toast/toastDomContent.web.js +298 -0
  41. package/lib/module/toast/toastDomContent.web.js.map +1 -0
  42. package/lib/module/toast/toastDomRenderer.web.js +695 -0
  43. package/lib/module/toast/toastDomRenderer.web.js.map +1 -0
  44. package/lib/module/toast/toastStyles.web.js +97 -0
  45. package/lib/module/toast/toastStyles.web.js.map +1 -0
  46. package/lib/module/toast/types.js +2 -0
  47. package/lib/module/toast/types.js.map +1 -0
  48. package/lib/module/web/animateTransition.js +38 -12
  49. package/lib/module/web/animateTransition.js.map +1 -1
  50. package/lib/module/web/overlayLayers.js +5 -0
  51. package/lib/module/web/overlayLayers.js.map +1 -1
  52. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts +13 -0
  53. package/lib/typescript/src/NativeOverlayNativeComponent.d.ts.map +1 -1
  54. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts +19 -0
  55. package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts.map +1 -0
  56. package/lib/typescript/src/OverlayView.d.ts.map +1 -1
  57. package/lib/typescript/src/animation/anchoredOrigin.d.ts +7 -0
  58. package/lib/typescript/src/animation/anchoredOrigin.d.ts.map +1 -0
  59. package/lib/typescript/src/animation/resolveAnimation.d.ts +9 -3
  60. package/lib/typescript/src/animation/resolveAnimation.d.ts.map +1 -1
  61. package/lib/typescript/src/animation/types.d.ts +5 -1
  62. package/lib/typescript/src/animation/types.d.ts.map +1 -1
  63. package/lib/typescript/src/index.d.ts +5 -0
  64. package/lib/typescript/src/index.d.ts.map +1 -1
  65. package/lib/typescript/src/toast/OverlayToastHost.d.ts +6 -0
  66. package/lib/typescript/src/toast/OverlayToastHost.d.ts.map +1 -0
  67. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts +6 -0
  68. package/lib/typescript/src/toast/OverlayToastHost.web.d.ts.map +1 -0
  69. package/lib/typescript/src/toast/OverlayToastStore.d.ts +47 -0
  70. package/lib/typescript/src/toast/OverlayToastStore.d.ts.map +1 -0
  71. package/lib/typescript/src/toast/toastBridge.d.ts +11 -0
  72. package/lib/typescript/src/toast/toastBridge.d.ts.map +1 -0
  73. package/lib/typescript/src/toast/toastDomContent.web.d.ts +15 -0
  74. package/lib/typescript/src/toast/toastDomContent.web.d.ts.map +1 -0
  75. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts +8 -0
  76. package/lib/typescript/src/toast/toastDomRenderer.web.d.ts.map +1 -0
  77. package/lib/typescript/src/toast/toastStyles.web.d.ts +2 -0
  78. package/lib/typescript/src/toast/toastStyles.web.d.ts.map +1 -0
  79. package/lib/typescript/src/toast/types.d.ts +240 -0
  80. package/lib/typescript/src/toast/types.d.ts.map +1 -0
  81. package/lib/typescript/src/web/animateTransition.d.ts +12 -0
  82. package/lib/typescript/src/web/animateTransition.d.ts.map +1 -1
  83. package/lib/typescript/src/web/overlayLayers.d.ts.map +1 -1
  84. package/package.json +3 -2
  85. package/react-native.config.js +1 -0
  86. package/src/NativeOverlayNativeComponent.ts +13 -0
  87. package/src/NativeOverlayToasterNativeComponent.ts +24 -0
  88. package/src/OverlayView.tsx +7 -0
  89. package/src/animation/anchoredOrigin.ts +35 -0
  90. package/src/animation/resolveAnimation.ts +28 -7
  91. package/src/animation/types.ts +5 -1
  92. package/src/index.ts +24 -0
  93. package/src/toast/OverlayToastHost.tsx +62 -0
  94. package/src/toast/OverlayToastHost.web.tsx +29 -0
  95. package/src/toast/OverlayToastStore.ts +254 -0
  96. package/src/toast/toastBridge.ts +62 -0
  97. package/src/toast/toastDomContent.web.ts +351 -0
  98. package/src/toast/toastDomRenderer.web.ts +856 -0
  99. package/src/toast/toastStyles.web.ts +97 -0
  100. package/src/toast/types.ts +251 -0
  101. package/src/web/animateTransition.ts +54 -14
  102. package/src/web/overlayLayers.ts +7 -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
+ }
@@ -1,3 +1,4 @@
1
+ import { getAnchoredTransformOrigin } from '../animation/anchoredOrigin';
1
2
  import { springToCssLinear } from '../animation/spring';
2
3
 
3
4
  import type { IResolvedOverlayTransition } from '../animation/resolveAnimation';
@@ -91,6 +92,45 @@ const VISIBLE_KEYFRAME: Keyframe = {
91
92
  transform: 'translate3d(0, 0, 0) scale(1)',
92
93
  };
93
94
 
95
+ export interface ITransitionKeyframeInput {
96
+ transition: IResolvedOverlayTransition;
97
+ extent: IContentExtent;
98
+ direction: 'in' | 'out';
99
+ /** Rendered frames of an interrupted run; the new run starts from them. */
100
+ sampled?: Keyframe;
101
+ }
102
+
103
+ /**
104
+ * Keyframes for one enter/exit run. Pure so the interruption rules can be
105
+ * tested without a DOM.
106
+ */
107
+ export function buildTransitionKeyframes({
108
+ transition,
109
+ extent,
110
+ direction,
111
+ sampled,
112
+ }: ITransitionKeyframeInput): [Keyframe, Keyframe] {
113
+ const hidden = hiddenKeyframe(transition, extent);
114
+ const visible: Keyframe = {};
115
+ Object.keys(hidden).forEach((key) => {
116
+ visible[key] = VISIBLE_KEYFRAME[key];
117
+ });
118
+ const initial = direction === 'in' ? hidden : visible;
119
+ const start: Keyframe = {};
120
+ Object.keys(initial).forEach((key) => {
121
+ start[key] = sampled?.[key] ?? initial[key];
122
+ });
123
+ const end: Keyframe = direction === 'in' ? visible : hidden;
124
+ // A fade-free exit does not animate opacity. Drop a partly transparent frame
125
+ // left by an interrupted fade-in so the card stays opaque while it scales out
126
+ // (OK-66647).
127
+ if (direction === 'out' && hidden.opacity === undefined) {
128
+ start.opacity = 1;
129
+ end.opacity = 1;
130
+ }
131
+ return [start, end];
132
+ }
133
+
94
134
  /**
95
135
  * Runs an enter (`direction: 'in'`) or exit transition on `element`. The
96
136
  * slide distance and scale origin come from the children of `contentRoot`,
@@ -120,21 +160,21 @@ export function animateTransition(
120
160
  anchoredContent instanceof HTMLElement ? anchoredContent : element;
121
161
  const targetRect =
122
162
  target === element ? undefined : target.getBoundingClientRect();
123
- target.style.transformOrigin = `${
124
- (extent.left + extent.right) / 2 - (targetRect?.left ?? 0)
125
- }px ${(extent.top + extent.bottom) / 2 - (targetRect?.top ?? 0)}px`;
126
- const hidden = hiddenKeyframe(effective, extent);
127
- const visible: Keyframe = {};
128
- Object.keys(hidden).forEach((key) => {
129
- visible[key] = VISIBLE_KEYFRAME[key];
130
- });
131
- const sampled = interruptedFrames?.get(target);
132
- const initial = direction === 'in' ? hidden : visible;
133
- const start: Keyframe = {};
134
- Object.keys(initial).forEach((key) => {
135
- start[key] = sampled?.[key] ?? initial[key];
163
+ const anchorOrigin =
164
+ target === element
165
+ ? undefined
166
+ : getAnchoredTransformOrigin(target.dataset.placement);
167
+ target.style.transformOrigin =
168
+ anchorOrigin ??
169
+ `${(extent.left + extent.right) / 2 - (targetRect?.left ?? 0)}px ${
170
+ (extent.top + extent.bottom) / 2 - (targetRect?.top ?? 0)
171
+ }px`;
172
+ const keyframes = buildTransitionKeyframes({
173
+ transition: effective,
174
+ extent,
175
+ direction,
176
+ sampled: interruptedFrames?.get(target),
136
177
  });
137
- const keyframes = [start, direction === 'in' ? visible : hidden];
138
178
  return target.animate(keyframes, {
139
179
  ...toTiming(effective.motion),
140
180
  fill: 'forwards',
@@ -70,6 +70,12 @@ function siblingsOutside(host: HTMLElement, root: HTMLElement) {
70
70
  }
71
71
 
72
72
  function inertEntriesBelow(container: ParentNode, top?: IOverlayEntry) {
73
+ const toastSection = container.querySelector<HTMLElement>(
74
+ '[data-onekey-toast-section]'
75
+ );
76
+ if (toastSection) {
77
+ setInert(toastSection, !!top);
78
+ }
73
79
  container
74
80
  .querySelectorAll<HTMLElement>(`[${ENTRY_ATTRIBUTE}]`)
75
81
  .forEach((node) => {
@@ -160,6 +166,7 @@ export function getOverlayLayerRoot(level: IOverlayLevel): HTMLDivElement {
160
166
  if (!root || !root.isConnected) {
161
167
  root = createLayerRoot(level);
162
168
  layerRoots.set(level, root);
169
+ syncOverlayInert();
163
170
  }
164
171
  return root;
165
172
  }