@applicaster/quick-brick-core 16.0.0-alpha.9225550512 → 16.0.0-alpha.9506982263

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.
@@ -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>
@@ -24,12 +24,19 @@ export interface ToastStyle {
24
24
  letterSpacing?: number;
25
25
  }
26
26
 
27
+ export const DEFAULT_TOAST_TIMEOUT = 4000;
28
+
29
+ export const CONFIRMATION_TOAST_SOURCE = "confirmation";
30
+
27
31
  export interface ToastPayload {
28
32
  id?: string;
29
33
  message: string;
30
34
  extraMessage?: string; // secondary line; TV renderers show it as a subtitle, mobile ignores it
31
- timeout?: number; // ms; if omitted, toast stays until dismissed
35
+ timeout?: number; // ms; defaults to DEFAULT_TOAST_TIMEOUT (4000) if omitted
32
36
  style?: ToastStyle;
37
+ // stamped by the showToast action; Theme confirmation styles apply when
38
+ // source === CONFIRMATION_TOAST_SOURCE ("confirmation")
39
+ source?: string;
33
40
  [key: string]: unknown;
34
41
  }
35
42
 
@@ -122,7 +129,11 @@ class NotificationToastManager {
122
129
  };
123
130
 
124
131
  private handleShowToast = (payload: ToastPayload) => {
125
- const item = { ...payload, id: payload.id ?? String(this.nextId++) };
132
+ const item = {
133
+ ...payload,
134
+ id: payload.id ?? String(this.nextId++),
135
+ timeout: payload.timeout ?? DEFAULT_TOAST_TIMEOUT,
136
+ };
126
137
 
127
138
  const queuedIndex = this.queue.findIndex((queued) => queued.id === item.id);
128
139
 
@@ -1,16 +1,22 @@
1
- import React, { useEffect, useRef, useState } from "react";
1
+ import React, { useEffect, useMemo, useRef, useState } from "react";
2
+ import { View, Text, Animated, StyleSheet, ViewStyle } from "react-native";
2
3
  import {
3
- View,
4
- Text,
5
- Animated,
6
- StyleSheet,
7
- TouchableWithoutFeedback,
8
- ViewStyle,
9
- } from "react-native";
10
-
11
- import { notificationToastManager } from "./NotificationToastManager";
4
+ Directions,
5
+ Gesture,
6
+ GestureDetector,
7
+ } from "react-native-gesture-handler";
8
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
9
+
10
+ import {
11
+ CONFIRMATION_TOAST_SOURCE,
12
+ notificationToastManager,
13
+ } from "./NotificationToastManager";
12
14
  import { useNotificationToastState } from "./useNotificationToastState";
13
15
  import { useNotificationHeight } from "./useNotificationHeight";
16
+ import { resolveConfirmationToastStyle } from "./resolveConfirmationToastStyle";
17
+
18
+ const DEFAULT_TOAST_BACKGROUND_COLOR = "#000";
19
+ const DEFAULT_TOAST_MESSAGE_COLOR = "#fff";
14
20
 
15
21
  const styles = StyleSheet.create({
16
22
  notificationView: {
@@ -28,6 +34,7 @@ type NumberBoolean = 0 | 1;
28
34
 
29
35
  export const NotificationToastRenderer = ({ children }) => {
30
36
  const { statusHeight, notificationHeight } = useNotificationHeight();
37
+ const theme = useTheme<BaseThemePropertiesMobile>();
31
38
 
32
39
  const toast = useNotificationToastState();
33
40
 
@@ -36,15 +43,22 @@ export const NotificationToastRenderer = ({ children }) => {
36
43
 
37
44
  const yPosition = useRef(new Animated.Value(0)).current;
38
45
 
39
- const backgroundColor = toast?.style?.backgroundColor ?? "#000";
40
- const color = toast?.style?.color ?? "#fff";
46
+ const resolvedStyle =
47
+ toast?.source === CONFIRMATION_TOAST_SOURCE
48
+ ? resolveConfirmationToastStyle(theme, toast.style)
49
+ : toast?.style;
50
+
51
+ const backgroundColor =
52
+ resolvedStyle?.backgroundColor ?? DEFAULT_TOAST_BACKGROUND_COLOR;
53
+
54
+ const color = resolvedStyle?.color ?? DEFAULT_TOAST_MESSAGE_COLOR;
41
55
 
42
56
  const textStyles = {
43
57
  color,
44
- fontFamily: toast?.style?.fontFamily,
45
- fontSize: toast?.style?.fontSize,
46
- lineHeight: toast?.style?.lineHeight,
47
- letterSpacing: toast?.style?.letterSpacing,
58
+ fontFamily: resolvedStyle?.fontFamily,
59
+ fontSize: resolvedStyle?.fontSize,
60
+ lineHeight: resolvedStyle?.lineHeight,
61
+ letterSpacing: resolvedStyle?.letterSpacing,
48
62
  };
49
63
 
50
64
  const animatedViewStyles: ViewStyle = {
@@ -64,6 +78,20 @@ export const NotificationToastRenderer = ({ children }) => {
64
78
  backgroundColor,
65
79
  };
66
80
 
81
+ const flingGesture = useMemo(
82
+ () =>
83
+ Gesture.Fling()
84
+ .direction(Directions.UP)
85
+ .enabled(!!toast)
86
+ .runOnJS(true)
87
+ .onEnd((_event, success) => {
88
+ if (success) {
89
+ notificationToastManager.dismiss();
90
+ }
91
+ }),
92
+ [toast]
93
+ );
94
+
67
95
  useEffect(() => {
68
96
  if (toast) {
69
97
  setNotificationOpacity(1);
@@ -83,20 +111,24 @@ export const NotificationToastRenderer = ({ children }) => {
83
111
  }, [toast]);
84
112
 
85
113
  return (
86
- <View testID="NotificationToastRenderer" style={StyleSheet.absoluteFill}>
114
+ <View
115
+ testID="NotificationToastRenderer"
116
+ style={StyleSheet.absoluteFill}
117
+ pointerEvents="box-none"
118
+ >
87
119
  {children}
88
- <TouchableWithoutFeedback
89
- testID="NotificationToastRenderer-touchable"
90
- style={styles.notificationView}
91
- onPress={() => notificationToastManager.dismiss()}
92
- >
93
- <Animated.View style={animatedViewStyles}>
120
+ <GestureDetector gesture={flingGesture}>
121
+ <Animated.View
122
+ testID="NotificationToastRenderer-fling"
123
+ pointerEvents={toast ? "auto" : "none"}
124
+ style={animatedViewStyles}
125
+ >
94
126
  <View style={{ height: statusHeight, backgroundColor }} />
95
127
  <Text testID="NotificationToastRenderer-message" style={textStyles}>
96
128
  {toast?.message}
97
129
  </Text>
98
130
  </Animated.View>
99
- </TouchableWithoutFeedback>
131
+ </GestureDetector>
100
132
  </View>
101
133
  );
102
134
  };
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  notificationToastManager,
3
3
  NOTIFICATION_TOAST_EVENTS,
4
+ DEFAULT_TOAST_TIMEOUT,
4
5
  } from "../NotificationToastManager";
5
6
  import { postEvent } from "@applicaster/zapp-react-native-utils/reactHooks/useSubscriberFor";
6
7
 
@@ -210,4 +211,27 @@ describe("NotificationToastManager", () => {
210
211
 
211
212
  expect(onShow).not.toHaveBeenCalled();
212
213
  });
214
+
215
+ it("defaults timeout to DEFAULT_TOAST_TIMEOUT (4000ms) when omitted and auto-hides", () => {
216
+ const onShow = jest.fn();
217
+ const onHide = jest.fn();
218
+ on(NOTIFICATION_TOAST_EVENTS.SHOW, onShow);
219
+ on(NOTIFICATION_TOAST_EVENTS.HIDE, onHide);
220
+
221
+ notificationToastManager.showToast({
222
+ message: "Added to queue",
223
+ });
224
+
225
+ expect(onShow).toHaveBeenCalledWith(
226
+ expect.objectContaining({
227
+ message: "Added to queue",
228
+ timeout: DEFAULT_TOAST_TIMEOUT,
229
+ }),
230
+ expect.any(Function)
231
+ );
232
+
233
+ jest.advanceTimersByTime(DEFAULT_TOAST_TIMEOUT);
234
+
235
+ expect(onHide).toHaveBeenCalledTimes(1);
236
+ });
213
237
  });
@@ -1,14 +1,68 @@
1
1
  import React from "react";
2
2
  import { Text } from "react-native";
3
3
  import { act, fireEvent, render } from "@testing-library/react-native";
4
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
4
5
 
5
- import { notificationToastManager } from "../NotificationToastManager";
6
+ import {
7
+ CONFIRMATION_TOAST_SOURCE,
8
+ notificationToastManager,
9
+ } from "../NotificationToastManager";
6
10
  import { NotificationToastRenderer } from "../NotificationToastRenderer";
7
11
 
8
12
  jest.mock("react-native-safe-area-context", () => ({
9
13
  useSafeAreaInsets: () => ({ top: 44 }),
10
14
  }));
11
15
 
16
+ jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
17
+ useTheme: jest.fn(),
18
+ }));
19
+
20
+ jest.mock("react-native-gesture-handler", () => {
21
+ const RN = require("react-native");
22
+ const ReactActual = require("react");
23
+ const actual = jest.requireActual("react-native-gesture-handler");
24
+
25
+ const GestureDetector = ReactActual.forwardRef(
26
+ ({ gesture, children }: any, ref: any) => {
27
+ const onEnd = gesture?.handlers?.onEnd;
28
+
29
+ return (
30
+ <RN.View
31
+ ref={ref}
32
+ testID="NotificationToastRenderer-fling-handler"
33
+ accessibilityState={{ disabled: gesture?.config?.enabled === false }}
34
+ // drive Gesture.Fling().onEnd via a test-only event
35
+ onEnd={() => onEnd?.({}, true)}
36
+ onEndFailed={() => onEnd?.({}, false)}
37
+ >
38
+ {children}
39
+ </RN.View>
40
+ );
41
+ }
42
+ );
43
+
44
+ return {
45
+ __esModule: true,
46
+ ...actual,
47
+ GestureDetector,
48
+ };
49
+ });
50
+
51
+ const mockedUseTheme = useTheme as jest.MockedFunction<typeof useTheme>;
52
+
53
+ const confirmationTheme: Partial<BaseThemePropertiesMobile> = {
54
+ confirmation_toast_style_background_color: "#0188FF",
55
+ confirmation_toast_style_color: "#EFEFEF",
56
+ confirmation_toast_style_ios_font_family: "SFProText-Semibold",
57
+ confirmation_toast_style_android_font_family: "Roboto-Medium",
58
+ confirmation_toast_style_ios_font_size: 14,
59
+ confirmation_toast_style_android_font_size: 14,
60
+ confirmation_toast_style_ios_line_height: 44,
61
+ confirmation_toast_style_android_line_height: 44,
62
+ confirmation_toast_style_ios_letter_spacing: -1.4,
63
+ confirmation_toast_style_android_letter_spacing: -1.4,
64
+ };
65
+
12
66
  describe("NotificationToastRenderer", () => {
13
67
  beforeAll(() => {
14
68
  jest.spyOn(console, "log").mockImplementation(() => {});
@@ -18,6 +72,12 @@ describe("NotificationToastRenderer", () => {
18
72
  (console.log as jest.Mock).mockRestore();
19
73
  });
20
74
 
75
+ beforeEach(() => {
76
+ mockedUseTheme.mockReturnValue(
77
+ confirmationTheme as BaseThemePropertiesMobile
78
+ );
79
+ });
80
+
21
81
  afterEach(() => {
22
82
  // drain whatever is left showing/queued so the next test starts clean
23
83
  for (let i = 0; i < 10; i++) {
@@ -73,13 +133,101 @@ describe("NotificationToastRenderer", () => {
73
133
  ).toEqual(expect.objectContaining({ color: "#123456", fontSize: 20 }));
74
134
  });
75
135
 
76
- it("dismisses the toast when the touchable area is pressed", () => {
136
+ it("applies Theme confirmation styles when source is confirmation", () => {
137
+ const { getByTestId } = render(<NotificationToastRenderer />);
138
+
139
+ act(() => {
140
+ notificationToastManager.showToast({
141
+ message: "Added to queue",
142
+ source: CONFIRMATION_TOAST_SOURCE,
143
+ });
144
+ });
145
+
146
+ expect(
147
+ getByTestId("NotificationToastRenderer-message").props.style
148
+ ).toEqual(
149
+ expect.objectContaining({
150
+ color: "#EFEFEF",
151
+ fontSize: 14,
152
+ lineHeight: 44,
153
+ letterSpacing: -1.4,
154
+ })
155
+ );
156
+ });
157
+
158
+ it("shallow-merges style overrides onto Theme confirmation defaults", () => {
159
+ const { getByTestId } = render(<NotificationToastRenderer />);
160
+
161
+ act(() => {
162
+ notificationToastManager.showToast({
163
+ message: "Playlist created",
164
+ source: CONFIRMATION_TOAST_SOURCE,
165
+ style: { backgroundColor: "#00FF00", fontSize: 20 },
166
+ });
167
+ });
168
+
169
+ expect(
170
+ getByTestId("NotificationToastRenderer-message").props.style
171
+ ).toEqual(
172
+ expect.objectContaining({
173
+ color: "#EFEFEF",
174
+ fontSize: 20,
175
+ lineHeight: 44,
176
+ })
177
+ );
178
+ });
179
+
180
+ it("does not apply Theme confirmation styles for non-confirmation toasts", () => {
181
+ const { getByTestId } = render(<NotificationToastRenderer />);
182
+
183
+ act(() => {
184
+ notificationToastManager.showToast({
185
+ message: "You are offline",
186
+ style: { color: "#abcdef" },
187
+ });
188
+ });
189
+
190
+ expect(
191
+ getByTestId("NotificationToastRenderer-message").props.style
192
+ ).toEqual(
193
+ expect.objectContaining({
194
+ color: "#abcdef",
195
+ })
196
+ );
197
+
198
+ expect(
199
+ getByTestId("NotificationToastRenderer-message").props.style.fontSize
200
+ ).toBeUndefined();
201
+ });
202
+
203
+ it("dismisses the toast on a successful upward fling", () => {
77
204
  const dismissSpy = jest.spyOn(notificationToastManager, "dismiss");
78
205
 
79
206
  const { getByTestId } = render(<NotificationToastRenderer />);
80
207
 
81
- fireEvent.press(getByTestId("NotificationToastRenderer-touchable"));
208
+ act(() => {
209
+ notificationToastManager.showToast({ message: "Added to queue" });
210
+ });
211
+
212
+ fireEvent(getByTestId("NotificationToastRenderer-fling-handler"), "end");
82
213
 
83
214
  expect(dismissSpy).toHaveBeenCalled();
84
215
  });
216
+
217
+ it("does not dismiss when the fling ends unsuccessfully", () => {
218
+ const dismissSpy = jest.spyOn(notificationToastManager, "dismiss");
219
+
220
+ const { getByTestId } = render(<NotificationToastRenderer />);
221
+
222
+ act(() => {
223
+ notificationToastManager.showToast({ message: "Added to queue" });
224
+ });
225
+
226
+ fireEvent(
227
+ getByTestId("NotificationToastRenderer-fling-handler"),
228
+ "endFailed"
229
+ );
230
+
231
+ expect(dismissSpy).not.toHaveBeenCalled();
232
+ });
85
233
  });
@@ -0,0 +1,118 @@
1
+ import { resolveConfirmationToastStyle } from "../resolveConfirmationToastStyle";
2
+
3
+ jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
4
+ // manifestKeyParser captures currentPlatform at module load from this map
5
+ platformSelect: jest.fn((platforms) => {
6
+ if (platforms?.ios === "ios" && platforms?.android === "android") {
7
+ return "ios";
8
+ }
9
+
10
+ return platforms?.default;
11
+ }),
12
+ }));
13
+
14
+ describe("resolveConfirmationToastStyle", () => {
15
+ const theme = {
16
+ confirmation_toast_style_background_color: "#0188FF",
17
+ confirmation_toast_style_color: "#EFEFEF",
18
+ confirmation_toast_style_ios_font_family: "SFProText-Semibold",
19
+ confirmation_toast_style_android_font_family: "Roboto-Medium",
20
+ confirmation_toast_style_ios_font_size: 14,
21
+ confirmation_toast_style_android_font_size: 16,
22
+ confirmation_toast_style_ios_line_height: 44,
23
+ confirmation_toast_style_android_line_height: 40,
24
+ confirmation_toast_style_ios_letter_spacing: -1.4,
25
+ confirmation_toast_style_android_letter_spacing: -0.5,
26
+ };
27
+
28
+ it("maps Theme confirmation_toast_style_* keys via getAllSpecificStyles (iOS platform)", () => {
29
+ expect(resolveConfirmationToastStyle(theme)).toEqual({
30
+ backgroundColor: "#0188FF",
31
+ color: "#EFEFEF",
32
+ fontFamily: "SFProText-Semibold",
33
+ fontSize: 14,
34
+ lineHeight: 44,
35
+ letterSpacing: -1.4,
36
+ });
37
+ });
38
+
39
+ it("ignores other-platform keys for the current platform", () => {
40
+ const result = resolveConfirmationToastStyle(theme);
41
+
42
+ expect(result.fontFamily).toBe("SFProText-Semibold");
43
+ expect(result.fontSize).toBe(14);
44
+
45
+ expect(result).not.toEqual(
46
+ expect.objectContaining({
47
+ fontFamily: "Roboto-Medium",
48
+ fontSize: 16,
49
+ })
50
+ );
51
+ });
52
+
53
+ it("shallow-merges override style on top of Theme defaults", () => {
54
+ expect(
55
+ resolveConfirmationToastStyle(theme, {
56
+ backgroundColor: "#00FF00",
57
+ fontSize: 20,
58
+ })
59
+ ).toEqual({
60
+ backgroundColor: "#00FF00",
61
+ color: "#EFEFEF",
62
+ fontFamily: "SFProText-Semibold",
63
+ fontSize: 20,
64
+ lineHeight: 44,
65
+ letterSpacing: -1.4,
66
+ });
67
+ });
68
+
69
+ it("returns override fields when Theme is missing", () => {
70
+ expect(resolveConfirmationToastStyle(undefined, { color: "#fff" })).toEqual(
71
+ {
72
+ color: "#fff",
73
+ }
74
+ );
75
+ });
76
+ });
77
+
78
+ describe("resolveConfirmationToastStyle (android platform)", () => {
79
+ it("maps android platform Theme keys", () => {
80
+ jest.resetModules();
81
+
82
+ jest.doMock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
83
+ platformSelect: jest.fn((platforms) => {
84
+ if (platforms?.ios === "ios" && platforms?.android === "android") {
85
+ return "android";
86
+ }
87
+
88
+ return platforms?.default;
89
+ }),
90
+ }));
91
+
92
+ const {
93
+ resolveConfirmationToastStyle: resolveAndroid,
94
+ } = require("../resolveConfirmationToastStyle");
95
+
96
+ const theme = {
97
+ confirmation_toast_style_background_color: "#0188FF",
98
+ confirmation_toast_style_color: "#EFEFEF",
99
+ confirmation_toast_style_ios_font_family: "SFProText-Semibold",
100
+ confirmation_toast_style_android_font_family: "Roboto-Medium",
101
+ confirmation_toast_style_ios_font_size: 14,
102
+ confirmation_toast_style_android_font_size: 16,
103
+ confirmation_toast_style_ios_line_height: 44,
104
+ confirmation_toast_style_android_line_height: 40,
105
+ confirmation_toast_style_ios_letter_spacing: -1.4,
106
+ confirmation_toast_style_android_letter_spacing: -0.5,
107
+ };
108
+
109
+ expect(resolveAndroid(theme)).toEqual({
110
+ backgroundColor: "#0188FF",
111
+ color: "#EFEFEF",
112
+ fontFamily: "Roboto-Medium",
113
+ fontSize: 16,
114
+ lineHeight: 40,
115
+ letterSpacing: -0.5,
116
+ });
117
+ });
118
+ });
@@ -1,27 +1,26 @@
1
1
  import { renderHook } from "@testing-library/react-native";
2
2
 
3
3
  let mockInsets = { top: 0 };
4
+ const mockGetNavbarHeight = jest.fn();
4
5
 
5
6
  jest.mock("react-native-safe-area-context", () => ({
6
7
  useSafeAreaInsets: () => mockInsets,
7
8
  }));
8
9
 
9
- jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
10
- ...jest.requireActual("@applicaster/zapp-react-native-utils/reactUtils"),
11
- platformSelect: jest.fn(({ ios, android }) => ({ ios, android })),
10
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/layout", () => ({
11
+ getNavbarHeight: () => mockGetNavbarHeight(),
12
12
  }));
13
13
 
14
- import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
15
14
  import { useNotificationHeight } from "../useNotificationHeight";
16
15
 
17
16
  describe("useNotificationHeight", () => {
18
17
  beforeEach(() => {
19
- (platformSelect as jest.Mock).mockClear();
18
+ mockGetNavbarHeight.mockClear();
20
19
  });
21
20
 
22
- it("adds the safe area top inset to the platform nav bar height", () => {
21
+ it("adds the safe area top inset to the nav bar height", () => {
23
22
  mockInsets = { top: 44 };
24
- (platformSelect as jest.Mock).mockReturnValueOnce(56);
23
+ mockGetNavbarHeight.mockReturnValueOnce(56);
25
24
 
26
25
  const { result } = renderHook(() => useNotificationHeight());
27
26
 
@@ -33,7 +32,7 @@ describe("useNotificationHeight", () => {
33
32
 
34
33
  it("falls back to a 0 status height when there is no top inset", () => {
35
34
  mockInsets = { top: 0 };
36
- (platformSelect as jest.Mock).mockReturnValueOnce(44);
35
+ mockGetNavbarHeight.mockReturnValueOnce(44);
37
36
 
38
37
  const { result } = renderHook(() => useNotificationHeight());
39
38
 
@@ -43,11 +42,17 @@ describe("useNotificationHeight", () => {
43
42
  });
44
43
  });
45
44
 
46
- it("selects the nav bar height per platform via platformSelect", () => {
45
+ it("uses getNavbarHeight for the nav bar height", () => {
47
46
  mockInsets = { top: 20 };
47
+ mockGetNavbarHeight.mockReturnValueOnce(56);
48
48
 
49
- renderHook(() => useNotificationHeight());
49
+ const { result } = renderHook(() => useNotificationHeight());
50
+
51
+ expect(mockGetNavbarHeight).toHaveBeenCalled();
50
52
 
51
- expect(platformSelect).toHaveBeenCalledWith({ ios: 44, android: 56 });
53
+ expect(result.current).toEqual({
54
+ statusHeight: 20,
55
+ notificationHeight: 76,
56
+ });
52
57
  });
53
58
  });
@@ -1,5 +1,11 @@
1
1
  export { notificationToastManager } from "./NotificationToastManager";
2
2
 
3
+ export type { ToastPayload, ToastStyle } from "./NotificationToastManager";
4
+
5
+ export { CONFIRMATION_TOAST_SOURCE } from "./NotificationToastManager";
6
+
3
7
  export { NotificationToastRenderer } from "./NotificationToastRenderer";
4
8
 
5
9
  export { useNotificationHeight } from "./useNotificationHeight";
10
+
11
+ export { resolveConfirmationToastStyle } from "./resolveConfirmationToastStyle";
@@ -0,0 +1,33 @@
1
+ import { getAllSpecificStyles } from "@applicaster/zapp-react-native-utils/configurationUtils/manifestKeyParser";
2
+
3
+ import { ToastStyle } from "./NotificationToastManager";
4
+
5
+ const CONFIRMATION_TOAST_STYLE_COMPONENT = "confirmation_toast";
6
+
7
+ /**
8
+ * Builds confirmation-toast style from Theme defaults via getAllSpecificStyles,
9
+ * then shallow-merges any caller override on top.
10
+ *
11
+ * Expected Theme keys follow:
12
+ * `confirmation_toast_style_[platform_]<style_name>`
13
+ * e.g. confirmation_toast_style_background_color,
14
+ * confirmation_toast_style_ios_font_family
15
+ */
16
+ export function resolveConfirmationToastStyle(
17
+ theme: Partial<BaseThemePropertiesMobile> | null | undefined,
18
+ overrideStyle?: ToastStyle | null
19
+ ): ToastStyle {
20
+ const outStyles: Record<string, ToastStyle> = {};
21
+
22
+ getAllSpecificStyles({
23
+ configuration: { ...(theme ?? {}) },
24
+ componentName: CONFIRMATION_TOAST_STYLE_COMPONENT,
25
+ subComponentName: "",
26
+ outStyles,
27
+ });
28
+
29
+ return {
30
+ ...outStyles.default,
31
+ ...overrideStyle,
32
+ };
33
+ }
@@ -1,11 +1,10 @@
1
1
  import { useSafeAreaInsets } from "react-native-safe-area-context";
2
-
3
- import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
2
+ import { getNavbarHeight } from "@applicaster/zapp-react-native-utils/reactHooks/layout";
4
3
 
5
4
  export const useNotificationHeight = () => {
6
5
  const insets = useSafeAreaInsets();
7
6
 
8
- const navBarHeight = platformSelect({ ios: 44, android: 56 });
7
+ const navBarHeight = getNavbarHeight();
9
8
 
10
9
  const statusHeight = insets.top;
11
10
  const notificationHeight = statusHeight + navBarHeight;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-core",
3
- "version": "16.0.0-alpha.9225550512",
3
+ "version": "16.0.0-alpha.9506982263",
4
4
  "description": "Core package for Applicaster's Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,13 +28,13 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "16.0.0-alpha.9225550512",
32
- "@applicaster/quick-brick-core-plugins": "16.0.0-alpha.9225550512",
33
- "@applicaster/zapp-pipes-v2-client": "16.0.0-alpha.9225550512",
34
- "@applicaster/zapp-react-native-bridge": "16.0.0-alpha.9225550512",
35
- "@applicaster/zapp-react-native-redux": "16.0.0-alpha.9225550512",
36
- "@applicaster/zapp-react-native-ui-components": "16.0.0-alpha.9225550512",
37
- "@applicaster/zapp-react-native-utils": "16.0.0-alpha.9225550512",
31
+ "@applicaster/applicaster-types": "16.0.0-alpha.9506982263",
32
+ "@applicaster/quick-brick-core-plugins": "16.0.0-alpha.9506982263",
33
+ "@applicaster/zapp-pipes-v2-client": "16.0.0-alpha.9506982263",
34
+ "@applicaster/zapp-react-native-bridge": "16.0.0-alpha.9506982263",
35
+ "@applicaster/zapp-react-native-redux": "16.0.0-alpha.9506982263",
36
+ "@applicaster/zapp-react-native-ui-components": "16.0.0-alpha.9506982263",
37
+ "@applicaster/zapp-react-native-utils": "16.0.0-alpha.9506982263",
38
38
  "atob": "^2.1.2",
39
39
  "axios": "^0.28.0",
40
40
  "btoa": "^1.2.1",