@applicaster/zapp-react-native-ui-components 16.0.0-alpha.8047301539 → 16.0.0-alpha.8415209737
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/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +9 -5
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +4 -1
- package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
- package/Components/GeneralContentScreen/hookAdapter/networkService.ts +1 -2
- package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +2 -7
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +5 -5
- package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
- package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
- package/Components/Layout/FullWidthRow.tsx +38 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +14 -2
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
- package/Components/PlayerContainer/PlayerContainer.tsx +2 -0
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +284 -0
- package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -2
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +1 -15
- package/Components/ZappFrameworkComponents/BarView/BarView.tsx +12 -5
- package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
- package/Contexts/CachedDimensionsContext/__tests__/index.test.ts +154 -0
- package/Contexts/CachedDimensionsContext/index.ts +17 -2
- package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
- package/Helpers/index.js +0 -39
- package/package.json +5 -5
- package/Helpers/Analytics/index.js +0 -95
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { GeneralContentScreen } from "./GeneralContentScreen";
|
|
3
|
+
import { HookContentFocusGroup } from "./hookFocus";
|
|
3
4
|
import { runInBackground } from "./hookAdapter/runInBackground";
|
|
4
5
|
import { log_error } from "./hookAdapter/logger";
|
|
5
6
|
|
|
@@ -19,11 +20,14 @@ function GeneralContentScreenHookComponent(props: HookComponentProps) {
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
return (
|
|
22
|
-
<
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
<HookContentFocusGroup>
|
|
24
|
+
<GeneralContentScreen
|
|
25
|
+
screenId={hookPlugin.screen_id}
|
|
26
|
+
isScreenWrappedInContainer={false}
|
|
27
|
+
focused={focused}
|
|
28
|
+
parentFocus={parentFocus}
|
|
29
|
+
/>
|
|
30
|
+
</HookContentFocusGroup>
|
|
27
31
|
);
|
|
28
32
|
}
|
|
29
33
|
|
|
@@ -41,7 +41,10 @@ describe("GeneralContentScreenHookAdapter", () => {
|
|
|
41
41
|
expect(getByTestId("general-content-screen")).toBeDefined();
|
|
42
42
|
|
|
43
43
|
expect(mockScreenSpy).toHaveBeenCalledWith(
|
|
44
|
-
expect.objectContaining({
|
|
44
|
+
expect.objectContaining({
|
|
45
|
+
screenId: "screen-1",
|
|
46
|
+
isScreenWrappedInContainer: false,
|
|
47
|
+
})
|
|
45
48
|
);
|
|
46
49
|
});
|
|
47
50
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
import { View } from "react-native";
|
|
4
|
+
|
|
5
|
+
import { HookContentFocusGroup } from "../hookFocus/index.web";
|
|
6
|
+
|
|
7
|
+
const mockFocusableGroupSpy = jest.fn();
|
|
8
|
+
const mockUseInitialFocusSpy = jest.fn();
|
|
9
|
+
|
|
10
|
+
const mockModalState = { isRunningInBackground: false };
|
|
11
|
+
|
|
12
|
+
jest.mock("../../FocusableGroup", () => ({
|
|
13
|
+
FocusableGroup: (props) => {
|
|
14
|
+
const React = require("react");
|
|
15
|
+
const { View } = require("react-native");
|
|
16
|
+
|
|
17
|
+
mockFocusableGroupSpy(props);
|
|
18
|
+
|
|
19
|
+
return <View testID="focusable-group">{props.children}</View>;
|
|
20
|
+
},
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
|
|
24
|
+
useContentId: () => "quick-brick-content___route",
|
|
25
|
+
useNavbarId: () => "quick-brick-navbar___route",
|
|
26
|
+
usePathname: () => "hooks-modal/profile-select",
|
|
27
|
+
}));
|
|
28
|
+
|
|
29
|
+
jest.mock("../../Screen/TV/hooks", () => ({
|
|
30
|
+
useInitialFocus: () => mockUseInitialFocusSpy(),
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
jest.mock("../../../Contexts/ZappHookModalContext", () => ({
|
|
34
|
+
useZappHookModalStore: (selector) => selector(mockModalState),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
describe("HookContentFocusGroup (web)", () => {
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
jest.clearAllMocks();
|
|
40
|
+
mockModalState.isRunningInBackground = false;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("wraps content in a preferred-focus content group and triggers initial focus when presented full screen", () => {
|
|
44
|
+
const { getByTestId } = render(
|
|
45
|
+
<HookContentFocusGroup>
|
|
46
|
+
<View testID="child" />
|
|
47
|
+
</HookContentFocusGroup>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(getByTestId("focusable-group")).toBeDefined();
|
|
51
|
+
expect(getByTestId("child")).toBeDefined();
|
|
52
|
+
expect(mockUseInitialFocusSpy).toHaveBeenCalledTimes(1);
|
|
53
|
+
|
|
54
|
+
expect(mockFocusableGroupSpy).toHaveBeenCalledWith(
|
|
55
|
+
expect.objectContaining({
|
|
56
|
+
id: "quick-brick-content___route",
|
|
57
|
+
groupId: "hooks-modal/profile-select",
|
|
58
|
+
nextFocusUp: "quick-brick-navbar___route",
|
|
59
|
+
preferredFocus: true,
|
|
60
|
+
shouldUsePreferredFocus: true,
|
|
61
|
+
})
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("injects the content group id into the wrapped child so its cells register under it", () => {
|
|
66
|
+
render(
|
|
67
|
+
<HookContentFocusGroup>
|
|
68
|
+
<View testID="child" />
|
|
69
|
+
</HookContentFocusGroup>
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const child = mockFocusableGroupSpy.mock.calls[0][0].children;
|
|
73
|
+
|
|
74
|
+
expect(child.props.groupId).toBe("quick-brick-content___route");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("renders the child without focus handling when running in background (not full screen)", () => {
|
|
78
|
+
mockModalState.isRunningInBackground = true;
|
|
79
|
+
|
|
80
|
+
const { getByTestId, queryByTestId } = render(
|
|
81
|
+
<HookContentFocusGroup>
|
|
82
|
+
<View testID="child" />
|
|
83
|
+
</HookContentFocusGroup>
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
expect(getByTestId("child")).toBeDefined();
|
|
87
|
+
expect(queryByTestId("focusable-group")).toBeNull();
|
|
88
|
+
expect(mockUseInitialFocusSpy).not.toHaveBeenCalled();
|
|
89
|
+
expect(mockFocusableGroupSpy).not.toHaveBeenCalled();
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -43,8 +43,7 @@ export const requestToSkipHook = async (
|
|
|
43
43
|
{ response: logData }
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
-
//
|
|
47
|
-
// response body means "skip the hook", an empty/null body means "run it".
|
|
46
|
+
// Non-empty body = skip the hook (same contract as hook-screen-wrapper)
|
|
48
47
|
return Boolean(responseHelper.responseData);
|
|
49
48
|
} catch (error) {
|
|
50
49
|
log_error(`requestToSkipHook: Error: ${error.message}`, { error });
|
|
@@ -3,13 +3,8 @@ import { requestToSkipHook } from "./networkService";
|
|
|
3
3
|
import { log_debug, log_error } from "./logger";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Headless pre-hook for the General Content Screen.
|
|
7
|
-
*
|
|
8
|
-
* `configuration` is the Hook object passed by the HooksManager, which has the
|
|
9
|
-
* hook river merged into it. The skip-hook fields are defined under the `rules`
|
|
10
|
-
* section of the General Content Screen manifest, so they are read from
|
|
11
|
-
* `configuration.rules` (unlike the standalone hook-screen-wrapper plugin, which
|
|
12
|
-
* defines them under `general`).
|
|
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`.
|
|
13
8
|
*/
|
|
14
9
|
export const runInBackground = async (
|
|
15
10
|
item,
|
|
@@ -6,11 +6,11 @@ import { log_error, log_info } from "./logger";
|
|
|
6
6
|
type ParseKey = { key: string; namespace?: string };
|
|
7
7
|
|
|
8
8
|
export function parseKeyEntries(input: string): ParseKey[] {
|
|
9
|
-
return input
|
|
10
|
-
.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
return input.split(",").flatMap((item) => {
|
|
10
|
+
const trimmed = item.trim();
|
|
11
|
+
|
|
12
|
+
return trimmed ? getNamespaceAndKey(trimmed) : [];
|
|
13
|
+
});
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const getKeyToSkipHook = async (key: string, namespace?: string) => {
|
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
|
+
|
|
4
|
+
const styles = StyleSheet.create({
|
|
5
|
+
row: { flexDirection: "row" },
|
|
6
|
+
basis: {
|
|
7
|
+
maxWidth: "100%",
|
|
8
|
+
flexBasis: "100%",
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
type Props = {
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Constrains its child to exactly the available parent width.
|
|
18
|
+
*
|
|
19
|
+
* UI components such as Hero and List render their items inside a parent
|
|
20
|
+
* `ScrollView` (e.g. when wrapped by tabs). A child placed directly in a
|
|
21
|
+
* scroll container can size itself to its own content rather than to the
|
|
22
|
+
* viewport, which causes items to be measured at a stale width and resize
|
|
23
|
+
* unexpectedly after layout changes such as device rotation.
|
|
24
|
+
*
|
|
25
|
+
* Wrapping the content in a `flexDirection: "row"` parent with a
|
|
26
|
+
* `flexBasis: "100%"` / `maxWidth: "100%"` child forces the child to
|
|
27
|
+
* re-derive its width from the parent on every layout pass instead of
|
|
28
|
+
* caching a measured pixel width, keeping it full-width and stable.
|
|
29
|
+
*
|
|
30
|
+
* @param children - The content to render at full parent width.
|
|
31
|
+
*/
|
|
32
|
+
export function FullWidthRow({ children }: Props) {
|
|
33
|
+
return (
|
|
34
|
+
<View style={styles.row}>
|
|
35
|
+
<View style={styles.basis}>{children}</View>
|
|
36
|
+
</View>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
toNumberWithDefault,
|
|
3
|
+
toNumberWithDefaultZero,
|
|
4
|
+
} from "@applicaster/zapp-react-native-utils/numberUtils";
|
|
2
5
|
import { compact } from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
3
6
|
|
|
4
7
|
import { Asset } from "./Asset";
|
|
@@ -10,6 +13,7 @@ import {
|
|
|
10
13
|
getPressableStyles,
|
|
11
14
|
getTextLabelStyles,
|
|
12
15
|
} from "./utils";
|
|
16
|
+
import { Spacer } from "./Spacer";
|
|
13
17
|
|
|
14
18
|
const displayModeStyle = (value) => {
|
|
15
19
|
const mode = value("display_mode") || "dynamic";
|
|
@@ -68,6 +72,9 @@ export const Button = ({
|
|
|
68
72
|
const testID = `mobile_action_button_${index + 1}`;
|
|
69
73
|
const actionIdentifier = getSlotBasedValue("assign_action");
|
|
70
74
|
const assetAlignment = getValue("asset_alignment") || "left";
|
|
75
|
+
const hasHorizontalAlignment = ["left", "right"].includes(assetAlignment);
|
|
76
|
+
const vGutter = toNumberWithDefaultZero(getValue("vertical_gutter"));
|
|
77
|
+
const hGutter = toNumberWithDefaultZero(getValue("horizontal_gutter"));
|
|
71
78
|
const actionAssetFlavour = getValue("action_asset_flavour");
|
|
72
79
|
const contentsAlignment = getValue("contents_alignment") || "center";
|
|
73
80
|
|
|
@@ -102,7 +109,12 @@ export const Button = ({
|
|
|
102
109
|
testID,
|
|
103
110
|
})
|
|
104
111
|
: null,
|
|
105
|
-
|
|
112
|
+
Spacer({
|
|
113
|
+
enabled: assetEnabled && labelEnabled,
|
|
114
|
+
style: hasHorizontalAlignment
|
|
115
|
+
? { width: hGutter }
|
|
116
|
+
: { height: vGutter },
|
|
117
|
+
}),
|
|
106
118
|
labelEnabled
|
|
107
119
|
? TextLabelsContainer({
|
|
108
120
|
style: getTextLabelStyles(getValue),
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
type Props = {
|
|
2
2
|
enabled?: boolean;
|
|
3
|
+
style?: object;
|
|
3
4
|
};
|
|
4
5
|
|
|
5
|
-
export const Spacer = ({
|
|
6
|
+
export const Spacer = ({
|
|
7
|
+
enabled = false,
|
|
8
|
+
style = { flex: 1 },
|
|
9
|
+
}: Props = {}) => {
|
|
6
10
|
if (!enabled) {
|
|
7
11
|
return null;
|
|
8
12
|
}
|
|
9
13
|
|
|
10
14
|
return {
|
|
11
15
|
type: "View",
|
|
12
|
-
style
|
|
13
|
-
flex: 1,
|
|
14
|
-
},
|
|
16
|
+
style,
|
|
15
17
|
};
|
|
16
18
|
};
|
|
@@ -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
|
+
});
|
|
@@ -9,7 +9,7 @@ import { useScreenConfiguration } from "../useScreenConfiguration";
|
|
|
9
9
|
import { RefreshControl } from "../RefreshControl";
|
|
10
10
|
import { ifEmptyUseFallback } from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
11
11
|
import {
|
|
12
|
-
|
|
12
|
+
useMarkPipesDataStale,
|
|
13
13
|
useProfilerLogging,
|
|
14
14
|
} from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
15
15
|
import { useLoadingState } from "./hooks/useLoadingState";
|
|
@@ -154,7 +154,7 @@ function ComponentsMapComponent(props: Props) {
|
|
|
154
154
|
[flatListHeight]
|
|
155
155
|
);
|
|
156
156
|
|
|
157
|
-
|
|
157
|
+
useMarkPipesDataStale(riverId, riverComponents);
|
|
158
158
|
|
|
159
159
|
const refreshControl = React.useMemo(
|
|
160
160
|
() => (pullToRefreshEnabled ? <RefreshControl /> : null),
|
|
@@ -10,11 +10,7 @@ exports[`componentsMap renders renders components map correctly 1`] = `
|
|
|
10
10
|
>
|
|
11
11
|
<View
|
|
12
12
|
onLayout={[Function]}
|
|
13
|
-
style={
|
|
14
|
-
{
|
|
15
|
-
"flex": 1,
|
|
16
|
-
}
|
|
17
|
-
}
|
|
13
|
+
style={{}}
|
|
18
14
|
>
|
|
19
15
|
<RCTScrollView
|
|
20
16
|
ListFooterComponent={
|
|
@@ -167,11 +163,6 @@ exports[`componentsMap renders renders components map correctly 1`] = `
|
|
|
167
163
|
>
|
|
168
164
|
<View
|
|
169
165
|
onLayout={[Function]}
|
|
170
|
-
style={
|
|
171
|
-
{
|
|
172
|
-
"flex": 1,
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
166
|
>
|
|
176
167
|
<View />
|
|
177
168
|
</View>
|
|
@@ -183,11 +174,6 @@ exports[`componentsMap renders renders components map correctly 1`] = `
|
|
|
183
174
|
>
|
|
184
175
|
<View
|
|
185
176
|
onLayout={[Function]}
|
|
186
|
-
style={
|
|
187
|
-
{
|
|
188
|
-
"flex": 1,
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
177
|
/>
|
|
192
178
|
</View>
|
|
193
179
|
<View
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { StyleSheet,
|
|
3
|
-
|
|
2
|
+
import { StyleSheet, SafeAreaView as RNSafeAreaView } from "react-native";
|
|
3
|
+
import { SafeAreaView } from "react-native-safe-area-context";
|
|
4
4
|
import { useIsRTL } from "@applicaster/zapp-react-native-utils/localizationUtils";
|
|
5
5
|
import CloseButton from "./Buttons/CloseButton";
|
|
6
6
|
import BackButton from "./Buttons/BackButton";
|
|
7
7
|
import BarTitle from "./BarTitle";
|
|
8
|
+
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
8
9
|
|
|
9
10
|
type Props = {
|
|
10
11
|
screenStyles: {
|
|
@@ -23,6 +24,11 @@ const defaultState: NavBarState = {
|
|
|
23
24
|
title: "",
|
|
24
25
|
};
|
|
25
26
|
|
|
27
|
+
const SafeAreaViewPlatform = platformSelect({
|
|
28
|
+
ios: RNSafeAreaView,
|
|
29
|
+
android: SafeAreaView,
|
|
30
|
+
});
|
|
31
|
+
|
|
26
32
|
const BarView = ({ screenStyles, barState = defaultState }: Props) => {
|
|
27
33
|
const isRTL = useIsRTL();
|
|
28
34
|
|
|
@@ -44,14 +50,15 @@ const BarView = ({ screenStyles, barState = defaultState }: Props) => {
|
|
|
44
50
|
);
|
|
45
51
|
|
|
46
52
|
return (
|
|
47
|
-
<
|
|
53
|
+
<SafeAreaViewPlatform
|
|
54
|
+
edges={["top", "left", "right"]}
|
|
48
55
|
style={[style.view, isRTL ? style.rtlStyle : {}]}
|
|
49
|
-
testID="BarView-
|
|
56
|
+
testID="BarView-safeAreaView"
|
|
50
57
|
>
|
|
51
58
|
{backButton}
|
|
52
59
|
<BarTitle title={barState.title} screenStyles={screenStyles} />
|
|
53
60
|
{closeButton}
|
|
54
|
-
</
|
|
61
|
+
</SafeAreaViewPlatform>
|
|
55
62
|
);
|
|
56
63
|
};
|
|
57
64
|
|
|
@@ -46,7 +46,7 @@ describe("BarView", () => {
|
|
|
46
46
|
<BarView screenStyles={screenStyles} barState={barState} />
|
|
47
47
|
);
|
|
48
48
|
|
|
49
|
-
expect(getByTestId("BarView-
|
|
49
|
+
expect(getByTestId("BarView-safeAreaView").props.style).toContainEqual({
|
|
50
50
|
transform: [{ scaleX: -1 }],
|
|
51
51
|
});
|
|
52
52
|
});
|
|
@@ -58,7 +58,7 @@ describe("BarView", () => {
|
|
|
58
58
|
<BarView screenStyles={screenStyles} barState={barState} />
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
-
expect(getByTestId("BarView-
|
|
61
|
+
expect(getByTestId("BarView-safeAreaView").props.style).not.toContainEqual({
|
|
62
62
|
transform: [{ scaleX: -1 }],
|
|
63
63
|
});
|
|
64
64
|
});
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { renderHook, act } from "@testing-library/react-native";
|
|
2
|
+
|
|
3
|
+
type DimensionsStore = {
|
|
4
|
+
setState: (
|
|
5
|
+
partial: { dimensions: Record<string, unknown>; ids: string[] },
|
|
6
|
+
replace?: boolean
|
|
7
|
+
) => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const createdStores: DimensionsStore[] = [];
|
|
11
|
+
|
|
12
|
+
jest.mock("zustand", () => {
|
|
13
|
+
const actual = jest.requireActual<typeof import("zustand")>("zustand");
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
...actual,
|
|
17
|
+
create: ((initializer: Parameters<typeof actual.create>[0]) => {
|
|
18
|
+
const store = actual.create(initializer);
|
|
19
|
+
createdStores.push(store);
|
|
20
|
+
|
|
21
|
+
return store;
|
|
22
|
+
}) as typeof actual.create,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
import { useCachedDimensions } from "../index";
|
|
27
|
+
|
|
28
|
+
const resetStore = () => {
|
|
29
|
+
const store = createdStores[createdStores.length - 1];
|
|
30
|
+
|
|
31
|
+
act(() => {
|
|
32
|
+
store?.setState({ dimensions: {}, ids: [] });
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe("useCachedDimensions", () => {
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
resetStore();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("getCachedDimensions", () => {
|
|
42
|
+
it("returns default dimensions when id has no cached value", () => {
|
|
43
|
+
const { result } = renderHook(() => useCachedDimensions("component-1"));
|
|
44
|
+
|
|
45
|
+
expect(result.current.getCachedDimensions()).toEqual({
|
|
46
|
+
width: undefined,
|
|
47
|
+
height: undefined,
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns cached dimensions after setCachedDimensions", () => {
|
|
52
|
+
const { result } = renderHook(() => useCachedDimensions("component-1"));
|
|
53
|
+
const dimensions = { width: 100, height: 200 };
|
|
54
|
+
|
|
55
|
+
act(() => {
|
|
56
|
+
result.current.setCachedDimensions(dimensions);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(result.current.getCachedDimensions()).toEqual(dimensions);
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe("setCachedDimensions", () => {
|
|
64
|
+
it("updates dimensions for the hook id", () => {
|
|
65
|
+
const { result } = renderHook(() => useCachedDimensions("component-1"));
|
|
66
|
+
|
|
67
|
+
act(() => {
|
|
68
|
+
result.current.setCachedDimensions({ width: 50, height: 75 });
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
expect(result.current.getCachedDimensions()).toEqual({
|
|
72
|
+
width: 50,
|
|
73
|
+
height: 75,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("shares cached dimensions between hook instances with the same id", () => {
|
|
78
|
+
const { result: first } = renderHook(() =>
|
|
79
|
+
useCachedDimensions("shared-id")
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const { result: second } = renderHook(() =>
|
|
83
|
+
useCachedDimensions("shared-id")
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
act(() => {
|
|
87
|
+
first.current.setCachedDimensions({ width: 10, height: 20 });
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
expect(second.current.getCachedDimensions()).toEqual({
|
|
91
|
+
width: 10,
|
|
92
|
+
height: 20,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe("getLastCachedDimensions", () => {
|
|
98
|
+
it("returns undefined when no dimensions have been cached", () => {
|
|
99
|
+
const { result } = renderHook(() => useCachedDimensions("component-1"));
|
|
100
|
+
|
|
101
|
+
expect(result.current.getLastCachedDimensions()).toBeUndefined();
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("returns the most recently cached dimensions across ids", () => {
|
|
105
|
+
const { result: first } = renderHook(() => useCachedDimensions("first"));
|
|
106
|
+
|
|
107
|
+
const { result: second } = renderHook(() =>
|
|
108
|
+
useCachedDimensions("second")
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
act(() => {
|
|
112
|
+
first.current.setCachedDimensions({ width: 100, height: 100 });
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
act(() => {
|
|
116
|
+
second.current.setCachedDimensions({ width: 200, height: 200 });
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(first.current.getLastCachedDimensions()).toEqual({
|
|
120
|
+
width: 200,
|
|
121
|
+
height: 200,
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("returns the latest dimensions when the same id is updated multiple times", () => {
|
|
126
|
+
const { result } = renderHook(() => useCachedDimensions("component-1"));
|
|
127
|
+
|
|
128
|
+
act(() => {
|
|
129
|
+
result.current.setCachedDimensions({ width: 100, height: 100 });
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
act(() => {
|
|
133
|
+
result.current.setCachedDimensions({ width: 300, height: 400 });
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(result.current.getLastCachedDimensions()).toEqual({
|
|
137
|
+
width: 300,
|
|
138
|
+
height: 400,
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("return value", () => {
|
|
144
|
+
it("exposes getCachedDimensions, setCachedDimensions, and getLastCachedDimensions", () => {
|
|
145
|
+
const { result } = renderHook(() => useCachedDimensions("component-1"));
|
|
146
|
+
|
|
147
|
+
expect(result.current).toEqual({
|
|
148
|
+
getCachedDimensions: expect.any(Function),
|
|
149
|
+
setCachedDimensions: expect.any(Function),
|
|
150
|
+
getLastCachedDimensions: expect.any(Function),
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { create, useStore } from "zustand";
|
|
2
2
|
import { produce } from "immer";
|
|
3
3
|
import { useCallback, useMemo } from "react";
|
|
4
|
+
import { last } from "@applicaster/zapp-react-native-utils/utils";
|
|
4
5
|
|
|
5
6
|
type Dimensions = {
|
|
6
7
|
width: Option<number>;
|
|
@@ -10,14 +11,17 @@ type Dimensions = {
|
|
|
10
11
|
type DimensionsState = {
|
|
11
12
|
dimensions: Record<string, Dimensions>;
|
|
12
13
|
setCachedDimensions: (id: string, dimensions: Dimensions) => void;
|
|
14
|
+
ids: string[];
|
|
13
15
|
};
|
|
14
16
|
|
|
15
17
|
const dimensionsStore = create<DimensionsState>((set) => ({
|
|
16
18
|
dimensions: {},
|
|
19
|
+
ids: [],
|
|
17
20
|
setCachedDimensions: (id, dimensions) =>
|
|
18
21
|
set(
|
|
19
22
|
produce((draft) => {
|
|
20
23
|
draft.dimensions[id] = dimensions;
|
|
24
|
+
draft.ids.push(id);
|
|
21
25
|
})
|
|
22
26
|
),
|
|
23
27
|
}));
|
|
@@ -28,7 +32,7 @@ const initialDimensions = () => ({
|
|
|
28
32
|
});
|
|
29
33
|
|
|
30
34
|
export const useCachedDimensions = (id: string) => {
|
|
31
|
-
const { dimensions, setCachedDimensions } = useStore(
|
|
35
|
+
const { dimensions, setCachedDimensions, ids } = useStore(
|
|
32
36
|
dimensionsStore
|
|
33
37
|
) as DimensionsState;
|
|
34
38
|
|
|
@@ -40,11 +44,22 @@ export const useCachedDimensions = (id: string) => {
|
|
|
40
44
|
setCachedDimensions(id, newDimensions);
|
|
41
45
|
}, []);
|
|
42
46
|
|
|
47
|
+
const getLastCachedDimensions = useCallback(() => {
|
|
48
|
+
const previousId = last(ids);
|
|
49
|
+
|
|
50
|
+
if (!previousId) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return dimensions[previousId];
|
|
55
|
+
}, [dimensions, ids]);
|
|
56
|
+
|
|
43
57
|
return useMemo(
|
|
44
58
|
() => ({
|
|
45
59
|
getCachedDimensions,
|
|
46
60
|
setCachedDimensions: handleSetCachedDimensions,
|
|
61
|
+
getLastCachedDimensions,
|
|
47
62
|
}),
|
|
48
|
-
[getCachedDimensions, handleSetCachedDimensions]
|
|
63
|
+
[getCachedDimensions, handleSetCachedDimensions, getLastCachedDimensions]
|
|
49
64
|
);
|
|
50
65
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { sendTapCellEvent, sendTapMenuItem } from "../Analytics";
|
|
2
1
|
import { getItemType } from "@applicaster/zapp-react-native-utils/navigationUtils";
|
|
3
2
|
import { SCREEN_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/itemTypes";
|
|
4
3
|
|
|
@@ -12,7 +11,6 @@ export function onCellPress(
|
|
|
12
11
|
itemIndex,
|
|
13
12
|
layoutVersion = "v1"
|
|
14
13
|
) {
|
|
15
|
-
sendTapCellEvent(entry, component, headerTitle, itemIndex);
|
|
16
14
|
const componentScreenType = screenTypeFromComponent(component);
|
|
17
15
|
const entryScreenType = screenTypeFromEntry(entry);
|
|
18
16
|
const itemType = getItemType(entry, layoutVersion);
|
|
@@ -37,7 +35,3 @@ function screenTypeFromComponent(component) {
|
|
|
37
35
|
function screenTypeFromEntry(entry) {
|
|
38
36
|
return entry && entry.screen_type;
|
|
39
37
|
}
|
|
40
|
-
|
|
41
|
-
export function onMenuItemFocus({ item, index, isHome }) {
|
|
42
|
-
sendTapMenuItem({ item, index, isHome });
|
|
43
|
-
}
|
package/Helpers/index.js
CHANGED
|
@@ -7,42 +7,3 @@ export const ASSETS = {
|
|
|
7
7
|
amazon: "tv_app_background",
|
|
8
8
|
}),
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
export const ANALYTICS_CORE_EVENTS = {
|
|
12
|
-
TAP_CELL: "Tap Cell",
|
|
13
|
-
PLAY_VOD_ITEM: "Play VOD Item",
|
|
14
|
-
VOD_ITEM_PLAY_WAS_TRIGGERED: "VOD Item: Play Was Triggered",
|
|
15
|
-
CHANNEL_ITEM_PLAY_WAS_TRIGGERED: "Channel Item: Play Was Triggered",
|
|
16
|
-
PROGRAM_ITEM_PLAY_WAS_TRIGGERED: "Program Item: Play Was Triggered",
|
|
17
|
-
TAP_MENU_ICON: "Tap Menu Item",
|
|
18
|
-
HOME_SCREEN_VIEWED: "Home Screen: Viewed",
|
|
19
|
-
ITEM_NOT_AVAILABLE: "N/A",
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const ANALYTICS_ENTRY_EVENTS = {
|
|
23
|
-
ITEM_TYPE: "Item Type",
|
|
24
|
-
ITEM_TITLE: "Item Name",
|
|
25
|
-
ITEM_ID: "Item ID",
|
|
26
|
-
ITEM_LINK: "Item Link",
|
|
27
|
-
ITEM_INDEX: "Item Number",
|
|
28
|
-
ITEM_TIME_PLAYED: "Item Total Time Played",
|
|
29
|
-
ITEM_TOTAL_TIME_PLAYED: "Item Total Time Played",
|
|
30
|
-
ITEM_PLAY_COMPLETED: "Completed",
|
|
31
|
-
ITEM_CUSTOM_PROPERTY: "Custom Property",
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const ANALYTICS_COMPONENT_EVENTS = {
|
|
35
|
-
COMPONENT_ID: "Component ID",
|
|
36
|
-
COMPONENT_TYPE: "Component Type",
|
|
37
|
-
CELL_STYLE: "Cell Style",
|
|
38
|
-
HEADER_TITLE: "Header Name",
|
|
39
|
-
COMPONENT_SOURCE: "Component Source",
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const ANALYTICS_MENU_ITEM_EVENTS = {
|
|
43
|
-
ITEM_TYPE: "Item Type",
|
|
44
|
-
ITEM_TITLE: "Item Name",
|
|
45
|
-
ITEM_ID: "Item ID",
|
|
46
|
-
ITEM_HOME_SCREEN: "Home Screen",
|
|
47
|
-
ITEM_INDEX: "Item Number",
|
|
48
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-ui-components",
|
|
3
|
-
"version": "16.0.0-alpha.
|
|
3
|
+
"version": "16.0.0-alpha.8415209737",
|
|
4
4
|
"description": "Applicaster Zapp React Native ui components for the Quick Brick App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@applicaster/applicaster-types": "16.0.0-alpha.
|
|
32
|
-
"@applicaster/zapp-react-native-bridge": "16.0.0-alpha.
|
|
33
|
-
"@applicaster/zapp-react-native-redux": "16.0.0-alpha.
|
|
34
|
-
"@applicaster/zapp-react-native-utils": "16.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "16.0.0-alpha.8415209737",
|
|
32
|
+
"@applicaster/zapp-react-native-bridge": "16.0.0-alpha.8415209737",
|
|
33
|
+
"@applicaster/zapp-react-native-redux": "16.0.0-alpha.8415209737",
|
|
34
|
+
"@applicaster/zapp-react-native-utils": "16.0.0-alpha.8415209737",
|
|
35
35
|
"fast-json-stable-stringify": "^2.1.0",
|
|
36
36
|
"promise": "^8.3.0",
|
|
37
37
|
"url": "^0.11.0",
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import * as R from "ramda";
|
|
2
|
-
import { postAnalyticEvent } from "@applicaster/zapp-react-native-tvos-app/AnalyticsManager";
|
|
3
|
-
import { extensionsEvents } from "@applicaster/zapp-react-native-utils/analyticsUtils/AnalyticsEvents/helper";
|
|
4
|
-
import {
|
|
5
|
-
ANALYTICS_CORE_EVENTS,
|
|
6
|
-
ANALYTICS_ENTRY_EVENTS,
|
|
7
|
-
ANALYTICS_COMPONENT_EVENTS,
|
|
8
|
-
ANALYTICS_MENU_ITEM_EVENTS,
|
|
9
|
-
} from "../";
|
|
10
|
-
|
|
11
|
-
export function sendTapCellEvent(item, component, headerTitle, itemIndex) {
|
|
12
|
-
const itemReadableIndex = itemIndex + 1;
|
|
13
|
-
|
|
14
|
-
const analyticsProperties = R.compose(
|
|
15
|
-
R.reject(R.isNil),
|
|
16
|
-
R.merge(eventForEntry(item, itemReadableIndex))
|
|
17
|
-
)(eventForComponent(component, headerTitle));
|
|
18
|
-
|
|
19
|
-
postEvent(ANALYTICS_CORE_EVENTS.TAP_CELL, analyticsProperties);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function sendTapMenuItem({ item, index, isHome }) {
|
|
23
|
-
const analyticsProperties = R.compose(R.reject(R.isNil))(
|
|
24
|
-
eventForMenuItemEntry({ item, index, isHome })
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
postEvent(ANALYTICS_CORE_EVENTS.TAP_MENU_ICON, analyticsProperties);
|
|
28
|
-
|
|
29
|
-
if (isHome) {
|
|
30
|
-
postEvent(ANALYTICS_CORE_EVENTS.HOME_SCREEN_VIEWED, null);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function postEvent(event, properties) {
|
|
35
|
-
postAnalyticEvent(event, properties);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function eventForEntry(item, itemIndex) {
|
|
39
|
-
const {
|
|
40
|
-
title,
|
|
41
|
-
type: { value: valueType },
|
|
42
|
-
id,
|
|
43
|
-
} = item;
|
|
44
|
-
|
|
45
|
-
const analyticsCustomProperties = extensionsEvents(item.extensions);
|
|
46
|
-
|
|
47
|
-
const analyticsEvents = {
|
|
48
|
-
[ANALYTICS_ENTRY_EVENTS.ITEM_TYPE]: valueType,
|
|
49
|
-
[ANALYTICS_ENTRY_EVENTS.ITEM_TITLE]: title,
|
|
50
|
-
[ANALYTICS_ENTRY_EVENTS.ITEM_ID]: id,
|
|
51
|
-
[ANALYTICS_ENTRY_EVENTS.ITEM_INDEX]:
|
|
52
|
-
(itemIndex && itemIndex.toString()) || null,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
if (analyticsCustomProperties) {
|
|
56
|
-
analyticsEvents.analyticsCustomProperties = analyticsCustomProperties;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return analyticsEvents;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function eventForComponent(
|
|
63
|
-
component,
|
|
64
|
-
headerTitle, // Zapp Pipes data passed for group components
|
|
65
|
-
zappPipesData = null
|
|
66
|
-
) {
|
|
67
|
-
const { id, component_type, styles, data } = component;
|
|
68
|
-
const { cell_style } = styles;
|
|
69
|
-
const source = data?.source || zappPipesData?.data?.url || null;
|
|
70
|
-
|
|
71
|
-
return {
|
|
72
|
-
[ANALYTICS_COMPONENT_EVENTS.COMPONENT_ID]: id,
|
|
73
|
-
[ANALYTICS_COMPONENT_EVENTS.COMPONENT_TYPE]: component_type,
|
|
74
|
-
[ANALYTICS_COMPONENT_EVENTS.CELL_STYLE]:
|
|
75
|
-
cell_style || ANALYTICS_CORE_EVENTS.ITEM_NOT_AVAILABLE,
|
|
76
|
-
[ANALYTICS_COMPONENT_EVENTS.COMPONENT_SOURCE]:
|
|
77
|
-
(source && encodeURIComponent(source)) || null,
|
|
78
|
-
[ANALYTICS_COMPONENT_EVENTS.HEADER_TITLE]: headerTitle,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function eventForMenuItemEntry({ item, index, isHome }) {
|
|
83
|
-
const { title, type, id } = item;
|
|
84
|
-
|
|
85
|
-
const itemReadableIndex = index + 1;
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
[ANALYTICS_MENU_ITEM_EVENTS.ITEM_INDEX]:
|
|
89
|
-
(itemReadableIndex && itemReadableIndex.toString()) || null,
|
|
90
|
-
[ANALYTICS_MENU_ITEM_EVENTS.ITEM_TYPE]: type,
|
|
91
|
-
[ANALYTICS_MENU_ITEM_EVENTS.ITEM_TITLE]: title,
|
|
92
|
-
[ANALYTICS_MENU_ITEM_EVENTS.ITEM_ID]: id,
|
|
93
|
-
[ANALYTICS_MENU_ITEM_EVENTS.ITEM_HOME_SCREEN]: isHome ? "YES" : "NO",
|
|
94
|
-
};
|
|
95
|
-
}
|