@applicaster/zapp-react-native-ui-components 12.0.0-alpha.5251355865 → 12.0.0-alpha.5335460000

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 (119) hide show
  1. package/Components/BaseFocusable/index.tsx +3 -3
  2. package/Components/Cell/Cell.tsx +32 -11
  3. package/Components/Cell/CellWithFocusable.tsx +40 -19
  4. package/Components/Cell/TvOSCellComponent.tsx +5 -9
  5. package/Components/ErrorScreen/index.tsx +1 -1
  6. package/Components/Focusable/Focusable.tsx +6 -1
  7. package/Components/FocusableCell/index.tsx +7 -7
  8. package/Components/FocusableGroup/index.tsx +11 -2
  9. package/Components/FocusableList/FocusableChild.ts +24 -14
  10. package/Components/FocusableList/FocusableItem.tsx +1 -1
  11. package/Components/FocusableList/FocusableListItemWrapper.tsx +76 -0
  12. package/Components/FocusableList/hooks/useCellState.android.ts +3 -1
  13. package/Components/FocusableList/index.tsx +26 -25
  14. package/Components/GeneralContentScreen/GeneralContentScreen.tsx +6 -3
  15. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +13 -6
  16. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +1 -1
  17. package/Components/HandlePlayable/HandlePlayable.tsx +3 -0
  18. package/Components/Image/Image.android.tsx +3 -25
  19. package/Components/Image/Image.tsx +18 -2
  20. package/Components/Image/utils/index.ts +39 -0
  21. package/Components/Layout/TV/ScreenContainer.tsx +79 -5
  22. package/Components/Layout/TV/ScreenLayoutContextProvider.tsx +2 -2
  23. package/Components/Layout/TV/__tests__/ScreenContainer.test.tsx +38 -28
  24. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +25 -13
  25. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +10 -10
  26. package/Components/Layout/TV/__tests__/index.test.tsx +20 -75
  27. package/Components/Layout/TV/index.tsx +14 -67
  28. package/Components/Layout/TV/index.web.tsx +33 -0
  29. package/Components/Layout/index.tsx +15 -11
  30. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +4 -1
  31. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +88 -112
  32. package/Components/MasterCell/DefaultComponents/DynamicBadge.tsx +4 -2
  33. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -1
  34. package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +9 -26
  35. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +5 -3
  36. package/Components/MasterCell/DefaultComponents/Image/hooks/useImageSize.ts +65 -0
  37. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -1
  38. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +37 -2
  39. package/Components/MasterCell/DefaultComponents/SecondaryImage/Image.tsx +3 -2
  40. package/Components/MasterCell/DefaultComponents/Text/index.tsx +14 -2
  41. package/Components/MasterCell/DefaultComponents/Toggle.tsx +5 -1
  42. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
  43. package/Components/MasterCell/DefaultComponents/__tests__/text.test.tsx +24 -9
  44. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.android.tsx +4 -1
  45. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.tsx +10 -2
  46. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +1 -3
  47. package/Components/MasterCell/dataAdapter.ts +31 -10
  48. package/Components/MasterCell/hooks/useAsyncRendering/index.ts +1 -1
  49. package/Components/MasterCell/index.tsx +3 -1
  50. package/Components/MasterCell/utils/__tests__/insertBetween.test.js +9 -0
  51. package/Components/MasterCell/utils/index.ts +53 -41
  52. package/Components/MeasurmentsPortal/BasicMeasurementsPortal.tsx +11 -7
  53. package/Components/MeasurmentsPortal/MeasurementsPortal.tsx +10 -1
  54. package/Components/Navigator/StackNavigator.tsx +57 -0
  55. package/Components/Navigator/index.ts +1 -0
  56. package/Components/PlayerContainer/PlayerContainer.tsx +66 -31
  57. package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -1
  58. package/Components/PlayerImageBackground/index.tsx +34 -8
  59. package/Components/River/ComponentsMap/ComponentsMap.tsx +92 -22
  60. package/Components/River/RefreshControl.tsx +55 -1
  61. package/Components/River/TV/River.tsx +2 -25
  62. package/Components/River/__tests__/componentsMap.test.js +7 -0
  63. package/Components/River/useScreenConfiguration.ts +2 -2
  64. package/Components/Screen/TV/hooks/index.ts +3 -0
  65. package/Components/Screen/TV/hooks/useInitialFocus.ts +70 -0
  66. package/Components/Screen/TV/hooks/useRestoreFocus.ts +22 -0
  67. package/Components/Screen/TV/index.web.tsx +165 -0
  68. package/Components/Screen/__tests__/Screen.test.tsx +8 -1
  69. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +14 -0
  70. package/Components/Screen/index.tsx +65 -48
  71. package/Components/Screen/navigationHandler.ts +5 -0
  72. package/Components/ScreenResolver/index.tsx +9 -12
  73. package/Components/Tabs/TV/styles.ts +1 -1
  74. package/Components/Transitioner/Scene.tsx +32 -26
  75. package/Components/Transitioner/Transitioner.tsx +21 -28
  76. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +12 -4
  77. package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +1 -0
  78. package/Components/VideoLive/LiveImageManager.ts +28 -1
  79. package/Components/VideoLive/PlayerLiveImageComponent.tsx +79 -48
  80. package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +45 -3
  81. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +21 -29
  82. package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +66 -0
  83. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +355 -0
  84. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +161 -0
  85. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +456 -0
  86. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +182 -0
  87. package/Components/VideoModal/ModalAnimation/index.ts +15 -0
  88. package/Components/VideoModal/ModalAnimation/utils.ts +302 -0
  89. package/Components/VideoModal/PlayerDetails.tsx +3 -3
  90. package/Components/VideoModal/PlayerWrapper.tsx +77 -47
  91. package/Components/VideoModal/VideoModal.tsx +23 -40
  92. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +13 -1
  93. package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +157 -105
  94. package/Components/VideoModal/hooks/useModalSize.ts +10 -12
  95. package/Components/VideoModal/utils.ts +8 -5
  96. package/Components/Viewport/ViewportTracker/ViewportTracker.tsx +31 -40
  97. package/Components/Viewport/ViewportTracker/index.tsx +1 -0
  98. package/Components/Viewport/utils.js +1 -1
  99. package/Components/ZappUIComponent/index.tsx +22 -12
  100. package/Contexts/FocusableGroupContext/FocusableGroupContext.ts +3 -0
  101. package/Contexts/FocusableGroupContext/FocusableGroupContextProvider.tsx +16 -0
  102. package/Contexts/FocusableGroupContext/__tests__/FocusableGroupContextProvider.test.tsx +22 -0
  103. package/Contexts/FocusableGroupContext/__tests__/withFocusableContext.test.tsx +26 -0
  104. package/Contexts/FocusableGroupContext/index.ts +7 -0
  105. package/Contexts/FocusableGroupContext/withFocusableContext.tsx +17 -0
  106. package/Contexts/MenuToggleContext/{index.js → index.ts} +16 -0
  107. package/Contexts/ScreenContext/__tests__/__snapshots__/index.test.tsx.snap +3 -0
  108. package/Contexts/ScreenContext/__tests__/index.test.tsx +27 -0
  109. package/Contexts/ScreenContext/index.tsx +94 -28
  110. package/Contexts/ScreenDataContext/index.tsx +20 -0
  111. package/Contexts/ZappPipesContext/ZappPipesEntryContext.ts +1 -1
  112. package/Decorators/ComponentsMapWrapper/withComponentsMapProvider.tsx +7 -2
  113. package/events/index.ts +1 -0
  114. package/package.json +5 -5
  115. package/Components/Layout/TV/TransitionOverlay.tsx +0 -64
  116. package/Components/VideoModal/hooks/usePosition.ts +0 -50
  117. /package/Components/FocusableGroup/{index.android.js → index.android.ts} +0 -0
  118. /package/Components/FocusableGroup/{index.ios.js → index.ios.ts} +0 -0
  119. /package/Contexts/{index.js → index.ts} +0 -0
@@ -18,6 +18,7 @@ type LiveImageProps = {
18
18
  imageKey?: string;
19
19
  state: "focused" | "unfocused" | "selected";
20
20
  audio_muted_by_default?: boolean;
21
+ uri: string; // cover image url
21
22
  };
22
23
 
23
24
  const DEFAULT_PLAYER_IDENTIFIER = "QuickBrickPlayerPlugin";
@@ -107,6 +108,26 @@ const prepareEntry = (entry) => {
107
108
  };
108
109
  }
109
110
 
111
+ const previewPlayback =
112
+ entry.extensions?.["brightcove"]?.["preview_playback"];
113
+
114
+ if (previewPlayback) {
115
+ return {
116
+ ...entry,
117
+ extensions: {
118
+ ...entry.extensions,
119
+ brightcove: {
120
+ ...entry?.extensions?.["brightcove"],
121
+ video_id: previewPlayback,
122
+ },
123
+ },
124
+ };
125
+ }
126
+
127
+ if (entry.extensions?.["brightcove"]?.["video_id"]) {
128
+ return entry;
129
+ }
130
+
110
131
  const src = entry.content?.src;
111
132
 
112
133
  if (!src) {
@@ -176,10 +197,23 @@ const getPlayerConfig = (player_screen_id, actionIdentifier) => {
176
197
  const positionAbsolute: ViewStyle = { position: "absolute" };
177
198
 
178
199
  const LiveImageComponent = (props: LiveImageProps) => {
179
- const { item, style, cellUUID, imageKey, actionIdentifier, state } = props;
200
+ const {
201
+ item,
202
+ style: componentStyle,
203
+ cellUUID,
204
+ imageKey,
205
+ actionIdentifier,
206
+ state,
207
+ } = props;
180
208
 
181
209
  const component = useUIComponentContext();
182
210
 
211
+ // Fix for blinking on state change
212
+ const style = React.useMemo(
213
+ () => ({ ...componentStyle, backgroundColor: "transparent" }),
214
+ [componentStyle]
215
+ );
216
+
183
217
  const componentType = React.useMemo(
184
218
  () => getPropComponentType(component),
185
219
  [component?.id]
@@ -209,10 +243,11 @@ const LiveImageComponent = (props: LiveImageProps) => {
209
243
 
210
244
  return (
211
245
  <>
212
- <Image {...props} />
246
+ <Image {...props} applyMaxSize />
213
247
  {isShouldRender && (
214
248
  <View style={[style, positionAbsolute]}>
215
249
  <PlayerLiveImage
250
+ uri={props.uri}
216
251
  playerId={cellUUID}
217
252
  playerPluginId={playerPluginId}
218
253
  screenConfig={screenConfig}
@@ -1,11 +1,12 @@
1
1
  import * as React from "react";
2
2
  import { isNil } from "ramda";
3
- import { Image as RNImage, ImageStyle, View } from "react-native";
3
+ import { ImageStyle, View } from "react-native";
4
4
  import {
5
5
  FIT_POSITION,
6
6
  IMAGE_SIZING_FIT,
7
7
  IMAGE_SIZING_FILL,
8
8
  } from "@applicaster/zapp-react-native-utils/manifestUtils/secondaryImage";
9
+ import { QBImage as Image } from "@applicaster/zapp-react-native-ui-components/Components/Image";
9
10
 
10
11
  import { useGetImageDimensions } from "./hooks";
11
12
  import {
@@ -59,7 +60,7 @@ const SecondaryImageComponent = (props: Props) => {
59
60
 
60
61
  return (
61
62
  <View style={style} onLayout={onAsyncRender}>
62
- <RNImage
63
+ <Image
63
64
  {...props}
64
65
  source={{ uri }}
65
66
  style={{
@@ -1,7 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { Text } from "react-native";
3
3
  import { omit } from "ramda";
4
- import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
5
4
  import {
6
5
  textTransform,
7
6
  dateFormat,
@@ -9,6 +8,9 @@ import {
9
8
 
10
9
  import { useTextLabel, withFocusedStyles } from "./hooks";
11
10
  import { withScaledLineHeight } from "./utils";
11
+ import { toNumber } from "@applicaster/zapp-react-native-utils/numberUtils";
12
+ import { MeasurementPortalContext } from "../../../MeasurmentsPortal";
13
+ import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
12
14
 
13
15
  type Props = {
14
16
  style: any;
@@ -32,14 +34,24 @@ const _Text = ({
32
34
  ...otherProps
33
35
  }: Props) => {
34
36
  const _label = useTextLabel({ label, entry });
37
+ const isMeasurement = React.useContext(MeasurementPortalContext);
35
38
 
36
39
  if (isNilOrEmpty(_label)) {
37
40
  return null;
38
41
  }
39
42
 
43
+ // set maximum possible height for the text in case of measurement
44
+ const height =
45
+ isMeasurement && otherProps.numberOfLines && style.lineHeight
46
+ ? toNumber(otherProps.numberOfLines) * toNumber(style.lineHeight)
47
+ : undefined;
48
+
40
49
  return (
41
50
  <Text
42
- style={withScaledLineHeight(withFocusedStyles({ style, otherProps }))}
51
+ style={[
52
+ withScaledLineHeight(withFocusedStyles({ style, otherProps })),
53
+ { height },
54
+ ]}
43
55
  {...withoutLabel(otherProps)}
44
56
  >
45
57
  {dateTransformEnabled
@@ -23,7 +23,11 @@ export const Toggle = (props: Props) => {
23
23
  iosBackgroundColor,
24
24
  } = style;
25
25
 
26
- const isSelected = React.useMemo(() => (cellState === "selected"), [item?.id, cellState]);
26
+ const isSelected = React.useMemo(
27
+ () => cellState === "selected",
28
+ [item?.id, cellState]
29
+ );
30
+
27
31
  const actionContext = useActions(action?.identifier);
28
32
 
29
33
  const [actionState, setActionState] = useState(
@@ -39,6 +39,6 @@ describe("image with no source", () => {
39
39
  );
40
40
 
41
41
  const testInstance = testRenderer.root;
42
- expect(testInstance.findByType(Image).props.source).toEqual({ uri: "" });
42
+ expect(testInstance.findByType(Image).props.source).toBeUndefined();
43
43
  });
44
44
  });
@@ -1,11 +1,23 @@
1
1
  import React from "react";
2
- import { Text } from "react-native";
2
+ import RN from "react-native";
3
3
  import { Provider } from "react-redux";
4
4
  import TestRenderer from "react-test-renderer";
5
- import configureStore from "redux-mock-store";
6
- import CustomText from "../Text";
5
+ import configureStoreFn from "redux-mock-store";
7
6
 
8
- const mockStore = configureStore();
7
+ const mockUseIsRTL = jest.fn(() => true);
8
+ const mockGetIsRTL = jest.fn(() => true);
9
+ const mockUseLocalizedStrings = jest.fn(() => ({}));
10
+ const mockGetUILanguage = jest.fn(() => "he-HE");
11
+
12
+ jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
13
+ useIsRTL: mockUseIsRTL,
14
+ getIsRTL: mockGetIsRTL,
15
+ useLocalizedStrings: mockUseLocalizedStrings,
16
+ getUILanguage: mockGetUILanguage,
17
+ }));
18
+
19
+ const CustomText = require("../Text").default;
20
+ const mockStore = configureStoreFn();
9
21
 
10
22
  const defaultProps = {
11
23
  entry: {},
@@ -22,7 +34,7 @@ const getRenderedText = (label: string, store: any) => {
22
34
  </Provider>
23
35
  );
24
36
 
25
- return testRenderer.root.findByType(Text).props.children;
37
+ return testRenderer.root.findByType(RN.Text).props.children;
26
38
  };
27
39
 
28
40
  describe("RTL app: Hebrew text contains english word", () => {
@@ -34,7 +46,7 @@ describe("RTL app: Hebrew text contains english word", () => {
34
46
  remoteConfigurations: { localizations: { he: {} } },
35
47
  appData: {
36
48
  languageCode: "he",
37
- countryCode: "HE",
49
+ countryCode: "IL",
38
50
  },
39
51
  });
40
52
 
@@ -47,18 +59,22 @@ describe("RTL app: Hebrew text contains english word", () => {
47
59
 
48
60
  it("Hebrew text contains not first english word", () => {
49
61
  const renderedText = getRenderedText(textWithNotFirstEnglishWord, store);
50
-
51
62
  expect(renderedText).toEqual(textWithNotFirstEnglishWord);
52
63
  });
53
64
 
54
65
  it("Hebrew text doesn't contain english word", () => {
55
66
  const renderedText = getRenderedText(textWithoutEnglishWord, store);
56
-
57
67
  expect(renderedText).toEqual(textWithoutEnglishWord);
58
68
  });
59
69
  });
60
70
 
61
71
  describe("LTR app: English text", () => {
72
+ beforeAll(() => {
73
+ mockUseIsRTL.mockReturnValue(false);
74
+ mockGetIsRTL.mockReturnValue(false);
75
+ mockGetUILanguage.mockReturnValue("en-US");
76
+ });
77
+
62
78
  const englishText = "Test sentence";
63
79
 
64
80
  const store = mockStore({
@@ -71,7 +87,6 @@ describe("LTR app: English text", () => {
71
87
 
72
88
  it("English text", () => {
73
89
  const renderedText = getRenderedText(englishText, store);
74
-
75
90
  expect(renderedText).toEqual(englishText);
76
91
  });
77
92
  });
@@ -61,7 +61,10 @@ export function ButtonContainerView({
61
61
  <View style={applyRTLStylesIfNeeded(style, isRTL)}>
62
62
  {insertBetween(
63
63
  (index) => (
64
- <HorizontalSeparator key={index} width={horizontalGutter} />
64
+ <HorizontalSeparator
65
+ key={`separator_${index}`}
66
+ width={horizontalGutter}
67
+ />
65
68
  ),
66
69
  cloneElementsWithIds(buttonIds, filteredChildren)
67
70
  )}
@@ -7,6 +7,10 @@ import type {
7
7
  ContainerProps,
8
8
  ContainerChildren,
9
9
  } from "./types";
10
+ import {
11
+ useIsRTL,
12
+ applyRTLStylesIfNeeded,
13
+ } from "@applicaster/zapp-react-native-utils/localizationUtils";
10
14
 
11
15
  const HorizontalSeparator = ({ width }: HorizontalSeparatorProps) => (
12
16
  <View style={{ width }} />
@@ -17,6 +21,7 @@ export function ButtonContainerView({
17
21
  children,
18
22
  ...otherProps
19
23
  }: ContainerProps) {
24
+ const isRTL = useIsRTL();
20
25
  const horizontalGutter = R.pathOr(0, ["horizontalGutter"], otherProps);
21
26
 
22
27
  const filteredChildren = useFilterChildren<ContainerChildren>(children);
@@ -26,10 +31,13 @@ export function ButtonContainerView({
26
31
  }
27
32
 
28
33
  return (
29
- <View style={style}>
34
+ <View style={applyRTLStylesIfNeeded(style, isRTL)}>
30
35
  {insertBetween(
31
36
  (index) => (
32
- <HorizontalSeparator key={index} width={horizontalGutter} />
37
+ <HorizontalSeparator
38
+ key={`separator_${index}`}
39
+ width={horizontalGutter}
40
+ />
33
41
  ),
34
42
  filteredChildren
35
43
  )}
@@ -51,9 +51,7 @@ export const CollapsibleTextContainer = ({
51
51
  func: (data) => {
52
52
  return getColorFromData({
53
53
  data,
54
- getValue,
55
- key: "background_color",
56
- defaultColor: additionalStyles.backgroundColor,
54
+ valueFromLayout: additionalStyles.backgroundColor,
57
55
  });
58
56
  },
59
57
  propName: "backgroundColor",
@@ -35,23 +35,36 @@ function retrieveData(entry, func, args) {
35
35
  * @param {?[Object]} element.elements Optional array of nested elements to render within the current node
36
36
  * @returns {Object} inflated configuration, ready to be rendered by the master cell's element mapper
37
37
  */
38
-
39
38
  export function configInflater(
40
- entry,
41
- { type, style, additionalProps = {}, data = [], elements }
39
+ entry: any,
40
+ {
41
+ type,
42
+ style,
43
+ additionalProps = {},
44
+ data = [],
45
+ elements,
46
+ }: {
47
+ type: any;
48
+ style: any;
49
+ additionalProps?: Record<string, any>;
50
+ data?: Array<{ propName: string; func: Function; args: any[] }>;
51
+ elements?: any[];
52
+ }
42
53
  ) {
43
- const props = R.reduce(
44
- (acc, curr) =>
45
- R.assoc(curr.propName, retrieveData(entry, curr.func, curr.args), acc),
46
- additionalProps,
47
- data
54
+ const props = data.reduce(
55
+ (acc, curr) => {
56
+ acc[curr.propName] = retrieveData(entry, curr.func, curr.args);
57
+
58
+ return acc;
59
+ },
60
+ { ...additionalProps }
48
61
  );
49
62
 
50
63
  let adjustedElements;
51
64
 
52
65
  if (Array.isArray(elements)) {
53
66
  adjustedElements = elements.map((element) =>
54
- configInflater(entry, element as any)
67
+ configInflater(entry, element)
55
68
  );
56
69
  }
57
70
 
@@ -63,6 +76,14 @@ export function configInflater(
63
76
  };
64
77
  }
65
78
 
79
+ /**
80
+ * Memoized version of configInflater to cache results based on entry and masterCellConfig
81
+ */
82
+ const memoizedConfigInflater = R.memoizeWith(
83
+ (entry, config) => `${entry.id}-${JSON.stringify(config)}`,
84
+ configInflater
85
+ );
86
+
66
87
  /**
67
88
  * Return the proper view tree according to entry's content type and UI state.
68
89
  * Falls back to "default" content type or state.
@@ -83,7 +104,7 @@ function resolveElementsNode(entry, state, elements) {
83
104
  export function defaultDataAdapter(elements) {
84
105
  return function elementsBuilder({ entry, state = "default" }) {
85
106
  return resolveElementsNode(entry, state, elements).map((element) =>
86
- configInflater(entry, element)
107
+ memoizedConfigInflater(entry, element)
87
108
  );
88
109
  };
89
110
  }
@@ -53,7 +53,7 @@ export const useAsyncRendering = (viewRef: React.RefObject<View>): Return => {
53
53
  measure(viewRef?.current, ({ width, height }) => {
54
54
  setDimensions({
55
55
  width,
56
- height,
56
+ height: Math.ceil(height),
57
57
  });
58
58
  });
59
59
  })
@@ -52,6 +52,8 @@ export function masterCellBuilder({
52
52
  const { View } = componentsMap;
53
53
  const elementsBuilder = dataAdapter(cellConfiguration);
54
54
 
55
+ // This is very expensive operation
56
+ // Keep calls to minimum
55
57
  const hasFocusableInside = hasFocusableInsideBuilder(elementsBuilder);
56
58
 
57
59
  /**
@@ -84,7 +86,7 @@ export function masterCellBuilder({
84
86
  entry: item,
85
87
  state: getEntryState(state, entryIsSelected),
86
88
  }),
87
- [state, item, entryIsSelected]
89
+ [state, item?.id, entryIsSelected] // Assuming that item won't mutate
88
90
  );
89
91
 
90
92
  const wrapperRef = React.useRef(null);
@@ -9,4 +9,13 @@ describe("insertBetween", () => {
9
9
 
10
10
  expect(result).toEqual([1, "|", 2, "|", 3]);
11
11
  });
12
+
13
+ it("insertBetween", () => {
14
+ const separator = (index) => `separator:${index}`;
15
+ const items = [1, 2, 3];
16
+
17
+ const result = insertBetween(separator, items);
18
+
19
+ expect(result).toEqual([1, "separator:0", 2, "separator:1", 3]);
20
+ });
12
21
  });
@@ -1,5 +1,6 @@
1
1
  import React, { useEffect, useMemo } from "react";
2
2
  import * as R from "ramda";
3
+ import validateColor from "validate-color";
3
4
  import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
4
5
  import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
5
6
 
@@ -9,6 +10,7 @@ import { usePlayer } from "@applicaster/zapp-react-native-utils/appUtils/playerM
9
10
  import { PushTopicManager } from "@applicaster/zapp-react-native-bridge/PushNotifications/PushTopicManager";
10
11
  import { StorageMultiSelectProvider } from "@applicaster/zapp-react-native-bridge/ZappStorage/StorageMultiSelectProvider";
11
12
  import { getCellState } from "../../Cell/utils";
13
+ import { getColorFromData } from "@applicaster/zapp-react-native-utils/cellUtils";
12
14
 
13
15
  const hasElementSpecificViewType = (viewType) => (element) => {
14
16
  if (R.isNil(element)) {
@@ -47,44 +49,29 @@ export const hasElementsSpecificViewType = (viewType) => (elements) => {
47
49
  return R.any(hasElementSpecificViewType(viewType))(elements);
48
50
  };
49
51
 
50
- const isColorOrEmpty = (value) =>
51
- value === null ||
52
- value === undefined ||
53
- value === "" ||
54
- value.startsWith("#") ||
55
- value.startsWith("rgba") ||
56
- value === "transparent";
57
-
58
52
  function resolveColorForProp(entry, style, colorProp) {
59
- const colorValue = style[colorProp];
60
-
61
- if (isColorOrEmpty(colorValue)) {
62
- return style;
53
+ const colorFromProp = style[colorProp];
54
+ const nestedEntryValue = R.path(colorFromProp.split("."), entry);
55
+
56
+ if (
57
+ nestedEntryValue === undefined &&
58
+ !validateColor(colorFromProp.replace(".00", "")) // https://github.com/dreamyguy/validate-color/issues/44
59
+ ) {
60
+ logWarning(colorFromProp, style, entry, nestedEntryValue);
63
61
  }
64
62
 
65
- const pathParts = colorValue.split(".");
66
- let nestedEntryValue = entry;
67
-
68
- for (const part of pathParts) {
69
- if (nestedEntryValue === null || typeof nestedEntryValue !== "object") {
70
- logWarning(colorValue, style, entry, nestedEntryValue);
71
-
72
- return style;
73
- }
74
-
75
- nestedEntryValue = nestedEntryValue[part];
76
- }
63
+ const colorValue = getColorFromData({
64
+ data: entry,
65
+ valueFromLayout: colorFromProp,
66
+ });
77
67
 
78
- if (nestedEntryValue === undefined) {
79
- logWarning(colorValue, style, entry, nestedEntryValue);
68
+ if (!colorValue) {
69
+ logWarning(colorProp, style, entry, colorValue);
80
70
 
81
71
  return style;
82
72
  }
83
73
 
84
- // After successful traversal, set the value.
85
- style[colorProp] = nestedEntryValue;
86
-
87
- return style;
74
+ return { ...style, [colorProp]: colorValue };
88
75
  }
89
76
 
90
77
  export function resolveColor(entry, style) {
@@ -92,13 +79,17 @@ export function resolveColor(entry, style) {
92
79
  return style;
93
80
  }
94
81
 
95
- // TODO can be optimized to remove 3 O(n) loops
96
- const styleKeys = Object.keys(style);
97
- const colorKeys = styleKeys.filter((key) => /color/i.test(key));
82
+ // Iterate through style object keys and resolve any color properties
83
+ // non-color properties are passed through unchanged
84
+ const resolvedStyle = Object.keys(style).reduce((acc, key) => {
85
+ if (key.includes("color")) {
86
+ return { ...acc, ...resolveColorForProp(entry, acc, key) };
87
+ }
98
88
 
99
- return colorKeys.reduce((acc, value) => {
100
- return { ...style, ...resolveColorForProp(entry, acc, value) };
89
+ return acc;
101
90
  }, style);
91
+
92
+ return resolvedStyle;
102
93
  }
103
94
 
104
95
  export function isVideoPreviewEnabled({
@@ -125,13 +116,24 @@ export const useFilterChildren = <
125
116
 
126
117
  const filteredChildren = children.filter((child) => {
127
118
  const item = child.props.item;
128
- const action = actions.actions[child.props.pluginIdentifier];
119
+ const actionIdentifier = child.props.pluginIdentifier;
120
+ const action = actions.actions[actionIdentifier];
121
+
129
122
  // context value of specific plugin
130
- const currentValue = action.module.context._currentValue;
123
+ if (action?.module && action.module.context) {
124
+ const currentValue = action.module.context._currentValue;
125
+
126
+ return currentValue?.isActionAvailable
127
+ ? currentValue.isActionAvailable(item)
128
+ : true;
129
+ }
130
+
131
+ masterCellLogger.error({
132
+ message: `Action plugin for ${actionIdentifier} could not be found, check the configuration of your action button`,
133
+ data: { item, action: child.props.pluginIdentifier },
134
+ });
131
135
 
132
- return currentValue?.isActionAvailable
133
- ? currentValue.isActionAvailable(item)
134
- : true;
136
+ return false;
135
137
  });
136
138
 
137
139
  return filteredChildren;
@@ -342,13 +344,23 @@ export const useCellState = ({
342
344
  return getCellState({ focused, selected: _isSelected });
343
345
  };
344
346
 
347
+ const cache = new Map<string, any>();
348
+
345
349
  export const hasFocusableInsideBuilder = (elementsBuilder) => (item) => {
346
350
  const elements = elementsBuilder({ entry: item });
347
351
 
348
- return R.anyPass([
352
+ if (cache.has(item.id)) {
353
+ return cache.get(item.id);
354
+ }
355
+
356
+ const result = R.anyPass([
349
357
  hasElementsSpecificViewType("ButtonContainerView"),
350
358
  hasElementsSpecificViewType("FocusableView"),
351
359
  ])(elements);
360
+
361
+ cache.set(item.id, result);
362
+
363
+ return result;
352
364
  };
353
365
 
354
366
  export function getEntryState(state, selected) {
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
2
  import { View, StyleSheet } from "react-native";
3
+ import { MeasurementPortalContext } from "./MeasurementsPortal";
3
4
 
4
5
  type Props = {
5
6
  Component: React.ElementType;
@@ -19,13 +20,16 @@ const _MeasurementsPortal = (
19
20
  { Component, onLayout, componentProps, containerStyle }: Props,
20
21
  ref
21
22
  ) => (
22
- <View
23
- onLayout={onLayout}
24
- style={[styles.container, containerStyle]}
25
- ref={ref}
26
- >
27
- <Component {...componentProps} />
28
- </View>
23
+ // hack for cell to determine if cell is in measurement mode
24
+ <MeasurementPortalContext.Provider value={{}}>
25
+ <View
26
+ onLayout={onLayout}
27
+ style={[styles.container, containerStyle]}
28
+ ref={ref}
29
+ >
30
+ <Component {...componentProps} />
31
+ </View>
32
+ </MeasurementPortalContext.Provider>
29
33
  );
30
34
 
31
35
  export const MeasurementsPortal = React.forwardRef(_MeasurementsPortal);
@@ -35,7 +35,16 @@ const MeasurementsPortal = ({ Component, onLayout, componentProps }: Props) => {
35
35
  );
36
36
  };
37
37
 
38
- const MeasurementPortalContext = React.createContext(null);
38
+ type MeasurementPortalContextType = {
39
+ measureComponent?: (
40
+ comp: React.ElementType,
41
+ props: Record<any, any>
42
+ ) => Promise<any>;
43
+ measuringInProgress?: boolean;
44
+ };
45
+
46
+ const MeasurementPortalContext =
47
+ React.createContext<null | MeasurementPortalContextType>(null);
39
48
 
40
49
  const MeasurementsPortalContextProvider = ({ children }) => {
41
50
  const Component = React.useRef(View);
@@ -0,0 +1,57 @@
1
+ import * as React from "react";
2
+ import { isEmpty } from "ramda";
3
+
4
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
5
+ import { getPathAttributes } from "@applicaster/zapp-react-native-utils/navigationUtils";
6
+ import { FocusableGroup } from "@applicaster/zapp-react-native-ui-components/Components/FocusableGroup";
7
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
8
+ import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
9
+
10
+ import { Screen } from "../Screen/TV/index.web";
11
+ import { isLast } from "@applicaster/zapp-react-native-utils/arrayUtils";
12
+ import { ScreenContextProvider } from "../../Contexts/ScreenContext";
13
+
14
+ type Components = {
15
+ NavBar: React.ComponentType<any>;
16
+ Background: React.ComponentType<any>;
17
+ };
18
+
19
+ type Props = {
20
+ Components: Components;
21
+ };
22
+
23
+ export const StackNavigator = ({ Components }: Props) => {
24
+ const { mainStack } = useNavigation();
25
+
26
+ const renderScreen = ({ route, state }, index) => {
27
+ const pathAttributes = getPathAttributes({ pathname: route });
28
+
29
+ if (isEmpty(pathAttributes)) {
30
+ return null;
31
+ }
32
+
33
+ // HACK: Adding index to route to avoid conflicts in the navigator.
34
+ // Startup hooks are all using PUSH navigation action to navigate, but their routes are always like root routes.
35
+ // This means some hooks can have the same routes, e.g., ["hooks/context-setter", "/hooks/login-plug", "hooks/context-setter"].
36
+ const routeId = `${route}--${index}`;
37
+
38
+ return (
39
+ <FocusableGroup
40
+ id={route}
41
+ preferredFocus={isLast(index, mainStack.length)}
42
+ excludeFromFocusSearching
43
+ key={routeId}
44
+ >
45
+ <ScreenDataContext.Provider value={state}>
46
+ <PathnameContext.Provider value={route}>
47
+ <ScreenContextProvider pathname={route}>
48
+ <Screen route={route} Components={Components} />
49
+ </ScreenContextProvider>
50
+ </PathnameContext.Provider>
51
+ </ScreenDataContext.Provider>
52
+ </FocusableGroup>
53
+ );
54
+ };
55
+
56
+ return <>{mainStack.map(renderScreen)}</>;
57
+ };
@@ -0,0 +1 @@
1
+ export { StackNavigator } from "./StackNavigator";