@applicaster/zapp-react-native-ui-components 13.0.0-alpha.6525006318 → 13.0.0-alpha.6944415045

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 (98) hide show
  1. package/Components/AppContainer/__tests__/__snapshots__/AppContainer.test.js.snap +1 -1
  2. package/Components/AudioPlayer/__tests__/__snapshots__/Runtime.test.js.snap +4 -4
  3. package/Components/AudioPlayer/__tests__/__snapshots__/artWork.test.js.snap +3 -3
  4. package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayer.test.js.snap +6 -6
  5. package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayerLayout.test.js.snap +7 -7
  6. package/Components/AudioPlayer/__tests__/__snapshots__/channel.test.js.snap +3 -3
  7. package/Components/AudioPlayer/__tests__/__snapshots__/summary.test.js.snap +2 -2
  8. package/Components/AudioPlayer/__tests__/__snapshots__/title.test.js.snap +2 -2
  9. package/Components/BaseFocusable/index.tsx +65 -28
  10. package/Components/Cell/Cell.tsx +11 -9
  11. package/Components/Cell/CellWithFocusable.tsx +1 -1
  12. package/Components/Cell/TvOSCellComponent.tsx +23 -30
  13. package/Components/Cell/index.js +3 -1
  14. package/Components/CellRendererResolver/__tests__/__snapshots__/cellRendererResolver.test.js.snap +20 -20
  15. package/Components/CellRendererResolver/__tests__/cellRendererResolver.test.js +5 -3
  16. package/Components/ComponentResolver/__tests__/__snapshots__/componentResolver.test.js.snap +5 -5
  17. package/Components/ComponentResolver/__tests__/componentResolver.test.js +11 -9
  18. package/Components/DisplayState/__tests__/__snapshots__/displayState.test.js.snap +2 -2
  19. package/Components/Focusable/Focusable.tsx +0 -54
  20. package/Components/Focusable/FocusableTvOS.tsx +6 -2
  21. package/Components/FocusableList/index.tsx +25 -10
  22. package/Components/FocusableScrollView/index.tsx +39 -12
  23. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +76 -7
  24. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +53 -9
  25. package/Components/Layout/TV/NavBarContainer.tsx +8 -7
  26. package/Components/Layout/TV/__tests__/ScreenContainer.test.tsx +1 -0
  27. package/Components/Layout/TV/__tests__/__snapshots__/LayoutContainer.test.tsx.snap +1 -1
  28. package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +3 -3
  29. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +9 -9
  30. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +1 -1
  31. package/Components/Layout/TV/__tests__/index.test.tsx +7 -3
  32. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +1 -1
  33. package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/__snapshots__/Image.test.tsx.snap +3 -3
  34. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/__snapshots__/index.test.tsx.snap +1 -1
  35. package/Components/MasterCell/__tests__/__snapshots__/dataAdapter.test.js.snap +180 -180
  36. package/Components/MasterCell/__tests__/__snapshots__/elementMapper.test.js.snap +7 -7
  37. package/Components/MasterCell/__tests__/__snapshots__/masterCell.test.js.snap +34 -34
  38. package/Components/MasterCell/hooks/useAsyncRendering/index.ts +2 -2
  39. package/Components/NativeFocusables/{index.js → index.ts} +4 -2
  40. package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +7 -7
  41. package/Components/OfflineHandler/__tests__/index.test.tsx +28 -25
  42. package/Components/PlayerContainer/PlayerContainer.tsx +5 -11
  43. package/Components/PlayerContainer/PlayerContainerContext.tsx +9 -0
  44. package/Components/River/RefreshControl.tsx +1 -1
  45. package/Components/River/TV/index.tsx +6 -1
  46. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +17 -17
  47. package/Components/River/__tests__/__snapshots__/river.test.js.snap +12 -12
  48. package/Components/River/__tests__/componentsMap.test.js +47 -12
  49. package/Components/RouteManager/__tests__/__snapshots__/routeManager.test.js.snap +1 -1
  50. package/Components/RouteManager/__tests__/__snapshots__/testId.test.js.snap +1 -1
  51. package/Components/Screen/__tests__/Screen.test.tsx +41 -27
  52. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +4 -4
  53. package/Components/ScreenResolver/__tests__/__snapshots__/screenResolver.test.js.snap +2 -2
  54. package/Components/ScreenResolver/__tests__/screenResolver.test.js +31 -27
  55. package/Components/Tabs/Tab.tsx +1 -0
  56. package/Components/TextInputTv/__tests__/TextInputTv.test.js +42 -42
  57. package/Components/TextInputTv/__tests__/__snapshots__/TextInputTv.test.js.snap +7 -0
  58. package/Components/TextInputTv/index.tsx +2 -2
  59. package/Components/Touchable/__tests__/__snapshots__/touchable.test.tsx.snap +2 -2
  60. package/Components/Transitioner/__tests__/__snapshots__/AnimationManager.test.js.snap +26 -26
  61. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +9 -9
  62. package/Components/Transitioner/__tests__/__snapshots__/config.test.js.snap +20 -20
  63. package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +2 -2
  64. package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +12 -7
  65. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +6 -6
  66. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +5 -1
  67. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +5 -1
  68. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +1 -1
  69. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +4 -10
  70. package/Components/VideoModal/ModalAnimation/index.ts +2 -1
  71. package/Components/VideoModal/ModalAnimation/useModalAnimationContext.ts +6 -0
  72. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +5 -2
  73. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +12 -9
  74. package/Components/VideoModal/__tests__/__snapshots__/PlayerDetails.test.tsx.snap +4 -4
  75. package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +78 -78
  76. package/Components/VideoModal/utils.ts +2 -4
  77. package/Components/Viewport/ViewportAware/__tests__/__snapshots__/viewportAware.test.js.snap +2 -2
  78. package/Components/Viewport/ViewportTracker/__tests__/__snapshots__/viewportTracker.test.js.snap +1 -1
  79. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +1 -0
  80. package/Components/ZappUIComponent/__tests__/__snapshots__/ZappUIComponent.test.js.snap +11 -11
  81. package/Components/default-cell-renderer/__tests__/__snapshots__/defaultCellRenderer.test.tsx.snap +30 -30
  82. package/Contexts/ComponentsMapOffsetContext/index.tsx +46 -0
  83. package/Contexts/ConfigutaionContext/__tests__/__snapshots__/ConfigurationProvider.test.tsx.snap +1 -1
  84. package/Contexts/FocusableGroupContext/withFocusableContext.tsx +18 -11
  85. package/Decorators/Analytics/{index.js → index.tsx} +11 -11
  86. package/Decorators/Navigator/__tests__/__snapshots__/navigator.test.js.snap +2 -2
  87. package/Decorators/RiverFeedLoader/__tests__/__snapshots__/riverFeedLoader.test.tsx.snap +77 -77
  88. package/Decorators/RiverFeedLoader/__tests__/riverFeedLoader.test.tsx +34 -39
  89. package/Decorators/RiverFeedLoader/__tests__/utils.test.ts +0 -9
  90. package/Decorators/RiverFeedLoader/index.tsx +1 -1
  91. package/Decorators/RiverFeedLoader/utils/getDatasourceUrl.ts +39 -0
  92. package/Decorators/RiverFeedLoader/utils/index.ts +29 -0
  93. package/Decorators/RiverFeedLoader/utils/usePipesContexts.ts +40 -0
  94. package/Decorators/RiverResolver/__tests__/__snapshots__/riverResolver.test.tsx.snap +5 -5
  95. package/Decorators/RiverResolver/__tests__/riverResolver.test.tsx +16 -10
  96. package/Decorators/ZappPipesDataConnector/index.tsx +1 -1
  97. package/package.json +12 -6
  98. package/Decorators/RiverFeedLoader/utils.ts +0 -100
@@ -4,19 +4,21 @@ import { shallow } from "enzyme";
4
4
  import { shallowToJson } from "enzyme-to-json";
5
5
  import configureStore from "redux-mock-store";
6
6
 
7
- const logger = {
7
+ const mockLogger = {
8
8
  warning: jest.fn(),
9
9
  };
10
10
 
11
11
  jest.mock("../../../Helpers/logger", () => ({
12
12
  componentsLogger: {
13
- addSubsystem: jest.fn(() => logger),
13
+ addSubsystem: jest.fn(() => mockLogger),
14
14
  },
15
15
  }));
16
16
 
17
- jest.mock("../../default-cell-renderer", () =>
18
- jest.fn((prop) => <View whoAmI="default renderer" someProp={prop} />)
19
- );
17
+ jest.mock("../../default-cell-renderer", () => {
18
+ const View = jest.requireActual("react-native").View;
19
+
20
+ return jest.fn((prop) => <View whoAmI="default renderer" someProp={prop} />);
21
+ });
20
22
 
21
23
  const mock_rtl_flag = false;
22
24
 
@@ -48,7 +50,7 @@ function clearAllMocks() {
48
50
  SomeComponent.mockClear();
49
51
  decorators.mockClear();
50
52
  renderFunction.mockClear();
51
- logger.warning.mockClear();
53
+ mockLogger.warning.mockClear();
52
54
  }
53
55
 
54
56
  describe("ComponentResolver", () => {
@@ -104,16 +106,16 @@ describe("ComponentResolverComponent", () => {
104
106
  expect(shallowToJson(wrapper)).toMatchSnapshot();
105
107
  expect(wrapper.isEmptyRender()).toBe(true);
106
108
 
107
- expect(logger.warning).toHaveBeenCalledTimes(2);
109
+ expect(mockLogger.warning).toHaveBeenCalledTimes(2);
108
110
 
109
- expect(logger.warning).toHaveBeenNthCalledWith(
111
+ expect(mockLogger.warning).toHaveBeenNthCalledWith(
110
112
  1,
111
113
  expect.objectContaining({
112
114
  message: "Could not resolve cell builder plugin",
113
115
  })
114
116
  );
115
117
 
116
- expect(logger.warning).toHaveBeenNthCalledWith(
118
+ expect(mockLogger.warning).toHaveBeenNthCalledWith(
117
119
  2,
118
120
  expect.objectContaining({
119
121
  message: warningMessage,
@@ -1,7 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
3
  exports[`DISPLAY_STATES matches the snapshot 1`] = `
4
- Object {
4
+ {
5
5
  "CONTENT": "CONTENT",
6
6
  "CONTROLS": "CONTROLS",
7
7
  "DISCOVERY": "DISCOVERY",
@@ -9,7 +9,7 @@ Object {
9
9
  `;
10
10
 
11
11
  exports[`DisplayStateContext has the correct properties 1`] = `
12
- Object {
12
+ {
13
13
  "Consumer": [MockFunction],
14
14
  "Provider": [MockFunction],
15
15
  "withConsumer": [MockFunction],
@@ -1,5 +1,4 @@
1
1
  import * as React from "react";
2
- import * as R from "ramda";
3
2
 
4
3
  import { BaseFocusable } from "../BaseFocusable";
5
4
  import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
@@ -42,8 +41,6 @@ class Focusable extends BaseFocusable<Props> {
42
41
  this.resetLongPressTimeout = this.resetLongPressTimeout.bind(this);
43
42
  this.longPress = this.longPress.bind(this);
44
43
  this.press = this.press.bind(this);
45
- this.focus = this.focus.bind(this);
46
- this.blur = this.blur.bind(this);
47
44
  }
48
45
 
49
46
  /**
@@ -55,37 +52,6 @@ class Focusable extends BaseFocusable<Props> {
55
52
  return this.preferredFocus();
56
53
  }
57
54
 
58
- /**
59
- * Sets the focus on this item. Will trigger sequentially a sequence of
60
- * functions (willReceiveFocus, focus, hasReceivedFocus). If these functions (defined in the Focusable
61
- * Item underlying component) return promises, execution will wait before it proceeds to the next. This
62
- * is useful for triggering sequential operations that specifically require to fully run before or after
63
- * focus is actually set on that item.
64
- * @param {string} scrollDirection string representation of the direction of the navigation which landed
65
- * to this item being focused
66
- */
67
- setFocus(scrollDirection) {
68
- const focusMethods = [
69
- this.willReceiveFocus,
70
- this.focus,
71
- this.hasReceivedFocus,
72
- ];
73
-
74
- const self = this;
75
-
76
- return R.reduce(
77
- (sequence, method) => {
78
- return sequence
79
- .then(() => method.apply(self, [scrollDirection]))
80
- .catch((e) => {
81
- throw e;
82
- });
83
- },
84
- Promise.resolve(),
85
- focusMethods
86
- );
87
- }
88
-
89
55
  startLongPressTimeout() {
90
56
  this.longPressTimeout = setTimeout(() => {
91
57
  this.longPress(null);
@@ -102,26 +68,6 @@ class Focusable extends BaseFocusable<Props> {
102
68
  }
103
69
  }
104
70
 
105
- /**
106
- * will invoke the underlying component's focus method
107
- * @param {Object} scrollDirection
108
- * @returns {Promise}
109
- */
110
- focus(scrollDirection) {
111
- return this.onFocus(this, scrollDirection); // invokeComponentMethod(this, "onFocus", scrollDirection);
112
- }
113
-
114
- /**
115
- * will invoke the underlying component's blur method
116
- * @param {Object} scrollDirection
117
- * @returns {Promise}
118
- */
119
- blur(
120
- scrollDirection?: FocusManager.Web.Direction | FocusManager.IOS.Direction
121
- ) {
122
- return this.onBlur(this, scrollDirection);
123
- }
124
-
125
71
  /**
126
72
  * will invoke the underlying component's press method
127
73
  * @param {Object} keyEvent
@@ -9,7 +9,7 @@ import {
9
9
  focusManager,
10
10
  forceFocusableFocus,
11
11
  } from "@applicaster/zapp-react-native-utils/appUtils/focusManager/index.ios";
12
- import { findNodeHandle } from "react-native";
12
+ import { findNodeHandle, ViewStyle } from "react-native";
13
13
 
14
14
  function noop() {}
15
15
 
@@ -35,6 +35,10 @@ type Props = {
35
35
  forceFocus?: boolean;
36
36
  initialFocus?: boolean;
37
37
  onLayout?: (e: any) => void;
38
+ willReceiveFocus: () => void;
39
+ hasReceivedFocus: () => void;
40
+ offsetUpdater: (arg1: string, arg2: number) => number;
41
+ style: ViewStyle;
38
42
  };
39
43
 
40
44
  export class Focusable extends BaseFocusable<Props> {
@@ -90,7 +94,7 @@ export class Focusable extends BaseFocusable<Props> {
90
94
  onBlur(nativeEvent);
91
95
  }
92
96
 
93
- setFocus(direction, callback) {
97
+ setFocus(_direction, callback) {
94
98
  const focusMethods = [
95
99
  { method: this.willReceiveFocus },
96
100
  { method: this.focus, args: [callback] },
@@ -15,6 +15,7 @@ import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
15
15
 
16
16
  import { useParentFocus, useCheckItemIdsForUnique } from "./hooks";
17
17
  import { FocusableListItemWrapper } from "./FocusableListItemWrapper";
18
+ import { FocusableScrollView } from "../FocusableScrollView";
18
19
 
19
20
  const mapIndexed = R.addIndex(R.map);
20
21
 
@@ -54,6 +55,7 @@ export type Props<ItemT> = FlatListProps<ItemT> & {
54
55
  disableNextFocusUp?: boolean;
55
56
  disableNextFocusLeft?: boolean;
56
57
  disableNextFocusRight?: boolean;
58
+ useScrollView?: boolean;
57
59
  } & ParentFocus;
58
60
 
59
61
  function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
@@ -87,8 +89,8 @@ function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
87
89
  initialFocusDirection = "down",
88
90
  data = [],
89
91
  // eslint-disable-next-line unused-imports/no-unused-vars
90
- onAllComponentsLoaded, // TODO: re-implement it
91
92
  omitPropsPropagation = [],
93
+ useScrollView = false,
92
94
  } = props;
93
95
 
94
96
  useCheckItemIdsForUnique({ componentId: props.id, items: data });
@@ -274,6 +276,7 @@ function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
274
276
  "initialFocusDirection",
275
277
  "withStateMemory",
276
278
  "useSequentialLoading",
279
+ "useScrollView",
277
280
  ...omitPropsPropagation,
278
281
  ],
279
282
  R.__
@@ -296,15 +299,27 @@ function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
296
299
  return (
297
300
  // @ts-ignore
298
301
  <ChildrenFocusDeactivatorView flex={1}>
299
- <FlatList
300
- focusable={false}
301
- scrollEnabled={false}
302
- ref={ref}
303
- {...getFlatListProps(props)}
304
- renderItem={renderItem}
305
- onEndReached={onEndReached}
306
- initialNumToRender={initialNumToRender}
307
- />
302
+ {useScrollView ? (
303
+ <FocusableScrollView
304
+ ref={ref}
305
+ {...getFlatListProps(props)}
306
+ onEndReached={onEndReached}
307
+ initialNumToRender={initialNumToRender}
308
+ renderItem={renderItem}
309
+ focused={focused}
310
+ data={data}
311
+ />
312
+ ) : (
313
+ <FlatList
314
+ focusable={false}
315
+ scrollEnabled={false}
316
+ ref={ref}
317
+ {...getFlatListProps(props)}
318
+ renderItem={renderItem}
319
+ onEndReached={onEndReached}
320
+ initialNumToRender={initialNumToRender}
321
+ />
322
+ )}
308
323
  </ChildrenFocusDeactivatorView>
309
324
  );
310
325
  }
@@ -11,6 +11,13 @@ import {
11
11
  useInitialFocus,
12
12
  } from "@applicaster/zapp-react-native-utils/focusManager";
13
13
 
14
+ export type FocusableScrollViewRenderItem = (info: {
15
+ item: ZappUIComponent;
16
+ index: number;
17
+ focused: boolean;
18
+ parentFocus: ParentFocus;
19
+ }) => React.ReactElement;
20
+
14
21
  export type Props = ScrollViewProps & {
15
22
  id?: number | string;
16
23
  horizontal?: boolean;
@@ -32,17 +39,27 @@ export type Props = ScrollViewProps & {
32
39
  initialFocusDirection?: FocusManager.Android.FocusNavigationDirections;
33
40
  onAllComponentsLoaded?: () => void;
34
41
  omitPropsPropagation?: Array<keyof FlatListProps<any>>;
35
- renderItem: (info: {
36
- item: ZappUIComponent;
37
- index: number;
38
- focused: boolean;
39
- parentFocus: ParentFocus;
40
- }) => React.ReactElement;
42
+ renderItem: FocusableScrollViewRenderItem;
41
43
  } & ParentFocus;
42
44
 
43
45
  type State = boolean[];
44
46
  type Action = { index?: number; isFocusable: boolean; type?: string };
45
47
 
48
+ const unwrapArray = (maybeArray) =>
49
+ Array.isArray(maybeArray) ? maybeArray[0] : maybeArray;
50
+
51
+ function getEntry<T>(data: T | T[], index: unknown): T {
52
+ let entry;
53
+
54
+ if (R.isNil(index)) {
55
+ entry = unwrapArray(data);
56
+ } else if (typeof index === "number") {
57
+ entry = unwrapArray(data[index]);
58
+ }
59
+
60
+ return entry;
61
+ }
62
+
46
63
  const focusableStateReducer = (
47
64
  state: State,
48
65
  { index = null, isFocusable, type = null }: Action
@@ -73,7 +90,7 @@ const extendScrollViewRef = (_ref, childCompsMeasurementsMap) => {
73
90
  };
74
91
 
75
92
  _ref.scrollToIndex = (params) => {
76
- const { index, viewOffset } = params;
93
+ const { index, viewOffset = 0 } = params;
77
94
 
78
95
  const itemByIndex = R.find(R.propEq("index", index))(
79
96
  R.values(childCompsMeasurementsMap)
@@ -129,8 +146,11 @@ function FocusableScrollViewComponent(props: Props, ref) {
129
146
  );
130
147
 
131
148
  const getFocusableEntryId = React.useCallback(
132
- (_entry: ZappEntry, index?: number) => {
133
- const entry = R.isNil(index) ? _entry : data[index];
149
+ (_entry: ZappEntry | null, index?: number) => {
150
+ const entry: { id?: string } = getEntry(
151
+ R.isNil(index) ? _entry : data,
152
+ index
153
+ );
134
154
 
135
155
  return entry ? `${props.id}--${entry?.id}` : undefined;
136
156
  },
@@ -273,11 +293,18 @@ function FocusableScrollViewComponent(props: Props, ref) {
273
293
  const renderItem = React.useCallback(
274
294
  (item, index) => {
275
295
  const renderArgs = { item, index };
276
- const id = `${props.id}--${renderArgs?.item?.id}`;
277
- const nextFocus = getNextFocus(renderArgs?.index);
296
+
297
+ const id = getFocusableEntryId(
298
+ Array.isArray(item) ? item[0] : item,
299
+ index
300
+ );
301
+
302
+ const nextFocus = getNextFocus(index);
278
303
 
279
304
  const onItemLayout = (event) => {
280
- childCompsMeasurementsMap.current[item.id] = {
305
+ childCompsMeasurementsMap.current[
306
+ Array.isArray(item) ? index : item.id
307
+ ] = {
281
308
  index,
282
309
  layout: event.nativeEvent.layout,
283
310
  };
@@ -1,3 +1,4 @@
1
+ import * as React from "react";
1
2
  import { renderHook } from "@testing-library/react-hooks";
2
3
 
3
4
  import {
@@ -9,6 +10,51 @@ import {
9
10
  import * as redux from "react-redux";
10
11
  import * as layoutPresets from "@applicaster/zapp-react-native-redux/hooks/useLayoutPresets";
11
12
  import * as pipesFeeds from "@applicaster/zapp-react-native-redux/hooks/useZappPipesFeeds";
13
+ import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
14
+ import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
15
+
16
+ import { Provider } from "react-redux";
17
+ import configureStore from "redux-mock-store";
18
+
19
+ jest.mock(
20
+ "@applicaster/zapp-react-native-utils/reactHooks/navigation/useRoute",
21
+ () => ({
22
+ useRoute: jest.fn().mockReturnValue({
23
+ pathname: "/home",
24
+ }),
25
+ })
26
+ );
27
+
28
+ const homeStack = {
29
+ route: "/home",
30
+ state: {
31
+ screen: { id: "123" },
32
+ entry: { id: "abc" },
33
+ },
34
+ };
35
+
36
+ const mainStackNavigator = {
37
+ getStackForPathname: jest.fn().mockReturnValue(homeStack),
38
+ modalState: {
39
+ screen: {
40
+ id: "modal-1",
41
+ },
42
+ },
43
+ };
44
+
45
+ const store = configureStore()({});
46
+
47
+ const wrapper = ({ children }) => (
48
+ <Provider store={store}>
49
+ <NavigationContext.Provider
50
+ value={{ ...mainStackNavigator, currentRoute: homeStack.route }}
51
+ >
52
+ <PathnameContext.Provider value={homeStack.route}>
53
+ {children}
54
+ </PathnameContext.Provider>
55
+ </NavigationContext.Provider>
56
+ </Provider>
57
+ );
12
58
 
13
59
  describe("getTransformedPreset should return the passed components if smartComponents is empty", () => {
14
60
  describe("getTransformedPreset function", () => {
@@ -94,9 +140,13 @@ describe("getTransformedPreset should return the passed components if smartCompo
94
140
  },
95
141
  };
96
142
 
143
+ const mockUrlsMap = {
144
+ [mockSmartComp.id]: mockSmartComp.data.source,
145
+ };
146
+
97
147
  it("should return the component itself if its component_type is not SMART_COMPONENT_TYPE", () => {
98
148
  expect(
99
- enrichComponent(mockComp, 0, mockFeeds, mockLayoutPresets)
149
+ enrichComponent(mockComp, 0, mockFeeds, mockLayoutPresets, mockUrlsMap)
100
150
  ).toEqual([mockComp]);
101
151
  });
102
152
 
@@ -106,8 +156,18 @@ describe("getTransformedPreset should return the passed components if smartCompo
106
156
  data: { source: "missing_source" },
107
157
  };
108
158
 
159
+ const missing_source_urls_map = {
160
+ [missing_source_comp.id]: missing_source_comp.data.source,
161
+ };
162
+
109
163
  expect(
110
- enrichComponent(missing_source_comp, 0, mockFeeds, mockLayoutPresets)
164
+ enrichComponent(
165
+ missing_source_comp,
166
+ 0,
167
+ mockFeeds,
168
+ mockLayoutPresets,
169
+ missing_source_urls_map
170
+ )
111
171
  ).toEqual(null);
112
172
  });
113
173
 
@@ -116,7 +176,8 @@ describe("getTransformedPreset should return the passed components if smartCompo
116
176
  mockSmartComp,
117
177
  0,
118
178
  mockFeeds,
119
- mockLayoutPresets
179
+ mockLayoutPresets,
180
+ mockUrlsMap
120
181
  );
121
182
 
122
183
  expect(Array.isArray(result)).toBe(true);
@@ -262,7 +323,9 @@ describe("getTransformedPreset should return the passed components if smartCompo
262
323
 
263
324
  mockUseLayoutPresets.mockReturnValue({});
264
325
 
265
- const { result } = renderHook(() => useCurationAPI(mockComponents));
326
+ const { result } = renderHook(() => useCurationAPI(mockComponents), {
327
+ wrapper,
328
+ });
266
329
 
267
330
  // if there are no smart components, it should return the original array
268
331
  expect(result.current).toEqual(mockComponents);
@@ -313,7 +376,9 @@ describe("getTransformedPreset should return the passed components if smartCompo
313
376
 
314
377
  mockUseLayoutPresets.mockReturnValue(mockLayoutPresets);
315
378
 
316
- const { result } = renderHook(() => useCurationAPI(mockComponents));
379
+ const { result } = renderHook(() => useCurationAPI(mockComponents), {
380
+ wrapper,
381
+ });
317
382
 
318
383
  expect(result.current).toEqual(mockTransformedComponents);
319
384
  });
@@ -383,7 +448,9 @@ describe("getTransformedPreset should return the passed components if smartCompo
383
448
 
384
449
  mockUseLayoutPresets.mockReturnValue(mockLayoutPresets);
385
450
 
386
- const { result } = renderHook(() => useCurationAPI(mockComponents));
451
+ const { result } = renderHook(() => useCurationAPI(mockComponents), {
452
+ wrapper,
453
+ });
387
454
 
388
455
  expect(result.current).toEqual(mockTransformedComponents);
389
456
  });
@@ -434,7 +501,9 @@ describe("getTransformedPreset should return the passed components if smartCompo
434
501
  const mockUseLayoutPresets = jest.spyOn(layoutPresets, "useLayoutPresets");
435
502
  mockUseLayoutPresets.mockReturnValue(mockLayoutPresets);
436
503
 
437
- const { result } = renderHook(() => useCurationAPI(mockComponents));
504
+ const { result } = renderHook(() => useCurationAPI(mockComponents), {
505
+ wrapper,
506
+ });
438
507
 
439
508
  expect(result.current).toEqual(mockTransformedComponents);
440
509
  });
@@ -9,6 +9,18 @@ import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
9
9
  import { isEmptyOrNil } from "@applicaster/zapp-react-native-utils/cellUtils";
10
10
  import { Categories } from "./logger";
11
11
  import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
12
+ import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useRoute";
13
+ import {
14
+ ZappPipesEntryContext,
15
+ ZappPipesScreenContext,
16
+ ZappPipesSearchContext,
17
+ } from "@applicaster/zapp-react-native-ui-components/Contexts";
18
+
19
+ import {
20
+ getInflatedDataSourceUrl,
21
+ getSearchContext,
22
+ } from "@applicaster/zapp-react-native-utils/reactHooks/feed/useInflatedUrl";
23
+
12
24
  import { produce } from "immer";
13
25
  // types reference
14
26
 
@@ -20,6 +32,7 @@ type LayoutPresets = PresetsMapping["presets_mappings"];
20
32
 
21
33
  const SMART_COMPONENT_TYPE = "quick-brick-smart-component";
22
34
  const SOURCE_PATH = ["data", "source"];
35
+ const MAPPING_PATH = ["data", "mapping"];
23
36
 
24
37
  const isSmartComponent = (component) =>
25
38
  component.component_type === SMART_COMPONENT_TYPE;
@@ -58,13 +71,14 @@ export const enrichComponent = (
58
71
  comp: ZappUIComponent,
59
72
  index: number,
60
73
  feeds: Feeds,
61
- layoutPresets: LayoutPresets
74
+ layoutPresets: LayoutPresets,
75
+ urlsMap: { [key: string]: string }
62
76
  ): ZappUIComponent[] | null => {
63
77
  if (!isSmartComponent(comp)) {
64
78
  return [comp];
65
79
  }
66
80
 
67
- const presets = prop<string[]>(path(SOURCE_PATH, comp), feeds);
81
+ const presets = prop<string[]>(urlsMap[comp.id], feeds);
68
82
 
69
83
  if (presets && presets.data && presets.data.entry) {
70
84
  return presets.data.entry
@@ -113,11 +127,35 @@ export const useCurationAPI = (
113
127
  [components]
114
128
  );
115
129
 
116
- const urls = useMemo<string[]>(
117
- () =>
118
- smartComponents?.map?.((component) => path(SOURCE_PATH, component)) ?? [],
119
- [smartComponents]
120
- );
130
+ const { pathname } = useRoute();
131
+ const [entryContext] = ZappPipesEntryContext.useZappPipesContext(pathname);
132
+ const [searchContext] = ZappPipesSearchContext.useZappPipesContext();
133
+ const [screenContext] = ZappPipesScreenContext.useZappPipesContext();
134
+
135
+ const urlsMap = useMemo<{ [key: string]: string }>(() => {
136
+ const map = {};
137
+
138
+ smartComponents?.forEach?.((component) => {
139
+ const url = path(SOURCE_PATH, component);
140
+ const mapping = path(MAPPING_PATH, component);
141
+
142
+ map[component.id] = mapping
143
+ ? getInflatedDataSourceUrl({
144
+ source: url,
145
+ contexts: {
146
+ entry: entryContext,
147
+ screen: screenContext,
148
+ search: getSearchContext(searchContext, mapping),
149
+ },
150
+ mapping,
151
+ })
152
+ : url;
153
+ });
154
+
155
+ return map;
156
+ }, [smartComponents, entryContext, screenContext, searchContext]);
157
+
158
+ const urls = useMemo<string[]>(() => Object.values(urlsMap), [urlsMap]);
121
159
 
122
160
  useEffect(() => {
123
161
  urls.forEach((url, index) => {
@@ -138,11 +176,17 @@ export const useCurationAPI = (
138
176
  if (!components) return [];
139
177
 
140
178
  return components.reduce((acc, comp, index) => {
141
- const enrichedComp = enrichComponent(comp, index, feeds, layoutPresets);
179
+ const enrichedComp = enrichComponent(
180
+ comp,
181
+ index,
182
+ feeds,
183
+ layoutPresets,
184
+ urlsMap
185
+ );
142
186
 
143
187
  return enrichedComp ? [...acc, ...enrichedComp] : acc;
144
188
  }, [] as Array<ZappUIComponent>);
145
- }, [components, feeds, layoutPresets]);
189
+ }, [components, feeds, layoutPresets, urlsMap]);
146
190
 
147
191
  return getFinalComponents(
148
192
  enrichedComponents,
@@ -1,7 +1,5 @@
1
1
  import * as React from "react";
2
2
  import { View, StyleSheet } from "react-native";
3
- import { ScreenLayoutContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenLayoutContext";
4
- import { ifEmptyUseFallback } from "@applicaster/zapp-react-native-utils/cellUtils";
5
3
  import { useCurrentScreenData } from "@applicaster/zapp-react-native-utils/reactHooks/screen";
6
4
  import { useScreenConfiguration } from "../../River/useScreenConfiguration";
7
5
 
@@ -12,12 +10,15 @@ type Props = {
12
10
  };
13
11
 
14
12
  const styles = StyleSheet.create({
15
- container: { position: "absolute", top: 0, zIndex: 10, width: 1920 },
13
+ container: {
14
+ position: "absolute",
15
+ top: 0,
16
+ zIndex: 10,
17
+ width: 1920,
18
+ },
16
19
  });
17
20
 
18
21
  export const NavBarContainer = ({ children, isVisible, onReady }: Props) => {
19
- const screenLayout = React.useContext(ScreenLayoutContext);
20
- const screenMarginTop = screenLayout?.screenMarginTop || 0;
21
22
  const screen = useCurrentScreenData();
22
23
  const screenConfig = useScreenConfiguration(screen?.id);
23
24
 
@@ -26,9 +27,9 @@ export const NavBarContainer = ({ children, isVisible, onReady }: Props) => {
26
27
  // limits the height of the focusable container of the TopMenuBarTV component
27
28
  // to prevent it from being overlapped by the screen content,
28
29
  // as it makes TopMenuBarTV unfocusable on tvOS
29
- maxHeight: ifEmptyUseFallback(screenConfig?.marginTop, screenMarginTop),
30
+ maxHeight: 1,
30
31
  }),
31
- [screenLayout, screenConfig]
32
+ [screenConfig]
32
33
  );
33
34
 
34
35
  React.useEffect(() => {
@@ -39,6 +39,7 @@ jest.mock(
39
39
  );
40
40
 
41
41
  jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
42
+ ...jest.requireActual<any>("@applicaster/zapp-react-native-utils/theme"),
42
43
  useTheme: () => ({}),
43
44
  }));
44
45
 
@@ -3,7 +3,7 @@
3
3
  exports[`LayoutContainer renders 1`] = `
4
4
  <View
5
5
  style={
6
- Object {
6
+ {
7
7
  "flex": 1,
8
8
  "height": 1080,
9
9
  "width": 1920,
@@ -3,14 +3,14 @@
3
3
  exports[`NavBarContainer renders 1`] = `
4
4
  <View
5
5
  style={
6
- Array [
7
- Object {
6
+ [
7
+ {
8
8
  "position": "absolute",
9
9
  "top": 0,
10
10
  "width": 1920,
11
11
  "zIndex": 10,
12
12
  },
13
- Object {
13
+ {
14
14
  "maxHeight": 10,
15
15
  },
16
16
  ]