@applicaster/zapp-react-native-ui-components 16.0.0-alpha.5803191443 → 16.0.0-alpha.6012452194

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 (29) hide show
  1. package/Components/CellRendererResolver/index.ts +1 -1
  2. package/Components/ComponentResolver/__tests__/componentResolver.test.js +1 -1
  3. package/Components/FocusableGroup/FocusableTvOS.tsx +11 -7
  4. package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
  5. package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
  6. package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
  7. package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
  8. package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
  9. package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +124 -0
  10. package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
  11. package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
  12. package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
  13. package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +72 -0
  14. package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
  15. package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
  16. package/Components/GeneralContentScreen/index.ts +2 -0
  17. package/Components/Layout/TV/ScreenContainer.tsx +5 -0
  18. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +25 -25
  19. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +1 -1
  20. package/Components/PlayerContainer/PlayerContainer.tsx +7 -7
  21. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +284 -0
  22. package/Components/Screen/TV/hooks/__tests__/useAfterPaint.test.ts +60 -0
  23. package/Components/Screen/TV/hooks/index.ts +2 -0
  24. package/Components/Screen/TV/hooks/useAfterPaint.ts +23 -0
  25. package/Components/Screen/TV/index.web.tsx +16 -7
  26. package/Components/VideoLive/LiveImageManager.ts +40 -42
  27. package/Components/VideoModal/utils.ts +6 -1
  28. package/package.json +5 -5
  29. package/Components/MasterCell/DefaultComponents/__tests__/ActionButton.test.tsx +0 -156
@@ -0,0 +1,48 @@
1
+ import { shouldSkipHook } from "./validationHelper";
2
+ import { requestToSkipHook } from "./networkService";
3
+ import { log_debug, log_error } from "./logger";
4
+
5
+ /**
6
+ * Headless pre-hook for the General Content Screen. `configuration` is the
7
+ * Hook object with the screen merged in; skip-hook fields live under `rules`.
8
+ */
9
+ export const runInBackground = async (
10
+ item,
11
+ callback,
12
+ configuration,
13
+ presentUI
14
+ ) => {
15
+ try {
16
+ const skipHookIfKeysExist = configuration?.rules?.skip_hook_storage_key;
17
+
18
+ if (skipHookIfKeysExist) {
19
+ const shouldSkip = await shouldSkipHook(skipHookIfKeysExist);
20
+
21
+ if (shouldSkip) {
22
+ log_debug(
23
+ `runInBackground: Storage key found: ${skipHookIfKeysExist}. Skipping hook.`
24
+ );
25
+
26
+ return callback({ success: true, error: null, payload: item });
27
+ }
28
+ }
29
+
30
+ const skipHookEndpoint = configuration?.rules?.skip_hook_endpoint;
31
+
32
+ if (skipHookEndpoint?.source) {
33
+ const success = await requestToSkipHook(skipHookEndpoint, item);
34
+
35
+ if (success) {
36
+ log_debug(
37
+ "runInBackground: Network call forced to finish hook. Skipping hook."
38
+ );
39
+
40
+ return callback({ success: true, error: null, payload: item });
41
+ }
42
+ }
43
+ } catch (error) {
44
+ log_error(`runInBackground: Error: ${error.message}`);
45
+ }
46
+
47
+ return presentUI();
48
+ };
@@ -0,0 +1,72 @@
1
+ import { getNamespaceAndKey } from "@applicaster/zapp-react-native-utils/appUtils/contextKeysManager/utils";
2
+ import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
3
+ import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
4
+ import { log_error, log_info } from "./logger";
5
+
6
+ type ParseKey = { key: string; namespace?: string };
7
+
8
+ export function parseKeyEntries(input: string): ParseKey[] {
9
+ return input.split(",").flatMap((item) => {
10
+ const trimmed = item.trim();
11
+
12
+ return trimmed ? getNamespaceAndKey(trimmed) : [];
13
+ });
14
+ }
15
+
16
+ export const getKeyToSkipHook = async (key: string, namespace?: string) => {
17
+ const value = await sessionStorage.getItem(key, namespace);
18
+
19
+ if (value) {
20
+ return value;
21
+ }
22
+
23
+ return await localStorage.getItem(key, namespace);
24
+ };
25
+
26
+ export const shouldSkipHook = async (
27
+ skipHookIfKeysExist?: string
28
+ ): Promise<boolean> => {
29
+ if (!skipHookIfKeysExist?.trim()) {
30
+ log_info("shouldSkipHook: No skipping condition provided");
31
+
32
+ return false;
33
+ }
34
+
35
+ const keyEntries = parseKeyEntries(skipHookIfKeysExist);
36
+
37
+ if (keyEntries.length === 0) {
38
+ log_info("shouldSkipHook: No valid keys provided");
39
+
40
+ return false;
41
+ }
42
+
43
+ for (const entry of keyEntries) {
44
+ try {
45
+ const value = await getKeyToSkipHook(entry.key, entry.namespace);
46
+
47
+ if (value) {
48
+ log_info(
49
+ `shouldSkipHook: Hook will be skipped due to: ${
50
+ entry.namespace ?? ""
51
+ } ${entry.key}. Finishing hook flow`
52
+ );
53
+
54
+ return true;
55
+ }
56
+ } catch (error) {
57
+ log_error(
58
+ `shouldSkipHook: Error: ${error.message} checking key: ${
59
+ entry.namespace ?? ""
60
+ } ${entry.key}`,
61
+ { error }
62
+ );
63
+ }
64
+ }
65
+
66
+ log_info(
67
+ // eslint-disable-next-line max-len
68
+ "shouldSkipHook: No skipping condition met, none of the provided keys found in storage, proceeding with hook"
69
+ );
70
+
71
+ return false;
72
+ };
@@ -0,0 +1,13 @@
1
+ import * as React from "react";
2
+
3
+ type Props = {
4
+ children: React.ReactElement;
5
+ };
6
+
7
+ /**
8
+ * On native platforms the river `ComponentsMap` registers its own initial focus,
9
+ * so a hook-presented general content screen needs no extra focus wrapper here.
10
+ * The web counterpart (`index.web.tsx`) recreates the content focus group that
11
+ * the `River` wrapper would normally provide.
12
+ */
13
+ export const HookContentFocusGroup = ({ children }: Props) => <>{children}</>;
@@ -0,0 +1,69 @@
1
+ import * as React from "react";
2
+ import { StyleSheet } from "react-native";
3
+ import { shallow } from "zustand/shallow";
4
+
5
+ import { FocusableGroup } from "../../FocusableGroup";
6
+ import {
7
+ useContentId,
8
+ useNavbarId,
9
+ usePathname,
10
+ } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
11
+ import { useZappHookModalStore } from "../../../Contexts/ZappHookModalContext";
12
+
13
+ import { useInitialFocus } from "../../Screen/TV/hooks";
14
+
15
+ const styles = StyleSheet.create({
16
+ container: { flex: 1 },
17
+ });
18
+
19
+ type Props = {
20
+ children: React.ReactElement;
21
+ };
22
+
23
+ /**
24
+ * A general content screen presented as a full-screen hook is rendered straight
25
+ * through `ComponentsMap`, bypassing the web `River` wrapper. That wrapper is what
26
+ * normally creates the `quick-brick-content` FocusableGroup (with `preferredFocus`)
27
+ * the focus manager relies on and what lets initial focus land on the content.
28
+ *
29
+ * Without it the hook screen renders but nothing is focusable on web TV. This
30
+ * recreates that content group and triggers initial focus, mirroring `River`.
31
+ */
32
+ const FocusedHookContent = ({ children }: Props) => {
33
+ const contentId = useContentId();
34
+ const navbarId = useNavbarId();
35
+ const pathname = usePathname();
36
+
37
+ useInitialFocus();
38
+
39
+ return (
40
+ <FocusableGroup
41
+ id={contentId}
42
+ // Nest under the hook-modal route so the focus manager treats this as the
43
+ // active screen's content node; `useInitialFocus` targets the same route.
44
+ groupId={pathname}
45
+ nextFocusUp={navbarId}
46
+ preferredFocus
47
+ shouldUsePreferredFocus
48
+ style={styles.container}
49
+ >
50
+ {React.cloneElement(children, { groupId: contentId })}
51
+ </FocusableGroup>
52
+ );
53
+ };
54
+
55
+ export const HookContentFocusGroup = ({ children }: Props) => {
56
+ const isRunningInBackground = useZappHookModalStore(
57
+ (state) => state.isRunningInBackground,
58
+ shallow
59
+ );
60
+
61
+ // A hook presented full screen (either as a `/hooks/<id>` screen or a
62
+ // full-screen modal) needs the content focus group. Only background runs,
63
+ // which render invisibly, must be left alone so they don't steal focus.
64
+ if (isRunningInBackground) {
65
+ return <>{children}</>;
66
+ }
67
+
68
+ return <FocusedHookContent>{children}</FocusedHookContent>;
69
+ };
@@ -1 +1,3 @@
1
1
  export { GeneralContentScreen } from "./GeneralContentScreen";
2
+
3
+ export { GeneralContentScreenHookAdapter } from "./GeneralContentScreenHookAdapter";
@@ -129,6 +129,11 @@ export const ScreenContainer = React.memo(function ScreenContainer({
129
129
  []
130
130
  );
131
131
 
132
+ // We need to render menu first and then proceed with screen content,
133
+ // otherwise screen will stay black until everything is loaded and screen
134
+ // rendering put huge load the CPU pushing rendering even further.
135
+ // With this approach, menu will be rendered immediately and screen content
136
+ // will be rendered after paint, which makes it more responsive and prevents black screen.
132
137
  const [navBarReady, setNavBarReady] = React.useState(false);
133
138
 
134
139
  const navBarContainer = (
@@ -4,7 +4,6 @@ import { TouchableOpacity, ViewStyle } from "react-native";
4
4
  import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
5
5
 
6
6
  import Image from "./Image";
7
-
8
7
  type Props = {
9
8
  item: ZappEntry | ZappFeed;
10
9
  flavour?: "flavour_1" | "flavour_2";
@@ -13,7 +12,7 @@ type Props = {
13
12
  src: {
14
13
  active: string;
15
14
  inactive: string;
16
- };
15
+ } & Record<string, string>;
17
16
  style: {};
18
17
  type: "Image" | "Svg" | "Lottie";
19
18
  };
@@ -33,21 +32,21 @@ function isStringAsset(asset) {
33
32
  return typeof asset === "string" || Array.isArray(asset);
34
33
  }
35
34
 
36
- /** return asset based on the asset, flavour, and fallbackAsset
37
- * usully fallback asset is set on cell configuration, while the asset is configured on action plugin configuration
38
- */
39
35
  function getAssetValue(asset, flavour, fallbackAsset = null) {
40
36
  if (!asset) {
41
37
  return null;
42
38
  }
43
39
 
44
- if (typeof asset === "string") return asset;
40
+ if (typeof asset === "string") return fallbackAsset || asset;
45
41
 
46
42
  if (Array.isArray(asset)) {
47
43
  const flavourIndex = Number(flavour.replace("flavour_", ""));
48
- if (flavour && flavourIndex > -1) return asset[flavourIndex - 1];
49
44
 
50
- return asset[0];
45
+ if (flavour && flavourIndex > -1) {
46
+ return fallbackAsset || asset[flavourIndex - 1];
47
+ }
48
+
49
+ return fallbackAsset || asset[0];
51
50
  }
52
51
 
53
52
  return asset.src || fallbackAsset;
@@ -64,33 +63,26 @@ export const ActionButton = React.memo(function ActionButtonComponent(
64
63
  typeof actionContext?.isActionAvailable === "function" &&
65
64
  !actionContext.isActionAvailable(item);
66
65
 
67
- const getActionEntryState = useCallback(() => {
68
- return actionContext.initialEntryState(item, {
69
- fallbackAssetSrc: asset?.src,
70
- });
71
- // eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
72
- }, [actionContext, item?.id, asset?.src]);
73
-
74
66
  // Note: in theory initialization is not needed anymore, we are using useEffect
75
67
  const [actionState, setActionState] = React.useState(
76
- actionDisabled || !actionContext ? null : getActionEntryState()
68
+ actionDisabled || !actionContext
69
+ ? null
70
+ : actionContext.initialEntryState(item)
77
71
  );
78
72
 
79
73
  useEffect(() => {
80
74
  if (!((actionDisabled || !actionContext) && actionState !== null)) {
81
- setActionState(getActionEntryState());
75
+ setActionState(actionContext.initialEntryState(item));
82
76
  }
83
- // eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
84
- }, [actionDisabled, item?.id, actionContext, getActionEntryState]);
77
+ }, [actionDisabled, item?.id, actionContext, action, setActionState]);
85
78
 
86
79
  const onPress = useCallback(() => {
87
80
  actionContext.invokeAction(item, {
88
- updateState: () => {
89
- setActionState(getActionEntryState());
81
+ updateState: (state) => {
82
+ setActionState(state);
90
83
  },
91
84
  });
92
- // eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
93
- }, [actionContext, item?.id, getActionEntryState]);
85
+ }, [actionState, actionContext?.state, item?.id]);
94
86
 
95
87
  useEffect(() => {
96
88
  if (typeof actionContext?.addListener === "function") {
@@ -120,13 +112,21 @@ export const ActionButton = React.memo(function ActionButtonComponent(
120
112
  <Image
121
113
  fadeDuration={0}
122
114
  style={asset?.style || props?.style}
123
- uri={getAssetValue(actionState.asset, flavour, asset?.src)}
115
+ uri={getAssetValue(
116
+ actionState.asset,
117
+ flavour,
118
+ actionState.state === 1 ? asset?.src.active : asset?.src.inactive
119
+ )}
124
120
  {...asset?.props}
125
121
  />
126
122
  ) : (
127
123
  <AssetComponent
128
124
  flavour={flavour}
129
- asset={getAssetValue(asset, flavour)}
125
+ asset={getAssetValue(
126
+ asset,
127
+ flavour,
128
+ actionState.state === 1 ? asset?.src.active : asset?.src.inactive
129
+ )}
130
130
  cellUUID={cellUUID}
131
131
  {...(props?.extraProps ?? {})}
132
132
  />
@@ -8,7 +8,7 @@ export function ButtonContainerView({
8
8
  children,
9
9
  }: ContainerProps) {
10
10
  return (
11
- <View style={style}>
11
+ <View style={style} pointerEvents="box-none">
12
12
  <View style={contentStyle}>{children}</View>
13
13
  </View>
14
14
  );
@@ -265,14 +265,12 @@ const PlayerContainerComponent = (props: Props) => {
265
265
  navigator.goBack();
266
266
  }, [isModal, state.playerId, showNavBar, navigator]);
267
267
 
268
- const pluginConfiguration = React.useMemo(() => {
269
- return (
270
- playerManager.getPluginConfiguration() ||
271
- R.prop("__plugin_configuration", Player)
272
- );
273
- }, [playerManager.isRegistered()]);
268
+ const pluginConfiguration = React.useMemo(
269
+ () => player?.getPluginConfiguration(),
270
+ [player]
271
+ );
274
272
 
275
- const playEntry = (entry) => navigator.replaceTop(entry, { mode });
273
+ const playEntry = (entry: ZappEntry) => navigator.replaceTop(entry, { mode });
276
274
 
277
275
  const onPlayNextPerformNextVideoPlay = React.useCallback(() => {
278
276
  if (!playNextOverlayState.entry) {
@@ -468,6 +466,8 @@ const PlayerContainerComponent = (props: Props) => {
468
466
  if (isModal && mode === VideoModalMode.MAXIMIZED) {
469
467
  if (disableMiniPlayer) {
470
468
  navigator.closeVideoModal();
469
+ } else {
470
+ navigator.minimiseVideoModal();
471
471
  }
472
472
  }
473
473
 
@@ -0,0 +1,284 @@
1
+ import * as React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+
4
+ jest.mock(
5
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager",
6
+ () => ({
7
+ playerManager: {
8
+ invokeHandler: jest.fn(),
9
+ getPluginConfiguration: jest.fn(() => ({})),
10
+ isRegistered: jest.fn(() => true),
11
+ on: jest.fn().mockReturnThis(),
12
+ removeHandler: jest.fn().mockReturnThis(),
13
+ getActivePlayer: jest.fn(() => null),
14
+ closeNativePlayer: jest.fn(),
15
+ },
16
+ })
17
+ );
18
+
19
+ jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
20
+ isTV: jest.fn(() => false),
21
+ isAndroidTVPlatform: jest.fn(() => false),
22
+ isTvOSPlatform: jest.fn(() => false),
23
+ platformSelect: jest.fn(({ native }) => native),
24
+ }));
25
+
26
+ jest.mock("@applicaster/zapp-react-native-utils/playerUtils", () => ({
27
+ isAudioItem: jest.fn(() => false),
28
+ isInlineTV: jest.fn(() => false),
29
+ }));
30
+
31
+ jest.mock(
32
+ "@applicaster/zapp-react-native-tvos-ui-components/Components/TVEventHandlerComponent",
33
+ () => ({
34
+ TVEventHandlerComponent: ({ children }) => children,
35
+ })
36
+ );
37
+
38
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/utils", () => ({
39
+ usePrevious: jest.fn(),
40
+ }));
41
+
42
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => {
43
+ const navigator = {
44
+ closeVideoModal: jest.fn(),
45
+ minimiseVideoModal: jest.fn(),
46
+ maximiseVideoModal: jest.fn(),
47
+ fullscreenVideoModal: jest.fn(),
48
+ isVideoModalDocked: jest.fn(() => false),
49
+ goBack: jest.fn(),
50
+ replaceTop: jest.fn(),
51
+ push: jest.fn(),
52
+ setPlayNextOverlay: jest.fn(),
53
+ currentRoute: "/playable/entry-1",
54
+ };
55
+
56
+ const backHandlerRef: { current: (() => boolean) | null } = {
57
+ current: null,
58
+ };
59
+
60
+ return {
61
+ useBackHandler: jest.fn((cb) => {
62
+ backHandlerRef.current = cb;
63
+ }),
64
+ useNavigation: jest.fn(() => navigator),
65
+ __navigator: navigator,
66
+ __backHandlerRef: backHandlerRef,
67
+ };
68
+ });
69
+
70
+ jest.mock("@applicaster/zapp-react-native-bridge/QuickBrick", () => ({
71
+ QUICK_BRICK_EVENTS: {
72
+ IDLE_TIMER_DISABLED: "IDLE_TIMER_DISABLED",
73
+ MOVE_APP_TO_BACKGROUND: "MOVE_APP_TO_BACKGROUND",
74
+ },
75
+ sendQuickBrickEvent: jest.fn(),
76
+ }));
77
+
78
+ jest.mock("../ProgramInfo", () => ({
79
+ ProgramInfo: () => null,
80
+ }));
81
+
82
+ jest.mock("../../AudioPlayer", () => ({
83
+ AudioPlayer: () => null,
84
+ }));
85
+
86
+ jest.mock("../logger", () => ({
87
+ log_debug: jest.fn(),
88
+ log_info: jest.fn(),
89
+ log_warning: jest.fn(),
90
+ playerContainerLogger: { error: jest.fn() },
91
+ }));
92
+
93
+ jest.mock(
94
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer",
95
+ () => {
96
+ const player = {
97
+ addListener: jest.fn(),
98
+ removeListener: jest.fn(),
99
+ isPaused: jest.fn(() => false),
100
+ isAd: jest.fn(() => false),
101
+ seekTo: jest.fn(),
102
+ getPluginConfiguration: jest.fn(() => ({})),
103
+ getOverlayObservable: jest.fn(() => ({ getPlayNextEntry: () => null })),
104
+ };
105
+
106
+ return {
107
+ usePlayer: jest.fn(() => player),
108
+ __player: player,
109
+ };
110
+ }
111
+ );
112
+
113
+ jest.mock(
114
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayNextOverlay",
115
+ () => ({
116
+ usePlayNextOverlay: jest.fn(() => null),
117
+ })
118
+ );
119
+
120
+ jest.mock(
121
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/playerNativeCommand",
122
+ () => ({
123
+ PlayerNativeCommandTypes: { clearPlayerData: "clearPlayerData" },
124
+ PlayerNativeSendCommand: jest.fn(),
125
+ })
126
+ );
127
+
128
+ jest.mock(
129
+ "@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext",
130
+ () => ({
131
+ useSetNavbarState: jest.fn(() => ({ setVisible: jest.fn() })),
132
+ })
133
+ );
134
+
135
+ jest.mock(
136
+ "@applicaster/zapp-react-native-utils/reactHooks/screen/useTargetScreenData",
137
+ () => ({
138
+ useTargetScreenData: jest.fn(() => ({ id: "screen-id", styles: {} })),
139
+ })
140
+ );
141
+
142
+ jest.mock("../PlayerContainerContext", () => {
143
+ const ReactActual = require("react");
144
+
145
+ return {
146
+ PlayerContainerContext: ReactActual.createContext({
147
+ isLanguageOverlayVisible: false,
148
+ bottomFocusableId: "bottom",
149
+ showComponentsContainer: false,
150
+ refs: null,
151
+ }),
152
+ PlayerContainerContextProvider: ({ children }) => children,
153
+ };
154
+ });
155
+
156
+ jest.mock(
157
+ "@applicaster/zapp-react-native-ui-components/Components/FocusableGroup",
158
+ () => ({
159
+ FocusableGroup: ({ children }) => children,
160
+ })
161
+ );
162
+
163
+ jest.mock("../WappersView/PlayerFocusableWrapperView", () => ({
164
+ PlayerFocusableWrapperView: ({ children }) => children,
165
+ }));
166
+
167
+ jest.mock("../WappersView/ComponentFocusableWrapperView", () => ({
168
+ ComponentFocusableWrapperView: () => null,
169
+ }));
170
+
171
+ jest.mock("../index", () => ({
172
+ FocusableGroupMainContainerId: "player-container-general",
173
+ }));
174
+
175
+ jest.mock(
176
+ "@applicaster/zapp-react-native-utils/navigationUtils/itemTypeMatchers",
177
+ () => ({
178
+ isPlayable: jest.fn(() => true),
179
+ })
180
+ );
181
+
182
+ jest.mock("../../GeneralContentScreen", () => ({
183
+ GeneralContentScreen: () => null,
184
+ }));
185
+
186
+ jest.mock("@applicaster/zapp-react-native-redux", () => ({
187
+ useAppData: jest.fn(() => ({ isTabletPortrait: false })),
188
+ }));
189
+
190
+ import { PlayerContainer, VideoModalMode } from "../PlayerContainer";
191
+
192
+ const { __navigator: mockNavigator, __backHandlerRef: mockBackHandlerRef } =
193
+ jest.requireMock("@applicaster/zapp-react-native-utils/reactHooks");
194
+
195
+ const { playerManager: mockPlayerManager } = jest.requireMock(
196
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager"
197
+ );
198
+
199
+ const { __player: mockPlayer } = jest.requireMock(
200
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer"
201
+ );
202
+
203
+ const Player = React.forwardRef(() => null);
204
+
205
+ const item = {
206
+ id: "entry-1",
207
+ title: "Test entry",
208
+ summary: "",
209
+ content: { src: "https://example.com/video.m3u8" },
210
+ extensions: {},
211
+ } as any;
212
+
213
+ const renderPlayerContainer = (props = {}) =>
214
+ render(
215
+ <PlayerContainer
216
+ Player={Player}
217
+ item={item}
218
+ style={{}}
219
+ loadPipesData={jest.fn()}
220
+ isModal={true}
221
+ mode={VideoModalMode.MAXIMIZED}
222
+ {...props}
223
+ />
224
+ );
225
+
226
+ const pressHardwareBack = () => {
227
+ if (!mockBackHandlerRef.current) {
228
+ throw new Error("back handler was not registered via useBackHandler");
229
+ }
230
+
231
+ return mockBackHandlerRef.current();
232
+ };
233
+
234
+ describe("PlayerContainer hardware back handling", () => {
235
+ beforeEach(() => {
236
+ jest.clearAllMocks();
237
+ mockBackHandlerRef.current = null;
238
+ mockPlayer.getPluginConfiguration.mockReturnValue({});
239
+ mockPlayer.isPaused.mockReturnValue(false);
240
+ mockPlayer.isAd.mockReturnValue(false);
241
+
242
+ mockPlayer.getOverlayObservable.mockReturnValue({
243
+ getPlayNextEntry: () => null,
244
+ });
245
+
246
+ mockPlayerManager.getPluginConfiguration.mockReturnValue({});
247
+ mockPlayerManager.on.mockReturnThis();
248
+ mockPlayerManager.removeHandler.mockReturnThis();
249
+ });
250
+
251
+ it("minimises the video modal on back press when mini player is enabled", () => {
252
+ renderPlayerContainer();
253
+
254
+ const handled = pressHardwareBack();
255
+
256
+ expect(mockNavigator.minimiseVideoModal).toHaveBeenCalled();
257
+ expect(mockNavigator.closeVideoModal).not.toHaveBeenCalled();
258
+ expect(handled).toBe(true);
259
+ });
260
+
261
+ it("closes the video modal on back press when mini player is disabled", () => {
262
+ mockPlayer.getPluginConfiguration.mockReturnValue({
263
+ disable_mini_player_when_inline: true,
264
+ });
265
+
266
+ renderPlayerContainer();
267
+
268
+ const handled = pressHardwareBack();
269
+
270
+ expect(mockNavigator.closeVideoModal).toHaveBeenCalled();
271
+ expect(mockNavigator.minimiseVideoModal).not.toHaveBeenCalled();
272
+ expect(handled).toBe(true);
273
+ });
274
+
275
+ it("does not handle back press when the player is already minimised", () => {
276
+ renderPlayerContainer({ mode: VideoModalMode.MINIMIZED });
277
+
278
+ const handled = pressHardwareBack();
279
+
280
+ expect(handled).toBe(false);
281
+ expect(mockNavigator.minimiseVideoModal).not.toHaveBeenCalled();
282
+ expect(mockNavigator.closeVideoModal).not.toHaveBeenCalled();
283
+ });
284
+ });