@onekeyfe/react-native-native-overlay 6.8.0-2 → 6.8.0-21
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/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayHost.kt +37 -5
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayPackage.kt +1 -1
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastCardView.kt +869 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToastSpec.kt +327 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterView.kt +574 -0
- package/android/src/main/java/com/onekey/nativeoverlay/NativeOverlayToasterViewManager.kt +54 -0
- package/android/src/test/java/com/onekey/nativeoverlay/NativeOverlayAccessibilityIsolationTest.kt +172 -0
- package/docs/SPEC.md +172 -11
- package/ios/NativeOverlayContainerView.swift +20 -4
- package/ios/NativeOverlayToastCardView.swift +572 -0
- package/ios/NativeOverlayToastSpec.swift +356 -0
- package/ios/NativeOverlayToasterView.swift +519 -0
- package/ios/RCTNativeOverlayToasterComponentView.h +11 -0
- package/ios/RCTNativeOverlayToasterComponentView.mm +85 -0
- package/lib/module/NativeOverlayToasterNativeComponent.ts +24 -0
- package/lib/module/OverlayStore.js +20 -3
- package/lib/module/OverlayStore.js.map +1 -1
- package/lib/module/OverlayView.web.js +9 -18
- package/lib/module/OverlayView.web.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/toast/OverlayToastHost.js +42 -0
- package/lib/module/toast/OverlayToastHost.js.map +1 -0
- package/lib/module/toast/OverlayToastHost.web.js +32 -0
- package/lib/module/toast/OverlayToastHost.web.js.map +1 -0
- package/lib/module/toast/OverlayToastStore.js +217 -0
- package/lib/module/toast/OverlayToastStore.js.map +1 -0
- package/lib/module/toast/toastBridge.js +65 -0
- package/lib/module/toast/toastBridge.js.map +1 -0
- package/lib/module/toast/toastDomContent.web.js +298 -0
- package/lib/module/toast/toastDomContent.web.js.map +1 -0
- package/lib/module/toast/toastDomRenderer.web.js +695 -0
- package/lib/module/toast/toastDomRenderer.web.js.map +1 -0
- package/lib/module/toast/toastStyles.web.js +97 -0
- package/lib/module/toast/toastStyles.web.js.map +1 -0
- package/lib/module/toast/types.js +2 -0
- package/lib/module/toast/types.js.map +1 -0
- package/lib/module/web/overlayLayers.js +82 -0
- package/lib/module/web/overlayLayers.js.map +1 -1
- package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts +19 -0
- package/lib/typescript/src/NativeOverlayToasterNativeComponent.d.ts.map +1 -0
- package/lib/typescript/src/OverlayStore.d.ts +8 -1
- package/lib/typescript/src/OverlayStore.d.ts.map +1 -1
- package/lib/typescript/src/OverlayView.web.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/toast/OverlayToastHost.d.ts +6 -0
- package/lib/typescript/src/toast/OverlayToastHost.d.ts.map +1 -0
- package/lib/typescript/src/toast/OverlayToastHost.web.d.ts +6 -0
- package/lib/typescript/src/toast/OverlayToastHost.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/OverlayToastStore.d.ts +47 -0
- package/lib/typescript/src/toast/OverlayToastStore.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastBridge.d.ts +11 -0
- package/lib/typescript/src/toast/toastBridge.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastDomContent.web.d.ts +15 -0
- package/lib/typescript/src/toast/toastDomContent.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastDomRenderer.web.d.ts +8 -0
- package/lib/typescript/src/toast/toastDomRenderer.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/toastStyles.web.d.ts +2 -0
- package/lib/typescript/src/toast/toastStyles.web.d.ts.map +1 -0
- package/lib/typescript/src/toast/types.d.ts +240 -0
- package/lib/typescript/src/toast/types.d.ts.map +1 -0
- package/lib/typescript/src/web/overlayLayers.d.ts +2 -0
- package/lib/typescript/src/web/overlayLayers.d.ts.map +1 -1
- package/package.json +3 -2
- package/react-native.config.js +1 -0
- package/src/NativeOverlayToasterNativeComponent.ts +24 -0
- package/src/OverlayStore.ts +35 -4
- package/src/OverlayView.web.tsx +10 -11
- package/src/index.ts +23 -0
- package/src/toast/OverlayToastHost.tsx +62 -0
- package/src/toast/OverlayToastHost.web.tsx +29 -0
- package/src/toast/OverlayToastStore.ts +254 -0
- package/src/toast/toastBridge.ts +62 -0
- package/src/toast/toastDomContent.web.ts +351 -0
- package/src/toast/toastDomRenderer.web.ts +856 -0
- package/src/toast/toastStyles.web.ts +97 -0
- package/src/toast/types.ts +251 -0
- package/src/web/overlayLayers.ts +114 -0
|
@@ -0,0 +1,240 @@
|
|
|
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
|
+
/** Where a toast group is anchored. */
|
|
10
|
+
export type IOverlayToastPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
11
|
+
/** Why a toast left. `programmatic` is a caller's `dismiss`. */
|
|
12
|
+
export type IOverlayToastDismissReason = 'timeout' | 'swipe' | 'close' | 'programmatic';
|
|
13
|
+
export type IOverlayToastFontWeight = '400' | '500' | '600' | '700';
|
|
14
|
+
/** One inline run of a paragraph. Unset fields inherit the paragraph. */
|
|
15
|
+
export interface IOverlayToastTextRun {
|
|
16
|
+
text: string;
|
|
17
|
+
color?: string;
|
|
18
|
+
fontWeight?: IOverlayToastFontWeight;
|
|
19
|
+
fontSize?: number;
|
|
20
|
+
underline?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Makes the run tappable. The value is opaque to the platform and comes
|
|
23
|
+
* back through `onLink`.
|
|
24
|
+
*/
|
|
25
|
+
link?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface IOverlayToastText {
|
|
28
|
+
/** Paragraphs, each laid out as its own block. */
|
|
29
|
+
paragraphs: IOverlayToastTextRun[][];
|
|
30
|
+
color: string;
|
|
31
|
+
fontSize: number;
|
|
32
|
+
lineHeight: number;
|
|
33
|
+
fontWeight: IOverlayToastFontWeight;
|
|
34
|
+
letterSpacing?: number;
|
|
35
|
+
/** A CSS font-family list on web, a font family name on native. */
|
|
36
|
+
fontFamily?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Native: the font name for each weight, for a typeface that ships one
|
|
39
|
+
* face per weight. A weight listed here selects that face.
|
|
40
|
+
*/
|
|
41
|
+
fontFaces?: Partial<Record<IOverlayToastFontWeight, string>>;
|
|
42
|
+
/** Equal-width digits. */
|
|
43
|
+
tabularNumbers?: boolean;
|
|
44
|
+
/** Web: let the text be selected. Off by default. */
|
|
45
|
+
selectable?: boolean;
|
|
46
|
+
/** Clamp per paragraph; unset means no clamp. */
|
|
47
|
+
numberOfLines?: number;
|
|
48
|
+
/** Web: background of a link run under the pointer and while pressed. */
|
|
49
|
+
linkHoverColor?: string;
|
|
50
|
+
linkPressedColor?: string;
|
|
51
|
+
}
|
|
52
|
+
export type IOverlayToastIcon = {
|
|
53
|
+
kind: 'icon';
|
|
54
|
+
/** Icon name for the native icon registry. */
|
|
55
|
+
name: string;
|
|
56
|
+
/** Target of an SVG `<use>`; web draws this with `currentColor`. */
|
|
57
|
+
href?: string;
|
|
58
|
+
color: string;
|
|
59
|
+
size: number;
|
|
60
|
+
} | {
|
|
61
|
+
kind: 'spinner';
|
|
62
|
+
color: string;
|
|
63
|
+
size: number;
|
|
64
|
+
} | {
|
|
65
|
+
kind: 'image';
|
|
66
|
+
uri: string;
|
|
67
|
+
size: number;
|
|
68
|
+
borderRadius?: number;
|
|
69
|
+
};
|
|
70
|
+
export interface IOverlayToastAction {
|
|
71
|
+
/** Opaque id reported through `onAction`. */
|
|
72
|
+
id: string;
|
|
73
|
+
label: string;
|
|
74
|
+
disabled?: boolean;
|
|
75
|
+
testID?: string;
|
|
76
|
+
/** Drawn before the label. */
|
|
77
|
+
icon?: IOverlayToastIcon;
|
|
78
|
+
/** Space between the icon and the label. */
|
|
79
|
+
iconGap?: number;
|
|
80
|
+
color: string;
|
|
81
|
+
backgroundColor: string;
|
|
82
|
+
hoverBackgroundColor?: string;
|
|
83
|
+
pressedBackgroundColor?: string;
|
|
84
|
+
focusRingColor?: string;
|
|
85
|
+
fontSize: number;
|
|
86
|
+
lineHeight: number;
|
|
87
|
+
fontWeight: IOverlayToastFontWeight;
|
|
88
|
+
fontFamily?: string;
|
|
89
|
+
/** Native: the font name for each weight. */
|
|
90
|
+
fontFaces?: Partial<Record<IOverlayToastFontWeight, string>>;
|
|
91
|
+
paddingHorizontal: number;
|
|
92
|
+
paddingVertical: number;
|
|
93
|
+
/** Outer margins; negative values pull the button over its neighbours. */
|
|
94
|
+
marginHorizontal?: number;
|
|
95
|
+
marginVertical?: number;
|
|
96
|
+
/** A transparent border that only adds to the button's size. */
|
|
97
|
+
borderWidth?: number;
|
|
98
|
+
borderRadius: number;
|
|
99
|
+
/** Opacity while `disabled`. */
|
|
100
|
+
disabledOpacity?: number;
|
|
101
|
+
}
|
|
102
|
+
interface IOverlayToastBase {
|
|
103
|
+
/** Stable id. Showing an id that is on screen updates that toast. */
|
|
104
|
+
id: string;
|
|
105
|
+
/** Auto-dismiss delay in ms. `Infinity` keeps it until dismissed. */
|
|
106
|
+
duration: number;
|
|
107
|
+
/** Defaults to the toaster's position. */
|
|
108
|
+
position?: IOverlayToastPosition;
|
|
109
|
+
testID?: string;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Status icon, title, message and an optional action row:
|
|
113
|
+
*
|
|
114
|
+
* ```
|
|
115
|
+
* [icon] title
|
|
116
|
+
* message
|
|
117
|
+
* [action] [action]
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export interface IOverlayMessageToast extends IOverlayToastBase {
|
|
121
|
+
layout: 'message';
|
|
122
|
+
icon?: IOverlayToastIcon;
|
|
123
|
+
title?: IOverlayToastText;
|
|
124
|
+
message?: IOverlayToastText;
|
|
125
|
+
actions?: IOverlayToastAction[];
|
|
126
|
+
actionsAlign?: 'left' | 'right';
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* A pressable notification row:
|
|
130
|
+
*
|
|
131
|
+
* ```
|
|
132
|
+
* (badge) title [image]
|
|
133
|
+
* message
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export interface IOverlayNotificationToast extends IOverlayToastBase {
|
|
137
|
+
layout: 'notification';
|
|
138
|
+
/** Drawn centred inside a round badge. */
|
|
139
|
+
icon: IOverlayToastIcon;
|
|
140
|
+
badgeColor: string;
|
|
141
|
+
badgeSize: number;
|
|
142
|
+
title?: IOverlayToastText;
|
|
143
|
+
message?: IOverlayToastText;
|
|
144
|
+
/** Trailing thumbnail. */
|
|
145
|
+
image?: {
|
|
146
|
+
uri: string;
|
|
147
|
+
size: number;
|
|
148
|
+
borderRadius?: number;
|
|
149
|
+
};
|
|
150
|
+
actions?: IOverlayToastAction[];
|
|
151
|
+
actionsAlign?: 'left' | 'right';
|
|
152
|
+
/** Report presses on the row through `onPress`. */
|
|
153
|
+
pressable?: boolean;
|
|
154
|
+
}
|
|
155
|
+
export type IOverlayToastSpec = IOverlayMessageToast | IOverlayNotificationToast;
|
|
156
|
+
export interface IOverlayToastHandlers {
|
|
157
|
+
/** The toast started leaving. */
|
|
158
|
+
onDismiss?: (reason: IOverlayToastDismissReason) => void;
|
|
159
|
+
/** The exit animation finished and the card is gone. */
|
|
160
|
+
onClose?: (reason: IOverlayToastDismissReason) => void;
|
|
161
|
+
onAction?: (actionId: string) => void;
|
|
162
|
+
onLink?: (link: string) => void;
|
|
163
|
+
onPress?: () => void;
|
|
164
|
+
}
|
|
165
|
+
/** Toaster-wide settings. Every field has a platform default. */
|
|
166
|
+
export interface IOverlayToasterConfig {
|
|
167
|
+
position?: IOverlayToastPosition;
|
|
168
|
+
/** Web chrome follows this; native reads `cardColor`. */
|
|
169
|
+
theme?: 'light' | 'dark';
|
|
170
|
+
/** Native card surface. */
|
|
171
|
+
cardColor?: string;
|
|
172
|
+
/**
|
|
173
|
+
* Native: the width of the card's content box. The card adds its own
|
|
174
|
+
* padding around it.
|
|
175
|
+
*/
|
|
176
|
+
contentWidth?: number;
|
|
177
|
+
/** Native: the tallest a card's content may grow. */
|
|
178
|
+
contentMaxHeight?: number;
|
|
179
|
+
/** Web: the tallest a card's content may grow. */
|
|
180
|
+
webContentMaxHeight?: number;
|
|
181
|
+
/**
|
|
182
|
+
* Bottom edge, in window points, of something hanging from the top of the
|
|
183
|
+
* window where top toasts land. Top toasts rest under it. 0 clears it.
|
|
184
|
+
*/
|
|
185
|
+
topObstruction?: number;
|
|
186
|
+
/** Air between the obstruction and the first toast under it. */
|
|
187
|
+
topObstructionGap?: number;
|
|
188
|
+
/** Room a toast keeps above the usable area's bottom edge. */
|
|
189
|
+
topObstructionRoom?: number;
|
|
190
|
+
/** Follow the system reduced-motion setting. Defaults to true. */
|
|
191
|
+
respectReducedMotion?: boolean;
|
|
192
|
+
/** Web: accessible label of the close button. */
|
|
193
|
+
closeButtonLabel?: string;
|
|
194
|
+
testID?: string;
|
|
195
|
+
}
|
|
196
|
+
export interface IOverlayToastHandle {
|
|
197
|
+
id: string;
|
|
198
|
+
dismiss: () => void;
|
|
199
|
+
}
|
|
200
|
+
/** What a platform renderer receives: the active toasts, newest first. */
|
|
201
|
+
export interface IOverlayToastItem {
|
|
202
|
+
spec: IOverlayToastSpec;
|
|
203
|
+
/** False once a caller dismissed it; the renderer plays the exit. */
|
|
204
|
+
visible: boolean;
|
|
205
|
+
/** Bumped whenever the spec changes, so the card is redrawn. */
|
|
206
|
+
revision: number;
|
|
207
|
+
/** Bumped by `show` only: a new generation restarts the toast's lifetime. */
|
|
208
|
+
generation: number;
|
|
209
|
+
}
|
|
210
|
+
export type IOverlayToastEvent = {
|
|
211
|
+
id: string;
|
|
212
|
+
generation?: number;
|
|
213
|
+
type: 'dismiss';
|
|
214
|
+
reason: IOverlayToastDismissReason;
|
|
215
|
+
} | {
|
|
216
|
+
id: string;
|
|
217
|
+
generation?: number;
|
|
218
|
+
type: 'close';
|
|
219
|
+
reason: IOverlayToastDismissReason;
|
|
220
|
+
} | {
|
|
221
|
+
id: string;
|
|
222
|
+
generation?: number;
|
|
223
|
+
type: 'action';
|
|
224
|
+
actionId: string;
|
|
225
|
+
} | {
|
|
226
|
+
id: string;
|
|
227
|
+
generation?: number;
|
|
228
|
+
type: 'link';
|
|
229
|
+
link: string;
|
|
230
|
+
} | {
|
|
231
|
+
id: string;
|
|
232
|
+
generation?: number;
|
|
233
|
+
type: 'press';
|
|
234
|
+
};
|
|
235
|
+
export interface IOverlayToastRenderer {
|
|
236
|
+
sync: (items: readonly IOverlayToastItem[], config: IOverlayToasterConfig) => void;
|
|
237
|
+
destroy: () => void;
|
|
238
|
+
}
|
|
239
|
+
export {};
|
|
240
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/toast/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,uCAAuC;AACvC,MAAM,MAAM,qBAAqB,GAC7B,UAAU,GACV,YAAY,GACZ,WAAW,GACX,aAAa,GACb,eAAe,GACf,cAAc,CAAC;AAEnB,gEAAgE;AAChE,MAAM,MAAM,0BAA0B,GAClC,SAAS,GACT,OAAO,GACP,OAAO,GACP,cAAc,CAAC;AAEnB,MAAM,MAAM,uBAAuB,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,CAAC;AAEpE,yEAAyE;AACzE,MAAM,WAAW,oBAAoB;IACnC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CAAC;IAChB,MAAM,EAAE,0BAA0B,CAAC;CACpC,GACD;IACE,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,0BAA0B,CAAC;CACpC,GACD;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GACrE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/D;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEvD,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,CACJ,KAAK,EAAE,SAAS,iBAAiB,EAAE,EACnC,MAAM,EAAE,qBAAqB,KAC1B,IAAI,CAAC;IACV,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { IOverlayRequestDismissReason } from '../OverlayViewTypes';
|
|
2
2
|
import type { IOverlayLevel } from '../types';
|
|
3
3
|
export declare const ENTRY_ATTRIBUTE = "data-onekey-overlay-entry";
|
|
4
|
+
export declare function focusOverlayEntry(entry: HTMLElement): void;
|
|
5
|
+
export declare function restoreOverlayEntryFocus(entry: HTMLElement): void;
|
|
4
6
|
/** Everything rendered below the topmost blocking entry becomes inert. */
|
|
5
7
|
export declare function syncOverlayInert(): void;
|
|
6
8
|
export declare function getOverlayLayerRoot(level: IOverlayLevel): HTMLDivElement;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlayLayers.d.ts","sourceRoot":"","sources":["../../../../src/web/overlayLayers.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,UAAU,CAAC;AAG7D,eAAO,MAAM,eAAe,8BAA8B,CAAC;AA+
|
|
1
|
+
{"version":3,"file":"overlayLayers.d.ts","sourceRoot":"","sources":["../../../../src/web/overlayLayers.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AACxE,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,UAAU,CAAC;AAG7D,eAAO,MAAM,eAAe,8BAA8B,CAAC;AAiD3D,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,QA+BnD;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,WAAW,QAsC1D;AA+CD,0EAA0E;AAC1E,wBAAgB,gBAAgB,SA0D/B;AA8BD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,aAAa,GAAG,cAAc,CASxE;AAED,wBAAgB,+BAA+B,CAC7C,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,CAAC,MAAM,EAAE,4BAA4B,KAAK,IAAI,GACxD,MAAM,IAAI,CAOZ;AAED,+EAA+E;AAC/E,wBAAgB,wBAAwB,SAEvC;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,cAAc,GACtB,MAAM,IAAI,CAYZ;AAED,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,QAAQ,EAAE,MAAM,IAAI,GACnB,MAAM,IAAI,CAYZ;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,GAAG,SAAS,GAC1B,cAAc,GAAG,SAAS,CAE5B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-native-overlay",
|
|
3
|
-
"version": "6.8.0-
|
|
3
|
+
"version": "6.8.0-21",
|
|
4
4
|
"description": "Native and Web overlay hosts with ordered levels, page scope and Fabric measurement",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -182,7 +182,8 @@
|
|
|
182
182
|
"ios": {
|
|
183
183
|
"componentProvider": {
|
|
184
184
|
"RNCNativeOverlay": "RCTNativeOverlayComponentView",
|
|
185
|
-
"RNCNativeOverlayPageHost": "RCTNativeOverlayPageHostComponentView"
|
|
185
|
+
"RNCNativeOverlayPageHost": "RCTNativeOverlayPageHostComponentView",
|
|
186
|
+
"RNCNativeOverlayToaster": "RCTNativeOverlayToasterComponentView"
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
189
|
}
|
package/react-native.config.js
CHANGED
|
@@ -5,6 +5,7 @@ module.exports = {
|
|
|
5
5
|
componentDescriptors: [
|
|
6
6
|
'RNCNativeOverlayComponentDescriptor',
|
|
7
7
|
'RNCNativeOverlayPageHostComponentDescriptor',
|
|
8
|
+
'RNCNativeOverlayToasterComponentDescriptor',
|
|
8
9
|
],
|
|
9
10
|
cmakeListsPath: '../android/src/main/jni/CMakeLists.txt',
|
|
10
11
|
packageImportPath:
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { codegenNativeComponent } from 'react-native';
|
|
2
|
+
|
|
3
|
+
import type { CodegenTypes, HostComponent, ViewProps } from 'react-native';
|
|
4
|
+
|
|
5
|
+
type INativeOverlayToastEvent = Readonly<{
|
|
6
|
+
toastId: string;
|
|
7
|
+
generation: CodegenTypes.Int32;
|
|
8
|
+
/** `dismiss` | `close` | `action` | `link` | `press`. */
|
|
9
|
+
type: string;
|
|
10
|
+
/** The dismiss reason, action id or link of the event; empty otherwise. */
|
|
11
|
+
value: string;
|
|
12
|
+
}>;
|
|
13
|
+
|
|
14
|
+
export interface INativeOverlayToasterNativeProps extends ViewProps {
|
|
15
|
+
/** JSON of `IOverlayToastItem[]`, newest first. */
|
|
16
|
+
toasts?: CodegenTypes.WithDefault<string, ''>;
|
|
17
|
+
/** JSON of `IOverlayToasterConfig`. */
|
|
18
|
+
config?: CodegenTypes.WithDefault<string, ''>;
|
|
19
|
+
onToastEvent?: CodegenTypes.DirectEventHandler<INativeOverlayToastEvent>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export default codegenNativeComponent<INativeOverlayToasterNativeProps>(
|
|
23
|
+
'RNCNativeOverlayToaster'
|
|
24
|
+
) as HostComponent<INativeOverlayToasterNativeProps>;
|
package/src/OverlayStore.ts
CHANGED
|
@@ -64,6 +64,10 @@ export class OverlayStore {
|
|
|
64
64
|
|
|
65
65
|
private readonly pageVisibility = new Map<string, boolean>();
|
|
66
66
|
|
|
67
|
+
private focusedPageHost: string | null | undefined;
|
|
68
|
+
|
|
69
|
+
private isPageHostAvailable?: (hostKey: string | undefined) => boolean;
|
|
70
|
+
|
|
67
71
|
private readonly listeners = new Set<() => void>();
|
|
68
72
|
|
|
69
73
|
private snapshot: IOverlaySnapshot = {
|
|
@@ -198,6 +202,25 @@ export class OverlayStore {
|
|
|
198
202
|
dropped.forEach((e) => this.notifyRemoved(e.id, reason));
|
|
199
203
|
}
|
|
200
204
|
|
|
205
|
+
setFocusedPageHost(hostKey: string | null | undefined): void {
|
|
206
|
+
if (this.focusedPageHost === hostKey) return;
|
|
207
|
+
this.focusedPageHost = hostKey;
|
|
208
|
+
this.emit();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
isPageHostFocused(hostKey: string | undefined): boolean {
|
|
212
|
+
return (
|
|
213
|
+
this.focusedPageHost === undefined || this.focusedPageHost === hostKey
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** @internal Web supplies its DOM host check for blocking and Escape. */
|
|
218
|
+
setPageHostAvailabilityCheck(
|
|
219
|
+
isAvailable: (hostKey: string | undefined) => boolean
|
|
220
|
+
): void {
|
|
221
|
+
this.isPageHostAvailable = isAvailable;
|
|
222
|
+
}
|
|
223
|
+
|
|
201
224
|
/** Native / navigation signal: the owning page was covered, detached or restored. */
|
|
202
225
|
setPageVisible(ownerKey: string, visible: boolean): void {
|
|
203
226
|
if ((this.pageVisibility.get(ownerKey) ?? true) === visible) {
|
|
@@ -248,8 +271,8 @@ export class OverlayStore {
|
|
|
248
271
|
!e.suspended &&
|
|
249
272
|
(e.blocking || e.dismissible) &&
|
|
250
273
|
(e.scope === 'global' ||
|
|
251
|
-
|
|
252
|
-
|
|
274
|
+
(this.isPageHostInteractive(e.hostKey) &&
|
|
275
|
+
(focusedHostKey === undefined || e.hostKey === focusedHostKey)))
|
|
253
276
|
);
|
|
254
277
|
const top = candidates[candidates.length - 1];
|
|
255
278
|
if (!top) {
|
|
@@ -260,12 +283,12 @@ export class OverlayStore {
|
|
|
260
283
|
: { kind: 'block' };
|
|
261
284
|
}
|
|
262
285
|
|
|
263
|
-
/** Topmost visible blocking entry; everything rendered below it is inert. */
|
|
264
286
|
/** The entry whose `statusBarStyle` applies (see `findStatusBarOwner`). */
|
|
265
287
|
getStatusBarOwner(): IOverlayEntry | undefined {
|
|
266
288
|
return findStatusBarOwner(this.snapshot);
|
|
267
289
|
}
|
|
268
290
|
|
|
291
|
+
/** Topmost visible blocking entry; everything rendered below it is inert. */
|
|
269
292
|
getBlockingTop(): IOverlayEntry | undefined {
|
|
270
293
|
const { entries } = this.snapshot;
|
|
271
294
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
@@ -274,7 +297,8 @@ export class OverlayStore {
|
|
|
274
297
|
entry &&
|
|
275
298
|
entry.phase !== 'closing' &&
|
|
276
299
|
!entry.suspended &&
|
|
277
|
-
entry.blocking
|
|
300
|
+
entry.blocking &&
|
|
301
|
+
(entry.scope === 'global' || this.isPageHostInteractive(entry.hostKey))
|
|
278
302
|
) {
|
|
279
303
|
return entry;
|
|
280
304
|
}
|
|
@@ -282,6 +306,13 @@ export class OverlayStore {
|
|
|
282
306
|
return undefined;
|
|
283
307
|
}
|
|
284
308
|
|
|
309
|
+
private isPageHostInteractive(hostKey: string | undefined): boolean {
|
|
310
|
+
return (
|
|
311
|
+
this.isPageHostFocused(hostKey) &&
|
|
312
|
+
(this.isPageHostAvailable?.(hostKey) ?? true)
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
285
316
|
private dismissWithoutEmit(
|
|
286
317
|
id: string,
|
|
287
318
|
reason: IOverlayDismissReason
|
package/src/OverlayView.web.tsx
CHANGED
|
@@ -19,9 +19,11 @@ import { useOverlayController } from './useOverlayController';
|
|
|
19
19
|
import { animateBackdrop, animateTransition } from './web/animateTransition';
|
|
20
20
|
import {
|
|
21
21
|
ENTRY_ATTRIBUTE,
|
|
22
|
+
focusOverlayEntry,
|
|
22
23
|
getOverlayLayerRoot,
|
|
23
24
|
getOverlayPageHost,
|
|
24
25
|
registerOverlayDismissRequester,
|
|
26
|
+
restoreOverlayEntryFocus,
|
|
25
27
|
scheduleOverlayInertSync,
|
|
26
28
|
subscribeOverlayPageHost,
|
|
27
29
|
} from './web/overlayLayers';
|
|
@@ -104,7 +106,6 @@ function WebOverlayEntry({
|
|
|
104
106
|
const backdropRef = useRef<HTMLDivElement>(null);
|
|
105
107
|
const directionRef = useRef<'in' | 'out' | undefined>(undefined);
|
|
106
108
|
const runningAnimationsRef = useRef<Animation[]>([]);
|
|
107
|
-
const restoreFocusRef = useRef<HTMLElement | null>(null);
|
|
108
109
|
const callbacksRef = useRef({ onPresented, onDismissed });
|
|
109
110
|
callbacksRef.current = { onPresented, onDismissed };
|
|
110
111
|
|
|
@@ -121,7 +122,8 @@ function WebOverlayEntry({
|
|
|
121
122
|
|
|
122
123
|
useLayoutEffect(() => {
|
|
123
124
|
const content = contentRef.current;
|
|
124
|
-
|
|
125
|
+
const entryElement = entryRef.current;
|
|
126
|
+
if (!content || !entryElement) {
|
|
125
127
|
return;
|
|
126
128
|
}
|
|
127
129
|
const direction = presented ? 'in' : 'out';
|
|
@@ -145,8 +147,7 @@ function WebOverlayEntry({
|
|
|
145
147
|
}
|
|
146
148
|
runningAnimationsRef.current = [];
|
|
147
149
|
if (direction === 'out' && (neverEntered || pannedAwayRef.current)) {
|
|
148
|
-
|
|
149
|
-
restoreFocusRef.current = null;
|
|
150
|
+
restoreOverlayEntryFocus(entryElement);
|
|
150
151
|
callbacksRef.current.onDismissed();
|
|
151
152
|
return;
|
|
152
153
|
}
|
|
@@ -157,9 +158,8 @@ function WebOverlayEntry({
|
|
|
157
158
|
if (backdropRef.current) {
|
|
158
159
|
backdropRef.current.style.opacity = '1';
|
|
159
160
|
}
|
|
160
|
-
if (blocking) {
|
|
161
|
-
|
|
162
|
-
entryRef.current?.focus({ preventScroll: true });
|
|
161
|
+
if (blocking && overlayStore.getBlockingTop()?.id === entryId) {
|
|
162
|
+
focusOverlayEntry(entryElement);
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
// A sheet is measured as a whole; other presentations by the children
|
|
@@ -194,15 +194,14 @@ function WebOverlayEntry({
|
|
|
194
194
|
if (direction === 'in') {
|
|
195
195
|
callbacksRef.current.onPresented();
|
|
196
196
|
} else {
|
|
197
|
-
|
|
198
|
-
restoreFocusRef.current = null;
|
|
197
|
+
restoreOverlayEntryFocus(entryElement);
|
|
199
198
|
callbacksRef.current.onDismissed();
|
|
200
199
|
}
|
|
201
200
|
})
|
|
202
201
|
.catch(() => {
|
|
203
202
|
// Cancelled by a newer transition; that run reports instead.
|
|
204
203
|
});
|
|
205
|
-
}, [presented, animation, blocking, isSheet]);
|
|
204
|
+
}, [presented, animation, blocking, isSheet, entryId]);
|
|
206
205
|
|
|
207
206
|
useEffect(
|
|
208
207
|
() => registerOverlayDismissRequester(entryId, onRequestDismiss),
|
|
@@ -311,7 +310,7 @@ function WebOverlayEntry({
|
|
|
311
310
|
return (
|
|
312
311
|
<div
|
|
313
312
|
ref={entryRef}
|
|
314
|
-
{...{ [ENTRY_ATTRIBUTE]:
|
|
313
|
+
{...{ [ENTRY_ATTRIBUTE]: entryId }}
|
|
315
314
|
{...(ownerKey ? { [OVERLAY_OWNER_ATTRIBUTE]: ownerKey } : {})}
|
|
316
315
|
data-stack-order={stackOrder}
|
|
317
316
|
data-overlay-level-order={levelOrder}
|
package/src/index.ts
CHANGED
|
@@ -54,3 +54,26 @@ export {
|
|
|
54
54
|
} from './OverlayPageScope';
|
|
55
55
|
export type { IOverlayPageScope } from './OverlayPageScope';
|
|
56
56
|
export { OverlayPageHost } from './OverlayPageHost';
|
|
57
|
+
export { OverlayToastHost } from './toast/OverlayToastHost';
|
|
58
|
+
export {
|
|
59
|
+
OverlayToastStore,
|
|
60
|
+
overlayToastStore,
|
|
61
|
+
} from './toast/OverlayToastStore';
|
|
62
|
+
export type { IOverlayToastSnapshot } from './toast/OverlayToastStore';
|
|
63
|
+
export type {
|
|
64
|
+
IOverlayMessageToast,
|
|
65
|
+
IOverlayNotificationToast,
|
|
66
|
+
IOverlayToastAction,
|
|
67
|
+
IOverlayToastDismissReason,
|
|
68
|
+
IOverlayToastEvent,
|
|
69
|
+
IOverlayToastFontWeight,
|
|
70
|
+
IOverlayToastHandle,
|
|
71
|
+
IOverlayToastHandlers,
|
|
72
|
+
IOverlayToastIcon,
|
|
73
|
+
IOverlayToastItem,
|
|
74
|
+
IOverlayToastPosition,
|
|
75
|
+
IOverlayToastSpec,
|
|
76
|
+
IOverlayToastText,
|
|
77
|
+
IOverlayToastTextRun,
|
|
78
|
+
IOverlayToasterConfig,
|
|
79
|
+
} from './toast/types';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useSyncExternalStore } from 'react';
|
|
2
|
+
|
|
3
|
+
import { StyleSheet } from 'react-native';
|
|
4
|
+
|
|
5
|
+
import NativeOverlayToaster from '../NativeOverlayToasterNativeComponent';
|
|
6
|
+
|
|
7
|
+
import { overlayToastStore } from './OverlayToastStore';
|
|
8
|
+
import { serializeToastItems, toToastEvent } from './toastBridge';
|
|
9
|
+
|
|
10
|
+
import type { NativeSyntheticEvent } from 'react-native';
|
|
11
|
+
|
|
12
|
+
const styles = StyleSheet.create({
|
|
13
|
+
// The host only carries data to the platform; the cards are drawn in the
|
|
14
|
+
// native `toast` overlay level, not inside this view.
|
|
15
|
+
host: { position: 'absolute', width: 0, height: 0 },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Hands the toast list to the platform renderer for as long as it is mounted.
|
|
20
|
+
* It draws nothing itself.
|
|
21
|
+
*/
|
|
22
|
+
export function OverlayToastHost() {
|
|
23
|
+
const snapshot = useSyncExternalStore(
|
|
24
|
+
overlayToastStore.subscribe,
|
|
25
|
+
overlayToastStore.getSnapshot,
|
|
26
|
+
overlayToastStore.getSnapshot
|
|
27
|
+
);
|
|
28
|
+
useEffect(() => overlayToastStore.attachRenderer(), []);
|
|
29
|
+
const toasts = useMemo(
|
|
30
|
+
() => serializeToastItems(snapshot.items),
|
|
31
|
+
[snapshot.items]
|
|
32
|
+
);
|
|
33
|
+
const config = useMemo(
|
|
34
|
+
() => JSON.stringify(snapshot.config),
|
|
35
|
+
[snapshot.config]
|
|
36
|
+
);
|
|
37
|
+
const handleToastEvent = useCallback(
|
|
38
|
+
(
|
|
39
|
+
event: NativeSyntheticEvent<{
|
|
40
|
+
toastId: string;
|
|
41
|
+
generation: number;
|
|
42
|
+
type: string;
|
|
43
|
+
value: string;
|
|
44
|
+
}>
|
|
45
|
+
) => {
|
|
46
|
+
const toastEvent = toToastEvent(event.nativeEvent);
|
|
47
|
+
if (toastEvent) {
|
|
48
|
+
overlayToastStore.handleEvent(toastEvent);
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
[]
|
|
52
|
+
);
|
|
53
|
+
return (
|
|
54
|
+
<NativeOverlayToaster
|
|
55
|
+
toasts={toasts}
|
|
56
|
+
config={config}
|
|
57
|
+
onToastEvent={handleToastEvent}
|
|
58
|
+
pointerEvents="none"
|
|
59
|
+
style={styles.host}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { overlayToastStore } from './OverlayToastStore';
|
|
4
|
+
import { createToastDomRenderer } from './toastDomRenderer.web';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Attaches the DOM toast renderer for as long as it is mounted. It renders no
|
|
8
|
+
* React output: the renderer draws straight into the `toast` overlay layer.
|
|
9
|
+
*/
|
|
10
|
+
export function OverlayToastHost() {
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const renderer = createToastDomRenderer((event) =>
|
|
13
|
+
overlayToastStore.handleEvent(event)
|
|
14
|
+
);
|
|
15
|
+
const detach = overlayToastStore.attachRenderer();
|
|
16
|
+
const sync = () => {
|
|
17
|
+
const { items, config } = overlayToastStore.getSnapshot();
|
|
18
|
+
renderer.sync(items, config);
|
|
19
|
+
};
|
|
20
|
+
sync();
|
|
21
|
+
const unsubscribe = overlayToastStore.subscribe(sync);
|
|
22
|
+
return () => {
|
|
23
|
+
unsubscribe();
|
|
24
|
+
renderer.destroy();
|
|
25
|
+
detach();
|
|
26
|
+
};
|
|
27
|
+
}, []);
|
|
28
|
+
return null;
|
|
29
|
+
}
|