@applicaster/zapp-react-native-utils 16.0.0-alpha.2663208063 → 16.0.0-alpha.2710214351

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 (138) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +10 -1
  3. package/actionsExecutor/ActionExecutorContext.tsx +29 -1
  4. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  5. package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
  6. package/actionsExecutor/__tests__/feedDecorator.test.ts +91 -0
  7. package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
  8. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
  9. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  10. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  11. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +267 -0
  12. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
  13. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +273 -1
  14. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  15. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  16. package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
  17. package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
  18. package/actionsExecutor/actions/goBack.ts +60 -0
  19. package/actionsExecutor/actions/goHome.ts +31 -0
  20. package/actionsExecutor/actions/index.ts +8 -0
  21. package/actionsExecutor/actions/navigateToScreen.ts +43 -45
  22. package/actionsExecutor/actions/openBottomSheet.ts +36 -16
  23. package/actionsExecutor/actions/presentScreen.ts +78 -0
  24. package/actionsExecutor/actions/screenToggleFlag.ts +1 -3
  25. package/actionsExecutor/actions/showAlert.ts +51 -0
  26. package/actionsExecutor/actions/showToast.ts +2 -2
  27. package/actionsExecutor/consts.ts +4 -0
  28. package/actionsExecutor/feedDecorator.ts +12 -6
  29. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -22
  30. package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
  31. package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
  32. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +0 -25
  33. package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
  34. package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
  35. package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
  36. package/appUtils/contextKeysManager/index.ts +28 -129
  37. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +4 -11
  38. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  39. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +9 -2
  40. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -1
  41. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -1
  42. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +21 -2
  43. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -1
  44. package/appUtils/playerManager/OverlayObserver/utils.ts +9 -7
  45. package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
  46. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  47. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  48. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
  49. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  50. package/appUtils/playerManager/const.ts +13 -0
  51. package/appUtils/playerManager/index.ts +7 -0
  52. package/appUtils/playerManager/player.ts +25 -0
  53. package/appUtils/playerManager/playerNative.ts +27 -3
  54. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  55. package/appUtils/playerManager/playerToolbox.ts +196 -0
  56. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
  57. package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
  58. package/arrayUtils/index.ts +26 -43
  59. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  60. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  61. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  62. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  63. package/cellUtils/index.ts +70 -3
  64. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  65. package/configurationUtils/__tests__/modalBlocksParser.test.ts +297 -1
  66. package/configurationUtils/manifestKeyParser.ts +12 -1
  67. package/configurationUtils/modalBlocksParser.ts +78 -4
  68. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  69. package/entryActions/aliasPresentation.ts +108 -0
  70. package/entryActions/buildEntryActions.ts +167 -0
  71. package/entryActions/index.ts +15 -0
  72. package/entryActions/types.ts +39 -0
  73. package/focusManager/FocusManager.ts +26 -0
  74. package/focusManager/__tests__/FocusManager.test.ts +9 -0
  75. package/localizationUtils/index.ts +12 -6
  76. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  77. package/logger/xrayToolbox.ts +67 -0
  78. package/manifestUtils/_internals/index.js +8 -3
  79. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  80. package/manifestUtils/defaultManifestConfigurations/player.js +30 -1
  81. package/manifestUtils/keys.js +7 -2
  82. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  83. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  84. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  85. package/modalState/ModalOrchestrator.ts +23 -9
  86. package/modalState/RemoteEditableCollection.ts +9 -1
  87. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +39 -0
  88. package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
  89. package/modalState/__tests__/index.test.ts +30 -1
  90. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  91. package/modalState/index.ts +8 -1
  92. package/modalState/store.ts +9 -2
  93. package/modalState/types.ts +42 -2
  94. package/modalState/useBottomSheetContent.ts +24 -17
  95. package/navigationUtils/xrayNavigator.ts +12 -0
  96. package/package.json +3 -2
  97. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  98. package/playerUtils/index.ts +17 -1
  99. package/playerUtils/resolvePlayerActions.ts +71 -0
  100. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  101. package/pluginUtils/index.ts +29 -0
  102. package/quickBrickAssets/__tests__/index.test.ts +18 -0
  103. package/quickBrickAssets/index.ts +35 -0
  104. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  105. package/reactHooks/actions/index.ts +74 -3
  106. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  107. package/reactHooks/cell-click/index.ts +21 -14
  108. package/reactHooks/connection/index.tsx +8 -5
  109. package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
  110. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
  111. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  112. package/reactHooks/feed/useFeedLoader.tsx +28 -1
  113. package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
  114. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  115. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  116. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  117. package/reactHooks/navigation/index.ts +2 -0
  118. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  119. package/reactHooks/navigation/useRoute.ts +22 -5
  120. package/reactHooks/usePluginConfiguration.ts +84 -46
  121. package/riverComponetsMeasurementProvider/index.tsx +3 -1
  122. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  123. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  124. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  125. package/uiActionsRegistrator/index.ts +25 -203
  126. package/uiActionsRegistrator/registry.ts +351 -0
  127. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  128. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  129. package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
  130. package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
  131. package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
  132. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
  133. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
  134. package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
  135. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
  136. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
  137. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  138. package/playerUtils/getPlayerActionButtons.ts +0 -17
@@ -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
+ });
@@ -0,0 +1,49 @@
1
+ import { showAlertAction } from "../showAlert";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+ import { showAlertDialog } from "../../../alertUtils";
4
+
5
+ jest.mock("../../../alertUtils", () => ({
6
+ showAlertDialog: jest.fn(),
7
+ }));
8
+
9
+ const dialog = showAlertDialog as jest.Mock;
10
+
11
+ const dismiss = () => dialog.mock.calls[0][0].completion();
12
+
13
+ describe("showAlert", () => {
14
+ beforeEach(() => dialog.mockReset());
15
+
16
+ it("shows the notice and resolves once it is dismissed", async () => {
17
+ const result = showAlertAction({
18
+ type: "showAlert",
19
+ options: { title: "Locked", message: "Ask the account owner." },
20
+ });
21
+
22
+ expect(dialog).toHaveBeenCalledWith(
23
+ expect.objectContaining({
24
+ title: "Locked",
25
+ message: "Ask the account owner.",
26
+ okButtonText: "OK",
27
+ })
28
+ );
29
+
30
+ dismiss();
31
+
32
+ // Dismissing a notice is not a cancellation: the chain carries on.
33
+ await expect(result).resolves.toBe(ActionResult.Success);
34
+ });
35
+
36
+ it("takes the dismiss label from the action", async () => {
37
+ const result = showAlertAction({
38
+ type: "showAlert",
39
+ options: { title: "Locked", okButtonText: "Got it" },
40
+ });
41
+
42
+ expect(dialog).toHaveBeenCalledWith(
43
+ expect.objectContaining({ okButtonText: "Got it" })
44
+ );
45
+
46
+ dismiss();
47
+ await result;
48
+ });
49
+ });
@@ -31,7 +31,7 @@ describe("showToastAction", () => {
31
31
  message: "Added to queue",
32
32
  extraMessage: "Extra info",
33
33
  style: undefined,
34
- timeout: 1000,
34
+ timeout: 5000,
35
35
  source: "confirmation",
36
36
  },
37
37
  ]);
@@ -78,7 +78,7 @@ describe("showToastAction", () => {
78
78
  message: undefined,
79
79
  extraMessage: undefined,
80
80
  style: undefined,
81
- timeout: 1000,
81
+ timeout: 5000,
82
82
  source: "confirmation",
83
83
  },
84
84
  ]);
@@ -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
+ }
@@ -15,6 +15,8 @@ export { appRestartAction } from "./appRestart";
15
15
 
16
16
  export { confirmDialogAction } from "./confirmDialog";
17
17
 
18
+ export { showAlertAction } from "./showAlert";
19
+
18
20
  export { sendCloudEventAction } from "./sendCloudEvent";
19
21
 
20
22
  export { sessionStorageToggleFlagAction } from "./sessionStorageToggleFlag";
@@ -27,6 +29,12 @@ export { screenToggleFlagAction } from "./screenToggleFlag";
27
29
 
28
30
  export { createNavigateToScreenAction } from "./navigateToScreen";
29
31
 
32
+ export { createPresentScreenAction } from "./presentScreen";
33
+
34
+ export { createGoBackAction } from "./goBack";
35
+
36
+ export { createGoHomeAction } from "./goHome";
37
+
30
38
  export { showToastAction } from "./showToast";
31
39
 
32
40
  export { openBottomSheetAction } from "./openBottomSheet";
@@ -13,7 +13,7 @@ const { log_info, log_error } = createLogger({
13
13
  */
14
14
  export interface NavigateToScreenOptions {
15
15
  /** The screen type to navigate to (from content types mapping) */
16
- typeMapping: string;
16
+ typeMapping?: string;
17
17
 
18
18
  /** Navigation action: push adds to history, replace replaces current screen */
19
19
  navigationAction?: "push" | "replace";
@@ -25,6 +25,19 @@ export interface NavigateToScreenOptions {
25
25
  * - undefined to navigate to screen without entry
26
26
  */
27
27
  entry?: "@{entry/}" | ZappEntry;
28
+
29
+ /**
30
+ * Arbitrary values passed through to the destination screen.
31
+ *
32
+ * They are stored on the navigation route as `NavigationScreenData.options`
33
+ * and read on the target screen via `useNavigation().data?.options`. Use this
34
+ * to hand per-navigation parameters to a screen instead of routing them
35
+ * through module-level state.
36
+ *
37
+ * Note: `legacyScreenData()` does not carry these values, so they are not
38
+ * visible through `useCurrentScreenData()` / `useRoute()`.
39
+ */
40
+ navigationOptions?: Record<string, unknown>;
28
41
  }
29
42
 
30
43
  /**
@@ -45,16 +58,9 @@ export function createNavigateToScreenAction(
45
58
  action,
46
59
  context?: ActionExecutionContext
47
60
  ): Promise<ActionResult> {
48
- const screenType = action.options?.typeMapping;
49
-
50
- if (!screenType) {
51
- log_error("navigateToScreen: typeMapping option is missing");
52
-
53
- return ActionResult.Error;
54
- }
55
-
56
61
  const navigationAction = action.options?.navigationAction;
57
62
  const entrySource = action.options?.entry;
63
+ const navigationOptions = action.options?.navigationOptions;
58
64
 
59
65
  const entry = entrySource
60
66
  ? entrySource === "@{entry/}"
@@ -62,61 +68,53 @@ export function createNavigateToScreenAction(
62
68
  : entrySource
63
69
  : null;
64
70
 
65
- if (entry) {
66
- if (typeof entry !== "object") {
67
- log_error(
68
- `navigateToScreen: entry option is not an object, entry: ${entry}`
69
- );
71
+ const screenType = action.options?.typeMapping || entry?.type?.value;
70
72
 
71
- return ActionResult.Error;
72
- }
73
+ const navigate =
74
+ navigationAction === "push" ? navigator.push : navigator.replace;
75
+
76
+ let navigatingEntry: ZappEntry | ZappRiver = entry;
73
77
 
78
+ if (entry && screenType) {
74
79
  log_info(
75
80
  `navigateToScreen: navigating to screen type: ${screenType} with entry id: ${entry.id}`
76
81
  );
77
82
 
78
- const overriddenEntry: ZappEntry = {
83
+ navigatingEntry = {
79
84
  ...entry,
80
- type: {
81
- value: screenType,
82
- },
85
+ type: { value: screenType },
83
86
  };
87
+ } else {
88
+ if (!screenType) {
89
+ log_error(
90
+ "navigateToScreen: options.typeMapping or entry?.type?.value is not provided"
91
+ );
84
92
 
85
- if (navigationAction === "push") {
86
- navigator.push(overriddenEntry);
87
- } else {
88
- // Use replaceTop for entries since replace() only accepts ZappRiver
89
- navigator.replaceTop(overriddenEntry);
93
+ return ActionResult.Error;
90
94
  }
91
95
 
92
- return ActionResult.Success;
93
- }
94
-
95
- const screenId = contentTypes?.[screenType]?.screen_id || null;
96
+ const screenId = contentTypes?.[screenType]?.screen_id || null;
97
+ const river = rivers?.[screenId];
96
98
 
97
- if (!screenId) {
98
- log_error(
99
- `navigateToScreen: can not resolve screen type mapping: ${screenType}`
100
- );
99
+ if (!screenId) {
100
+ log_error(
101
+ `navigateToScreen: can not resolve screen type mapping: ${screenType}`
102
+ );
101
103
 
102
- return ActionResult.Error;
103
- }
104
+ return ActionResult.Error;
105
+ }
104
106
 
105
- const river = rivers[screenId];
107
+ if (!river) {
108
+ log_error("navigateToScreen: can not resolve river");
106
109
 
107
- if (!river) {
108
- log_error("navigateToScreen: can not resolve river");
110
+ return ActionResult.Error;
111
+ }
109
112
 
110
- return ActionResult.Error;
113
+ navigatingEntry = river;
111
114
  }
112
115
 
113
116
  context?.callback?.({ success: false, error: null, abort: true });
114
-
115
- if (navigationAction === "push") {
116
- navigator.push(river);
117
- } else {
118
- navigator.replace(river);
119
- }
117
+ navigate(navigatingEntry, navigationOptions);
120
118
 
121
119
  return ActionResult.Success;
122
120
  };
@@ -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,11 @@ 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
+ },
215
+ themePluginId,
210
216
  },
211
217
  });
212
218
 
@@ -222,7 +228,18 @@ export async function openBottomSheetAction(
222
228
 
223
229
  let dynamicCollection: DynamicCollectionOptions | undefined;
224
230
 
225
- if (Array.isArray(inlineItems) && inlineItems.length > 0) {
231
+ const rawDynamicCollection =
232
+ content?.dynamicCollection ??
233
+ content?.extensions?.dynamic_collection_options;
234
+
235
+ // An empty items array is a valid starting state for a provider-backed or
236
+ // offline collection. A sheet with neither items nor a source still errors.
237
+ const hasDynamicCollection = Boolean(rawDynamicCollection);
238
+
239
+ if (
240
+ Array.isArray(inlineItems) &&
241
+ (inlineItems.length > 0 || hasDynamicCollection)
242
+ ) {
226
243
  log_info("openBottomSheet: using inline items from action options", {
227
244
  count: inlineItems.length,
228
245
  });
@@ -234,10 +251,7 @@ export async function openBottomSheetAction(
234
251
  entryToMenuItem(entry, behavior?.currentSelection ?? [])
235
252
  );
236
253
 
237
- dynamicCollection = parseDynamicCollectionOptions(
238
- content?.dynamicCollection ??
239
- content?.extensions?.dynamic_collection_options
240
- );
254
+ dynamicCollection = parseDynamicCollectionOptions(rawDynamicCollection);
241
255
  } else if (itemsUrl) {
242
256
  log_info(`openBottomSheet: loading items from source: ${itemsUrl}`);
243
257
 
@@ -275,6 +289,9 @@ export async function openBottomSheetAction(
275
289
  dynamicCollection,
276
290
  themePluginId,
277
291
  styleOverrides: styleOverrides ?? content?.styleOverrides,
292
+ emptyMessage: content?.emptyMessage,
293
+ operationButtons: content?.operationButtons,
294
+ context,
278
295
  },
279
296
  };
280
297
 
@@ -288,18 +305,21 @@ export async function openBottomSheetAction(
288
305
  * reference it.
289
306
  */
290
307
  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
- }
308
+ const actions = getMenuItemActions(item);
295
309
 
296
- await actionExecutor.handleAction(
297
- item.action as ActionType,
298
- {
299
- ...context,
300
- entry: item as any,
301
- } as any
310
+ const executableActions = actions.filter(
311
+ (action) => !isPresentSubMenuAction(action)
302
312
  );
313
+
314
+ if (executableActions.length > 0) {
315
+ await actionExecutor.handleActions(
316
+ executableActions as ActionType[],
317
+ {
318
+ ...context,
319
+ entry: item as any,
320
+ } as any
321
+ );
322
+ }
303
323
  };
304
324
 
305
325
  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
+ }
@@ -27,12 +27,10 @@ export const screenToggleFlagAction: ActionHandler<
27
27
  const screenRoute = context?.screenRoute;
28
28
  const screenStateStore = context?.screenStateStore;
29
29
 
30
- await screenToggleFlag(
30
+ return await screenToggleFlag(
31
31
  screenRoute,
32
32
  screenStateStore,
33
33
  { entry: context?.entry, options: action.options },
34
34
  action
35
35
  );
36
-
37
- return ActionResult.Success;
38
36
  };