@applicaster/zapp-react-native-ui-components 16.0.0-rc.99 → 17.0.0-alpha.1102403272

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 (112) hide show
  1. package/Components/AudioPlayer/index.web.tsx +10 -0
  2. package/Components/Cell/PlatformCellComponent.ts +9 -0
  3. package/Components/Cell/PlatformCellComponent.web.ts +3 -0
  4. package/Components/Cell/index.js +2 -9
  5. package/Components/CellRendererResolver/index.ts +22 -3
  6. package/Components/ComponentResolver/ComponentResolver.ts +6 -2
  7. package/Components/ComponentResolver/__tests__/componentResolver.test.js +13 -5
  8. package/Components/ContentScreen/index.js +2 -2
  9. package/Components/Focusable/index.web.tsx +3 -0
  10. package/Components/FocusableList/hooks/useCheckItemIdsForUnique.ts +2 -7
  11. package/Components/GeneralContentScreen/GeneralContentScreen.tsx +1 -1
  12. package/Components/GeneralContentScreen/hookAdapter/logger.ts +1 -1
  13. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +158 -1
  14. package/Components/GeneralContentScreen/utils/index.ts +2 -2
  15. package/Components/GeneralContentScreen/utils/logger.ts +3 -4
  16. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +32 -10
  17. package/Components/HandlePlayable/utils.ts +2 -7
  18. package/Components/HookRenderer/HookRenderer.tsx +2 -2
  19. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +42 -4
  20. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.android.tv.tsx +7 -4
  21. package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +1 -0
  22. package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +10 -4
  23. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts +1 -1
  24. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/index.ts +2 -4
  25. package/Components/MasterCell/DefaultComponents/Image/hooks/checkTooBigImageSize.ts +2 -7
  26. package/Components/MasterCell/DefaultComponents/Image/index.web.ts +7 -0
  27. package/Components/MasterCell/DefaultComponents/LiveImage/__tests__/prepareEntry.test.ts +30 -0
  28. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +34 -7
  29. package/Components/MasterCell/DefaultComponents/PressableView.tsx +3 -0
  30. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +2 -7
  31. package/Components/MasterCell/DefaultComponents/__tests__/ActionButton.missingPlugin.test.tsx +66 -0
  32. package/Components/MasterCell/DefaultComponents/__tests__/ActionButton.test.tsx +288 -0
  33. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +2 -1
  34. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +4 -2
  35. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/factory.test.ts +2 -2
  36. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +2 -1
  37. package/Components/MasterCell/__tests__/masterCell.test.js +116 -0
  38. package/Components/MasterCell/index.tsx +45 -6
  39. package/Components/MasterCell/logger.ts +2 -2
  40. package/Components/MasterCell/utils/__tests__/getFocusableElementId.test.ts +38 -0
  41. package/Components/MasterCell/utils/__tests__/useIsCellSelected.test.ts +91 -0
  42. package/Components/MasterCell/utils/__tests__/withoutFocusedState.test.js +20 -0
  43. package/Components/MasterCell/utils/behaviorProvider.ts +57 -38
  44. package/Components/MasterCell/utils/index.ts +60 -19
  45. package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +1 -1
  46. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +7 -3
  47. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +22 -1
  48. package/Components/ModalComponent/AudioPlayer/Components/__tests__/Item.test.tsx +52 -1
  49. package/Components/ModalComponent/AudioPlayer/utils/__tests__/mergeStyles.test.ts +77 -0
  50. package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +58 -16
  51. package/Components/ModalComponent/BottomSheetDragArea.web.tsx +15 -0
  52. package/Components/ModalComponent/BottomSheetModalContent.tsx +51 -82
  53. package/Components/ModalComponent/Button/index.tsx +3 -1
  54. package/Components/ModalComponent/SortableList.tsx +2 -3
  55. package/Components/ModalComponent/__tests__/BottomSheetDragArea.test.tsx +30 -0
  56. package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +237 -17
  57. package/Components/ModalComponent/__tests__/showTextInput.test.ts +25 -0
  58. package/Components/ModalComponent/presets/__tests__/getCell.test.ts +29 -2
  59. package/Components/ModalComponent/presets/index.ts +2 -3
  60. package/Components/ModalComponent/showTextInput.ts +2 -0
  61. package/Components/OfflineHandler/__tests__/index.test.tsx +136 -0
  62. package/Components/OfflineHandler/index.tsx +45 -6
  63. package/Components/PlayerContainer/PlayerContainer.tsx +30 -6
  64. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +51 -0
  65. package/Components/PlayerContainer/logger.ts +9 -5
  66. package/Components/River/ComponentsMap/ComponentsMap.tsx +4 -1
  67. package/Components/River/ComponentsMap/index.web.tsx +3 -0
  68. package/Components/River/RiverItem.tsx +4 -0
  69. package/Components/River/TV/River.tsx +7 -1
  70. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -0
  71. package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +2 -2
  72. package/Components/ScreenResolver/index.tsx +6 -4
  73. package/Components/Tabs/TV/index.web.tsx +5 -0
  74. package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +56 -10
  75. package/Components/TopCutoffOverlay/index.tsx +41 -10
  76. package/Components/Transitioner/AnimationManager.js +1 -1
  77. package/Components/Transitioner/Scene.tsx +4 -3
  78. package/Components/Transitioner/Transitioner.tsx +71 -33
  79. package/Components/Transitioner/__tests__/transitioner.test.js +372 -3
  80. package/Components/VideoLive/LiveImageManager.ts +126 -12
  81. package/Components/VideoLive/MuteUnmuteController.ts +135 -0
  82. package/Components/VideoLive/PlayerLiveImageComponent.tsx +15 -19
  83. package/Components/VideoLive/__tests__/LiveImageManager.test.ts +30 -0
  84. package/Components/VideoLive/__tests__/LiveImageMuteState.test.ts +311 -0
  85. package/Components/VideoLive/__tests__/MuteUnmuteController.test.ts +135 -0
  86. package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +63 -1
  87. package/Components/VideoLive/loggerHelper.ts +2 -2
  88. package/Components/VideoModal/PlayerDetails.tsx +27 -2
  89. package/Components/VideoModal/PlayerWrapper.tsx +9 -2
  90. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +84 -0
  91. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -0
  92. package/Components/VideoModal/__tests__/playerWrapperStyle.test.ts +263 -0
  93. package/Components/VideoModal/__tests__/playerWrapperUtils.test.ts +125 -0
  94. package/Components/VideoModal/hooks/useModalSize.ts +2 -7
  95. package/Components/VideoModal/playerWrapperStyle.ts +62 -23
  96. package/Components/VideoModal/playerWrapperUtils.ts +141 -1
  97. package/Components/__tests__/webVariants.test.js +73 -0
  98. package/Components/default-cell-renderer/containerStyles/index.web.ts +6 -0
  99. package/Components/default-cell-renderer/viewTrees/index.web.ts +10 -0
  100. package/Contexts/ZappPipesContext/ZappPipesContextFactory.tsx +3 -5
  101. package/Decorators/RiverResolver/__tests__/riverResolver.missingRiver.test.tsx +52 -0
  102. package/Decorators/RiverResolver/index.tsx +25 -0
  103. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +4 -3
  104. package/Decorators/ZappPipesDataConnector/__tests__/screenToolbox.test.ts +347 -0
  105. package/Decorators/ZappPipesDataConnector/__tests__/screenToolboxUnavailable.test.ts +53 -0
  106. package/Decorators/ZappPipesDataConnector/index.tsx +19 -4
  107. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +2 -21
  108. package/Decorators/ZappPipesDataConnector/screenToolbox.ts +384 -0
  109. package/Decorators/ZappPipesDataConnector/utils/mongoFilter.ts +1 -1
  110. package/Decorators/ZappPipesDataConnector/utils/useFilter.tsx +1 -1
  111. package/Helpers/logger.js +2 -2
  112. package/package.json +5 -5
@@ -5,6 +5,7 @@ export type ContainerChildProps = {
5
5
  item: any;
6
6
  pluginIdentifier: string;
7
7
  cellUUID: string;
8
+ cellInstanceId?: string;
8
9
  suffixId: string;
9
10
  nextFocusLeft?: string;
10
11
  nextFocusRight?: string;
@@ -4,14 +4,15 @@ import { Focusable } from "@applicaster/zapp-react-native-ui-components/Componen
4
4
  import { useFocusable } from "@applicaster/zapp-react-native-ui-components/Components/Focusable/index.android";
5
5
  import { useIsRTL } from "@applicaster/zapp-react-native-utils/localizationUtils";
6
6
 
7
- import { recursiveCloneElementsWithState } from "../../utils";
7
+ import {
8
+ recursiveCloneElementsWithState,
9
+ getFocusableElementId,
10
+ } from "../../utils";
8
11
 
9
12
  type ButtonProps = Record<string, any> & {
10
13
  style: ImageStyle;
11
14
  };
12
15
 
13
- const generateId = (cellUUID, suffixId) => `${cellUUID}--${suffixId}`;
14
-
15
16
  const getNextFocusLeft = ({ nextFocusLeft, parentFocus, isRTL }) => {
16
17
  return (
17
18
  nextFocusLeft ||
@@ -32,6 +33,7 @@ export function FocusableViewComponent(
32
33
  ) {
33
34
  const {
34
35
  cellUUID,
36
+ cellInstanceId,
35
37
  groupId,
36
38
  suffixId,
37
39
  normalStyles,
@@ -58,7 +60,11 @@ export function FocusableViewComponent(
58
60
 
59
61
  return (
60
62
  <Focusable
61
- id={generateId(cellUUID, suffixId)}
63
+ id={getFocusableElementId({
64
+ playerId: cellUUID,
65
+ cellInstanceId,
66
+ suffix: suffixId,
67
+ })}
62
68
  disableFocus={disableFocus}
63
69
  groupId={groupId}
64
70
  onPress={otherProps.onPress}
@@ -8,7 +8,7 @@ jest.mock("@applicaster/zapp-react-native-utils/logger", () => {
8
8
  warning: (...args) => mockWarning(...args),
9
9
  };
10
10
 
11
- return { coreLogger: mockLogger };
11
+ return { coreLogger: mockLogger, subsystemLogger: () => mockLogger };
12
12
  });
13
13
 
14
14
  describe("withDimensions", () => {
@@ -1,10 +1,8 @@
1
1
  import { toFiniteNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
2
2
  import { isNil } from "ramda";
3
- import { coreLogger } from "@applicaster/zapp-react-native-utils/logger";
3
+ import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
4
4
 
5
- const imageResizingLogger = coreLogger
6
- ?.addSubsystem("components")
7
- ?.addSubsystem("ImageResizing");
5
+ const imageResizingLogger = subsystemLogger("ui/images", "ImageResizing");
8
6
 
9
7
  const TEMPLATE_REGEX = /{{(width|height)}}/gi;
10
8
  const UNRESOLVED_PLACEHOLDER_REGEX = /{{[^}]*}}?/;
@@ -1,6 +1,6 @@
1
1
  import { Image as RNImage } from "react-native";
2
2
  import memoizee from "memoizee";
3
- import { quickBrickLogger } from "@applicaster/zapp-react-native-utils/logger";
3
+ import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
4
4
  import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
5
5
  import { toFiniteNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
6
6
 
@@ -9,12 +9,7 @@ type Size = {
9
9
  height: number;
10
10
  };
11
11
 
12
- const logger = quickBrickLogger
13
- .addSubsystem("zapp-react-native-ui-components")
14
- .addSubsystem("Components")
15
- .addSubsystem("MasterCell")
16
- .addSubsystem("DefaultComponents")
17
- .addSubsystem("Image.android");
12
+ const logger = subsystemLogger("ui/images", "CheckTooBigImageSize");
18
13
 
19
14
  const THRESHOLD = 2; // in how many times size should be BIGGER than expected
20
15
 
@@ -0,0 +1,7 @@
1
+ import ImageWeb from "./Image.web";
2
+
3
+ import { withDimensionsHOC } from "./hoc/withDimensions";
4
+
5
+ // Web builds always select the web image, so the Android and iOS ones stay out of
6
+ // web bundles.
7
+ export default withDimensionsHOC(ImageWeb);
@@ -258,6 +258,36 @@ describe("prepareEntry", () => {
258
258
 
259
259
  expect(prepareEntry(entry)).toBeNull();
260
260
  });
261
+
262
+ it("should return entry when the media extension is followed by a query or hash", () => {
263
+ const entry = makeEntry({
264
+ extensions: {
265
+ autoplay_settings: { start_time: "00:10", end_time: "00:35" },
266
+ },
267
+ content: { src: "https://example.com/video.m3u8?token=abc#t=10" },
268
+ });
269
+
270
+ expect(prepareEntry(entry)).toBe(entry);
271
+ });
272
+
273
+ it("should return entry for an HLS or DASH content type without a file extension", () => {
274
+ const types = [
275
+ "application/x-mpegURL",
276
+ "application/vnd.apple.mpegurl",
277
+ "application/dash+xml",
278
+ ];
279
+
280
+ for (const type of types) {
281
+ const entry = makeEntry({
282
+ extensions: {
283
+ autoplay_settings: { start_time: "00:10", end_time: "00:35" },
284
+ },
285
+ content: { src: "https://example.com/stream", type },
286
+ });
287
+
288
+ expect(prepareEntry(entry)).toBe(entry);
289
+ }
290
+ });
261
291
  });
262
292
 
263
293
  describe("priority order", () => {
@@ -67,10 +67,28 @@ const isSupportedTVForLiveImage = () => {
67
67
  }
68
68
  };
69
69
 
70
+ // HLS and DASH are not `video/*`. Trimming (`autoplay_settings`) plays `content.src`,
71
+ // so these types have to count. A preview URL skips this check.
72
+ const playableStreamTypes = new Set([
73
+ "application/x-mpegurl",
74
+ "application/vnd.apple.mpegurl",
75
+ "application/dash+xml",
76
+ ]);
77
+
78
+ const isPlayableContentType = (type?: string): boolean => {
79
+ const normalized = type?.split(";")[0].trim().toLowerCase();
80
+
81
+ return (
82
+ !!normalized &&
83
+ (normalized.startsWith("video") || playableStreamTypes.has(normalized))
84
+ );
85
+ };
86
+
70
87
  const isVideoUrl = (streamUrl: string): boolean => {
71
- // TODO: Not the best. Will fail if there is query params
88
+ const path = streamUrl.split(/[?#]/)[0];
89
+
72
90
  for (const key in knownMediaExtensions) {
73
- if (streamUrl.endsWith(key)) {
91
+ if (path.endsWith(key)) {
74
92
  return true;
75
93
  }
76
94
  }
@@ -140,11 +158,11 @@ export const prepareEntry = (entry: ZappEntry) => {
140
158
  return null;
141
159
  }
142
160
 
143
- if (entry.content?.type?.startsWith("video")) {
161
+ if (isPlayableContentType(entry.content?.type) || isVideoUrl(src)) {
144
162
  return entry;
145
163
  }
146
164
 
147
- return isVideoUrl(src) ? entry : null;
165
+ return null;
148
166
  };
149
167
 
150
168
  const getPlayableEntry = (entry) => {
@@ -245,10 +263,19 @@ const LiveImageComponent = (props: LiveImageProps) => {
245
263
 
246
264
  const isCurrentlyFocused = useTrackCurrentAutoScrollingElement(componentId);
247
265
 
248
- const { playerPluginId, screenConfig, preloadHooks } =
249
- getPlayerConfig(player_screen_id, actionIdentifier) ?? {};
266
+ // New object identities here restart PlayerLiveImage's register effect,
267
+ // which throws away the in-flight player and runs preload hooks again.
268
+ const playerConfig = React.useMemo(
269
+ () => getPlayerConfig(player_screen_id, actionIdentifier),
270
+ [player_screen_id, actionIdentifier]
271
+ );
250
272
 
251
- const playableEntry = playerPluginId ? getPlayableEntry(item) : null;
273
+ const { playerPluginId, screenConfig, preloadHooks } = playerConfig ?? {};
274
+
275
+ const playableEntry = React.useMemo(
276
+ () => (playerPluginId ? getPlayableEntry(item) : null),
277
+ [playerPluginId, item?.id]
278
+ );
252
279
 
253
280
  const playerPlugin = getPluginByIdentifier(playerPluginId);
254
281
 
@@ -11,6 +11,7 @@ type Props = {
11
11
  accessibilityHint?: string;
12
12
  onPress?: () => void;
13
13
  testOnly_pressed?: boolean;
14
+ checked?: boolean;
14
15
  };
15
16
 
16
17
  export function PressableView({
@@ -22,11 +23,13 @@ export function PressableView({
22
23
  pressedStyle,
23
24
  onPress,
24
25
  testOnly_pressed = false,
26
+ checked,
25
27
  }: Props) {
26
28
  return (
27
29
  <Pressable
28
30
  testOnly_pressed={testOnly_pressed}
29
31
  onPress={onPress}
32
+ accessibilityState={checked === undefined ? undefined : { checked }}
30
33
  testID={testID}
31
34
  accessibilityLabel={accessibilityLabel}
32
35
  accessibilityHint={accessibilityHint}
@@ -2,14 +2,9 @@ import * as React from "react";
2
2
  import * as R from "ramda";
3
3
  import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
4
4
  import { useIsRTL } from "@applicaster/zapp-react-native-utils/localizationUtils";
5
- import { getXray } from "@applicaster/zapp-react-native-utils/logger";
5
+ import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
6
6
 
7
- const { Logger } = getXray();
8
-
9
- const logger = new Logger(
10
- "plugin",
11
- "plugins/navigation-action|plugins/local-storage-favourites-action"
12
- );
7
+ const logger = subsystemLogger("ui/cells", "plugin");
13
8
 
14
9
  const firstEnglishWordRegex = /(^[a-zA-Z]+)/;
15
10
 
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+ import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
4
+ import { masterCellLogger } from "../../logger";
5
+
6
+ import { ActionButton } from "../ActionButton";
7
+
8
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
9
+ useActions: jest.fn(),
10
+ }));
11
+
12
+ jest.mock("../../logger", () => ({
13
+ masterCellLogger: {
14
+ warning: jest.fn(),
15
+ error: jest.fn(),
16
+ info: jest.fn(),
17
+ debug: jest.fn(),
18
+ },
19
+ }));
20
+
21
+ describe("ActionButton", () => {
22
+ beforeEach(() => {
23
+ jest.clearAllMocks();
24
+ });
25
+
26
+ it("does not crash when actionContext is undefined and logs a warning", () => {
27
+ (useActions as jest.Mock).mockReturnValue(undefined);
28
+
29
+ const item = { id: "entry-1", title: "Test" } as any;
30
+ const action = { identifier: "uninstalled-action-plugin" };
31
+
32
+ const { toJSON } = render(
33
+ <ActionButton item={item} action={action} style={{}} />
34
+ );
35
+
36
+ expect(toJSON()).toBeNull();
37
+
38
+ expect(masterCellLogger.warning).toHaveBeenCalledWith(
39
+ expect.objectContaining({
40
+ message: expect.stringContaining(
41
+ 'action plugin "uninstalled-action-plugin" is not available'
42
+ ),
43
+ data: expect.objectContaining({
44
+ diagnostic: { code: "action-plugin-missing" },
45
+ identifier: "uninstalled-action-plugin",
46
+ entryId: "entry-1",
47
+ }),
48
+ })
49
+ );
50
+ });
51
+
52
+ it("does not crash when actionContext has no initialEntryState method", () => {
53
+ (useActions as jest.Mock).mockReturnValue({
54
+ invokeAction: jest.fn(),
55
+ });
56
+
57
+ const item = { id: "entry-2", title: "Test 2" } as any;
58
+ const action = { identifier: "legacy-action-plugin" };
59
+
60
+ const { toJSON } = render(
61
+ <ActionButton item={item} action={action} style={{}} />
62
+ );
63
+
64
+ expect(toJSON()).toBeNull();
65
+ });
66
+ });
@@ -0,0 +1,288 @@
1
+ import React from "react";
2
+ import { act, fireEvent, render } from "@testing-library/react-native";
3
+
4
+ import { ActionButton } from "../ActionButton";
5
+ import { ActionButton as MobileActionButton } from "../mobile/MobileActionButtons/ActionButton";
6
+ import { Text } from "react-native";
7
+
8
+ type EntryStateListener = (state: CellActionEntryState) => void;
9
+
10
+ const PLUGIN_ASSETS = {
11
+ mute: ["plugin_mute_1", "plugin_mute_2"],
12
+ unmute: ["plugin_unmute_1", "plugin_unmute_2"],
13
+ };
14
+
15
+ // Fake of the mute_unmute_action context, following its entry state contract.
16
+ type FakeState = {
17
+ available: boolean;
18
+ muted: boolean;
19
+ visibleInCells?: string[];
20
+ };
21
+
22
+ const createFakeContext = (initial: FakeState) => {
23
+ let current = initial;
24
+ const listeners = new Set<EntryStateListener>();
25
+
26
+ const toEntryState = ({
27
+ available,
28
+ muted,
29
+ visibleInCells,
30
+ }: FakeState): CellActionEntryState => ({
31
+ state: muted ? 1 : 0,
32
+ asset: available
33
+ ? muted
34
+ ? PLUGIN_ASSETS.unmute
35
+ : PLUGIN_ASSETS.mute
36
+ : undefined,
37
+ label: muted ? "Unmute" : "Mute",
38
+ mobileButtonAssets: muted ? PLUGIN_ASSETS.unmute : PLUGIN_ASSETS.mute,
39
+ visibleInCells,
40
+ });
41
+
42
+ const emit = (next: FakeState) => {
43
+ current = next;
44
+ listeners.forEach((listener) => listener(toEntryState(current)));
45
+ };
46
+
47
+ const context = {
48
+ initialEntryState: jest.fn(() => toEntryState(current)),
49
+ addListener: jest.fn((_id: string, listener: EntryStateListener) => {
50
+ listeners.add(listener);
51
+
52
+ return () => listeners.delete(listener);
53
+ }),
54
+ invokeAction: jest.fn((_item, options) => {
55
+ if (!current.available) return;
56
+
57
+ current = { ...current, muted: !current.muted };
58
+ options?.updateState?.(toEntryState(current));
59
+ listeners.forEach((listener) => listener(toEntryState(current)));
60
+ }),
61
+ };
62
+
63
+ return { context, emit, listeners };
64
+ };
65
+
66
+ let mockContext: ReturnType<typeof createFakeContext>["context"];
67
+
68
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
69
+ useActions: jest.fn(() => mockContext),
70
+ }));
71
+
72
+ jest.mock(
73
+ "@applicaster/zapp-react-native-ui-components/Contexts/UIComponentContext",
74
+ () => ({ useUIComponentContext: jest.fn(() => undefined) })
75
+ );
76
+
77
+ jest.mock("../Image", () => {
78
+ const { Text: MockText } = require("react-native");
79
+
80
+ return {
81
+ __esModule: true,
82
+ default: ({ uri }) => <MockText testID="asset">{uri}</MockText>,
83
+ };
84
+ });
85
+
86
+ const item = { id: "entry-1" } as unknown as ZappEntry;
87
+
88
+ it("keeps the standalone button visible and limits actions to the playing cell instance", () => {
89
+ const fake = createFakeContext({
90
+ available: true,
91
+ muted: true,
92
+ visibleInCells: [],
93
+ });
94
+
95
+ mockContext = fake.context;
96
+
97
+ const Label = ({
98
+ children,
99
+ testID,
100
+ }: {
101
+ children?: React.ReactNode;
102
+ testID?: string;
103
+ mobileActionRole?: string;
104
+ }) => <Text testID={testID}>{children}</Text>;
105
+
106
+ const { getByTestId, queryByTestId } = render(
107
+ <>
108
+ {["first", "second"].map((cellUUID) => (
109
+ <ActionButton
110
+ key={cellUUID}
111
+ item={item}
112
+ action={{ identifier: "mute_unmute_action" }}
113
+ cellUUID={cellUUID}
114
+ testID={`cell-${cellUUID}`}
115
+ style={{}}
116
+ />
117
+ ))}
118
+ <MobileActionButton
119
+ action={{ identifier: "mute_unmute_action" }}
120
+ entry={item}
121
+ testID="standalone"
122
+ style={{}}
123
+ focusedStyles={{}}
124
+ >
125
+ <Label mobileActionRole="label">Toggle sound</Label>
126
+ </MobileActionButton>
127
+ </>
128
+ );
129
+
130
+ expect(queryByTestId("cell-first")).toBeNull();
131
+ expect(queryByTestId("cell-second")).toBeNull();
132
+ expect(getByTestId("standalone")).toBeTruthy();
133
+ fireEvent.press(getByTestId("standalone"));
134
+ expect(fake.context.invokeAction).toHaveBeenCalledTimes(1);
135
+
136
+ act(() =>
137
+ fake.emit({ available: true, muted: false, visibleInCells: ["first"] })
138
+ );
139
+
140
+ expect(getByTestId("cell-first")).toBeTruthy();
141
+ expect(queryByTestId("cell-second")).toBeNull();
142
+
143
+ act(() =>
144
+ fake.emit({ available: true, muted: false, visibleInCells: ["second"] })
145
+ );
146
+
147
+ expect(queryByTestId("cell-first")).toBeNull();
148
+ expect(getByTestId("cell-second")).toBeTruthy();
149
+
150
+ act(() => fake.emit({ available: true, muted: false, visibleInCells: [] }));
151
+
152
+ expect(queryByTestId("cell-first")).toBeNull();
153
+ expect(queryByTestId("cell-second")).toBeNull();
154
+ expect(getByTestId("standalone")).toBeTruthy();
155
+ });
156
+
157
+ const renderButton = (
158
+ flavour: "flavour_1" | "flavour_2",
159
+ asset?: React.ComponentProps<typeof ActionButton>["asset"]
160
+ ) =>
161
+ render(
162
+ <ActionButton
163
+ item={item}
164
+ flavour={flavour}
165
+ action={{ identifier: "mute_unmute_action" }}
166
+ asset={asset}
167
+ style={{}}
168
+ testID="mute-button"
169
+ />
170
+ );
171
+
172
+ const cellAsset = {
173
+ props: {},
174
+ src: { active: "cell_selected", inactive: "cell_unselected" },
175
+ style: {},
176
+ type: "Image",
177
+ } as const;
178
+
179
+ describe.each([
180
+ ["flavour_1", 0],
181
+ ["flavour_2", 1],
182
+ ] as const)("mute_unmute_action cell action (%s)", (flavour, index) => {
183
+ let fake: ReturnType<typeof createFakeContext>;
184
+
185
+ const setup = (state: { available: boolean; muted: boolean }, asset?) => {
186
+ fake = createFakeContext(state);
187
+ mockContext = fake.context;
188
+
189
+ return renderButton(flavour, asset);
190
+ };
191
+
192
+ it("renders nothing while the preview has not started", () => {
193
+ const { queryByTestId } = setup({ available: false, muted: false });
194
+
195
+ expect(queryByTestId("mute-button")).toBeNull();
196
+ expect(queryByTestId("asset")).toBeNull();
197
+ });
198
+
199
+ it("shows the Mute icon while the preview plays with sound on", () => {
200
+ const { getByTestId } = setup({ available: true, muted: false });
201
+
202
+ expect(getByTestId("asset").props.children).toBe(PLUGIN_ASSETS.mute[index]);
203
+ });
204
+
205
+ it("shows the Unmute icon while the preview plays muted", () => {
206
+ const { getByTestId } = setup({ available: true, muted: true });
207
+
208
+ expect(getByTestId("asset").props.children).toBe(
209
+ PLUGIN_ASSETS.unmute[index]
210
+ );
211
+ });
212
+
213
+ it("toggles the sound and updates the icon on tap", () => {
214
+ const { getByTestId } = setup({ available: true, muted: false });
215
+
216
+ fireEvent.press(getByTestId("mute-button"));
217
+
218
+ expect(fake.context.invokeAction).toHaveBeenCalledTimes(1);
219
+
220
+ expect(getByTestId("asset").props.children).toBe(
221
+ PLUGIN_ASSETS.unmute[index]
222
+ );
223
+
224
+ fireEvent.press(getByTestId("mute-button"));
225
+
226
+ expect(getByTestId("asset").props.children).toBe(PLUGIN_ASSETS.mute[index]);
227
+ });
228
+
229
+ it("follows state emitted through addListener", () => {
230
+ const { getByTestId, queryByTestId } = setup({
231
+ available: false,
232
+ muted: false,
233
+ });
234
+
235
+ act(() => fake.emit({ available: true, muted: false }));
236
+
237
+ expect(getByTestId("asset").props.children).toBe(PLUGIN_ASSETS.mute[index]);
238
+
239
+ act(() => fake.emit({ available: true, muted: true }));
240
+
241
+ expect(getByTestId("asset").props.children).toBe(
242
+ PLUGIN_ASSETS.unmute[index]
243
+ );
244
+
245
+ expect(queryByTestId("mute-button")).not.toBeNull();
246
+ });
247
+
248
+ it("hides again when the preview stops or another cell starts", () => {
249
+ const { queryByTestId } = setup({ available: true, muted: false });
250
+
251
+ expect(queryByTestId("mute-button")).not.toBeNull();
252
+
253
+ act(() => fake.emit({ available: false, muted: false }));
254
+
255
+ expect(queryByTestId("mute-button")).toBeNull();
256
+ });
257
+
258
+ it("unsubscribes from the context on unmount", () => {
259
+ const { unmount } = setup({ available: true, muted: false });
260
+
261
+ expect(fake.listeners.size).toBe(1);
262
+
263
+ unmount();
264
+
265
+ expect(fake.listeners.size).toBe(0);
266
+ });
267
+
268
+ it("prefers the cell's selected icon when muted (state 1)", () => {
269
+ const { getByTestId } = setup({ available: true, muted: true }, cellAsset);
270
+
271
+ expect(getByTestId("asset").props.children).toBe("cell_selected");
272
+ });
273
+
274
+ it("prefers the cell's unselected icon when sound is on (state 0)", () => {
275
+ const { getByTestId } = setup({ available: true, muted: false }, cellAsset);
276
+
277
+ expect(getByTestId("asset").props.children).toBe("cell_unselected");
278
+ });
279
+
280
+ it("uses the plugin asset when the cell has no icons", () => {
281
+ const { getByTestId } = setup({ available: true, muted: false }, {
282
+ ...cellAsset,
283
+ src: { active: undefined, inactive: undefined },
284
+ } as any);
285
+
286
+ expect(getByTestId("asset").props.children).toBe(PLUGIN_ASSETS.mute[index]);
287
+ });
288
+ });
@@ -166,9 +166,10 @@ export const ActionButton = ({
166
166
  <PressableView
167
167
  testOnly_pressed={props.testOnly_pressed}
168
168
  testID={props.testID || `${entry?.id}`}
169
- style={style}
169
+ style={[style, props.alignment]}
170
170
  pressedStyle={focusedStyles}
171
171
  onPress={renderProps.onPress}
172
+ checked={renderProps.actionState?.checked}
172
173
  accessibilityLabel={props.accessibilityLabel || `${entry?.id}`}
173
174
  accessibilityHint={props.accessibilityHint}
174
175
  >
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { Pressable, Text as RNText, View } from "react-native";
2
+ import { Pressable, StyleSheet, Text as RNText, View } from "react-native";
3
3
  import { render, fireEvent } from "@testing-library/react-native";
4
4
  import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
5
5
 
@@ -282,7 +282,9 @@ describe("MobileActionButton", () => {
282
282
  expect(pressable.props.testID).toBe("mobile_action_button_1");
283
283
  expect(pressable.props.accessibilityLabel).toBe("entry-1");
284
284
 
285
- expect(pressable.props.style({ pressed: false })[0]).toMatchObject({
285
+ expect(
286
+ StyleSheet.flatten(pressable.props.style({ pressed: false }))
287
+ ).toMatchObject({
286
288
  backgroundColor: "rgba(1,1,1,1)",
287
289
  borderColor: "rgba(2,2,2,1)",
288
290
  borderWidth: 1,
@@ -20,13 +20,13 @@ const getValue = (key: string) => {
20
20
  };
21
21
 
22
22
  describe("CollapsibleTextContainer view tree", () => {
23
- it("stretches to the parent width so labels wrap using the cell width", () => {
23
+ it("aligns the label to the text alignment instead of stretching the cell", () => {
24
24
  const result = CollapsibleTextContainer({
25
25
  getValue,
26
26
  elements: [],
27
27
  additionalStyles: { backgroundColor: "transparent" },
28
28
  });
29
29
 
30
- expect(result.style.alignSelf).toBe("stretch");
30
+ expect(result.style.alignSelf).toBe("flex-start");
31
31
  });
32
32
  });
@@ -3,6 +3,7 @@ import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/he
3
3
  import {
4
4
  getColorFromData,
5
5
  getKeyForLabel,
6
+ mapSelfAlignment,
6
7
  } from "@applicaster/zapp-react-native-utils/cellUtils";
7
8
  import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/numberUtils";
8
9
 
@@ -22,7 +23,7 @@ export const CollapsibleTextContainer = ({
22
23
  return {
23
24
  type: "CollapsibleTextContainer", // Collapsible Text Container,
24
25
  style: {
25
- alignSelf: "stretch",
26
+ alignSelf: mapSelfAlignment(getValue("text_alignment")),
26
27
  marginTop: toNumberWithDefaultZero(getValue("margin_top")),
27
28
  marginRight: toNumberWithDefaultZero(getValue("margin_right")),
28
29
  marginBottom: toNumberWithDefaultZero(getValue("margin_bottom")),