@applicaster/zapp-react-native-utils 16.0.0-alpha.2434153375 → 16.0.0-alpha.2500443242
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/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 +139 -5
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +201 -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 +29 -45
- package/actionsExecutor/actions/openBottomSheet.ts +35 -16
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +2 -2
- package/actionsExecutor/consts.ts +4 -0
- 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.ts +15 -2
- package/appUtils/playerManager/OverlayObserver/utils.ts +2 -5
- package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
- package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -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 +10 -0
- package/appUtils/playerManager/playerNative.ts +22 -0
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/appUtils/playerManager/playerToolbox.ts +157 -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 +74 -19
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +286 -1
- package/configurationUtils/index.ts +77 -73
- package/configurationUtils/manifestKeyParser.ts +12 -1
- package/configurationUtils/modalBlocksParser.ts +78 -4
- package/entryActions/__tests__/buildEntryActions.test.ts +97 -18
- package/entryActions/aliasPresentation.ts +26 -42
- package/entryActions/buildEntryActions.ts +1 -0
- package/entryActions/index.ts +0 -2
- 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 +8 -0
- package/manifestUtils/keys.js +6 -1
- 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 +22 -9
- package/modalState/RemoteEditableCollection.ts +9 -1
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +16 -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 +6 -1
- package/modalState/store.ts +9 -2
- package/modalState/types.ts +31 -2
- package/modalState/useBottomSheetContent.ts +24 -17
- package/navigationUtils/xrayNavigator.ts +12 -0
- package/package.json +2 -2
- package/perfTracker.ts +206 -0
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
- 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__/useMarkPipesDataStale.test.tsx +243 -0
- 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 +8 -1
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
- package/uiActionsRegistrator/registry.ts +16 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { registerXrayToolbox, XrayToolSpec } from "../../logger/xrayToolbox";
|
|
2
|
+
import type { PlayerManager } from "./index";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* X-Ray `player.*` toolbox: lets an agent read and drive the active player without screenshots.
|
|
6
|
+
* Registered by the PlayerManager singleton itself, so it exists wherever players do. Skipped
|
|
7
|
+
* when the installed X-Ray plugin has no React toolbox API.
|
|
8
|
+
*
|
|
9
|
+
* How the player is shown (video modal mode, mini player) is navigation state: see `nav.*`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const toNumber = (value: unknown) =>
|
|
13
|
+
typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
14
|
+
|
|
15
|
+
const clamp = (value: number, max: number) => Math.min(Math.max(value, 0), max);
|
|
16
|
+
|
|
17
|
+
/** The range a seek can reach: the DVR window on live, the content on VOD. */
|
|
18
|
+
const requireSeekable = (player: {
|
|
19
|
+
getSeekableDuration: () => number | undefined;
|
|
20
|
+
}) => {
|
|
21
|
+
const seekable = toNumber(player.getSeekableDuration());
|
|
22
|
+
|
|
23
|
+
if (!seekable) throw new Error("Seek is not supported");
|
|
24
|
+
|
|
25
|
+
return seekable;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const tools = (manager: PlayerManager): XrayToolSpec[] => {
|
|
29
|
+
const requirePlayer = () => {
|
|
30
|
+
const player = manager.getActivePlayer();
|
|
31
|
+
|
|
32
|
+
if (!player) throw new Error("No active player");
|
|
33
|
+
|
|
34
|
+
return player;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
name: "state",
|
|
40
|
+
description:
|
|
41
|
+
"The active player: entry, position and duration in seconds, playing/buffering/ad/live/muted, " +
|
|
42
|
+
"role (Primary, Cell, Chromecast) and casting. active: false when nothing plays.",
|
|
43
|
+
handler: () => {
|
|
44
|
+
const player = manager.getActivePlayer();
|
|
45
|
+
|
|
46
|
+
if (!player) return { active: false, casting: manager.isCasting() };
|
|
47
|
+
|
|
48
|
+
const entry = player.getEntry();
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
active: true,
|
|
52
|
+
playerId: player.playerId,
|
|
53
|
+
entry: entry ? { id: entry.id, title: entry.title } : null,
|
|
54
|
+
position: toNumber(player.getPosition()),
|
|
55
|
+
duration: toNumber(player.getDuration()),
|
|
56
|
+
// isPlaying() only means "not paused", which is also true before the stream starts.
|
|
57
|
+
playing: !!player.isReadyToPlay() && player.isPlaying(),
|
|
58
|
+
buffering: !!player.isBuffering(),
|
|
59
|
+
readyToPlay: !!player.isReadyToPlay(),
|
|
60
|
+
ad: player.isAd(),
|
|
61
|
+
live: !!player.isLive(),
|
|
62
|
+
muted: !!player.getIsMuted(),
|
|
63
|
+
role: player.playerRole,
|
|
64
|
+
casting: manager.isCasting(),
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "play",
|
|
70
|
+
description: "Resume the active player.",
|
|
71
|
+
handler: () => {
|
|
72
|
+
requirePlayer().play();
|
|
73
|
+
|
|
74
|
+
return "OK";
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "pause",
|
|
79
|
+
description: "Pause the active player.",
|
|
80
|
+
handler: () => {
|
|
81
|
+
requirePlayer().pause();
|
|
82
|
+
|
|
83
|
+
return "OK";
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "seek",
|
|
88
|
+
description:
|
|
89
|
+
"Seek to an absolute position, as the player's console command does: seconds from the start, " +
|
|
90
|
+
"or from the end when negative. Clamped to the seekable range. Where it lands can differ: " +
|
|
91
|
+
"server-side ads snap back to the break before the target; read player.state afterwards.",
|
|
92
|
+
parameters: [
|
|
93
|
+
{
|
|
94
|
+
name: "position",
|
|
95
|
+
type: "number",
|
|
96
|
+
description:
|
|
97
|
+
"Seconds from the start; negative values count back from the end.",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
handler: ({ position }) => {
|
|
101
|
+
const player = requirePlayer();
|
|
102
|
+
const seconds = toNumber(position);
|
|
103
|
+
|
|
104
|
+
if (seconds === null) {
|
|
105
|
+
throw new Error("'position' must be a number of seconds");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const seekable = requireSeekable(player);
|
|
109
|
+
|
|
110
|
+
const target =
|
|
111
|
+
seconds >= 0
|
|
112
|
+
? Math.min(seconds, seekable)
|
|
113
|
+
: clamp(seekable + seconds, seekable);
|
|
114
|
+
|
|
115
|
+
player.seekTo(target);
|
|
116
|
+
|
|
117
|
+
return { position: target };
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "offset",
|
|
122
|
+
description:
|
|
123
|
+
"Seek relative to the current position, as the player's console command does: positive " +
|
|
124
|
+
"forward, negative back. Clamped to the seekable range.",
|
|
125
|
+
parameters: [
|
|
126
|
+
{
|
|
127
|
+
name: "seconds",
|
|
128
|
+
type: "number",
|
|
129
|
+
description: "Seconds to move: positive forward, negative back.",
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
handler: ({ seconds }) => {
|
|
133
|
+
const player = requirePlayer();
|
|
134
|
+
const delta = toNumber(seconds);
|
|
135
|
+
|
|
136
|
+
if (delta === null) throw new Error("'seconds' must be a number");
|
|
137
|
+
|
|
138
|
+
if (delta === 0) throw new Error("Ignored zero relative seek");
|
|
139
|
+
|
|
140
|
+
const seekable = requireSeekable(player);
|
|
141
|
+
const from = toNumber(player.getContentPosition()) ?? 0;
|
|
142
|
+
const target = clamp(from + delta, seekable);
|
|
143
|
+
|
|
144
|
+
player.seekTo(target);
|
|
145
|
+
|
|
146
|
+
return { from, position: target };
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const registerPlayerToolbox = (manager: PlayerManager) =>
|
|
153
|
+
registerXrayToolbox({
|
|
154
|
+
name: "player",
|
|
155
|
+
description: "Inspect and control the active player.",
|
|
156
|
+
tools: tools(manager),
|
|
157
|
+
});
|
|
@@ -8,6 +8,7 @@ import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/
|
|
|
8
8
|
import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
|
|
9
9
|
import { KeyInputHandler } from "../keyInputHandler/KeyInputHandler";
|
|
10
10
|
import { isTV } from "../../reactUtils";
|
|
11
|
+
import { PlayerAnalyticsManager } from "../../analyticsUtils/PlayerAnalyticsManager";
|
|
11
12
|
|
|
12
13
|
// TODO: Rename to ControllerType
|
|
13
14
|
export const usePlayerControllerSetup = ({
|
|
@@ -68,6 +69,11 @@ export const usePlayerControllerSetup = ({
|
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
// The analytics manager attaches its listener when a player registers, so it
|
|
73
|
+
// must exist first; on web the Player wrapper that also creates it renders
|
|
74
|
+
// only after the lazily loaded engine chunk, i.e. after registration.
|
|
75
|
+
PlayerAnalyticsManager.getInstance();
|
|
76
|
+
|
|
71
77
|
playerManager.registerPlayer({
|
|
72
78
|
id: playerId,
|
|
73
79
|
playerController,
|
|
@@ -47,4 +47,17 @@ describe("reorderByIds", () => {
|
|
|
47
47
|
|
|
48
48
|
expect(result.map((i) => i.key)).toEqual(["c", "b", "a"]);
|
|
49
49
|
});
|
|
50
|
+
|
|
51
|
+
it("reorders duplicate items when using unique slot identifiers via getId", () => {
|
|
52
|
+
const duplicateItems = [
|
|
53
|
+
{ id: "x", slot: "s1", name: "First X" },
|
|
54
|
+
{ id: "y", slot: "s2", name: "Y" },
|
|
55
|
+
{ id: "x", slot: "s3", name: "Second X" },
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const result = reorderByIds(duplicateItems, ["s3", "s1"], (i) => i.slot);
|
|
59
|
+
|
|
60
|
+
expect(result).toHaveLength(3);
|
|
61
|
+
expect(result.map((i) => i.name)).toEqual(["Second X", "Y", "First X"]);
|
|
62
|
+
});
|
|
50
63
|
});
|
package/arrayUtils/index.ts
CHANGED
|
@@ -167,7 +167,7 @@ export const anyTruthy = (xs: boolean[]) => xs.some(Boolean);
|
|
|
167
167
|
export function reorderByIds<T>(
|
|
168
168
|
items: T[],
|
|
169
169
|
orderedIds: string[],
|
|
170
|
-
getId: (item: T) => string
|
|
170
|
+
getId: (item: T) => string = (item: any) => item?.id
|
|
171
171
|
): T[] {
|
|
172
172
|
if (!items || items.length === 0) return [];
|
|
173
173
|
if (!orderedIds || orderedIds.length === 0) return [...items];
|
|
@@ -175,14 +175,16 @@ export function reorderByIds<T>(
|
|
|
175
175
|
const itemMap = new Map<string, T>();
|
|
176
176
|
|
|
177
177
|
items.forEach((item) => {
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
const id = getId(item);
|
|
179
|
+
|
|
180
|
+
if (
|
|
181
|
+
id !== undefined &&
|
|
182
|
+
id !== null &&
|
|
183
|
+
id !== "" &&
|
|
184
|
+
!itemMap.has(String(id))
|
|
185
|
+
) {
|
|
186
|
+
itemMap.set(String(id), item);
|
|
187
|
+
}
|
|
186
188
|
});
|
|
187
189
|
|
|
188
190
|
const reorderedSubset: T[] = [];
|
|
@@ -192,48 +194,29 @@ export function reorderByIds<T>(
|
|
|
192
194
|
const strId = String(id);
|
|
193
195
|
const item = itemMap.get(strId);
|
|
194
196
|
|
|
195
|
-
if (item && !
|
|
197
|
+
if (item && !orderedIdsSet.has(strId)) {
|
|
196
198
|
reorderedSubset.push(item);
|
|
197
|
-
|
|
198
|
-
const keys = Array.isArray(rawId) ? rawId : [rawId];
|
|
199
|
-
|
|
200
|
-
keys.forEach((k) => {
|
|
201
|
-
if (k !== undefined && k !== null && k !== "") {
|
|
202
|
-
orderedIdsSet.add(String(k));
|
|
203
|
-
}
|
|
204
|
-
});
|
|
199
|
+
orderedIdsSet.add(strId);
|
|
205
200
|
}
|
|
206
201
|
});
|
|
207
202
|
|
|
208
203
|
if (reorderedSubset.length === 0) return [...items];
|
|
209
204
|
|
|
210
205
|
let subsetIdx = 0;
|
|
211
|
-
const result: T[] = [];
|
|
212
|
-
|
|
213
|
-
items.forEach((item) => {
|
|
214
|
-
const rawId = getId(item);
|
|
215
|
-
const keys = Array.isArray(rawId) ? rawId : [rawId];
|
|
216
|
-
|
|
217
|
-
const isMatched = keys.some(
|
|
218
|
-
(k) =>
|
|
219
|
-
k !== undefined &&
|
|
220
|
-
k !== null &&
|
|
221
|
-
k !== "" &&
|
|
222
|
-
orderedIdsSet.has(String(k))
|
|
223
|
-
);
|
|
224
206
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
207
|
+
return items.map((item) => {
|
|
208
|
+
const id = getId(item);
|
|
209
|
+
|
|
210
|
+
if (
|
|
211
|
+
id !== undefined &&
|
|
212
|
+
id !== null &&
|
|
213
|
+
id !== "" &&
|
|
214
|
+
orderedIdsSet.has(String(id)) &&
|
|
215
|
+
subsetIdx < reorderedSubset.length
|
|
216
|
+
) {
|
|
217
|
+
return reorderedSubset[subsetIdx++];
|
|
231
218
|
}
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
while (subsetIdx < reorderedSubset.length) {
|
|
235
|
-
result.push(reorderedSubset[subsetIdx++]);
|
|
236
|
-
}
|
|
237
219
|
|
|
238
|
-
|
|
220
|
+
return item;
|
|
221
|
+
});
|
|
239
222
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getButtonsEnabled } from "..";
|
|
2
|
+
|
|
3
|
+
describe("getButtonsEnabled", () => {
|
|
4
|
+
it("returns true when the buttons container is enabled", () => {
|
|
5
|
+
expect(
|
|
6
|
+
getButtonsEnabled({ mobile_buttons_container_buttons_enabled: true })
|
|
7
|
+
).toBe(true);
|
|
8
|
+
|
|
9
|
+
expect(
|
|
10
|
+
getButtonsEnabled({ mobile_buttons_container_buttons_enabled: "true" })
|
|
11
|
+
).toBe(true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("returns false when the buttons container is disabled", () => {
|
|
15
|
+
expect(
|
|
16
|
+
getButtonsEnabled({ mobile_buttons_container_buttons_enabled: false })
|
|
17
|
+
).toBe(false);
|
|
18
|
+
|
|
19
|
+
expect(
|
|
20
|
+
getButtonsEnabled({ mobile_buttons_container_buttons_enabled: "false" })
|
|
21
|
+
).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("returns false when the key or styles are missing", () => {
|
|
25
|
+
expect(getButtonsEnabled({})).toBe(false);
|
|
26
|
+
expect(getButtonsEnabled(undefined)).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getCellNavigationEnabled } from "..";
|
|
2
|
+
|
|
3
|
+
describe("getCellNavigationEnabled", () => {
|
|
4
|
+
it("returns true when cell navigation is enabled", () => {
|
|
5
|
+
expect(
|
|
6
|
+
getCellNavigationEnabled({
|
|
7
|
+
mobile_buttons_container_cell_navigation_enabled: true,
|
|
8
|
+
})
|
|
9
|
+
).toBe(true);
|
|
10
|
+
|
|
11
|
+
expect(
|
|
12
|
+
getCellNavigationEnabled({
|
|
13
|
+
mobile_buttons_container_cell_navigation_enabled: "true",
|
|
14
|
+
})
|
|
15
|
+
).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("returns false when cell navigation is disabled", () => {
|
|
19
|
+
expect(
|
|
20
|
+
getCellNavigationEnabled({
|
|
21
|
+
mobile_buttons_container_cell_navigation_enabled: false,
|
|
22
|
+
})
|
|
23
|
+
).toBe(false);
|
|
24
|
+
|
|
25
|
+
expect(
|
|
26
|
+
getCellNavigationEnabled({
|
|
27
|
+
mobile_buttons_container_cell_navigation_enabled: "false",
|
|
28
|
+
})
|
|
29
|
+
).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("returns false when the key or styles are missing", () => {
|
|
33
|
+
expect(getCellNavigationEnabled({})).toBe(false);
|
|
34
|
+
expect(getCellNavigationEnabled(undefined)).toBe(false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { getIsCellNavigationEnabled } from "..";
|
|
2
|
+
|
|
3
|
+
describe("getIsCellNavigationEnabled", () => {
|
|
4
|
+
it("is disabled when buttons are enabled and cell navigation is off", () => {
|
|
5
|
+
expect(
|
|
6
|
+
getIsCellNavigationEnabled({
|
|
7
|
+
mobile_buttons_container_buttons_enabled: true,
|
|
8
|
+
mobile_buttons_container_cell_navigation_enabled: false,
|
|
9
|
+
})
|
|
10
|
+
).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("is enabled when buttons and cell navigation are both on", () => {
|
|
14
|
+
expect(
|
|
15
|
+
getIsCellNavigationEnabled({
|
|
16
|
+
mobile_buttons_container_buttons_enabled: true,
|
|
17
|
+
mobile_buttons_container_cell_navigation_enabled: true,
|
|
18
|
+
})
|
|
19
|
+
).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("is enabled when buttons are disabled", () => {
|
|
23
|
+
expect(
|
|
24
|
+
getIsCellNavigationEnabled({
|
|
25
|
+
mobile_buttons_container_buttons_enabled: false,
|
|
26
|
+
mobile_buttons_container_cell_navigation_enabled: false,
|
|
27
|
+
})
|
|
28
|
+
).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("is enabled when the keys or styles are missing", () => {
|
|
32
|
+
expect(getIsCellNavigationEnabled({})).toBe(true);
|
|
33
|
+
expect(getIsCellNavigationEnabled(undefined)).toBe(true);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { isCellNavigationEnabled } from "..";
|
|
2
|
+
|
|
3
|
+
describe("isCellNavigationEnabled", () => {
|
|
4
|
+
it("is enabled when buttons are disabled, regardless of the toggle", () => {
|
|
5
|
+
expect(isCellNavigationEnabled(false, false)).toBe(true);
|
|
6
|
+
expect(isCellNavigationEnabled(false, true)).toBe(true);
|
|
7
|
+
expect(isCellNavigationEnabled(undefined, undefined)).toBe(true);
|
|
8
|
+
expect(isCellNavigationEnabled("false", false)).toBe(true);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("is disabled when buttons are enabled and the toggle is off or missing", () => {
|
|
12
|
+
expect(isCellNavigationEnabled(true, false)).toBe(false);
|
|
13
|
+
expect(isCellNavigationEnabled(true, undefined)).toBe(false);
|
|
14
|
+
expect(isCellNavigationEnabled("true", "false")).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("is enabled when buttons and the toggle are both enabled", () => {
|
|
18
|
+
expect(isCellNavigationEnabled(true, true)).toBe(true);
|
|
19
|
+
expect(isCellNavigationEnabled("true", "true")).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
});
|
package/cellUtils/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
|
12
12
|
import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
|
|
13
13
|
|
|
14
14
|
import { toNumberWithDefault, toNumberWithDefaultZero } from "../numberUtils";
|
|
15
|
+
import { isTrue } from "../booleanUtils";
|
|
15
16
|
|
|
16
17
|
const CUSTOM_KEY = "other";
|
|
17
18
|
|
|
@@ -192,14 +193,19 @@ export const textTransform = (transformType, value) => {
|
|
|
192
193
|
*/
|
|
193
194
|
export const getCellWidth = (componentStyles) => {
|
|
194
195
|
const DEFAULT_CELL_WIDTH = 1920;
|
|
196
|
+
if (!componentStyles) return DEFAULT_CELL_WIDTH;
|
|
195
197
|
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
R.keys
|
|
200
|
-
)(componentStyles);
|
|
198
|
+
for (const key in componentStyles) {
|
|
199
|
+
if (key.includes("cell_width")) {
|
|
200
|
+
const val = Number(componentStyles[key]);
|
|
201
201
|
|
|
202
|
-
|
|
202
|
+
if (!isNaN(val) && val > 0) {
|
|
203
|
+
return val;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return DEFAULT_CELL_WIDTH;
|
|
203
209
|
};
|
|
204
210
|
|
|
205
211
|
/**
|
|
@@ -210,7 +216,7 @@ export const getCellWidth = (componentStyles) => {
|
|
|
210
216
|
*/
|
|
211
217
|
export const getHeight = (width, aspectRatio) => {
|
|
212
218
|
const DEFAULT_CELL_HEIGHT = 216;
|
|
213
|
-
const height =
|
|
219
|
+
const height = width / aspectRatio;
|
|
214
220
|
|
|
215
221
|
return toNumberWithDefault(DEFAULT_CELL_HEIGHT, height);
|
|
216
222
|
};
|
|
@@ -362,14 +368,18 @@ export const ifElseFocusedSelected = (
|
|
|
362
368
|
*/
|
|
363
369
|
|
|
364
370
|
export const getValue = (stylesObj) => (key) => {
|
|
365
|
-
|
|
371
|
+
if (!stylesObj) return null;
|
|
372
|
+
const val = stylesObj[key];
|
|
373
|
+
|
|
374
|
+
return val === undefined ? null : val;
|
|
366
375
|
};
|
|
367
376
|
|
|
368
377
|
export const CELL_CONFIG_ID_PATH = ["styles", "cell_plugin_configuration_id"];
|
|
369
378
|
|
|
370
|
-
export const getCellConfigPath =
|
|
379
|
+
export const getCellConfigPath = (component) =>
|
|
380
|
+
component?.styles?.cell_plugin_configuration_id;
|
|
371
381
|
|
|
372
|
-
export const getPropComponentType =
|
|
382
|
+
export const getPropComponentType = (component) => component?.component_type;
|
|
373
383
|
|
|
374
384
|
/**
|
|
375
385
|
*
|
|
@@ -423,14 +433,11 @@ export const castAndFallbackNumber = toNumberWithDefaultZero;
|
|
|
423
433
|
|
|
424
434
|
const DEFAULT_COLOR = "#FFFFFF";
|
|
425
435
|
|
|
426
|
-
export const castAndFallbackColor =
|
|
427
|
-
|
|
428
|
-
R.always(DEFAULT_COLOR),
|
|
429
|
-
fixColorHexCode
|
|
430
|
-
);
|
|
436
|
+
export const castAndFallbackColor = (value) =>
|
|
437
|
+
value == null ? DEFAULT_COLOR : fixColorHexCode(value);
|
|
431
438
|
|
|
432
439
|
export const getTextTransform = (textTransform: string) => {
|
|
433
|
-
if (
|
|
440
|
+
if (!textTransform) {
|
|
434
441
|
return "none";
|
|
435
442
|
}
|
|
436
443
|
|
|
@@ -454,15 +461,24 @@ export const withAntialising = () => {
|
|
|
454
461
|
|
|
455
462
|
export const compact = (xs) => xs.filter(isNotNil);
|
|
456
463
|
|
|
457
|
-
export const mergeConfiguration = (configuration, config) =>
|
|
458
|
-
|
|
464
|
+
export const mergeConfiguration = (configuration, config) => {
|
|
465
|
+
if (!config) return config;
|
|
466
|
+
|
|
467
|
+
return {
|
|
468
|
+
...config,
|
|
469
|
+
configuration:
|
|
470
|
+
typeof configuration === "function"
|
|
471
|
+
? configuration(config.configuration)
|
|
472
|
+
: configuration,
|
|
473
|
+
};
|
|
474
|
+
};
|
|
459
475
|
|
|
460
476
|
export const extractCellConfiguration =
|
|
461
477
|
(manifestConfiguration) => (component, cellStyles) => {
|
|
462
478
|
const cellConfigId = getCellConfigPath(component);
|
|
463
479
|
const componentType = getPropComponentType(component);
|
|
464
480
|
|
|
465
|
-
const cellStylesConfig = Object.assign(cellStyles[cellConfigId], {
|
|
481
|
+
const cellStylesConfig = Object.assign({}, cellStyles?.[cellConfigId], {
|
|
466
482
|
componentType,
|
|
467
483
|
});
|
|
468
484
|
|
|
@@ -572,3 +588,42 @@ export const hasTextLabelsEnabled = (
|
|
|
572
588
|
return Boolean(value);
|
|
573
589
|
});
|
|
574
590
|
};
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Reads the mobile buttons container "buttons enabled" switch from cell styles.
|
|
594
|
+
*/
|
|
595
|
+
export const getButtonsEnabled = (styles?: Record<string, any>): boolean => {
|
|
596
|
+
return isTrue(styles?.mobile_buttons_container_buttons_enabled);
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Reads the mobile buttons container "cell navigation enabled" switch from cell styles.
|
|
601
|
+
*/
|
|
602
|
+
export const getCellNavigationEnabled = (
|
|
603
|
+
styles?: Record<string, any>
|
|
604
|
+
): boolean => {
|
|
605
|
+
return isTrue(styles?.mobile_buttons_container_cell_navigation_enabled);
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Whether tapping a cell outside its action buttons triggers the cell's navigation.
|
|
610
|
+
* Always true when the buttons are disabled.
|
|
611
|
+
* @param buttonsEnabled the cell's "buttons enabled" switch value
|
|
612
|
+
* @param cellNavigationEnabled the cell's "cell navigation enabled" switch value
|
|
613
|
+
*/
|
|
614
|
+
export const isCellNavigationEnabled = (
|
|
615
|
+
buttonsEnabled: unknown,
|
|
616
|
+
cellNavigationEnabled: unknown
|
|
617
|
+
): boolean => !isTrue(buttonsEnabled) || isTrue(cellNavigationEnabled);
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Whether tapping a mobile cell outside its action buttons triggers the cell's navigation,
|
|
621
|
+
* read from the cell styles.
|
|
622
|
+
*/
|
|
623
|
+
export const getIsCellNavigationEnabled = (
|
|
624
|
+
styles?: Record<string, any>
|
|
625
|
+
): boolean =>
|
|
626
|
+
isCellNavigationEnabled(
|
|
627
|
+
getButtonsEnabled(styles),
|
|
628
|
+
getCellNavigationEnabled(styles)
|
|
629
|
+
);
|
|
@@ -176,6 +176,27 @@ describe("getAllSpecificStyles", () => {
|
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
178
|
|
|
179
|
+
it("should normalize Studio focus alias onto focused state", () => {
|
|
180
|
+
const outStyles = {};
|
|
181
|
+
|
|
182
|
+
const configuration = {
|
|
183
|
+
button_style_focus_background_color: "#FF3B30",
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
getAllSpecificStyles({
|
|
187
|
+
componentName: "button",
|
|
188
|
+
subComponentName: "",
|
|
189
|
+
configuration,
|
|
190
|
+
outStyles,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(outStyles.focused).toEqual({
|
|
194
|
+
backgroundColor: "#FF3B30",
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
expect(outStyles.focus).toBeUndefined();
|
|
198
|
+
});
|
|
199
|
+
|
|
179
200
|
it("should handle selected state", () => {
|
|
180
201
|
const outStyles = {};
|
|
181
202
|
|