@applicaster/zapp-react-native-ui-components 16.0.0-alpha.8443457654 → 16.0.0-alpha.8525514228

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 (53) hide show
  1. package/Components/CellRendererResolver/index.ts +1 -1
  2. package/Components/FocusableGroup/FocusableTvOS.tsx +11 -7
  3. package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
  4. package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
  5. package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
  6. package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
  7. package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
  8. package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +124 -0
  9. package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
  10. package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
  11. package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
  12. package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +72 -0
  13. package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
  14. package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
  15. package/Components/GeneralContentScreen/index.ts +2 -0
  16. package/Components/Layout/FullWidthRow.tsx +38 -0
  17. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +14 -2
  18. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
  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/ModalComponent/AudioPlayer/Components/Action.tsx +368 -0
  25. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +424 -0
  26. package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +728 -0
  27. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +709 -0
  28. package/Components/ModalComponent/AudioPlayer/Components/index.ts +7 -0
  29. package/Components/ModalComponent/BottomSheetModalContent.tsx +49 -5
  30. package/Components/ModalComponent/Header/index.tsx +15 -10
  31. package/Components/ModalComponent/Header/utils.ts +1 -1
  32. package/Components/ModalComponent/index.tsx +1 -3
  33. package/Components/ModalComponent/types.ts +3 -0
  34. package/Components/ModalComponent/utils.ts +1 -1
  35. package/Components/PlayerContainer/PlayerContainer.tsx +9 -3
  36. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +284 -0
  37. package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -2
  38. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +3 -15
  39. package/Components/Screen/index.tsx +8 -4
  40. package/Components/SortableList/components/SortableList.tsx +168 -0
  41. package/Components/SortableList/index.ts +1 -0
  42. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +12 -5
  43. package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
  44. package/Contexts/CachedDimensionsContext/__tests__/index.test.ts +154 -0
  45. package/Contexts/CachedDimensionsContext/index.ts +17 -2
  46. package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
  47. package/Helpers/index.js +0 -39
  48. package/package.json +5 -5
  49. package/Components/Screen/utils.ts +0 -16
  50. package/Helpers/Analytics/index.js +0 -95
  51. /package/Components/BackgroundImage/{BackgroundImage.tv.android.tsx → BackgroundImage.android.tv.tsx} +0 -0
  52. /package/Components/BackgroundImage/{BackgroundImage.tv.ios.tsx → BackgroundImage.ios.tv.tsx} +0 -0
  53. /package/Components/MasterCell/DefaultComponents/ButtonContainerView/{index.tv.android.tsx → index.android.tv.tsx} +0 -0
@@ -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
+ }
@@ -1,4 +1,7 @@
1
- import { toNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
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 = ({ enabled = false }: Props = {}) => {
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
  };
@@ -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
  ]);