@applicaster/quick-brick-core 16.0.0-alpha.6088600543 → 16.0.0-alpha.6409114856

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.
@@ -3,6 +3,14 @@ import * as R from "ramda";
3
3
 
4
4
  import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ActionsContext";
5
5
  import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
6
+ import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
7
+
8
+ import { LegacyActionsRegistryAdapter } from "./LegacyActionsRegistryAdapter";
9
+
10
+ const { log_debug } = createLogger({
11
+ subsystem: "ActionsProvider",
12
+ category: "ActionRegistration",
13
+ });
6
14
 
7
15
  type Props = {
8
16
  children: React.ReactNode;
@@ -36,19 +44,17 @@ const abstractIdentifier = (actionPlugins: Plugin[]): PluginsIdMap =>
36
44
  * Component returning children.
37
45
  * Can be used to create Component from children
38
46
  */
39
- const ChildrenWrapper = ({
40
- children,
41
- }: {
42
- children: React.ReactElement<any>;
43
- }) => {
44
- return children;
47
+ const ChildrenWrapper = ({ children }: { children: React.ReactNode }) => {
48
+ return <>{children}</>;
45
49
  };
46
50
 
47
51
  /**
48
52
  * It wraps children in multiple context providers
49
53
  * @param contexts - Array of React Context Providers
50
54
  */
51
- const contextComposer = (contexts: Plugin[]): React.ExoticComponent =>
55
+ const contextComposer = (
56
+ contexts: Plugin[]
57
+ ): React.ComponentType<React.PropsWithChildren> =>
52
58
  R.compose(...contexts)(ChildrenWrapper);
53
59
 
54
60
  /**
@@ -69,6 +75,19 @@ export function ActionsProvider(props: Props) {
69
75
  [plugins]
70
76
  );
71
77
 
78
+ React.useEffect(() => {
79
+ const count = Object.keys(actionPlugins).length;
80
+
81
+ if (count > 0) {
82
+ log_debug(
83
+ `ActionsProvider: composed ${count} action plugin(s) into context`,
84
+ { identifiers: Object.keys(actionPlugins) }
85
+ );
86
+ } else {
87
+ log_debug("ActionsProvider: no action plugins to compose");
88
+ }
89
+ }, [actionPlugins]);
90
+
72
91
  const contextProviders = React.useMemo((): [Plugin] | [] => {
73
92
  try {
74
93
  const providers = R.compose(
@@ -88,7 +107,7 @@ export function ActionsProvider(props: Props) {
88
107
  ? contextComposer(contextProviders)
89
108
  : React.Fragment,
90
109
  []
91
- );
110
+ ) as React.ComponentType<React.PropsWithChildren>;
92
111
 
93
112
  const contextValue = React.useMemo(
94
113
  () => ({ actions: actionPlugins }),
@@ -97,7 +116,10 @@ export function ActionsProvider(props: Props) {
97
116
 
98
117
  return (
99
118
  <ActionsContext.Provider value={contextValue}>
100
- <Context>{children}</Context>
119
+ <Context>
120
+ <LegacyActionsRegistryAdapter actionPlugins={actionPlugins} />
121
+ {children}
122
+ </Context>
101
123
  </ActionsContext.Provider>
102
124
  );
103
125
  }
@@ -0,0 +1,107 @@
1
+ import * as React from "react";
2
+ import * as R from "ramda";
3
+
4
+ import { uiActionsRegistry } from "@applicaster/zapp-react-native-utils/uiActionsRegistrator";
5
+ import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
6
+
7
+ const { log_debug, log_warning } = createLogger({
8
+ subsystem: "LegacyActionsRegistryAdapter",
9
+ category: "ActionRegistration",
10
+ });
11
+
12
+ type LegacyActionPlugin = Record<string, any> & {
13
+ identifier: string;
14
+ module: {
15
+ context?: React.Context<any>;
16
+ [key: string]: any;
17
+ };
18
+ };
19
+
20
+ /**
21
+ * Bridges a single legacy action plugin (one that exposes `module.context`)
22
+ * into the `uiActionsRegistry`.
23
+ *
24
+ * Reactivity note: legacy stateful actions rely on React Context re-renders to
25
+ * propagate their latest value to subscribed UI (via `useActions`). We keep
26
+ * that mechanism intact and only *mirror* the current value into the registry
27
+ * through a ref, so registry-based consumers always read the freshest value at
28
+ * call time without changing legacy reactivity.
29
+ */
30
+ function LegacyActionBridge({ plugin }: { plugin: LegacyActionPlugin }) {
31
+ // `plugin.module.context` is stable for the lifetime of the plugin, so this
32
+ // single `useContext` call is safe and rules-of-hooks compliant.
33
+ const value = React.useContext(plugin.module.context as React.Context<any>);
34
+
35
+ const valueRef = React.useRef(value);
36
+ valueRef.current = value;
37
+
38
+ React.useEffect(() => {
39
+ if (value == null) {
40
+ log_warning(
41
+ `LegacyActionBridge: context value for "${plugin.identifier}" is null/undefined – skipping registration`,
42
+ { identifier: plugin.identifier }
43
+ );
44
+ } else {
45
+ log_debug(
46
+ `LegacyActionBridge: context value ready for "${plugin.identifier}", registering in UIActionsRegistry`,
47
+ { identifier: plugin.identifier }
48
+ );
49
+ }
50
+
51
+ const unregister = uiActionsRegistry.registerActionProvider(
52
+ plugin.identifier,
53
+ () =>
54
+ valueRef.current
55
+ ? [{ identifier: plugin.identifier, action: valueRef.current }]
56
+ : []
57
+ );
58
+
59
+ return () => {
60
+ log_debug(
61
+ `LegacyActionBridge: unmounting bridge for "${plugin.identifier}"`,
62
+ { identifier: plugin.identifier }
63
+ );
64
+
65
+ unregister();
66
+ };
67
+ }, [plugin.identifier]);
68
+
69
+ return null;
70
+ }
71
+
72
+ type Props = {
73
+ actionPlugins: Record<string, LegacyActionPlugin>;
74
+ };
75
+
76
+ /**
77
+ * Registers every legacy action plugin's live context value into the
78
+ * `uiActionsRegistry`. It must be rendered *inside* the composed context
79
+ * providers (see `ActionsProvider`) so that each plugin's context is populated.
80
+ *
81
+ * This is the compatibility layer that lets new, registry-based consumers read
82
+ * actions coming from old plugins that still export `contextProvider`/`context`.
83
+ */
84
+ export function LegacyActionsRegistryAdapter({ actionPlugins }: Props) {
85
+ const bridgedPlugins = React.useMemo(
86
+ () =>
87
+ R.values(actionPlugins).filter(
88
+ (plugin) => plugin?.module?.context != null
89
+ ),
90
+ [actionPlugins]
91
+ );
92
+
93
+ log_debug(
94
+ `LegacyActionsRegistryAdapter: bridging ${bridgedPlugins.length} legacy action plugin(s)`,
95
+ { identifiers: bridgedPlugins.map((p) => p.identifier) }
96
+ );
97
+
98
+ return (
99
+ <>
100
+ {bridgedPlugins.map((plugin) => (
101
+ <LegacyActionBridge key={plugin.identifier} plugin={plugin} />
102
+ ))}
103
+ </>
104
+ );
105
+ }
106
+
107
+ LegacyActionsRegistryAdapter.displayName = "LegacyActionsRegistryAdapter";
@@ -0,0 +1,88 @@
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+ import { State } from "react-native-gesture-handler";
5
+ import { DraggableBottomSheet } from "../index";
6
+
7
+ // Render the gesture handlers as passthrough Views so we can mount the sheet
8
+ // and drive its release handler directly. State stays real (we need ACTIVE).
9
+ jest.mock("react-native-gesture-handler", () => {
10
+ const RN = require("react-native");
11
+ const ReactActual = require("react");
12
+ const actual = jest.requireActual("react-native-gesture-handler");
13
+
14
+ const Passthrough = ReactActual.forwardRef(({ children }: any, _ref: any) => (
15
+ <RN.View>{children}</RN.View>
16
+ ));
17
+
18
+ return {
19
+ __esModule: true,
20
+ ...actual,
21
+ PanGestureHandler: Passthrough,
22
+ TapGestureHandler: Passthrough,
23
+ };
24
+ });
25
+
26
+ // height 800, sheetHeight 400, no header:
27
+ // SnapPoints.top = 800 - 400 = 400 (lastSnap after mount)
28
+ // SnapPoints.threshold = max(800 - 400 / 2, 100) = 600
29
+ // Release dismisses when lastSnap + translationY + 0.05 * velocityY > 600,
30
+ // i.e. once the drag+toss pushes past 200px.
31
+ const mountSheet = () => {
32
+ const dismiss = jest.fn();
33
+ const ref = React.createRef<DraggableBottomSheet>();
34
+
35
+ render(
36
+ <DraggableBottomSheet
37
+ ref={ref}
38
+ header={() => null}
39
+ dismiss={dismiss}
40
+ visible={true}
41
+ sheetHeight={400}
42
+ width={320}
43
+ height={800}
44
+ hasHeader={false}
45
+ maxWidth={320}
46
+ >
47
+ <View testID="child" />
48
+ </DraggableBottomSheet>
49
+ );
50
+
51
+ return { instance: ref.current as DraggableBottomSheet, dismiss };
52
+ };
53
+
54
+ const release = (
55
+ instance: DraggableBottomSheet,
56
+ translationY: number,
57
+ velocityY = 0
58
+ ) =>
59
+ instance._onHandlerStateChange({
60
+ nativeEvent: { oldState: State.ACTIVE, translationY, velocityY },
61
+ });
62
+
63
+ describe("DraggableBottomSheet release", () => {
64
+ // Mounting an open sheet schedules a deferred animateIn via setTimeout. Keep
65
+ // it on fake timers so it never fires into a torn-down Jest environment.
66
+ beforeEach(() => jest.useFakeTimers());
67
+
68
+ afterEach(() => {
69
+ jest.clearAllTimers();
70
+ jest.useRealTimers();
71
+ });
72
+
73
+ it("dismisses when the release lands past the threshold", () => {
74
+ const { instance, dismiss } = mountSheet();
75
+
76
+ release(instance, 300);
77
+
78
+ expect(dismiss).toHaveBeenCalledTimes(1);
79
+ });
80
+
81
+ it("springs back (does not dismiss) when the release is below the threshold", () => {
82
+ const { instance, dismiss } = mountSheet();
83
+
84
+ release(instance, 50);
85
+
86
+ expect(dismiss).not.toHaveBeenCalled();
87
+ });
88
+ });
@@ -1,15 +1,24 @@
1
- import React, { Component, ReactChild, ReactElement } from "react";
1
+ import React, { Component, ReactElement } from "react";
2
2
  import { Animated, StyleSheet, View, Easing } from "react-native";
3
3
  import {
4
4
  PanGestureHandler,
5
- NativeViewGestureHandler,
6
5
  State,
7
6
  TapGestureHandler,
8
7
  } from "react-native-gesture-handler";
9
8
 
10
9
  import { SnapPoints } from "./SnapPoints";
11
-
12
- const USE_NATIVE_DRIVER = true;
10
+ import {
11
+ BottomSheetContext,
12
+ BottomSheetContextValue,
13
+ } from "@applicaster/zapp-react-native-utils/bottomSheet";
14
+
15
+ // Must stay false: the sheet drives _dragY from old-API PanGestureHandler
16
+ // onGestureEvent props via RN Animated.event. This RNGH version cannot attach
17
+ // a native (useNativeDriver: true) Animated.event to those handlers — it leaks
18
+ // the AnimatedEvent object into the JS event path and throws "Expected
19
+ // onGestureHandlerEvent listener to be a function". Native-threaded dragging
20
+ // needs the full reanimated + Gesture-API migration (tracked separately).
21
+ const USE_NATIVE_DRIVER = false;
13
22
  const HEADER_HEIGHT = 44;
14
23
 
15
24
  const ANIMATION_DURATION = 400;
@@ -24,7 +33,7 @@ const styles = StyleSheet.create({
24
33
  });
25
34
 
26
35
  type Props = {
27
- children: ReactChild;
36
+ children: ReactElement;
28
37
  header: (boolean) => ReactElement;
29
38
  dismiss: () => void;
30
39
  visible: boolean;
@@ -49,35 +58,24 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
49
58
  _isMounted = false;
50
59
  _animatedIn = false;
51
60
  _animating = false;
52
- _lastScrollYValue: number;
53
- _lastScrollY: Animated.Value;
54
61
  _dragY: Animated.Value;
55
- _reverseLastScrollY: Animated.AnimatedInterpolation<number>;
56
62
  _translateYOffset: Animated.Value;
57
63
  _translateY: Animated.AnimatedInterpolation<number>;
58
64
  _snapPoints: SnapPoints;
59
65
  _prevContentHeight = 0;
66
+ _bottomSheetContextValue: BottomSheetContextValue;
60
67
 
61
68
  _callWhenMounted: () => void | null;
62
69
 
63
- _onRegisterLastScroll: (...args: any[]) => void;
70
+ // One shared JS Animated.event feeds _dragY for every drag handler (top
71
+ // handle, header drag-area, body). Safe because useNativeDriver is false — the
72
+ // event is a plain JS listener that setValue's _dragY for whichever handler
73
+ // is active, and only one gesture is ever active at a time.
64
74
  _onGestureEvent: (...args: any[]) => void;
65
75
 
66
76
  constructor(props) {
67
77
  super(props);
68
78
 
69
- this._lastScrollYValue = 0;
70
- this._lastScrollY = new Animated.Value(0);
71
-
72
- this._onRegisterLastScroll = Animated.event(
73
- [{ nativeEvent: { contentOffset: { y: this._lastScrollY } } }],
74
- { useNativeDriver: USE_NATIVE_DRIVER }
75
- );
76
-
77
- this._lastScrollY.addListener(({ value }) => {
78
- this._lastScrollYValue = value;
79
- });
80
-
81
79
  this._dragY = new Animated.Value(0);
82
80
 
83
81
  this._onGestureEvent = Animated.event(
@@ -85,10 +83,11 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
85
83
  { useNativeDriver: USE_NATIVE_DRIVER }
86
84
  );
87
85
 
88
- this._reverseLastScrollY = Animated.multiply(
89
- new Animated.Value(-1),
90
- this._lastScrollY
91
- );
86
+ this._bottomSheetContextValue = {
87
+ masterDrawerRef: this.masterdrawer,
88
+ onDragGestureEvent: this._onGestureEvent,
89
+ onDragStateChange: this._onHeaderHandlerStateChange,
90
+ };
92
91
 
93
92
  const initialSnapPoints = new SnapPoints(props.height, props.sheetHeight);
94
93
 
@@ -181,7 +180,7 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
181
180
 
182
181
  this._translateY = Animated.add(
183
182
  this._translateYOffset,
184
- Animated.add(this._dragY, this._reverseLastScrollY)
183
+ this._dragY
185
184
  ).interpolate({
186
185
  inputRange: [this._snapPoints.top, this._snapPoints.bottom],
187
186
  outputRange: [this._snapPoints.top, this._snapPoints.bottom],
@@ -226,10 +225,6 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
226
225
  return;
227
226
  }
228
227
 
229
- if (nativeEvent.oldState === State.BEGAN) {
230
- this._lastScrollY.setValue(0);
231
- }
232
-
233
228
  this._onHandlerStateChange({ nativeEvent });
234
229
  };
235
230
 
@@ -240,8 +235,7 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
240
235
 
241
236
  if (nativeEvent.oldState === State.ACTIVE) {
242
237
  const { velocityY } = nativeEvent;
243
- let { translationY } = nativeEvent;
244
- translationY -= this._lastScrollYValue;
238
+ const { translationY } = nativeEvent;
245
239
  const dragToss = 0.05;
246
240
 
247
241
  const endOffsetY =
@@ -300,7 +294,7 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
300
294
  >
301
295
  <PanGestureHandler
302
296
  ref={this.drawerheader}
303
- simultaneousHandlers={[this.scroll, this.masterdrawer]}
297
+ simultaneousHandlers={[this.masterdrawer]}
304
298
  shouldCancelWhenOutside={false}
305
299
  onGestureEvent={this._onGestureEvent}
306
300
  onHandlerStateChange={this._onHeaderHandlerStateChange}
@@ -309,31 +303,11 @@ export class DraggableBottomSheet extends Component<Props, ComponentState> {
309
303
  {this.props?.header(this.state.dragging)}
310
304
  </Animated.View>
311
305
  </PanGestureHandler>
312
- <PanGestureHandler
313
- ref={this.drawer}
314
- simultaneousHandlers={[this.scroll, this.masterdrawer]}
315
- shouldCancelWhenOutside={false}
316
- onGestureEvent={this._onGestureEvent}
317
- onHandlerStateChange={this._onHandlerStateChange}
318
- >
306
+ <BottomSheetContext.Provider value={this._bottomSheetContextValue}>
319
307
  <Animated.View style={styles.container}>
320
- <NativeViewGestureHandler
321
- ref={this.scroll}
322
- waitFor={this.masterdrawer}
323
- simultaneousHandlers={this.drawer}
324
- >
325
- <Animated.ScrollView
326
- bounces={false}
327
- onScrollBeginDrag={this._onRegisterLastScroll}
328
- scrollEventThrottle={1}
329
- scrollEnabled={false}
330
- showsVerticalScrollIndicator={false}
331
- >
332
- {this.props.children}
333
- </Animated.ScrollView>
334
- </NativeViewGestureHandler>
308
+ {this.props.children}
335
309
  </Animated.View>
336
- </PanGestureHandler>
310
+ </BottomSheetContext.Provider>
337
311
  </Animated.View>
338
312
  </View>
339
313
  </TapGestureHandler>
@@ -0,0 +1,203 @@
1
+ import { subscriber } from "@applicaster/zapp-react-native-utils/functionUtils";
2
+ import { subscriberFor } from "@applicaster/zapp-react-native-utils/reactHooks/useSubscriberFor";
3
+
4
+ // events accepted on the shared cross-package event bus (see useSubscriberFor),
5
+ // so packages that must not depend on quick-brick-core (e.g. OfflineHandler in
6
+ // zapp-react-native-ui-components) can trigger a toast by event name alone,
7
+ // without importing notificationToastManager directly.
8
+ const unwrapEventPayload = (payload: unknown) =>
9
+ Array.isArray(payload) ? payload[0] : payload;
10
+
11
+ export const NOTIFICATION_TOAST_EVENTS = {
12
+ SHOW_TOAST: "showToast", // in: request to enqueue a toast
13
+ DISMISS: "dismiss", // in: renderer/user dismissed the visible toast early
14
+ SHOW: "show", // out: renderer should display this toast
15
+ HIDE: "hide", // out: renderer should hide the current toast
16
+ } as const;
17
+
18
+ export interface ToastStyle {
19
+ backgroundColor?: string;
20
+ color?: string;
21
+ fontFamily?: string;
22
+ fontSize?: number;
23
+ lineHeight?: number;
24
+ letterSpacing?: number;
25
+ }
26
+
27
+ export interface ToastPayload {
28
+ id?: string;
29
+ message: string;
30
+ extraMessage?: string; // secondary line; TV renderers show it as a subtitle, mobile ignores it
31
+ timeout?: number; // ms; if omitted, toast stays until dismissed
32
+ style?: ToastStyle;
33
+ [key: string]: unknown;
34
+ }
35
+
36
+ class NotificationToastManager {
37
+ private static instance: NotificationToastManager;
38
+
39
+ private eventHandler = subscriber();
40
+ private queue: ToastPayload[] = [];
41
+ private hideTimer: ReturnType<typeof setTimeout> | null = null;
42
+ private isShowing = false;
43
+ private nextId = 0;
44
+
45
+ private constructor() {
46
+ // subscribe to the shared event bus so other packages can trigger toasts
47
+ subscriberFor(
48
+ NOTIFICATION_TOAST_EVENTS.SHOW_TOAST,
49
+ this.handleShowToastEvent
50
+ );
51
+
52
+ subscriberFor(NOTIFICATION_TOAST_EVENTS.DISMISS, this.handleDismiss);
53
+
54
+ this.getCurrentState = this.getCurrentState.bind(this);
55
+ this.subscribe = this.subscribe.bind(this);
56
+ }
57
+
58
+ static getInstance(): NotificationToastManager {
59
+ if (!NotificationToastManager.instance) {
60
+ NotificationToastManager.instance = new NotificationToastManager();
61
+ }
62
+
63
+ return NotificationToastManager.instance;
64
+ }
65
+
66
+ on(event: string, callback: (...args: any[]) => void) {
67
+ this.eventHandler.on(event, callback);
68
+ }
69
+
70
+ removeHandler(event: string, callback: (...args: any[]) => void) {
71
+ this.eventHandler.removeHandler(event, callback);
72
+ }
73
+
74
+ showToast(payload: ToastPayload) {
75
+ this.handleShowToast(payload);
76
+ }
77
+
78
+ dismiss() {
79
+ this.handleDismiss();
80
+ }
81
+
82
+ getCurrentState() {
83
+ return this.queue[0] ?? null;
84
+ }
85
+
86
+ subscribe(callback) {
87
+ this.eventHandler.on(NOTIFICATION_TOAST_EVENTS.SHOW, callback);
88
+
89
+ this.eventHandler.on(NOTIFICATION_TOAST_EVENTS.HIDE, callback);
90
+
91
+ return () => {
92
+ this.eventHandler.removeHandler(NOTIFICATION_TOAST_EVENTS.SHOW, callback);
93
+
94
+ this.eventHandler.removeHandler(NOTIFICATION_TOAST_EVENTS.HIDE, callback);
95
+ };
96
+ }
97
+
98
+ // subscriberFor's shared bus can deliver the raw payload (component emitters,
99
+ // see useSubscriberFor) or an args array (postEvent-style callers) - accept both.
100
+ private handleShowToastEvent = (payload: unknown) => {
101
+ if (!payload) {
102
+ console.warn(
103
+ "NotificationToastManager: Invalid showToast payload:",
104
+ payload
105
+ );
106
+
107
+ return;
108
+ }
109
+
110
+ const unwrappedPayload = unwrapEventPayload(payload) as ToastPayload;
111
+
112
+ if (!unwrappedPayload || typeof unwrappedPayload.message !== "string") {
113
+ console.warn(
114
+ "NotificationToastManager: Invalid showToast payload:",
115
+ payload
116
+ );
117
+
118
+ return;
119
+ }
120
+
121
+ this.handleShowToast(unwrappedPayload);
122
+ };
123
+
124
+ private handleShowToast = (payload: ToastPayload) => {
125
+ const item = { ...payload, id: payload.id ?? String(this.nextId++) };
126
+
127
+ const queuedIndex = this.queue.findIndex((queued) => queued.id === item.id);
128
+
129
+ if (queuedIndex === -1) {
130
+ this.queue.push(item);
131
+ } else if (queuedIndex === 0 && this.isShowing) {
132
+ // this id is the toast currently on screen - swap its content in place
133
+ // (new one appears in front of it) and dismiss the old timer/content
134
+ this.clearTimer();
135
+ this.queue[0] = item;
136
+ this.eventHandler.invokeHandler(NOTIFICATION_TOAST_EVENTS.SHOW, item);
137
+
138
+ if (item.timeout) {
139
+ this.hideTimer = setTimeout(() => this.finishCurrent(), item.timeout);
140
+ }
141
+
142
+ return;
143
+ } else {
144
+ // still queued, not yet shown - update it in place instead of duplicating
145
+ this.queue[queuedIndex] = item;
146
+
147
+ return;
148
+ }
149
+
150
+ if (!this.isShowing) {
151
+ this.processNext();
152
+ }
153
+ };
154
+
155
+ private handleDismiss = () => {
156
+ if (!this.isShowing) {
157
+ return;
158
+ }
159
+
160
+ this.finishCurrent();
161
+ };
162
+
163
+ private processNext() {
164
+ const next = this.queue[0];
165
+
166
+ if (!next) {
167
+ this.isShowing = false;
168
+
169
+ return;
170
+ }
171
+
172
+ this.isShowing = true;
173
+ this.eventHandler.invokeHandler(NOTIFICATION_TOAST_EVENTS.SHOW, next);
174
+
175
+ if (next.timeout) {
176
+ this.hideTimer = setTimeout(() => this.finishCurrent(), next.timeout);
177
+ }
178
+ }
179
+
180
+ private finishCurrent() {
181
+ this.clearTimer();
182
+ this.queue.shift();
183
+ this.eventHandler.invokeHandler(NOTIFICATION_TOAST_EVENTS.HIDE);
184
+ this.isShowing = false;
185
+ this.processNext();
186
+ }
187
+
188
+ private clearTimer() {
189
+ if (this.hideTimer) {
190
+ clearTimeout(this.hideTimer);
191
+ this.hideTimer = null;
192
+ }
193
+ }
194
+
195
+ public reset(): void {
196
+ this.clearTimer();
197
+ this.queue = [];
198
+ this.isShowing = false;
199
+ this.nextId = 0;
200
+ }
201
+ }
202
+
203
+ export const notificationToastManager = NotificationToastManager.getInstance();