@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.
- package/actionUtils/index.ts +3 -1
- package/actionsExecutor/ActionExecutor.ts +10 -1
- package/actionsExecutor/ActionExecutorContext.tsx +29 -1
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +91 -0
- package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +267 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +273 -1
- package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
- package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
- package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +8 -0
- package/actionsExecutor/actions/navigateToScreen.ts +43 -45
- package/actionsExecutor/actions/openBottomSheet.ts +36 -16
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +1 -3
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +2 -2
- package/actionsExecutor/consts.ts +4 -0
- package/actionsExecutor/feedDecorator.ts +12 -6
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -22
- package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
- package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +0 -25
- package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
- package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
- package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
- package/appUtils/contextKeysManager/index.ts +28 -129
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +4 -11
- package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +9 -2
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -1
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -1
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +21 -2
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -1
- package/appUtils/playerManager/OverlayObserver/utils.ts +9 -7
- package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
- package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
- package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
- package/appUtils/playerManager/const.ts +13 -0
- package/appUtils/playerManager/index.ts +7 -0
- package/appUtils/playerManager/player.ts +25 -0
- package/appUtils/playerManager/playerNative.ts +27 -3
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/appUtils/playerManager/playerToolbox.ts +196 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
- package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
- package/arrayUtils/index.ts +26 -43
- package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
- package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
- package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
- package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
- package/cellUtils/index.ts +70 -3
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +297 -1
- package/configurationUtils/manifestKeyParser.ts +12 -1
- package/configurationUtils/modalBlocksParser.ts +78 -4
- package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
- package/entryActions/aliasPresentation.ts +108 -0
- package/entryActions/buildEntryActions.ts +167 -0
- package/entryActions/index.ts +15 -0
- package/entryActions/types.ts +39 -0
- package/focusManager/FocusManager.ts +26 -0
- package/focusManager/__tests__/FocusManager.test.ts +9 -0
- package/localizationUtils/index.ts +12 -6
- package/logger/__tests__/xrayToolbox.test.ts +69 -0
- package/logger/xrayToolbox.ts +67 -0
- package/manifestUtils/_internals/index.js +8 -3
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +30 -1
- package/manifestUtils/keys.js +7 -2
- package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
- package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
- package/manifestUtils/mobileAction/groups/defaults.js +2 -1
- package/modalState/ModalOrchestrator.ts +23 -9
- package/modalState/RemoteEditableCollection.ts +9 -1
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +39 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
- package/modalState/__tests__/index.test.ts +30 -1
- package/modalState/__tests__/useModalStoreState.test.ts +142 -0
- package/modalState/index.ts +8 -1
- package/modalState/store.ts +9 -2
- package/modalState/types.ts +42 -2
- package/modalState/useBottomSheetContent.ts +24 -17
- package/navigationUtils/xrayNavigator.ts +12 -0
- package/package.json +3 -2
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/index.ts +17 -1
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/quickBrickAssets/__tests__/index.test.ts +18 -0
- package/quickBrickAssets/index.ts +35 -0
- package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
- package/reactHooks/actions/index.ts +74 -3
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +21 -14
- package/reactHooks/connection/index.tsx +8 -5
- package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
- package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
- package/reactHooks/feed/useFeedLoader.tsx +28 -1
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
- package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
- package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
- package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
- package/reactHooks/navigation/index.ts +2 -0
- package/reactHooks/navigation/usePresentScreen.ts +157 -0
- package/reactHooks/navigation/useRoute.ts +22 -5
- package/reactHooks/usePluginConfiguration.ts +84 -46
- package/riverComponetsMeasurementProvider/index.tsx +3 -1
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -203
- package/uiActionsRegistrator/registry.ts +351 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
- package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { act, renderHook } from "@testing-library/react-native";
|
|
2
|
+
|
|
3
|
+
import { modalStore, useModalStoreState } from "../";
|
|
4
|
+
|
|
5
|
+
const item = { id: "river-general", name: "Test Modal" };
|
|
6
|
+
const props = { entry: { id: "modal-entry-1" } };
|
|
7
|
+
|
|
8
|
+
const openModal = () =>
|
|
9
|
+
act(() => {
|
|
10
|
+
modalStore.getState().openModal({ item, props } as any);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Counts every render of the hook so the tests can assert on subscription
|
|
14
|
+
// behaviour, not just on the returned value.
|
|
15
|
+
const renderModalStoreState = (skipSubscription?: boolean) => {
|
|
16
|
+
const renders = { count: 0 };
|
|
17
|
+
|
|
18
|
+
const view = renderHook(() => {
|
|
19
|
+
renders.count += 1;
|
|
20
|
+
|
|
21
|
+
return skipSubscription === undefined
|
|
22
|
+
? useModalStoreState()
|
|
23
|
+
: useModalStoreState(skipSubscription);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return { ...view, renders };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe("useModalStoreState", () => {
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
act(() => {
|
|
32
|
+
modalStore.getState().dismissModal();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("when subscribed (default)", () => {
|
|
37
|
+
it("returns the live modal state when called without arguments", () => {
|
|
38
|
+
const { result } = renderModalStoreState();
|
|
39
|
+
|
|
40
|
+
expect(result.current.visible).toBe(false);
|
|
41
|
+
|
|
42
|
+
openModal();
|
|
43
|
+
|
|
44
|
+
expect(result.current.visible).toBe(true);
|
|
45
|
+
expect(result.current.screen).toBe(item);
|
|
46
|
+
expect(result.current.props).toBe(props);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("re-renders the consumer when the modal state changes", () => {
|
|
50
|
+
const { renders } = renderModalStoreState(false);
|
|
51
|
+
|
|
52
|
+
const rendersBeforeOpen = renders.count;
|
|
53
|
+
|
|
54
|
+
openModal();
|
|
55
|
+
|
|
56
|
+
expect(renders.count).toBeGreaterThan(rendersBeforeOpen);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Counterpart to "returns a stable reference across store updates": an open
|
|
60
|
+
// modal is the one point where a live subscription and a skipped one hold
|
|
61
|
+
// different references, which is what makes that assertion meaningful.
|
|
62
|
+
it("returns a new reference while the modal is open", () => {
|
|
63
|
+
const { result } = renderModalStoreState(false);
|
|
64
|
+
|
|
65
|
+
const firstValue = result.current;
|
|
66
|
+
|
|
67
|
+
openModal();
|
|
68
|
+
|
|
69
|
+
expect(result.current).not.toBe(firstValue);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("when subscription is skipped", () => {
|
|
74
|
+
it("reports an empty modal state even while a modal is open", () => {
|
|
75
|
+
openModal();
|
|
76
|
+
|
|
77
|
+
expect(modalStore.getState().modalState.visible).toBe(true);
|
|
78
|
+
|
|
79
|
+
const { result } = renderModalStoreState(true);
|
|
80
|
+
|
|
81
|
+
expect(result.current).toMatchObject({
|
|
82
|
+
visible: false,
|
|
83
|
+
screen: null,
|
|
84
|
+
options: {},
|
|
85
|
+
props: {},
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("does not re-render the consumer when the modal state changes", () => {
|
|
90
|
+
const { renders } = renderModalStoreState(true);
|
|
91
|
+
|
|
92
|
+
const rendersBeforeOpen = renders.count;
|
|
93
|
+
|
|
94
|
+
openModal();
|
|
95
|
+
|
|
96
|
+
expect(renders.count).toBe(rendersBeforeOpen);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// The skipped branch has to hand back a module-level constant. Returning a
|
|
100
|
+
// fresh object would fail zustand's Object.is check and re-render on every
|
|
101
|
+
// store notification - the opposite of what skipping is for.
|
|
102
|
+
it("returns a stable reference across store updates", () => {
|
|
103
|
+
const { result } = renderModalStoreState(true);
|
|
104
|
+
|
|
105
|
+
const firstValue = result.current;
|
|
106
|
+
|
|
107
|
+
openModal();
|
|
108
|
+
|
|
109
|
+
// Asserted while the modal is open: dismissing resets the store to the
|
|
110
|
+
// very same initialModalState object, so an end-to-end round trip would
|
|
111
|
+
// hold this identity even for a live subscription.
|
|
112
|
+
expect(result.current).toBe(firstValue);
|
|
113
|
+
|
|
114
|
+
act(() => {
|
|
115
|
+
modalStore.getState().dismissModal();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(result.current).toBe(firstValue);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("picks up the current modal state when it starts subscribing", () => {
|
|
123
|
+
let skipSubscription = true;
|
|
124
|
+
|
|
125
|
+
const { result, rerender } = renderHook(() =>
|
|
126
|
+
useModalStoreState(skipSubscription)
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
openModal();
|
|
130
|
+
|
|
131
|
+
expect(result.current.visible).toBe(false);
|
|
132
|
+
|
|
133
|
+
skipSubscription = false;
|
|
134
|
+
|
|
135
|
+
act(() => {
|
|
136
|
+
rerender(undefined);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
expect(result.current.visible).toBe(true);
|
|
140
|
+
expect(result.current.screen).toBe(item);
|
|
141
|
+
});
|
|
142
|
+
});
|
package/modalState/index.ts
CHANGED
|
@@ -23,8 +23,15 @@ export type {
|
|
|
23
23
|
SecondaryAction,
|
|
24
24
|
SelectMode,
|
|
25
25
|
SelectionBehavior,
|
|
26
|
+
OperationButton,
|
|
27
|
+
OperationButtons,
|
|
26
28
|
} from "./types";
|
|
27
29
|
|
|
28
|
-
export {
|
|
30
|
+
export {
|
|
31
|
+
isPresentSubMenuAction,
|
|
32
|
+
getMenuItemActions,
|
|
33
|
+
OPERATIONS,
|
|
34
|
+
hasOperation,
|
|
35
|
+
} from "./types";
|
|
29
36
|
|
|
30
37
|
export { useBottomSheetContent } from "./useBottomSheetContent";
|
package/modalState/store.ts
CHANGED
|
@@ -98,5 +98,12 @@ export const openBottomSheetModal = ({
|
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Pass `skipSubscription` from callers that render outside of a modal: the
|
|
103
|
+
* selector then returns the stable `initialModalState` reference, so the
|
|
104
|
+
* component is never re-rendered by modal state it does not read.
|
|
105
|
+
*/
|
|
106
|
+
export const useModalStoreState = (skipSubscription = false): ModalState =>
|
|
107
|
+
useModalStore<ModalState>((state) =>
|
|
108
|
+
skipSubscription ? initialModalState : state.modalState
|
|
109
|
+
);
|
package/modalState/types.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { EntryAction } from "../entryActions/types";
|
|
2
|
+
|
|
1
3
|
export interface Header {
|
|
2
4
|
title: string;
|
|
3
5
|
subtitle?: string;
|
|
@@ -37,8 +39,8 @@ export interface MenuItem {
|
|
|
37
39
|
summary?: string;
|
|
38
40
|
icon?: string;
|
|
39
41
|
isSelected?: boolean;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
actions?: (Action | PresentSubMenuAction)[];
|
|
43
|
+
/** @deprecated Use `actions` array instead. Maintained for backwards compatibility. */
|
|
42
44
|
action?: Action | PresentSubMenuAction;
|
|
43
45
|
secondaryAction?: SecondaryAction;
|
|
44
46
|
trailingButton?: any;
|
|
@@ -107,6 +109,13 @@ export interface DynamicCollectionOptions {
|
|
|
107
109
|
events?: Record<CollectionScopedOperation | string, Action[]>;
|
|
108
110
|
}
|
|
109
111
|
|
|
112
|
+
/** Presentation of a sheet-synthesized operation control; same fields as an entry action button. */
|
|
113
|
+
export type OperationButton = Pick<EntryAction["button"], "title" | "iconURL">;
|
|
114
|
+
|
|
115
|
+
export type OperationButtons = Partial<
|
|
116
|
+
Record<CollectionScopedOperation | string, OperationButton>
|
|
117
|
+
>;
|
|
118
|
+
|
|
110
119
|
export interface Content {
|
|
111
120
|
title: string;
|
|
112
121
|
stickyTitle?: boolean;
|
|
@@ -118,6 +127,11 @@ export interface Content {
|
|
|
118
127
|
dynamicCollection?: DynamicCollectionOptions;
|
|
119
128
|
themePluginId?: string;
|
|
120
129
|
styleOverrides?: Record<string, any>;
|
|
130
|
+
/** Shown under Next Up when the queue sheet has no upcoming items. */
|
|
131
|
+
emptyMessage?: string;
|
|
132
|
+
/** Producer-owned presentation for sheet-synthesized operation controls (e.g. `add`). */
|
|
133
|
+
operationButtons?: OperationButtons;
|
|
134
|
+
context?: Record<string, any>;
|
|
121
135
|
}
|
|
122
136
|
|
|
123
137
|
export interface Menu {
|
|
@@ -131,3 +145,29 @@ export function isPresentSubMenuAction(
|
|
|
131
145
|
): action is PresentSubMenuAction {
|
|
132
146
|
return !!action && typeof action === "object" && "menu" in action;
|
|
133
147
|
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Normalizes an item's action/actions into an array of Action items.
|
|
151
|
+
* Supports canonical `actions: Action[]` and backwards-compatible `action: Action | Action[]`.
|
|
152
|
+
*/
|
|
153
|
+
export function getMenuItemActions(
|
|
154
|
+
item?: Partial<MenuItem> | null
|
|
155
|
+
): (Action | PresentSubMenuAction)[] {
|
|
156
|
+
if (!item) {
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (Array.isArray(item.actions) && item.actions.length > 0) {
|
|
161
|
+
return item.actions;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (Array.isArray((item as any).action)) {
|
|
165
|
+
return (item as any).action;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (item.action) {
|
|
169
|
+
return [item.action];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return [];
|
|
173
|
+
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
1
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
2
2
|
import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
isPresentSubMenuAction,
|
|
6
|
-
MenuItem,
|
|
7
|
-
modalOrchestrator,
|
|
8
|
-
} from "./ModalOrchestrator";
|
|
4
|
+
import { MenuItem, modalOrchestrator } from "./ModalOrchestrator";
|
|
9
5
|
|
|
10
6
|
import { ContentViewModel } from "./ContentViewModel";
|
|
11
|
-
import
|
|
7
|
+
import {
|
|
8
|
+
DynamicCollectionOptions,
|
|
9
|
+
getMenuItemActions,
|
|
10
|
+
isPresentSubMenuAction,
|
|
11
|
+
SelectionBehavior,
|
|
12
|
+
} from "./types";
|
|
12
13
|
import type { EditableCollection } from "./EditableCollection";
|
|
13
14
|
|
|
14
15
|
type Props = {
|
|
@@ -44,7 +45,9 @@ export const useBottomSheetContent = (props: Props): Return => {
|
|
|
44
45
|
// Subscribe to the viewModel state changes
|
|
45
46
|
useEffect(() => {
|
|
46
47
|
return viewModel?.subscribe((nextState) => {
|
|
47
|
-
setState(
|
|
48
|
+
setState((state) => {
|
|
49
|
+
return state === nextState ? state : nextState;
|
|
50
|
+
});
|
|
48
51
|
});
|
|
49
52
|
}, [viewModel]);
|
|
50
53
|
|
|
@@ -64,15 +67,19 @@ export const useBottomSheetContent = (props: Props): Return => {
|
|
|
64
67
|
* - If the item was a leaf action (not a submenu), triggers viewModel.refetch()
|
|
65
68
|
* so that checkmarks (isSelected) reflect the updated server state.
|
|
66
69
|
*/
|
|
67
|
-
const handleItemPress =
|
|
68
|
-
|
|
70
|
+
const handleItemPress = useCallback(
|
|
71
|
+
async (item: MenuItem) => {
|
|
72
|
+
const actions = getMenuItemActions(item);
|
|
73
|
+
const isSubMenu = actions.some(isPresentSubMenuAction);
|
|
69
74
|
|
|
70
|
-
|
|
75
|
+
await onPress(item);
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
77
|
+
if (!isSubMenu) {
|
|
78
|
+
await viewModel?.refetch();
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
[onPress, viewModel]
|
|
82
|
+
);
|
|
76
83
|
|
|
77
84
|
const goBackOrClose = React.useCallback(() => {
|
|
78
85
|
if (modalOrchestrator.canGoBack) {
|
|
@@ -80,7 +87,7 @@ export const useBottomSheetContent = (props: Props): Return => {
|
|
|
80
87
|
} else {
|
|
81
88
|
modalOrchestrator.close();
|
|
82
89
|
}
|
|
83
|
-
}, [
|
|
90
|
+
}, []);
|
|
84
91
|
|
|
85
92
|
return {
|
|
86
93
|
items: viewModel?.editableCollection ? editableItems : state?.items,
|
|
@@ -92,7 +99,7 @@ export const useBottomSheetContent = (props: Props): Return => {
|
|
|
92
99
|
canGoBack: modalOrchestrator.canGoBack,
|
|
93
100
|
handleItemPress,
|
|
94
101
|
goBackOrClose,
|
|
95
|
-
close: () => modalOrchestrator.close(),
|
|
102
|
+
close: useCallback(() => modalOrchestrator.close(), []),
|
|
96
103
|
role: state?.role,
|
|
97
104
|
behavior: state?.behavior,
|
|
98
105
|
dynamicCollection: state?.dynamicCollection,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app navigator for the X-Ray toolboxes (nav, screen), which run outside React. The
|
|
3
|
+
* NavigationProvider sets it after each commit; it is a plain module variable, so updating it
|
|
4
|
+
* never renders anything.
|
|
5
|
+
*/
|
|
6
|
+
let navigator: QuickBrickAppNavigator | undefined;
|
|
7
|
+
|
|
8
|
+
export const setXrayNavigator = (value: QuickBrickAppNavigator | undefined) => {
|
|
9
|
+
navigator = value;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const getXrayNavigator = () => navigator;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "16.0.0-alpha.
|
|
3
|
+
"version": "16.0.0-alpha.2710214351",
|
|
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.
|
|
30
|
+
"@applicaster/applicaster-types": "16.0.0-alpha.2710214351",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"prop-types": "^15.0.0"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
+
"@applicaster/quick-brick-assets": "*",
|
|
39
40
|
"@applicaster/zapp-pipes-v2-client": "*",
|
|
40
41
|
"@react-native-community/netinfo": "*",
|
|
41
42
|
"react": "*",
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { resolvePlayerActions } from "../resolvePlayerActions";
|
|
2
|
+
import { selectActionButtons } from "../../conf/player/selectors";
|
|
3
|
+
import { uiActionsRegistry } from "../../uiActionsRegistrator";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../conf/player/selectors", () => ({
|
|
6
|
+
selectActionButtons: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const action = (identifier: string) =>
|
|
10
|
+
({ identifier, action: { invokeAction: jest.fn() } }) as any;
|
|
11
|
+
|
|
12
|
+
describe("resolvePlayerActions", () => {
|
|
13
|
+
const entry = {
|
|
14
|
+
id: "e1",
|
|
15
|
+
extensions: {
|
|
16
|
+
entry_action: [
|
|
17
|
+
{ button: { alias: "add_to_playlist" }, actions: [{ type: "test" }] },
|
|
18
|
+
{ button: { alias: "add_to_queue" }, actions: [{ type: "test" }] },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// The entry's own actions never reach the registry; the caller expands them.
|
|
24
|
+
const expandEntryActions = jest.fn(() => [
|
|
25
|
+
action("entry_action_0"),
|
|
26
|
+
action("entry_action_1"),
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
expandEntryActions.mockClear();
|
|
31
|
+
|
|
32
|
+
jest
|
|
33
|
+
.spyOn(uiActionsRegistry, "getActions")
|
|
34
|
+
.mockImplementation((name) => [action(name)]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
jest.restoreAllMocks();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("expands entry_actions through the caller and keeps config order", () => {
|
|
42
|
+
(selectActionButtons as jest.Mock).mockReturnValue(
|
|
43
|
+
"entry_actions,local_storage_favourites_action,offline-content-button"
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const result = resolvePlayerActions({
|
|
47
|
+
configuration: {},
|
|
48
|
+
entry,
|
|
49
|
+
expandEntryActions,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expect(expandEntryActions).toHaveBeenCalledWith(entry);
|
|
53
|
+
|
|
54
|
+
expect(uiActionsRegistry.getActions).not.toHaveBeenCalledWith(
|
|
55
|
+
"entry_actions",
|
|
56
|
+
entry
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(result.map((item) => item.identifier)).toEqual([
|
|
60
|
+
"entry_action_0",
|
|
61
|
+
"entry_action_1",
|
|
62
|
+
"local_storage_favourites_action",
|
|
63
|
+
"offline-content-button",
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it.each([undefined, null, ""])(
|
|
68
|
+
"resolves nothing when the config is %p",
|
|
69
|
+
(configured) => {
|
|
70
|
+
(selectActionButtons as jest.Mock).mockReturnValue(configured);
|
|
71
|
+
|
|
72
|
+
expect(
|
|
73
|
+
resolvePlayerActions({ configuration: {}, entry, expandEntryActions })
|
|
74
|
+
).toEqual([]);
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
it("does not cap the resolved list at two items", () => {
|
|
79
|
+
(selectActionButtons as jest.Mock).mockReturnValue("a,b,c");
|
|
80
|
+
|
|
81
|
+
expect(
|
|
82
|
+
resolvePlayerActions({
|
|
83
|
+
configuration: {},
|
|
84
|
+
entry,
|
|
85
|
+
expandEntryActions,
|
|
86
|
+
}).map((item) => item.identifier)
|
|
87
|
+
).toEqual(["a", "b", "c"]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("has no special case for any plugin identifier", () => {
|
|
91
|
+
(selectActionButtons as jest.Mock).mockReturnValue(
|
|
92
|
+
"open-modal-bottom-sheet-cell-action,local_storage_favourites_action"
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
expect(
|
|
96
|
+
resolvePlayerActions({
|
|
97
|
+
configuration: {},
|
|
98
|
+
entry,
|
|
99
|
+
expandEntryActions,
|
|
100
|
+
}).map((item) => item.identifier)
|
|
101
|
+
).toEqual([
|
|
102
|
+
"open-modal-bottom-sheet-cell-action",
|
|
103
|
+
"local_storage_favourites_action",
|
|
104
|
+
]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("collapses a repeated identifier in the config string", () => {
|
|
108
|
+
(selectActionButtons as jest.Mock).mockReturnValue(
|
|
109
|
+
"favorites,favorites,share"
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(
|
|
113
|
+
resolvePlayerActions({
|
|
114
|
+
configuration: {},
|
|
115
|
+
entry,
|
|
116
|
+
expandEntryActions,
|
|
117
|
+
}).map((item) => item.identifier)
|
|
118
|
+
).toEqual(["favorites", "share"]);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("drops resolved items that cannot be invoked", () => {
|
|
122
|
+
(selectActionButtons as jest.Mock).mockReturnValue("broken,share");
|
|
123
|
+
|
|
124
|
+
(uiActionsRegistry.getActions as jest.Mock).mockImplementation((name) =>
|
|
125
|
+
name === "broken"
|
|
126
|
+
? [{ identifier: "broken" } as any]
|
|
127
|
+
: [action(name as string)]
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(
|
|
131
|
+
resolvePlayerActions({
|
|
132
|
+
configuration: {},
|
|
133
|
+
entry,
|
|
134
|
+
expandEntryActions,
|
|
135
|
+
}).map((item) => item.identifier)
|
|
136
|
+
).toEqual(["share"]);
|
|
137
|
+
});
|
|
138
|
+
});
|
package/playerUtils/index.ts
CHANGED
|
@@ -7,7 +7,23 @@ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
|
7
7
|
import { getBoolFromConfigValue } from "../configurationUtils";
|
|
8
8
|
import { Dimensions } from "react-native";
|
|
9
9
|
|
|
10
|
-
export {
|
|
10
|
+
export { resolvePlayerActions } from "./resolvePlayerActions";
|
|
11
|
+
|
|
12
|
+
export { isEntryAction } from "../entryActions";
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
parseActionIdentifiers,
|
|
16
|
+
resolveActionIdentifiers,
|
|
17
|
+
} from "../uiActionsRegistrator";
|
|
18
|
+
|
|
19
|
+
export type { ResolveActionIdentifiersParams } from "../uiActionsRegistrator";
|
|
20
|
+
|
|
21
|
+
export type {
|
|
22
|
+
ActionButtonDescriptor,
|
|
23
|
+
OverflowDescriptor,
|
|
24
|
+
PlayerControlDescriptor,
|
|
25
|
+
ResolvePlayerActionsParams,
|
|
26
|
+
} from "./resolvePlayerActions";
|
|
11
27
|
|
|
12
28
|
export {
|
|
13
29
|
resolvePlayerContentText,
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { selectActionButtons } from "../conf/player/selectors";
|
|
2
|
+
import {
|
|
3
|
+
usableActionItems,
|
|
4
|
+
RegisteredAction,
|
|
5
|
+
resolveActionIdentifiers,
|
|
6
|
+
} from "../uiActionsRegistrator";
|
|
7
|
+
|
|
8
|
+
export type ResolvePlayerActionsParams = {
|
|
9
|
+
configuration: any;
|
|
10
|
+
entry: ZappEntry | ZappFeed;
|
|
11
|
+
/** Expands the `entry_actions` token; see `resolveActionIdentifiers`. */
|
|
12
|
+
expandEntryActions?: (entry: ZappEntry | ZappFeed) => RegisteredAction[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The player's action buttons, resolved against the entry.
|
|
17
|
+
*
|
|
18
|
+
* Every `player_action_buttons` token goes through `uiActionsRegistry`, except
|
|
19
|
+
* `entry_actions`, which the caller expands from the entry itself. The list is
|
|
20
|
+
* not capped; the overlay decides how many fit and sends the rest to the sheet.
|
|
21
|
+
*/
|
|
22
|
+
export function resolvePlayerActions({
|
|
23
|
+
configuration,
|
|
24
|
+
entry,
|
|
25
|
+
expandEntryActions,
|
|
26
|
+
}: ResolvePlayerActionsParams): RegisteredAction[] {
|
|
27
|
+
const buttonsString = selectActionButtons(configuration);
|
|
28
|
+
|
|
29
|
+
if (!buttonsString) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Deduped at the source: `player_action_buttons` is a hand-typed string, so
|
|
34
|
+
// the same identifier can legitimately appear twice. Left alone, a repeat
|
|
35
|
+
// would be counted twice against the inline limit, rendered twice on the
|
|
36
|
+
// overlay, and collide as a React key. Items with no `invokeAction` are
|
|
37
|
+
// dropped here too - they can never do anything.
|
|
38
|
+
return usableActionItems(
|
|
39
|
+
resolveActionIdentifiers({
|
|
40
|
+
identifiers: buttonsString,
|
|
41
|
+
entry,
|
|
42
|
+
expandEntryActions,
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** One control on the player overlay, before overflow is applied. */
|
|
48
|
+
export type ActionButtonDescriptor =
|
|
49
|
+
| { kind: "subtitle" }
|
|
50
|
+
| { kind: "close" }
|
|
51
|
+
| { kind: "airplay" }
|
|
52
|
+
| { kind: "action"; action: RegisteredAction };
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The Overflow control, produced by `splitOverflow` when more content actions
|
|
56
|
+
* resolve than fit on the overlay.
|
|
57
|
+
*/
|
|
58
|
+
export type OverflowDescriptor = {
|
|
59
|
+
kind: "overflow";
|
|
60
|
+
/**
|
|
61
|
+
* Every content action, the overlay companion included. An overlay button
|
|
62
|
+
* renders nothing when its action has no icon, so the companion needs the
|
|
63
|
+
* sheet as a second home or it could be reachable from nowhere.
|
|
64
|
+
*/
|
|
65
|
+
additionalActions: RegisteredAction[];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** What the overlay actually renders, once overflow has been applied. */
|
|
69
|
+
export type PlayerControlDescriptor =
|
|
70
|
+
| ActionButtonDescriptor
|
|
71
|
+
| OverflowDescriptor;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
const mockAppStoreGet = jest.fn();
|
|
2
|
+
|
|
3
|
+
jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
|
|
4
|
+
appStore: { get: (key) => mockAppStoreGet(key) },
|
|
5
|
+
}));
|
|
6
|
+
|
|
1
7
|
import * as R from "ramda";
|
|
2
8
|
import * as pluginUtils from "../index";
|
|
3
9
|
|
|
@@ -148,6 +154,32 @@ describe("findPluginByIdentifier", () => {
|
|
|
148
154
|
});
|
|
149
155
|
});
|
|
150
156
|
|
|
157
|
+
describe("getPluginByIdentifier", () => {
|
|
158
|
+
const { getPluginByIdentifier } = pluginUtils;
|
|
159
|
+
|
|
160
|
+
const plugins = {
|
|
161
|
+
foo: pluginMock("foo", "foo", "some_plugin_type"),
|
|
162
|
+
bar: pluginMock("foo", "bar", "some_plugin_type"),
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
beforeEach(() => {
|
|
166
|
+
mockAppStoreGet.mockReset();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("reads plugins from appStore and returns the matching plugin", () => {
|
|
170
|
+
mockAppStoreGet.mockReturnValue(plugins);
|
|
171
|
+
|
|
172
|
+
expect(getPluginByIdentifier("foo")).toEqual(plugins.foo);
|
|
173
|
+
expect(mockAppStoreGet).toHaveBeenCalledWith("plugins");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("returns undefined when the plugin is not found", () => {
|
|
177
|
+
mockAppStoreGet.mockReturnValue(plugins);
|
|
178
|
+
|
|
179
|
+
expect(getPluginByIdentifier("do_not_exist")).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
151
183
|
describe("findPluginByType", () => {
|
|
152
184
|
const { findPluginByType } = pluginUtils;
|
|
153
185
|
|
package/pluginUtils/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
|
+
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
2
3
|
import { toCamelCase, toPascalCase } from "../stringUtils";
|
|
3
4
|
|
|
4
5
|
import { getNavigationType } from "../navigationUtils";
|
|
@@ -97,6 +98,34 @@ export function findPluginByIdentifier(
|
|
|
97
98
|
return plugin;
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Like findPluginByIdentifier, but reads the current plugins list from appStore.
|
|
103
|
+
* Convenience for non-render / hook code that doesn't already have `plugins` in hand.
|
|
104
|
+
* @param identifier of the plugin to look for
|
|
105
|
+
* @param doNotWarn if set to true, will not log a warning if plugin is not found
|
|
106
|
+
* @return whole plugin if found, undefined otherwise
|
|
107
|
+
*/
|
|
108
|
+
export function getPluginByIdentifier(
|
|
109
|
+
identifier: string,
|
|
110
|
+
doNotWarn: boolean = false
|
|
111
|
+
): (QuickBrickPlugin | ZappPlugin | Plugin) | undefined {
|
|
112
|
+
try {
|
|
113
|
+
const plugins = appStore.get("plugins") ?? {};
|
|
114
|
+
|
|
115
|
+
return findPluginByIdentifier(identifier, plugins, doNotWarn);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (!doNotWarn) {
|
|
118
|
+
pluginUtilsLogger.warning({
|
|
119
|
+
message:
|
|
120
|
+
"Could not read plugins from appStore while resolving plugin by identifier",
|
|
121
|
+
data: { identifier, error },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
100
129
|
const pluginTypeForItemTypeMap = {
|
|
101
130
|
playable: "player",
|
|
102
131
|
};
|