@applicaster/zapp-react-native-utils 16.0.0-alpha.1212303401 → 16.0.0-alpha.1218188693

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +26 -1
  2. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
  3. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  4. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  5. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +113 -1
  6. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  7. package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
  8. package/actionsExecutor/actions/goBack.ts +60 -0
  9. package/actionsExecutor/actions/goHome.ts +31 -0
  10. package/actionsExecutor/actions/index.ts +6 -0
  11. package/actionsExecutor/actions/openBottomSheet.ts +20 -11
  12. package/actionsExecutor/actions/presentScreen.ts +78 -0
  13. package/actionsExecutor/consts.ts +3 -0
  14. package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
  15. package/appUtils/playerManager/playerNative.ts +5 -3
  16. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  17. package/configurationUtils/__tests__/modalBlocksParser.test.ts +153 -0
  18. package/configurationUtils/manifestKeyParser.ts +12 -1
  19. package/configurationUtils/modalBlocksParser.ts +118 -0
  20. package/entryActions/__tests__/buildEntryActions.test.ts +195 -0
  21. package/entryActions/aliasPresentation.ts +124 -0
  22. package/entryActions/buildEntryActions.ts +167 -0
  23. package/entryActions/index.ts +17 -0
  24. package/entryActions/types.ts +39 -0
  25. package/manifestUtils/_internals/index.js +8 -3
  26. package/manifestUtils/defaultManifestConfigurations/player.js +22 -1
  27. package/modalState/ModalOrchestrator.ts +21 -9
  28. package/modalState/RemoteEditableCollection.ts +9 -1
  29. package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
  30. package/modalState/__tests__/index.test.ts +30 -1
  31. package/modalState/index.ts +6 -1
  32. package/modalState/types.ts +29 -2
  33. package/modalState/useBottomSheetContent.ts +9 -7
  34. package/package.json +2 -2
  35. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  36. package/playerUtils/index.ts +17 -1
  37. package/playerUtils/resolvePlayerActions.ts +71 -0
  38. package/reactHooks/actions/index.ts +67 -2
  39. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  40. package/reactHooks/cell-click/index.ts +21 -14
  41. package/reactHooks/navigation/__tests__/index.test.tsx +48 -0
  42. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  43. package/reactHooks/navigation/index.ts +2 -0
  44. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  45. package/reactHooks/navigation/useRoute.ts +14 -1
  46. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  47. package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
  48. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  49. package/uiActionsRegistrator/index.ts +25 -203
  50. package/uiActionsRegistrator/registry.ts +335 -0
  51. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  52. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  53. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  54. package/playerUtils/getPlayerActionButtons.ts +0 -17
@@ -9,7 +9,7 @@ import { ActionExecutionContext, ActionHandler } from "./types";
9
9
  import { batchRemoveAllFromNamespaceForStorage } from "../zappFrameworkUtils/localStorageHelper";
10
10
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
11
11
 
12
- import { useNavigation, useRivers } from "../reactHooks";
12
+ import { useNavigation, usePresentScreen, useRivers } from "../reactHooks";
13
13
  import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
14
14
  import { useSubscriberFor } from "../reactHooks/useSubscriberFor";
15
15
  import { APP_EVENTS } from "../appUtils/events";
@@ -18,11 +18,14 @@ import { createLogger } from "../logger";
18
18
  import {
19
19
  appRestartAction,
20
20
  confirmDialogAction,
21
+ createGoBackAction,
22
+ createGoHomeAction,
21
23
  createNavigateToScreenAction,
22
24
  dismissBottomSheetAction,
23
25
  localStorageRemoveAction,
24
26
  localStorageSetAction,
25
27
  localStorageToggleFlagAction,
28
+ createPresentScreenAction,
26
29
  openBottomSheetAction,
27
30
  refreshComponentAction,
28
31
  screenSetVariableAction,
@@ -155,6 +158,7 @@ export function withActionExecutor(Component) {
155
158
  const navigator = useNavigation();
156
159
  const rivers = useRivers();
157
160
  const contentTypes = useContentTypes();
161
+ const presentScreen = usePresentScreen();
158
162
 
159
163
  const handlers = useMemo(() => {
160
164
  return {
@@ -189,6 +193,27 @@ export function withActionExecutor(Component) {
189
193
  );
190
194
  }, [navigator, rivers, contentTypes]);
191
195
 
196
+ useEffect(() => {
197
+ return _actionExecutor.registerAction(
198
+ ACTION_TYPES.PRESENT_SCREEN,
199
+ createPresentScreenAction(presentScreen)
200
+ );
201
+ }, [presentScreen]);
202
+
203
+ useEffect(() => {
204
+ return _actionExecutor.registerAction(
205
+ ACTION_TYPES.GO_BACK,
206
+ createGoBackAction(navigator)
207
+ );
208
+ }, [navigator]);
209
+
210
+ useEffect(() => {
211
+ return _actionExecutor.registerAction(
212
+ ACTION_TYPES.GO_HOME,
213
+ createGoHomeAction(navigator)
214
+ );
215
+ }, [navigator]);
216
+
192
217
  return (
193
218
  <ActionExecutorContext.Provider value={handlers}>
194
219
  <Component {...props} />
@@ -4,6 +4,9 @@ import { ActionResult } from "../../ActionExecutor";
4
4
 
5
5
  jest.mock("../../../modalState", () => ({
6
6
  dismissModal: jest.fn(),
7
+ modalOrchestrator: {
8
+ close: jest.fn(),
9
+ },
7
10
  }));
8
11
 
9
12
  describe("dismissBottomSheetAction", () => {
@@ -0,0 +1,62 @@
1
+ import { createGoBackAction } from "../goBack";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+
4
+ function createNavigator(canGoBack = true) {
5
+ return {
6
+ goBack: jest.fn(),
7
+ canGoBack: jest.fn().mockReturnValue(canGoBack),
8
+ } as unknown as QuickBrickAppNavigator;
9
+ }
10
+
11
+ describe("goBack", () => {
12
+ it("goes back with fallbackToHome enabled when no options are provided", async () => {
13
+ const navigator = createNavigator();
14
+
15
+ const result = await createGoBackAction(navigator)({ type: "goBack" });
16
+
17
+ expect(navigator.goBack).toHaveBeenCalledWith(true, false, false);
18
+ expect(result).toBe(ActionResult.Success);
19
+ });
20
+
21
+ it("forwards backToTop", async () => {
22
+ const navigator = createNavigator();
23
+
24
+ const action = {
25
+ type: "goBack",
26
+ options: { backToTop: true },
27
+ };
28
+
29
+ const result = await createGoBackAction(navigator)(action);
30
+
31
+ expect(navigator.goBack).toHaveBeenCalledWith(true, false, true);
32
+ expect(result).toBe(ActionResult.Success);
33
+ });
34
+
35
+ it("goes back without falling back to home when the stack allows it", async () => {
36
+ const navigator = createNavigator(true);
37
+
38
+ const action = {
39
+ type: "goBack",
40
+ options: { fallbackToHome: false },
41
+ };
42
+
43
+ const result = await createGoBackAction(navigator)(action);
44
+
45
+ expect(navigator.goBack).toHaveBeenCalledWith(false, false, false);
46
+ expect(result).toBe(ActionResult.Success);
47
+ });
48
+
49
+ it("does nothing when there is nothing to go back to and fallbackToHome is off", async () => {
50
+ const navigator = createNavigator(false);
51
+
52
+ const action = {
53
+ type: "goBack",
54
+ options: { fallbackToHome: false },
55
+ };
56
+
57
+ const result = await createGoBackAction(navigator)(action);
58
+
59
+ expect(navigator.goBack).not.toHaveBeenCalled();
60
+ expect(result).toBe(ActionResult.Error);
61
+ });
62
+ });
@@ -0,0 +1,19 @@
1
+ import { createGoHomeAction } from "../goHome";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+
4
+ function createNavigator() {
5
+ return {
6
+ goHome: jest.fn(),
7
+ } as unknown as QuickBrickAppNavigator;
8
+ }
9
+
10
+ describe("goHome", () => {
11
+ it("navigates to the home screen", async () => {
12
+ const navigator = createNavigator();
13
+
14
+ const result = await createGoHomeAction(navigator)({ type: "goHome" });
15
+
16
+ expect(navigator.goHome).toHaveBeenCalledWith();
17
+ expect(result).toBe(ActionResult.Success);
18
+ });
19
+ });
@@ -1,5 +1,5 @@
1
1
  import { openBottomSheetAction } from "../openBottomSheet";
2
- import { ActionResult } from "../../ActionExecutor";
2
+ import { actionExecutor, ActionResult } from "../../ActionExecutor";
3
3
  import { modalOrchestrator } from "../../../modalState/ModalOrchestrator";
4
4
 
5
5
  jest.mock("../../../modalState/store", () => ({
@@ -97,4 +97,116 @@ describe("openBottomSheetAction inline items", () => {
97
97
  expect(modalOrchestrator.replace).toHaveBeenCalledTimes(1);
98
98
  expect(modalOrchestrator.open).not.toHaveBeenCalled();
99
99
  });
100
+
101
+ it("executes all actions in tap_actions when onItemPress is called", async () => {
102
+ const multiActionSheet = {
103
+ type: "openBottomSheet",
104
+ options: {
105
+ header: { title: "Target Playlists" },
106
+ content: {
107
+ role: "collection_selector",
108
+ behavior: { selectMode: "none", currentSelection: [] },
109
+ items: [
110
+ {
111
+ id: "playlist-1",
112
+ title: "My Playlist",
113
+ extensions: {
114
+ tap_actions: {
115
+ actions: [
116
+ {
117
+ type: "sendCloudEvent",
118
+ options: { subject: "add_collection_to_collection" },
119
+ },
120
+ {
121
+ type: "showToast",
122
+ options: { message: "Added to playlist" },
123
+ },
124
+ { type: "dismissBottomSheet", options: {} },
125
+ ],
126
+ },
127
+ },
128
+ },
129
+ ],
130
+ },
131
+ },
132
+ } as any;
133
+
134
+ await openBottomSheetAction(multiActionSheet);
135
+
136
+ const [menu, onItemPress] = (modalOrchestrator.open as jest.Mock).mock
137
+ .calls[0];
138
+
139
+ expect(menu.content.items[0].actions).toHaveLength(3);
140
+
141
+ const handleActionsSpy = jest
142
+ .spyOn(actionExecutor, "handleActions")
143
+ .mockResolvedValue(ActionResult.Success);
144
+
145
+ await onItemPress(menu.content.items[0]);
146
+
147
+ expect(handleActionsSpy).toHaveBeenCalledWith(
148
+ [
149
+ {
150
+ type: "sendCloudEvent",
151
+ options: { subject: "add_collection_to_collection" },
152
+ },
153
+ {
154
+ type: "showToast",
155
+ options: { message: "Added to playlist" },
156
+ },
157
+ { type: "dismissBottomSheet", options: {} },
158
+ ],
159
+ expect.objectContaining({
160
+ entry: menu.content.items[0],
161
+ })
162
+ );
163
+
164
+ handleActionsSpy.mockRestore();
165
+ });
166
+
167
+ it("executes preceding actions and excludes presentSubMenu from actionExecutor", async () => {
168
+ const subMenuSheet = {
169
+ type: "openBottomSheet",
170
+ options: {
171
+ header: { title: "Menu" },
172
+ content: {
173
+ items: [
174
+ {
175
+ id: "item-with-submenu",
176
+ title: "More Options",
177
+ extensions: {
178
+ tap_actions: {
179
+ actions: [
180
+ { type: "sendAnalytics", options: { event: "click_more" } },
181
+ {
182
+ type: "presentSubMenu",
183
+ menu: { content: { title: "Sub Options", items: [] } },
184
+ },
185
+ ],
186
+ },
187
+ },
188
+ },
189
+ ],
190
+ },
191
+ },
192
+ } as any;
193
+
194
+ await openBottomSheetAction(subMenuSheet);
195
+
196
+ const [menu, onItemPress] = (modalOrchestrator.open as jest.Mock).mock
197
+ .calls[0];
198
+
199
+ const handleActionsSpy = jest
200
+ .spyOn(actionExecutor, "handleActions")
201
+ .mockResolvedValue(ActionResult.Success);
202
+
203
+ await onItemPress(menu.content.items[0]);
204
+
205
+ expect(handleActionsSpy).toHaveBeenCalledWith(
206
+ [{ type: "sendAnalytics", options: { event: "click_more" } }],
207
+ expect.objectContaining({ entry: menu.content.items[0] })
208
+ );
209
+
210
+ handleActionsSpy.mockRestore();
211
+ });
100
212
  });
@@ -0,0 +1,127 @@
1
+ import { createPresentScreenAction } from "../presentScreen";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+
4
+ const contextEntry = { id: "context-entry" } as any;
5
+
6
+ const succeeded = { success: true, cancelled: false };
7
+
8
+ const cancelled = { success: false, cancelled: true };
9
+
10
+ describe("presentScreenAction", () => {
11
+ let presentScreen: jest.Mock;
12
+ let presentScreenAction: ReturnType<typeof createPresentScreenAction>;
13
+
14
+ beforeEach(() => {
15
+ presentScreen = jest.fn().mockResolvedValue(succeeded);
16
+ presentScreenAction = createPresentScreenAction(presentScreen);
17
+ });
18
+
19
+ it("presents the screen named by typeMapping", async () => {
20
+ await presentScreenAction({
21
+ type: "presentScreen",
22
+ options: { typeMapping: "parent_lock" },
23
+ });
24
+
25
+ expect(presentScreen).toHaveBeenCalledWith({
26
+ typeMapping: "parent_lock",
27
+ entry: undefined,
28
+ });
29
+ });
30
+
31
+ it("fails without presenting anything when typeMapping is missing", async () => {
32
+ const result = await presentScreenAction({
33
+ type: "presentScreen",
34
+ options: {},
35
+ });
36
+
37
+ expect(result).toBe(ActionResult.Error);
38
+ expect(presentScreen).not.toHaveBeenCalled();
39
+ });
40
+
41
+ it("resolves the '@{entry/}' token to the entry from the execution context", async () => {
42
+ await presentScreenAction(
43
+ {
44
+ type: "presentScreen",
45
+ options: { typeMapping: "parent_lock", entry: "@{entry/}" },
46
+ },
47
+ { entry: contextEntry }
48
+ );
49
+
50
+ expect(presentScreen).toHaveBeenCalledWith({
51
+ typeMapping: "parent_lock",
52
+ entry: contextEntry,
53
+ });
54
+ });
55
+
56
+ it("presents an entry supplied inline in the options", async () => {
57
+ const inlineEntry = { id: "inline-entry" } as any;
58
+
59
+ await presentScreenAction({
60
+ type: "presentScreen",
61
+ options: { typeMapping: "parent_lock", entry: inlineEntry },
62
+ });
63
+
64
+ expect(presentScreen).toHaveBeenCalledWith({
65
+ typeMapping: "parent_lock",
66
+ entry: inlineEntry,
67
+ });
68
+ });
69
+
70
+ it("fails without presenting anything when the entry option is not an object", async () => {
71
+ const result = await presentScreenAction({
72
+ type: "presentScreen",
73
+ options: { typeMapping: "parent_lock", entry: "not-an-entry" as any },
74
+ });
75
+
76
+ expect(result).toBe(ActionResult.Error);
77
+ expect(presentScreen).not.toHaveBeenCalled();
78
+ });
79
+
80
+ it("succeeds when the presented screen reports success", async () => {
81
+ presentScreen.mockResolvedValue(succeeded);
82
+
83
+ const result = await presentScreenAction({
84
+ type: "presentScreen",
85
+ options: { typeMapping: "parent_lock" },
86
+ });
87
+
88
+ expect(result).toBe(ActionResult.Success);
89
+ });
90
+
91
+ it("cancels the action chain when the presented screen is cancelled", async () => {
92
+ presentScreen.mockResolvedValue(cancelled);
93
+
94
+ const result = await presentScreenAction({
95
+ type: "presentScreen",
96
+ options: { typeMapping: "parent_lock" },
97
+ });
98
+
99
+ expect(result).toBe(ActionResult.Cancel);
100
+ });
101
+
102
+ it("cancels the action chain when the presented screen reports failure", async () => {
103
+ presentScreen.mockResolvedValue({ success: false, cancelled: false });
104
+
105
+ const result = await presentScreenAction({
106
+ type: "presentScreen",
107
+ options: { typeMapping: "parent_lock" },
108
+ });
109
+
110
+ expect(result).toBe(ActionResult.Cancel);
111
+ });
112
+
113
+ it("errors when the screen could not be presented at all", async () => {
114
+ presentScreen.mockResolvedValue({
115
+ success: false,
116
+ cancelled: false,
117
+ error: "can not resolve screen type mapping: parent_lock",
118
+ });
119
+
120
+ const result = await presentScreenAction({
121
+ type: "presentScreen",
122
+ options: { typeMapping: "parent_lock" },
123
+ });
124
+
125
+ expect(result).toBe(ActionResult.Error);
126
+ });
127
+ });
@@ -1,5 +1,5 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
- import { dismissModal } from "../../modalState";
2
+ import { dismissModal, modalOrchestrator } from "../../modalState";
3
3
  import { ActionResult } from "../ActionExecutor";
4
4
  import { ActionHandler } from "../types";
5
5
  import { createLogger } from "../../logger";
@@ -16,6 +16,7 @@ export const dismissBottomSheetAction: ActionHandler<
16
16
  any
17
17
  > = async (): Promise<ActionResult> => {
18
18
  log_info("handleAction: dismissBottomSheet");
19
+ modalOrchestrator.close();
19
20
  dismissModal();
20
21
 
21
22
  return ActionResult.Success;
@@ -0,0 +1,60 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { createLogger } from "../../logger";
5
+
6
+ const { log_info } = createLogger({
7
+ subsystem: "ActionExecutorContext",
8
+ category: "General",
9
+ });
10
+
11
+ /**
12
+ * Options for the goBack action.
13
+ */
14
+ export interface GoBackOptions {
15
+ /**
16
+ * Navigate to the home screen when there is no screen to go back to.
17
+ * Defaults to true.
18
+ */
19
+ fallbackToHome?: boolean;
20
+
21
+ /**
22
+ * Go back to the first screen of the stack instead of the previous one.
23
+ * Defaults to false.
24
+ */
25
+ backToTop?: boolean;
26
+ }
27
+
28
+ /**
29
+ * Creates a go back action handler with the provided dependencies.
30
+ * This factory pattern allows the action to access navigation state at runtime.
31
+ *
32
+ * @param navigator - The app navigator performing the back navigation
33
+ * @returns An action handler that navigates back
34
+ */
35
+ export function createGoBackAction(
36
+ navigator: QuickBrickAppNavigator
37
+ ): ActionHandler<GoBackOptions> {
38
+ return async function goBackAction(action): Promise<ActionResult> {
39
+ const fallbackToHome = action.options?.fallbackToHome ?? true;
40
+ const backToTop = action.options?.backToTop ?? false;
41
+
42
+ // With fallbackToHome on, the navigator goes home on an empty stack by
43
+ // itself. The guard only matters when the caller opted out of that.
44
+ if (!fallbackToHome && !navigator.canGoBack()) {
45
+ log_info(
46
+ "goBack: no screen to go back to and fallbackToHome is disabled, ignoring"
47
+ );
48
+
49
+ return ActionResult.Error;
50
+ }
51
+
52
+ log_info(
53
+ `goBack: navigating back, fallbackToHome: ${fallbackToHome}, backToTop: ${backToTop}`
54
+ );
55
+
56
+ navigator.goBack(fallbackToHome, false, backToTop);
57
+
58
+ return ActionResult.Success;
59
+ };
60
+ }
@@ -0,0 +1,31 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { createLogger } from "../../logger";
5
+
6
+ const { log_info } = createLogger({
7
+ subsystem: "ActionExecutorContext",
8
+ category: "General",
9
+ });
10
+
11
+ /**
12
+ * Creates a go home action handler with the provided dependencies.
13
+ * This factory pattern allows the action to access navigation state at runtime.
14
+ *
15
+ * The navigator's `initialLaunch` flag is intentionally not exposed: it selects
16
+ * the offline home river during app bootstrap and is not a per-action choice.
17
+ *
18
+ * @param navigator - The app navigator performing the navigation
19
+ * @returns An action handler that navigates to the home screen
20
+ */
21
+ export function createGoHomeAction(
22
+ navigator: QuickBrickAppNavigator
23
+ ): ActionHandler {
24
+ return async function goHomeAction(): Promise<ActionResult> {
25
+ log_info("goHome: navigating to the home screen");
26
+
27
+ navigator.goHome();
28
+
29
+ return ActionResult.Success;
30
+ };
31
+ }
@@ -27,6 +27,12 @@ export { screenToggleFlagAction } from "./screenToggleFlag";
27
27
 
28
28
  export { createNavigateToScreenAction } from "./navigateToScreen";
29
29
 
30
+ export { createPresentScreenAction } from "./presentScreen";
31
+
32
+ export { createGoBackAction } from "./goBack";
33
+
34
+ export { createGoHomeAction } from "./goHome";
35
+
30
36
  export { showToastAction } from "./showToast";
31
37
 
32
38
  export { openBottomSheetAction } from "./openBottomSheet";
@@ -8,6 +8,7 @@ import { modalOrchestrator } from "../../modalState/ModalOrchestrator";
8
8
  import { openBottomSheetModal } from "../../modalState/store";
9
9
  import {
10
10
  DynamicCollectionOptions,
11
+ getMenuItemActions,
11
12
  isPresentSubMenuAction,
12
13
  Menu,
13
14
  MenuItem,
@@ -91,6 +92,7 @@ export function entryToMenuItem(
91
92
  icon: firstImage?.src,
92
93
  isSelected: currentSelection.includes(itemId),
93
94
  action: primaryAction,
95
+ actions: tapActions,
94
96
  entryActions: entry.extensions?.entry_action || [],
95
97
  };
96
98
  }
@@ -206,7 +208,10 @@ export async function openBottomSheetAction(
206
208
  items: [],
207
209
  onPress: () => {},
208
210
  contentComponent: content.component,
209
- contentComponentProps: content.props || {},
211
+ contentComponentProps: {
212
+ ...(content.props || {}),
213
+ actionContext: context,
214
+ },
210
215
  },
211
216
  });
212
217
 
@@ -275,6 +280,7 @@ export async function openBottomSheetAction(
275
280
  dynamicCollection,
276
281
  themePluginId,
277
282
  styleOverrides: styleOverrides ?? content?.styleOverrides,
283
+ context,
278
284
  },
279
285
  };
280
286
 
@@ -288,18 +294,21 @@ export async function openBottomSheetAction(
288
294
  * reference it.
289
295
  */
290
296
  const onItemPress = async (item: MenuItem): Promise<void> => {
291
- if (!item.action || isPresentSubMenuAction(item.action)) {
292
- // Submenu navigation is handled internally by the orchestrator
293
- return;
294
- }
297
+ const actions = getMenuItemActions(item);
295
298
 
296
- await actionExecutor.handleAction(
297
- item.action as ActionType,
298
- {
299
- ...context,
300
- entry: item as any,
301
- } as any
299
+ const executableActions = actions.filter(
300
+ (action) => !isPresentSubMenuAction(action)
302
301
  );
302
+
303
+ if (executableActions.length > 0) {
304
+ await actionExecutor.handleActions(
305
+ executableActions as ActionType[],
306
+ {
307
+ ...context,
308
+ entry: item as any,
309
+ } as any
310
+ );
311
+ }
303
312
  };
304
313
 
305
314
  if (action.options?.replace) {
@@ -0,0 +1,78 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler, ActionExecutionContext } from "../types";
4
+ import type { PresentScreenFn } from "../../reactHooks/navigation/usePresentScreen";
5
+ import { createLogger } from "../../logger";
6
+
7
+ const { log_error } = createLogger({
8
+ subsystem: "ActionExecutorContext",
9
+ category: "General",
10
+ });
11
+
12
+ /**
13
+ * Options for the presentScreen action.
14
+ */
15
+ export interface PresentScreenOptions {
16
+ /** The screen type to present (from content types mapping) */
17
+ typeMapping: string;
18
+
19
+ /**
20
+ * Entry to present the screen with. Can be:
21
+ * - "@{entry/}" to use the context entry
22
+ * - A ZappEntry object
23
+ * - undefined to present the screen without an entry
24
+ */
25
+ entry?: "@{entry/}" | ZappEntry;
26
+ }
27
+
28
+ /**
29
+ * Creates a present-screen action handler with the provided dependencies.
30
+ *
31
+ * Unlike navigateToScreen, this action does not return until the presented
32
+ * screen reports a result, so a screen that gates the flow (a parental lock,
33
+ * for example) can stop the remaining actions by being cancelled.
34
+ *
35
+ * @param presentScreen - Presents a screen as a modal and resolves with its result
36
+ * @returns An action handler that presents a screen and awaits its outcome
37
+ */
38
+ export function createPresentScreenAction(
39
+ presentScreen: PresentScreenFn
40
+ ): ActionHandler<PresentScreenOptions> {
41
+ return async function presentScreenAction(
42
+ action,
43
+ context?: ActionExecutionContext
44
+ ): Promise<ActionResult> {
45
+ const typeMapping = action.options?.typeMapping;
46
+
47
+ if (!typeMapping) {
48
+ log_error("presentScreen: typeMapping option is missing");
49
+
50
+ return ActionResult.Error;
51
+ }
52
+
53
+ const entrySource = action.options?.entry;
54
+
55
+ const entry = entrySource
56
+ ? entrySource === "@{entry/}"
57
+ ? context?.entry
58
+ : entrySource
59
+ : undefined;
60
+
61
+ if (entry && typeof entry !== "object") {
62
+ log_error(
63
+ `presentScreen: entry option is not an object, entry: ${entry}`
64
+ );
65
+
66
+ return ActionResult.Error;
67
+ }
68
+
69
+ const result = await presentScreen({ typeMapping, entry });
70
+
71
+ if (result.error) {
72
+ return ActionResult.Error;
73
+ }
74
+
75
+ // Anything short of success stops the remaining actions in the chain.
76
+ return result.success ? ActionResult.Success : ActionResult.Cancel;
77
+ };
78
+ }
@@ -9,6 +9,9 @@ export const ACTION_TYPES = {
9
9
  PRESENT_SUB_MENU: "presentSubMenu",
10
10
  SEND_CLOUD_EVENT: "sendCloudEvent",
11
11
  NAVIGATE_TO_SCREEN: "navigateToScreen",
12
+ PRESENT_SCREEN: "presentScreen",
13
+ GO_BACK: "goBack",
14
+ GO_HOME: "goHome",
12
15
  SHOW_TOAST: "showToast",
13
16
  LOCAL_STORAGE_SET: "localStorageSet",
14
17
  LOCAL_STORAGE_REMOVE: "localStorageRemove",