@applicaster/zapp-react-native-ui-components 16.0.0-alpha.4342281394 → 16.0.0-alpha.5041622385

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 (41) hide show
  1. package/Components/CellRendererResolver/index.ts +2 -2
  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/FullWidthRow.tsx +38 -0
  18. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
  19. package/Components/MasterCell/dataAdapter.ts +15 -5
  20. package/Components/MasterCell/index.tsx +30 -5
  21. package/Components/MasterCell/utils/__tests__/resolveColor.test.js +169 -132
  22. package/Components/MasterCell/utils/__tests__/resolveColorForProp.test.js +92 -0
  23. package/Components/MasterCell/utils/index.ts +85 -46
  24. package/Components/PlayerContainer/PlayerContainer.tsx +14 -10
  25. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +284 -0
  26. package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -2
  27. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +3 -15
  28. package/Components/Screen/index.tsx +8 -4
  29. package/Components/VideoModal/utils.ts +6 -1
  30. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +12 -5
  31. package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
  32. package/Contexts/CachedDimensionsContext/__tests__/index.test.ts +154 -0
  33. package/Contexts/CachedDimensionsContext/index.ts +17 -2
  34. package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
  35. package/Helpers/index.js +0 -39
  36. package/package.json +5 -5
  37. package/Components/Screen/utils.ts +0 -16
  38. package/Helpers/Analytics/index.js +0 -95
  39. /package/Components/BackgroundImage/{BackgroundImage.tv.android.tsx → BackgroundImage.android.tv.tsx} +0 -0
  40. /package/Components/BackgroundImage/{BackgroundImage.tv.ios.tsx → BackgroundImage.ios.tv.tsx} +0 -0
  41. /package/Components/MasterCell/DefaultComponents/ButtonContainerView/{index.tv.android.tsx → index.android.tv.tsx} +0 -0
@@ -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";
@@ -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
+ }
@@ -37,13 +37,16 @@ function getAssetValue(asset, flavour, fallbackAsset = null) {
37
37
  return null;
38
38
  }
39
39
 
40
- if (typeof asset === "string") return asset;
40
+ if (typeof asset === "string") return fallbackAsset || asset;
41
41
 
42
42
  if (Array.isArray(asset)) {
43
43
  const flavourIndex = Number(flavour.replace("flavour_", ""));
44
- if (flavour && flavourIndex > -1) return asset[flavourIndex - 1];
45
44
 
46
- return asset[0];
45
+ if (flavour && flavourIndex > -1) {
46
+ return fallbackAsset || asset[flavourIndex - 1];
47
+ }
48
+
49
+ return fallbackAsset || asset[0];
47
50
  }
48
51
 
49
52
  return asset.src || fallbackAsset;
@@ -109,13 +112,21 @@ export const ActionButton = React.memo(function ActionButtonComponent(
109
112
  <Image
110
113
  fadeDuration={0}
111
114
  style={asset?.style || props?.style}
112
- 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
+ )}
113
120
  {...asset?.props}
114
121
  />
115
122
  ) : (
116
123
  <AssetComponent
117
124
  flavour={flavour}
118
- asset={getAssetValue(asset, flavour)}
125
+ asset={getAssetValue(
126
+ asset,
127
+ flavour,
128
+ actionState.state === 1 ? asset?.src.active : asset?.src.inactive
129
+ )}
119
130
  cellUUID={cellUUID}
120
131
  {...(props?.extraProps ?? {})}
121
132
  />
@@ -1,5 +1,6 @@
1
1
  import * as R from "ramda";
2
2
  import { isFunction } from "@applicaster/zapp-react-native-utils/functionUtils";
3
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
3
4
 
4
5
  import { functionForName } from "./MappingFunctions";
5
6
  import { resolveColor } from "./utils";
@@ -52,7 +53,8 @@ export function configInflater(
52
53
  additionalProps?: Record<string, any>;
53
54
  data?: Array<{ propName: string; func: Function; args: any[] }>;
54
55
  elements?: any[];
55
- }
56
+ },
57
+ allowDynamicColorsOutsideExtensions: boolean
56
58
  ) {
57
59
  const props = data.reduce(
58
60
  (acc, curr) => {
@@ -68,13 +70,13 @@ export function configInflater(
68
70
 
69
71
  if (Array.isArray(elements)) {
70
72
  adjustedElements = elements.map((element) =>
71
- configInflater(entry, element as any)
73
+ configInflater(entry, element as any, allowDynamicColorsOutsideExtensions)
72
74
  );
73
75
  }
74
76
 
75
77
  return {
76
78
  type,
77
- style: resolveColor(entry, style),
79
+ style: resolveColor(entry, style, allowDynamicColorsOutsideExtensions),
78
80
  props,
79
81
  elements: adjustedElements,
80
82
  };
@@ -98,9 +100,17 @@ function resolveElementsNode(entry, state, elements) {
98
100
  }
99
101
 
100
102
  export function defaultDataAdapter(elements) {
101
- return function elementsBuilder({ entry, state = "default" }) {
103
+ return function elementsBuilder({
104
+ entry,
105
+ state = "default",
106
+ allowDynamicColorsOutsideExtensions,
107
+ }) {
102
108
  return resolveElementsNode(entry, state, elements).map((element) =>
103
- configInflater(entry, element)
109
+ configInflater(
110
+ entry,
111
+ element,
112
+ toBooleanWithDefaultFalse(allowDynamicColorsOutsideExtensions)
113
+ )
104
114
  );
105
115
  };
106
116
  }
@@ -2,7 +2,10 @@ import * as R from "ramda";
2
2
  import * as React from "react";
3
3
  import { v4 as uuid } from "uuid";
4
4
 
5
+ import { isHorizontalList } from "@applicaster/zapp-react-native-utils/componentsUtils";
6
+ import { isVideoPreviewEnabled } from "@applicaster/zapp-react-native-ui-components/Components/MasterCell/utils";
5
7
  import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
8
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
6
9
  import { useScreenState } from "@applicaster/zapp-react-native-utils/screenState";
7
10
  import { defaultComponents } from "./DefaultComponents";
8
11
  import { defaultDataAdapter } from "./dataAdapter";
@@ -34,8 +37,8 @@ type MasterCellBuilderOptions = {
34
37
  containerStyle: any;
35
38
  cellOptions?: {
36
39
  isRTL?: boolean;
37
- generateId?: () => string;
38
40
  skipButtons?: boolean;
41
+ component?: ZappComponent;
39
42
  };
40
43
  };
41
44
 
@@ -46,7 +49,7 @@ export function masterCellBuilder({
46
49
  containerStyle = defaultContainerStyle,
47
50
  cellOptions = {},
48
51
  }: MasterCellBuilderOptions) {
49
- const { generateId = uuid, skipButtons = false } = cellOptions;
52
+ const { skipButtons = false, component } = cellOptions;
50
53
 
51
54
  const componentsMap = R.merge(defaultComponents, components);
52
55
  const { View } = componentsMap;
@@ -65,6 +68,7 @@ export function masterCellBuilder({
65
68
  */
66
69
  function MasterCell({ item, state, ...otherProps }: Props) {
67
70
  const { screenData } = useRoute();
71
+ const theme = useTheme();
68
72
 
69
73
  const screenId =
70
74
  screenData && "targetScreen" in screenData
@@ -85,14 +89,35 @@ export function masterCellBuilder({
85
89
  elementsBuilder({
86
90
  entry: item,
87
91
  state: getEntryState(state, entryIsSelected),
92
+ allowDynamicColorsOutsideExtensions:
93
+ theme?.allow_dynamic_colors_outside_extensions,
88
94
  }),
89
- [state, item, entryIsSelected] // Assuming that item won't mutate
95
+ [
96
+ state,
97
+ item,
98
+ entryIsSelected,
99
+ theme?.allow_dynamic_colors_outside_extensions,
100
+ ] // Assuming that item won't mutate
90
101
  );
91
102
 
92
103
  const wrapperRef = React.useRef(null);
93
104
 
94
- const cellUUID = React.useMemo<string>(generateId, [
95
- generateId,
105
+ const cellUUID = React.useMemo<string>(() => {
106
+ const isLiveImage = isVideoPreviewEnabled({
107
+ enable_video_preview: component?.rules?.enable_video_preview,
108
+ player_screen_id: component?.rules?.player_screen_id,
109
+ });
110
+
111
+ const isHL = isHorizontalList(component);
112
+
113
+ return isHL && isLiveImage
114
+ ? `${component?.id}-${component?.styles?.cell_plugin_configuration_id}`
115
+ : uuid();
116
+ }, [
117
+ component?.id,
118
+ component?.styles?.cell_plugin_configuration_id,
119
+ component?.rules?.enable_video_preview,
120
+ component?.rules?.player_screen_id,
96
121
  screenId,
97
122
  item?.id,
98
123
  ]);