@applicaster/zapp-react-native-utils 16.0.0-alpha.9530606740 → 16.0.0-alpha.9739533780

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.
@@ -22,7 +22,6 @@ import {
22
22
  localStorageRemoveAction,
23
23
  localStorageSetAction,
24
24
  localStorageToggleFlagAction,
25
- openBottomSheetAction,
26
25
  refreshComponentAction,
27
26
  screenSetVariableAction,
28
27
  screenToggleFlagAction,
@@ -31,6 +30,7 @@ import {
31
30
  sessionStorageSetAction,
32
31
  sessionStorageToggleFlagAction,
33
32
  switchLayoutAction,
33
+ showToastAction,
34
34
  } from "./actions";
35
35
 
36
36
  export const { log_error, log_info, log_debug } = createLogger({
@@ -90,7 +90,7 @@ const prepareDefaultActions = (actionExecutor) => {
90
90
 
91
91
  actionExecutor.registerAction("screenSetVariable", screenSetVariableAction);
92
92
  actionExecutor.registerAction("screenToggleFlag", screenToggleFlagAction);
93
- actionExecutor.registerAction("openBottomSheet", openBottomSheetAction);
93
+ actionExecutor.registerAction("showToast", showToastAction);
94
94
  };
95
95
 
96
96
  export const ActionExecutorContext =
@@ -27,4 +27,4 @@ export { screenToggleFlagAction } from "./screenToggleFlag";
27
27
 
28
28
  export { createNavigateToScreenAction } from "./navigateToScreen";
29
29
 
30
- export { openBottomSheetAction } from "./openBottomSheet";
30
+ export { showToastAction } from "./showToast";
@@ -0,0 +1,31 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { postEvent } from "../../reactHooks/useSubscriberFor";
5
+
6
+ /**
7
+ * Options for showToast action.
8
+ */
9
+ export interface ShowToastActionOptions {
10
+ id: string;
11
+ message: string;
12
+ extraMessage?: string;
13
+ style?: any;
14
+ timeout?: number;
15
+ }
16
+
17
+ export const showToastAction: ActionHandler<ShowToastActionOptions> = async (
18
+ action
19
+ ): Promise<ActionResult> => {
20
+ postEvent("showToast", [
21
+ {
22
+ id: action.options.id,
23
+ message: action.options.message,
24
+ extraMessage: action.options.extraMessage,
25
+ style: action.options.style,
26
+ timeout: action.options.timeout,
27
+ },
28
+ ]);
29
+
30
+ return ActionResult.Success;
31
+ };
@@ -33,7 +33,7 @@ export interface ActionExecutionContext {
33
33
  /** Callback function for action completion */
34
34
  callback?: (result: { success: boolean; error: any; abort: boolean }) => void;
35
35
 
36
- screenState: Record<any, any>;
36
+ screenState?: Record<any, any>;
37
37
  }
38
38
 
39
39
  /**
@@ -1,34 +1,83 @@
1
- export {
2
- modalStore,
3
- useModalStore,
4
- openModal,
5
- dismissModal,
6
- openBottomSheetModal,
7
- useModalStoreState,
8
- } from "./store";
1
+ import { useStore, createStore } from "zustand";
9
2
 
10
- export type { ModalState, ModalStore } from "./store";
3
+ interface ModalState {
4
+ visible: boolean;
5
+ screen: any;
6
+ options: Record<string, unknown>;
7
+ props: Record<string, unknown>;
8
+ }
11
9
 
12
- export { modalOrchestrator } from "./ModalOrchestrator";
10
+ interface ModalStore {
11
+ modalState: ModalState;
12
+ setModalState: (newState: Partial<ModalState>) => void;
13
+ openModal: (
14
+ item: any,
15
+ options?: Record<string, unknown>,
16
+ props?: Record<string, unknown>
17
+ ) => void;
18
+ dismissModal: () => void;
19
+ }
13
20
 
14
- export { ContentViewModel } from "./ContentViewModel";
21
+ const initialModalState: ModalState = {
22
+ visible: false,
23
+ screen: null,
24
+ options: {},
25
+ props: {},
26
+ };
15
27
 
16
- export { BottomSheetHeader } from "./components/BottomSheetHeader";
28
+ export const modalStore = createStore<ModalStore>((set) => ({
29
+ modalState: initialModalState,
30
+ setModalState: (newState) =>
31
+ set((state) => ({
32
+ modalState: { ...state.modalState, ...newState },
33
+ })),
34
+ openModal: ({ item, options = {}, props }: OpenModalArg) =>
35
+ set({
36
+ modalState: {
37
+ visible: true,
38
+ screen: item,
39
+ options: {
40
+ animated: true,
41
+ animationType: "slide",
42
+ onShow: () => {},
43
+ presentationStyle: "overFullScreen",
44
+ transparent: true,
45
+ ...options,
46
+ onDismiss: () => set({ modalState: initialModalState }),
47
+ onRequestClose: () => set({ modalState: initialModalState }),
48
+ },
49
+ props,
50
+ },
51
+ }),
52
+ dismissModal: () => set(() => ({ modalState: initialModalState })),
53
+ }));
17
54
 
18
- export { ActionItem } from "./components/ActionItem";
55
+ export const useModalStore = <T>(selector: (state: ModalStore) => T) =>
56
+ useStore(modalStore, selector);
19
57
 
20
- export { TrackItem } from "./components/TrackItem";
58
+ export const openModal = modalStore.getInitialState().openModal;
21
59
 
22
- export { PrimaryButton } from "./components/PrimaryButton";
60
+ export const dismissModal = modalStore.getInitialState().dismissModal;
23
61
 
24
- export type {
25
- Menu,
26
- MenuItem,
27
- Header,
28
- Content,
29
- Action,
30
- PresentSubMenuAction,
31
- SecondaryAction,
32
- } from "./types";
62
+ export const openBottomSheetModal = ({
63
+ ModalBottomSheetContent,
64
+ modalBottomSheetContentProps,
65
+ props = {},
66
+ options = {},
67
+ }: OpenModalBottomSheetArgs) => {
68
+ openModal({
69
+ item: {
70
+ ModalBottomSheetContent,
71
+ modalBottomSheetContentProps,
72
+ },
73
+ props,
74
+ options: {
75
+ animationType: "none",
76
+ animated: false,
77
+ ...options,
78
+ },
79
+ });
80
+ };
33
81
 
34
- export { isPresentSubMenuAction } from "./types";
82
+ export const useModalStoreState = (): ModalState =>
83
+ useModalStore<ModalState>((state) => state.modalState);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "16.0.0-alpha.9530606740",
3
+ "version": "16.0.0-alpha.9739533780",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "16.0.0-alpha.9530606740",
30
+ "@applicaster/applicaster-types": "16.0.0-alpha.9739533780",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -38,3 +38,7 @@ export const useNavigationPluginData = jest.fn().mockReturnValue(mockMenu);
38
38
  export const useIsNavBarVisible = jest.fn().mockReturnValue(true);
39
39
 
40
40
  export const useIsScreenActive = jest.fn().mockReturnValue(true);
41
+
42
+ export const isScreenActiveForRoute = jest.fn(
43
+ (route, currentRoute) => route === currentRoute
44
+ );
@@ -0,0 +1,42 @@
1
+ import { isScreenActiveForRoute } from "../useIsScreenActive";
2
+
3
+ describe("isScreenActiveForRoute", () => {
4
+ const route = "/river/home/river/tabs";
5
+ const currentRoute = "/river/home/river/tabs";
6
+
7
+ it("returns false when route does not match", () => {
8
+ expect(
9
+ isScreenActiveForRoute(route, "/river/home", { visible: false })
10
+ ).toBe(false);
11
+ });
12
+
13
+ it("keeps underlying screen active when video modal is docked", () => {
14
+ expect(
15
+ isScreenActiveForRoute(route, currentRoute, {
16
+ visible: true,
17
+ mode: "MINIMIZED",
18
+ })
19
+ ).toBe(true);
20
+ });
21
+
22
+ it.each(["FULLSCREEN", "MAXIMIZED", "PIP"])(
23
+ "deactivates underlying screen when video modal is visible",
24
+ (mode) => {
25
+ expect(
26
+ isScreenActiveForRoute(route, currentRoute, {
27
+ visible: true,
28
+ mode,
29
+ })
30
+ ).toBe(false);
31
+ }
32
+ );
33
+
34
+ it("keeps video-modal route active when video modal is open", () => {
35
+ expect(
36
+ isScreenActiveForRoute("video-modal/123", currentRoute, {
37
+ visible: true,
38
+ mode: "FULLSCREEN",
39
+ })
40
+ ).toBe(true);
41
+ });
42
+ });
@@ -32,7 +32,7 @@ export { useNavigationType } from "./useNavigationType";
32
32
 
33
33
  export { useGetBottomTabBarHeight } from "./useGetBottomTabBarHeight";
34
34
 
35
- export { useIsScreenActive } from "./useIsScreenActive";
35
+ export { useIsScreenActive, isScreenActiveForRoute } from "./useIsScreenActive";
36
36
 
37
37
  export { useProfilerLogging } from "./useProfilerLogging";
38
38
 
@@ -2,20 +2,41 @@ import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtil
2
2
  import { useNavigation } from "./useNavigation";
3
3
  import { usePathname } from "./usePathname";
4
4
 
5
- // If current screen is active/focused (visible to the user)
6
- export const useIsScreenActive = () => {
7
- const pathname = usePathname();
8
- const { currentRoute, videoModalState } = useNavigation();
5
+ type VideoModalState = {
6
+ visible?: boolean;
7
+ mode?: string;
8
+ } | null;
9
9
 
10
- if (videoModalState.visible) {
11
- if (pathname.includes(ROUTE_TYPES.VIDEO_MODAL)) {
10
+ /**
11
+ * Whether a navigation route should be treated as the active/focused screen.
12
+ * Docked (MINIMIZED) video modal does not deactivate the underlying screen —
13
+ * only FULLSCREEN / MAXIMIZED / PIP do.
14
+ */
15
+ export function isScreenActiveForRoute(
16
+ route: string,
17
+ currentRoute: string,
18
+ videoModalState: VideoModalState
19
+ ) {
20
+ if (videoModalState?.visible) {
21
+ if (route.includes(ROUTE_TYPES.VIDEO_MODAL)) {
12
22
  return true;
13
23
  }
14
24
 
15
- if (["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)) {
25
+ if (
26
+ ["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode ?? "")
27
+ ) {
16
28
  return false;
17
29
  }
30
+ // MINIMIZED (docked): fall through — underlying screen stays active
18
31
  }
19
32
 
20
- return pathname === currentRoute;
33
+ return route === currentRoute;
34
+ }
35
+
36
+ // If current screen is active/focused (visible to the user)
37
+ export const useIsScreenActive = () => {
38
+ const pathname = usePathname();
39
+ const { currentRoute, videoModalState } = useNavigation();
40
+
41
+ return isScreenActiveForRoute(pathname, currentRoute, videoModalState);
21
42
  };
@@ -41,5 +41,5 @@ export const useComponentScreenState = <T = unknown>(
41
41
  [componentId, store]
42
42
  );
43
43
 
44
- return [value, setValue] as const;
44
+ return [value, setValue];
45
45
  };
@@ -1,177 +0,0 @@
1
- /// <reference types="@applicaster/applicaster-types" />
2
- import {
3
- PipesClientResponseHelper,
4
- RequestBuilder,
5
- } from "@applicaster/zapp-pipes-v2-client";
6
- import { modalOrchestrator } from "../../modalState/ModalOrchestrator";
7
- import { isPresentSubMenuAction, Menu, MenuItem } from "../../modalState/types";
8
- import { actionExecutor, ActionResult } from "../ActionExecutor";
9
- import { createLogger } from "../../logger";
10
-
11
- const { log_info, log_error } = createLogger({
12
- subsystem: "ActionExecutorContext",
13
- category: "General",
14
- });
15
-
16
- /**
17
- * Converts a ZappEntry from a pipes feed into a MenuItem.
18
- * - Icon: first src found in the image media_group.
19
- * - Primary action: taken from tap_actions.actions[0].
20
- * - isSelected: true when entry.id is in currentSelection.
21
- */
22
- export function entryToMenuItem(
23
- entry: ZappEntry,
24
- currentSelection: string[] = []
25
- ): MenuItem {
26
- const imageGroup = entry.media_group?.find((g) => g.type === "image");
27
-
28
- const firstImage = Array.isArray(imageGroup?.media_item)
29
- ? imageGroup.media_item[0]
30
- : imageGroup?.media_item;
31
-
32
- // Primary action — first tap_action on the entry
33
- const tapActions = entry.extensions?.tap_actions?.actions || [];
34
- const primaryAction = tapActions.length > 0 ? tapActions[0] : undefined;
35
-
36
- let summary = entry.summary as string;
37
-
38
- // TODO: remove just a small logic for debugging
39
-
40
- if (
41
- !summary &&
42
- entry.extensions &&
43
- typeof entry.extensions.item_count === "number"
44
- ) {
45
- const count = entry.extensions.item_count;
46
- summary = `${count} ${count === 1 ? "Item" : "Items"}`;
47
- }
48
-
49
- return {
50
- title: entry.title as string,
51
- summary,
52
- icon: firstImage?.src,
53
- isSelected: currentSelection.includes(String(entry.id)),
54
- action: primaryAction,
55
- };
56
- }
57
-
58
- // Exported so MultiLevelBottomSheetContent can lazy-load sub-levels
59
- export async function loadItemsFromSource(
60
- source: string,
61
- context?: Record<string, any>
62
- ): Promise<MenuItem[]> {
63
- const requestBuilder = new RequestBuilder()
64
- .setEntryContext(context?.entry || {})
65
- .setScreenContext(context?.screenData || {})
66
- .setUrl(source);
67
-
68
- await requestBuilder.buildAxiosRequest();
69
-
70
- const responseData = await requestBuilder.call<ZappFeed>();
71
-
72
- const responseHelper = new PipesClientResponseHelper(responseData);
73
-
74
- if (responseHelper.error) {
75
- throw responseHelper.error;
76
- }
77
-
78
- const feed = responseData?.response as ZappFeed;
79
-
80
- const rawSelection = feed?.extensions?.behavior?.current_selection;
81
-
82
- const currentSelection: string[] = Array.isArray(rawSelection)
83
- ? (rawSelection as any).map(String)
84
- : rawSelection !== undefined && rawSelection !== null
85
- ? [String(rawSelection)]
86
- : [];
87
-
88
- return (feed?.entry || []).map((entry) =>
89
- entryToMenuItem(entry, currentSelection)
90
- );
91
- }
92
-
93
- export async function openBottomSheetAction(
94
- action: ActionType,
95
- context?: Record<string, any>
96
- ): Promise<ActionResult> {
97
- try {
98
- const { content, header } = action.options || {};
99
-
100
- const inlineItems: ZappEntry[] = content?.items;
101
- const itemsUrl: string = content?.itemsUrl;
102
-
103
- let items: MenuItem[];
104
-
105
- if (Array.isArray(inlineItems) && inlineItems.length > 0) {
106
- log_info("openBottomSheet: using inline items from action options", {
107
- count: inlineItems.length,
108
- });
109
-
110
- items = inlineItems.map((entry) => entryToMenuItem(entry));
111
- } else if (itemsUrl) {
112
- log_info(`openBottomSheet: loading items from source: ${itemsUrl}`);
113
-
114
- items = await loadItemsFromSource(itemsUrl, context);
115
-
116
- log_info(
117
- `openBottomSheet: loaded ${items.length} items from source: ${itemsUrl}`
118
- );
119
- } else {
120
- log_error(
121
- "openBottomSheet: no itemsUrl or items provided in action options"
122
- );
123
-
124
- return ActionResult.Error;
125
- }
126
-
127
- const menu: Menu = {
128
- header: header
129
- ? {
130
- title: header.title,
131
- subtitle: header.subtitle,
132
- icon: header.icon,
133
- }
134
- : undefined,
135
- content: {
136
- title: content?.title ?? "",
137
- items,
138
- itemsUrl, // stored so the component can reload after an action
139
- },
140
- };
141
-
142
- /**
143
- * Called when the user taps a menu item.
144
- *
145
- * - PresentSubMenuAction → handled by the orchestrator (pushes sub-menu)
146
- * - Any other Action type → forwarded to the action executor, keeping the
147
- * original execution context so screen/entry data is available to handlers.
148
- * The pressed item is also added as `entry` so downstream actions can
149
- * reference it.
150
- */
151
- const onItemPress = async (item: MenuItem): Promise<void> => {
152
- if (!item.action || isPresentSubMenuAction(item.action)) {
153
- // Submenu navigation is handled internally by the orchestrator
154
- return;
155
- }
156
-
157
- await actionExecutor.handleAction(
158
- item.action as ActionType,
159
- {
160
- ...context,
161
- entry: item as any,
162
- } as any
163
- );
164
- };
165
-
166
- modalOrchestrator.open(menu, onItemPress);
167
-
168
- return ActionResult.Success;
169
- } catch (error) {
170
- log_error("openBottomSheet: failed to open bottom sheet", {
171
- error,
172
- action,
173
- });
174
-
175
- return ActionResult.Error;
176
- }
177
- }
@@ -1,59 +0,0 @@
1
- import { BehaviorSubject, Observable } from "rxjs";
2
- import { Content, MenuItem } from "./types";
3
- import { loadItemsFromSource } from "../actionsExecutor/actions/openBottomSheet";
4
-
5
- export interface ContentState {
6
- items: MenuItem[];
7
- isLoading: boolean;
8
- error?: Error | string;
9
- }
10
-
11
- export class ContentViewModel {
12
- private state$: BehaviorSubject<ContentState>;
13
- readonly itemsUrl?: string;
14
-
15
- constructor(content: Content) {
16
- this.itemsUrl = content.itemsUrl;
17
-
18
- this.state$ = new BehaviorSubject<ContentState>({
19
- items: content.items || [],
20
- isLoading: false,
21
- });
22
-
23
- if (this.itemsUrl && this.state$.value.items.length === 0) {
24
- this.refetch();
25
- }
26
- }
27
-
28
- getState = (): ContentState => this.state$.value;
29
-
30
- get stateObservable(): Observable<ContentState> {
31
- return this.state$.asObservable();
32
- }
33
-
34
- subscribe = (listener: (state: ContentState) => void) => {
35
- const subscription = this.state$.subscribe(listener);
36
-
37
- return () => subscription.unsubscribe();
38
- };
39
-
40
- private updateState(partialState: Partial<ContentState>) {
41
- this.state$.next({ ...this.state$.value, ...partialState });
42
- }
43
-
44
- refetch = async () => {
45
- if (!this.itemsUrl) return;
46
-
47
- this.updateState({ isLoading: true, error: undefined });
48
-
49
- try {
50
- const items = await loadItemsFromSource(this.itemsUrl);
51
- this.updateState({ items, isLoading: false });
52
- } catch (err) {
53
- this.updateState({
54
- error: err?.message || "Failed to load",
55
- isLoading: false,
56
- });
57
- }
58
- };
59
- }