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

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 (169) hide show
  1. package/Components/AppContainer/__tests__/AppContainer.test.js +4 -6
  2. package/Components/AppContainer/__tests__/__snapshots__/AppContainer.test.js.snap +1 -1
  3. package/Components/AudioPlayer/__tests__/Runtime.test.js +5 -8
  4. package/Components/AudioPlayer/__tests__/__snapshots__/Runtime.test.js.snap +4 -4
  5. package/Components/AudioPlayer/__tests__/__snapshots__/artWork.test.js.snap +3 -3
  6. package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayer.test.js.snap +56 -113
  7. package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayerLayout.test.js.snap +39 -23
  8. package/Components/AudioPlayer/__tests__/__snapshots__/channel.test.js.snap +3 -3
  9. package/Components/AudioPlayer/__tests__/__snapshots__/summary.test.js.snap +2 -2
  10. package/Components/AudioPlayer/__tests__/__snapshots__/title.test.js.snap +2 -2
  11. package/Components/AudioPlayer/__tests__/artWork.test.js +3 -5
  12. package/Components/AudioPlayer/__tests__/audioPlayer.test.js +3 -5
  13. package/Components/AudioPlayer/__tests__/audioPlayerLayout.test.js +7 -8
  14. package/Components/AudioPlayer/__tests__/channel.test.js +3 -5
  15. package/Components/AudioPlayer/__tests__/summary.test.js +3 -5
  16. package/Components/AudioPlayer/__tests__/title.test.js +3 -5
  17. package/Components/BaseFocusable/index.ios.ts +1 -1
  18. package/Components/BaseFocusable/index.tsx +67 -31
  19. package/Components/Cell/Cell.tsx +15 -9
  20. package/Components/Cell/CellWithFocusable.ios.tsx +126 -0
  21. package/Components/Cell/CellWithFocusable.tsx +44 -59
  22. package/Components/Cell/TvOSCellComponent.tsx +23 -30
  23. package/Components/Cell/__tests__/CellWIthFocusable.test.js +13 -6
  24. package/Components/Cell/index.js +3 -1
  25. package/Components/CellRendererResolver/__tests__/cellRendererResolver.test.js +50 -50
  26. package/Components/ComponentResolver/__tests__/__snapshots__/componentResolver.test.js.snap +1 -42
  27. package/Components/ComponentResolver/__tests__/componentResolver.test.js +26 -30
  28. package/Components/ContentScreen/__tests__/contentScreen.test.js +3 -3
  29. package/Components/DisplayState/__tests__/__snapshots__/displayState.test.js.snap +2 -2
  30. package/Components/ErrorScreen/index.tsx +6 -6
  31. package/Components/Focusable/Focusable.tsx +1 -54
  32. package/Components/Focusable/FocusableTvOS.tsx +6 -2
  33. package/Components/Focusable/Touchable.tsx +19 -20
  34. package/Components/Focusable/index.android.tsx +10 -3
  35. package/Components/FocusableList/index.tsx +26 -10
  36. package/Components/FocusableScrollView/index.tsx +43 -13
  37. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +76 -7
  38. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +53 -9
  39. package/Components/Layout/TV/NavBarContainer.tsx +19 -23
  40. package/Components/Layout/TV/__tests__/ScreenContainer.test.tsx +1 -0
  41. package/Components/Layout/TV/__tests__/__snapshots__/LayoutContainer.test.tsx.snap +1 -1
  42. package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +6 -5
  43. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +12 -11
  44. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +1 -1
  45. package/Components/Layout/TV/__tests__/index.test.tsx +7 -3
  46. package/Components/MasterCell/DefaultComponents/BorderContainerView/__tests__/index.test.tsx +66 -0
  47. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +4 -1
  48. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +6 -12
  49. package/Components/MasterCell/DefaultComponents/ImageBorderContainer/__tests__/index.test.ts +93 -0
  50. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +2 -2
  51. package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/__snapshots__/Image.test.tsx.snap +3 -3
  52. package/Components/MasterCell/DefaultComponents/SecondaryImage/utils.ts +1 -1
  53. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
  54. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/__snapshots__/index.test.tsx.snap +1 -1
  55. package/Components/MasterCell/__tests__/__snapshots__/dataAdapter.test.js.snap +180 -180
  56. package/Components/MasterCell/__tests__/__snapshots__/elementMapper.test.js.snap +11 -19
  57. package/Components/MasterCell/__tests__/__snapshots__/masterCell.test.js.snap +6 -235
  58. package/Components/MasterCell/__tests__/elementMapper.test.js +18 -5
  59. package/Components/MasterCell/__tests__/masterCell.test.js +26 -26
  60. package/Components/MasterCell/hooks/useAsyncRendering/MasterCellAsyncRenderManager.ts +2 -2
  61. package/Components/MasterCell/hooks/useAsyncRendering/index.ts +2 -2
  62. package/Components/MasterCell/utils/index.ts +1 -1
  63. package/Components/ModalComponent/Button/index.tsx +6 -6
  64. package/Components/ModalComponent/Header/index.tsx +3 -3
  65. package/Components/NativeFocusables/{index.js → index.ts} +4 -2
  66. package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +2 -2
  67. package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +2 -2
  68. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +0 -5
  69. package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +7 -7
  70. package/Components/OfflineHandler/__tests__/index.test.tsx +28 -25
  71. package/Components/PlayerContainer/PlayerContainer.tsx +13 -19
  72. package/Components/PlayerContainer/PlayerContainerContext.tsx +9 -0
  73. package/Components/PlayerContainer/ProgramInfo/index.tsx +2 -2
  74. package/Components/River/ComponentsMap/ComponentsMap.tsx +39 -65
  75. package/Components/River/ComponentsMap/hooks/useLoadingState.ts +78 -51
  76. package/Components/River/RefreshControl.tsx +1 -1
  77. package/Components/River/RiverFooter.tsx +39 -9
  78. package/Components/River/RiverItem.tsx +37 -2
  79. package/Components/River/TV/index.tsx +6 -1
  80. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +114 -45
  81. package/Components/River/__tests__/__snapshots__/river.test.js.snap +21 -83
  82. package/Components/River/__tests__/componentsMap.test.js +64 -17
  83. package/Components/River/__tests__/river.test.js +75 -40
  84. package/Components/RouteManager/__tests__/__snapshots__/routeManager.test.js.snap +12 -5
  85. package/Components/RouteManager/__tests__/routeManager.test.js +29 -14
  86. package/Components/RouteManager/__tests__/testId.test.js +8 -6
  87. package/Components/Screen/__tests__/Screen.test.tsx +41 -27
  88. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +4 -4
  89. package/Components/Screen/hooks.ts +56 -0
  90. package/Components/Screen/index.tsx +16 -42
  91. package/Components/ScreenResolver/__tests__/screenResolver.test.js +95 -70
  92. package/Components/Tabs/Tab.tsx +12 -9
  93. package/Components/TextInputTv/__tests__/TextInputTv.test.js +42 -42
  94. package/Components/TextInputTv/__tests__/__snapshots__/TextInputTv.test.js.snap +7 -0
  95. package/Components/TextInputTv/index.tsx +6 -5
  96. package/Components/Touchable/__tests__/__snapshots__/touchable.test.tsx.snap +2 -2
  97. package/Components/Transitioner/AnimationManager.js +8 -8
  98. package/Components/Transitioner/Scene.tsx +53 -24
  99. package/Components/Transitioner/Transitioner.tsx +3 -3
  100. package/Components/Transitioner/__tests__/Scene.test.js +25 -14
  101. package/Components/Transitioner/__tests__/__snapshots__/AnimationManager.test.js.snap +26 -26
  102. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +10 -50
  103. package/Components/Transitioner/__tests__/__snapshots__/config.test.js.snap +20 -20
  104. package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +4 -4
  105. package/Components/Transitioner/__tests__/transitioner.test.js +13 -4
  106. package/Components/Transitioner/index.js +8 -4
  107. package/Components/VideoLive/LiveImageManager.ts +27 -1
  108. package/Components/VideoLive/PlayerLiveImageComponent.tsx +32 -24
  109. package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +63 -8
  110. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +5 -10
  111. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +16 -12
  112. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +5 -1
  113. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +15 -14
  114. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +6 -13
  115. package/Components/VideoModal/ModalAnimation/index.ts +2 -1
  116. package/Components/VideoModal/ModalAnimation/useModalAnimationContext.ts +6 -0
  117. package/Components/VideoModal/ModalAnimation/utils.ts +2 -2
  118. package/Components/VideoModal/OpaqueLayer.tsx +33 -0
  119. package/Components/VideoModal/PlayerDetails.tsx +5 -5
  120. package/Components/VideoModal/PlayerWrapper.tsx +17 -36
  121. package/Components/VideoModal/VideoModal.tsx +14 -23
  122. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +5 -2
  123. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +13 -10
  124. package/Components/VideoModal/__tests__/__snapshots__/PlayerDetails.test.tsx.snap +4 -4
  125. package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +66 -156
  126. package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +89 -0
  127. package/Components/VideoModal/hooks/index.ts +7 -0
  128. package/Components/VideoModal/hooks/useDelayedPlayerDetails.ts +49 -0
  129. package/Components/VideoModal/hooks/utils/__tests__/showDetails.test.ts +91 -0
  130. package/Components/VideoModal/hooks/utils/index.ts +33 -0
  131. package/Components/VideoModal/utils.ts +3 -5
  132. package/Components/Viewport/ViewportAware/__tests__/__snapshots__/viewportAware.test.js.snap +24 -36
  133. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +12 -18
  134. package/Components/Viewport/ViewportTracker/__tests__/__snapshots__/viewportTracker.test.js.snap +1 -1
  135. package/Components/Viewport/__tests__/utils.test.js +5 -4
  136. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +1 -0
  137. package/Components/ZappUIComponent/Placeholder.tsx +3 -1
  138. package/Components/ZappUIComponent/__tests__/{ZappUIComponent.test.js → ZappUIComponent.test.tsx} +26 -10
  139. package/Components/ZappUIComponent/index.tsx +3 -16
  140. package/Components/default-cell-renderer/__tests__/defaultCellRenderer.test.tsx +20 -17
  141. package/Components/default-cell-renderer/viewTrees/tv/DefaultCell/__tests__/DefaultCell.test.tsx +15 -11
  142. package/Contexts/ComponentsMapOffsetContext/index.tsx +49 -0
  143. package/Contexts/ConfigutaionContext/__tests__/__snapshots__/ConfigurationProvider.test.tsx.snap +1 -1
  144. package/Contexts/FocusableGroupContext/withFocusableContext.tsx +18 -11
  145. package/Contexts/ScreenContext/index.tsx +3 -2
  146. package/Decorators/Analytics/{index.js → index.tsx} +11 -11
  147. package/Decorators/Navigator/__tests__/navigator.test.js +16 -16
  148. package/Decorators/Navigator/index.tsx +1 -1
  149. package/Decorators/RiverFeedLoader/__tests__/__snapshots__/riverFeedLoader.test.tsx.snap +77 -77
  150. package/Decorators/RiverFeedLoader/__tests__/riverFeedLoader.test.tsx +34 -39
  151. package/Decorators/RiverFeedLoader/__tests__/utils.test.ts +0 -9
  152. package/Decorators/RiverFeedLoader/index.tsx +1 -1
  153. package/Decorators/RiverFeedLoader/utils/getDatasourceUrl.ts +39 -0
  154. package/Decorators/RiverFeedLoader/utils/index.ts +29 -0
  155. package/Decorators/RiverFeedLoader/utils/usePipesContexts.ts +40 -0
  156. package/Decorators/RiverResolver/__tests__/riverResolver.test.tsx +27 -27
  157. package/Decorators/RiverResolver/index.tsx +1 -1
  158. package/Decorators/ZappPipesDataConnector/__tests__/Hero.js +1 -1
  159. package/Decorators/ZappPipesDataConnector/__tests__/zappPipesDataConnector.test.js +29 -22
  160. package/Decorators/ZappPipesDataConnector/index.tsx +32 -2
  161. package/package.json +14 -8
  162. package/Components/CellRendererResolver/__tests__/__snapshots__/cellRendererResolver.test.js.snap +0 -53
  163. package/Components/RouteManager/__tests__/__snapshots__/testId.test.js.snap +0 -17
  164. package/Components/ScreenResolver/__tests__/__snapshots__/screenResolver.test.js.snap +0 -17
  165. package/Components/ZappUIComponent/__tests__/__snapshots__/ZappUIComponent.test.js.snap +0 -91
  166. package/Components/default-cell-renderer/__tests__/__snapshots__/defaultCellRenderer.test.tsx.snap +0 -338
  167. package/Decorators/Navigator/__tests__/__snapshots__/navigator.test.js.snap +0 -18
  168. package/Decorators/RiverFeedLoader/utils.ts +0 -100
  169. package/Decorators/RiverResolver/__tests__/__snapshots__/riverResolver.test.tsx.snap +0 -28
@@ -1,13 +1,12 @@
1
1
  import * as React from "react";
2
+ import * as R from "ramda";
2
3
 
3
4
  import {
4
5
  BaseFocusable as BaseFocusableInterface,
5
6
  BoundingRect,
6
7
  } from "./BaseFocusable.interface";
7
8
 
8
- import { createReactRef } from "@applicaster/zapp-react-native-utils/reactUtils";
9
9
  import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
10
- import * as FOCUS_EVENTS from "@applicaster/zapp-react-native-utils/appUtils/focusManager/events";
11
10
  import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
12
11
 
13
12
  type ScrollDirection = FocusManager.IOS.Direction | FocusManager.Web.Direction;
@@ -35,7 +34,7 @@ type Props = {
35
34
  };
36
35
 
37
36
  export class BaseFocusable<
38
- T extends Props = Props
37
+ T extends Props = Props,
39
38
  > extends BaseFocusableInterface<T> {
40
39
  constructor(props) {
41
40
  super(props);
@@ -45,7 +44,7 @@ export class BaseFocusable<
45
44
  focused: initialFocus || false,
46
45
  };
47
46
 
48
- this.ref = createReactRef();
47
+ this.ref = React.createRef();
49
48
  }
50
49
 
51
50
  componentDidMount() {
@@ -131,12 +130,6 @@ export class BaseFocusable<
131
130
  willLoseFocus: FocusManager.FocusEventCB = (focusable, scrollDirection) => {
132
131
  const { willLoseFocus = noop } = this.props;
133
132
  willLoseFocus(focusable, scrollDirection);
134
-
135
- focusManager.invokeHandler?.(
136
- FOCUS_EVENTS.WILL_LOSE_FOCUS,
137
- this,
138
- scrollDirection
139
- );
140
133
  };
141
134
 
142
135
  willReceiveFocus: FocusManager.FocusEventCB = (
@@ -145,12 +138,6 @@ export class BaseFocusable<
145
138
  ) => {
146
139
  const { willReceiveFocus = noop } = this.props;
147
140
  willReceiveFocus(focusable, scrollDirection);
148
-
149
- focusManager.invokeHandler?.(
150
- FOCUS_EVENTS.WILL_RECEIVE_FOCUS,
151
- this,
152
- scrollDirection
153
- );
154
141
  };
155
142
 
156
143
  /**
@@ -163,8 +150,6 @@ export class BaseFocusable<
163
150
  const { onFocus = noop } = this.props;
164
151
  this.setFocusedState(true);
165
152
  onFocus(focusable, scrollDirection);
166
-
167
- focusManager.invokeHandler?.(FOCUS_EVENTS.FOCUS, this, scrollDirection);
168
153
  };
169
154
 
170
155
  /**
@@ -179,12 +164,6 @@ export class BaseFocusable<
179
164
  ) => {
180
165
  const { hasReceivedFocus = noop } = this.props;
181
166
  hasReceivedFocus(focusable, scrollDirection);
182
-
183
- focusManager.invokeHandler?.(
184
- FOCUS_EVENTS.HAS_RECEIVED_FOCUS,
185
- this,
186
- scrollDirection
187
- );
188
167
  };
189
168
 
190
169
  /**
@@ -196,12 +175,6 @@ export class BaseFocusable<
196
175
  hasLostFocus: FocusManager.FocusEventCB = (focusable, scrollDirection) => {
197
176
  const { hasLostFocus = noop } = this.props;
198
177
  hasLostFocus(focusable, scrollDirection);
199
-
200
- focusManager.invokeHandler?.(
201
- FOCUS_EVENTS.HAS_LOST_FOCUS,
202
- this,
203
- scrollDirection
204
- );
205
178
  };
206
179
 
207
180
  /**
@@ -228,7 +201,6 @@ export class BaseFocusable<
228
201
  const { onBlur = noop } = this.props;
229
202
  this.setFocusedState(false);
230
203
  onBlur(focusable, scrollDirection);
231
- focusManager.invokeHandler?.(FOCUS_EVENTS.BLUR, this, scrollDirection);
232
204
  };
233
205
 
234
206
  onPress = (keyEvent?: Nullable<React.MouseEvent>) => {
@@ -269,4 +241,68 @@ export class BaseFocusable<
269
241
  this.setState({ focused });
270
242
  }
271
243
  };
244
+
245
+ /**
246
+ * will invoke the underlying component's focus method
247
+ * @param {Object} scrollDirection
248
+ * @returns {Promise}
249
+ */
250
+ focus(_, scrollDirection) {
251
+ return this.onFocus(this, scrollDirection); // invokeComponentMethod(this, "onFocus", scrollDirection);
252
+ }
253
+
254
+ /**
255
+ * will invoke the underlying component's blur method
256
+ * @param {Object} scrollDirection
257
+ * @returns {Promise}
258
+ */
259
+ blur(
260
+ _,
261
+ scrollDirection?: FocusManager.Web.Direction | FocusManager.IOS.Direction
262
+ ) {
263
+ return this.onBlur(this, scrollDirection);
264
+ }
265
+
266
+ /**
267
+ * Sets the focus on this item. Will trigger sequentially a sequence of
268
+ * functions (willReceiveFocus, focus, hasReceivedFocus). If these functions (defined in the Focusable
269
+ * Item underlying component) return promises, execution will wait before it proceeds to the next. This
270
+ * is useful for triggering sequential operations that specifically require to fully run before or after
271
+ * focus is actually set on that item.
272
+ * @param {string} scrollDirection string representation of the direction of the navigation which landed
273
+ * to this item being focused
274
+ */
275
+ _executeFocusSequence(methodNames, scrollDirection) {
276
+ return R.reduce(
277
+ (sequence, methodName) => {
278
+ const method = this[methodName]; // Access the method by name
279
+
280
+ if (typeof method !== "function") {
281
+ throw new Error(
282
+ `Method '${methodName}' not found or not a function.`
283
+ );
284
+ }
285
+
286
+ return sequence
287
+ .then(() => method.call(this, scrollDirection))
288
+ .catch((e) => {
289
+ throw e; // Re-throw for consistent error handling
290
+ });
291
+ },
292
+ Promise.resolve(),
293
+ methodNames
294
+ );
295
+ }
296
+
297
+ setFocus(scrollDirection) {
298
+ const focusMethods = ["willReceiveFocus", "focus", "hasReceivedFocus"];
299
+
300
+ return this._executeFocusSequence(focusMethods, scrollDirection);
301
+ }
302
+
303
+ setBlur(scrollDirection) {
304
+ const blurMethods = ["willLoseFocus", "blur", "hasLostFocus"];
305
+
306
+ return this._executeFocusSequence(blurMethods, scrollDirection);
307
+ }
272
308
  }
@@ -14,10 +14,7 @@ import { BaseFocusable } from "../BaseFocusable";
14
14
  import { AccessibilityManager } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager";
15
15
 
16
16
  type Props = {
17
- item: {
18
- id: string;
19
- title: string;
20
- };
17
+ item: ZappEntry;
21
18
  index: number;
22
19
  shouldScrollHorizontally: (arg1: [any]) => boolean | null | undefined;
23
20
  shouldScrollVertically: (...args: any) => boolean | null | undefined;
@@ -33,10 +30,9 @@ type Props = {
33
30
  id: string;
34
31
  };
35
32
  selected?: boolean;
36
- CellRenderer: React.ComponentType<{
37
- item: any;
38
- state: string;
39
- }> & { hasFocusableInside: (item: Record<string, string>) => boolean };
33
+ CellRenderer: React.FunctionComponent<any> & {
34
+ hasFocusableInside: (item: ZappEntry) => boolean;
35
+ };
40
36
  preferredFocus: boolean;
41
37
  navigator: {
42
38
  push: (arg1: Record<any, any>) => void;
@@ -65,6 +61,7 @@ type Props = {
65
61
  skipFocusManagerRegistration?: boolean;
66
62
  shouldUpdate: boolean;
67
63
  behavior: Behavior;
64
+ componentsMapOffset: number;
68
65
  };
69
66
 
70
67
  type State = {
@@ -276,7 +273,16 @@ export class CellComponent extends React.Component<Props, State> {
276
273
 
277
274
  if (isFocused) {
278
275
  const accessibilityManager = AccessibilityManager.getInstance();
279
- accessibilityManager.readText({ text: item.title });
276
+
277
+ const accessibilityTitle =
278
+ item?.extensions?.accessibility?.label || item?.title || "";
279
+
280
+ const accessibilityHint =
281
+ item?.extensions?.accessibility?.hint || "";
282
+
283
+ accessibilityManager.readText({
284
+ text: `${accessibilityTitle} ${accessibilityHint}`,
285
+ });
280
286
  }
281
287
 
282
288
  return (
@@ -0,0 +1,126 @@
1
+ /** TODO: Remove this file when tvos FocusableGroup
2
+ * behaviour is aligned to the web one
3
+ * FocusableGroup should only send onFocus and onBlur events when
4
+ * Focus enters and leaves the Focusables inside the branch
5
+ */
6
+ import * as React from "react";
7
+
8
+ import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
9
+ import * as FOCUS_EVENTS from "@applicaster/zapp-react-native-utils/appUtils/focusManager/events";
10
+ import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
11
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
12
+
13
+ import { isAppleTV } from "../../Helpers/Platform";
14
+ import { useCellState } from "../MasterCell/utils";
15
+
16
+ const useCellFocusedState = (
17
+ skipFocusManagerRegistration: boolean,
18
+ groupId: string,
19
+ id: string
20
+ ) => {
21
+ const [currentCellFocused, setCurrentCellFocused] = React.useState(false);
22
+
23
+ React.useEffect(() => {
24
+ const isGroupItemFocused = () => {
25
+ if (!skipFocusManagerRegistration) {
26
+ const isFocused = focusManager.isGroupItemFocused(groupId, id);
27
+ setCurrentCellFocused(isFocused);
28
+ }
29
+ };
30
+
31
+ const handler = () => {
32
+ // tvOS hack for properly checking focus
33
+ if (isAppleTV()) {
34
+ setTimeout(() => {
35
+ isGroupItemFocused();
36
+ }, 0);
37
+ } else {
38
+ isGroupItemFocused();
39
+ }
40
+ };
41
+
42
+ focusManager.on(FOCUS_EVENTS.FOCUS, handler);
43
+
44
+ return () => {
45
+ focusManager.removeHandler(FOCUS_EVENTS.FOCUS, handler);
46
+ };
47
+ }, [groupId, skipFocusManagerRegistration]);
48
+
49
+ return currentCellFocused;
50
+ };
51
+
52
+ type Props = {
53
+ item: ZappEntry;
54
+ CellRenderer: React.FunctionComponent<any>;
55
+ id: string;
56
+ groupId: string;
57
+ onFocus: Function;
58
+ index: number;
59
+ scrollTo: Function;
60
+ preferredFocus?: boolean;
61
+ skipFocusManagerRegistration?: boolean;
62
+ isFocusable?: boolean;
63
+ behavior: Behavior;
64
+ focused?: boolean;
65
+ };
66
+
67
+ export function CellWithFocusable(props: Props) {
68
+ const {
69
+ index,
70
+ item,
71
+ CellRenderer,
72
+ id,
73
+ groupId,
74
+ onFocus,
75
+ scrollTo = noop,
76
+ preferredFocus,
77
+ skipFocusManagerRegistration,
78
+ isFocusable,
79
+ behavior,
80
+ focused,
81
+ } = props;
82
+
83
+ const isFocused = useCellFocusedState(
84
+ skipFocusManagerRegistration,
85
+ groupId,
86
+ id
87
+ );
88
+
89
+ const state = useCellState({
90
+ id: item.id,
91
+ behavior,
92
+ focused: isFocused || toBooleanWithDefaultFalse(focused),
93
+ });
94
+
95
+ const [focusedButtonId, setFocusedButtonId] = React.useState(undefined);
96
+
97
+ // for horizontal scrolling
98
+ React.useEffect(() => {
99
+ if (focusedButtonId) {
100
+ scrollTo(index);
101
+ }
102
+ }, [focusedButtonId]);
103
+
104
+ const handleToggleFocus = (value) => {
105
+ setFocusedButtonId(value.focusedButtonId);
106
+
107
+ if (value.focusable) {
108
+ onFocus(value.focusable, value.mouse);
109
+ }
110
+ };
111
+
112
+ return (
113
+ <CellRenderer
114
+ item={item}
115
+ groupId={groupId}
116
+ onToggleFocus={handleToggleFocus}
117
+ state={state}
118
+ prefixId={id}
119
+ focusedButtonId={focusedButtonId}
120
+ preferredFocus={preferredFocus}
121
+ skipFocusManagerRegistration={skipFocusManagerRegistration}
122
+ isFocusable={isFocusable}
123
+ focused={focused}
124
+ />
125
+ );
126
+ }
@@ -1,52 +1,14 @@
1
1
  import * as React from "react";
2
2
 
3
- import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
4
- import * as FOCUS_EVENTS from "@applicaster/zapp-react-native-utils/appUtils/focusManager/events";
5
3
  import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
6
4
  import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
7
5
 
8
- import { isAppleTV } from "../../Helpers/Platform";
9
6
  import { useCellState } from "../MasterCell/utils";
10
-
11
- const useCellFocusedState = (
12
- skipFocusManagerRegistration: boolean,
13
- groupId: string,
14
- id: string
15
- ) => {
16
- const [currentCellFocused, setCurrentCellFocused] = React.useState(false);
17
-
18
- React.useEffect(() => {
19
- const isGroupItemFocused = () => {
20
- if (!skipFocusManagerRegistration) {
21
- const isFocused = focusManager.isGroupItemFocused(groupId, id);
22
- setCurrentCellFocused(isFocused);
23
- }
24
- };
25
-
26
- const handler = () => {
27
- // tvOS hack for properly checking focus
28
- if (isAppleTV()) {
29
- setTimeout(() => {
30
- isGroupItemFocused();
31
- }, 0);
32
- } else {
33
- isGroupItemFocused();
34
- }
35
- };
36
-
37
- focusManager.on(FOCUS_EVENTS.FOCUS, handler);
38
-
39
- return () => {
40
- focusManager.removeHandler(FOCUS_EVENTS.FOCUS, handler);
41
- };
42
- }, [groupId, skipFocusManagerRegistration]);
43
-
44
- return currentCellFocused;
45
- };
7
+ import { FocusableGroup } from "../FocusableGroup";
46
8
 
47
9
  type Props = {
48
10
  item: ZappEntry;
49
- CellRenderer: React.ComponentType<{ item: Object; state: string }>;
11
+ CellRenderer: React.FunctionComponent<any>;
50
12
  id: string;
51
13
  groupId: string;
52
14
  onFocus: Function;
@@ -75,11 +37,7 @@ export function CellWithFocusable(props: Props) {
75
37
  focused,
76
38
  } = props;
77
39
 
78
- const isFocused = useCellFocusedState(
79
- skipFocusManagerRegistration,
80
- groupId,
81
- id
82
- );
40
+ const [isFocused, setIsFocused] = React.useState(false);
83
41
 
84
42
  const state = useCellState({
85
43
  id: item.id,
@@ -96,26 +54,53 @@ export function CellWithFocusable(props: Props) {
96
54
  }
97
55
  }, [focusedButtonId]);
98
56
 
99
- const handleToggleFocus = (value) => {
100
- setFocusedButtonId(value.focusedButtonId);
57
+ const handleToggleFocus = React.useCallback(
58
+ (value) => {
59
+ setFocusedButtonId(value.focusedButtonId);
60
+
61
+ if (value.focusable) {
62
+ onFocus(value.focusable, value.mouse);
63
+ }
64
+ },
65
+ [onFocus]
66
+ );
67
+
68
+ const onGroupFocus = React.useCallback(() => {
69
+ if (!skipFocusManagerRegistration) {
70
+ setIsFocused(true);
71
+ }
72
+ }, [skipFocusManagerRegistration]);
101
73
 
102
- if (value.focusable) {
103
- onFocus(value.focusable, value.mouse);
74
+ const onGroupBlur = React.useCallback(() => {
75
+ if (!skipFocusManagerRegistration) {
76
+ setIsFocused(false);
104
77
  }
105
- };
78
+ }, [skipFocusManagerRegistration]);
106
79
 
107
80
  return (
108
- <CellRenderer
109
- item={item}
81
+ <FocusableGroup
82
+ id={`focusable-cell-wrapper-${id}`}
83
+ testID={"cell-with-focusable-cell-renderer-focusable-group"}
110
84
  groupId={groupId}
111
- onToggleFocus={handleToggleFocus}
112
- state={state}
113
- prefixId={id}
114
- focusedButtonId={focusedButtonId}
115
85
  preferredFocus={preferredFocus}
86
+ shouldUsePreferredFocus
87
+ onFocus={onGroupFocus}
88
+ onBlur={onGroupBlur}
116
89
  skipFocusManagerRegistration={skipFocusManagerRegistration}
117
- isFocusable={isFocusable}
118
- focused={focused}
119
- />
90
+ >
91
+ <CellRenderer
92
+ testID={"cell-with-focusable-cell-renderer"}
93
+ item={item}
94
+ groupId={`focusable-cell-wrapper-${id}`}
95
+ onToggleFocus={handleToggleFocus}
96
+ state={state}
97
+ prefixId={id}
98
+ focusedButtonId={focusedButtonId}
99
+ preferredFocus={true}
100
+ skipFocusManagerRegistration={skipFocusManagerRegistration}
101
+ isFocusable={isFocusable}
102
+ focused={focused}
103
+ />
104
+ </FocusableGroup>
120
105
  );
121
106
  }
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import * as R from "ramda";
3
3
  import { View, StyleSheet } from "react-native";
4
4
 
5
- import { Focusable } from "@applicaster/zapp-react-native-ui-components/Components/Focusable";
5
+ import { Focusable } from "@applicaster/zapp-react-native-ui-components/Components/Focusable/FocusableTvOS";
6
6
  import { FocusableCell } from "@applicaster/zapp-react-native-ui-components/Components/FocusableCell";
7
7
  import { getItemType } from "@applicaster/zapp-react-native-utils/navigationUtils";
8
8
  import { SCREEN_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/itemTypes";
@@ -10,10 +10,6 @@ import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focu
10
10
  import { sendSelectCellEvent } from "@applicaster/zapp-react-native-utils/analyticsUtils";
11
11
  import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
12
12
  import { CellWithFocusable } from "./CellWithFocusable";
13
- import { getCellState } from "./utils";
14
-
15
- const _getCellState = (focused, selected) =>
16
- getCellState({ focused, selected });
17
13
 
18
14
  type Props = {
19
15
  item: ZappEntry;
@@ -36,10 +32,9 @@ type Props = {
36
32
  component_type: string;
37
33
  };
38
34
  selected: boolean;
39
- CellRenderer: React.ComponentType<{
40
- item: any;
41
- state: string;
42
- }> & { hasFocusableInside: (item: any) => boolean };
35
+ CellRenderer: React.FunctionComponent<any> & {
36
+ hasFocusableInside: (item: any) => boolean;
37
+ };
43
38
  preferredFocus: boolean;
44
39
  navigator: {
45
40
  push: (arg1: Record<any, any>) => void;
@@ -70,6 +65,7 @@ type Props = {
70
65
  isFocusable: boolean;
71
66
  shouldUpdate: boolean;
72
67
  behavior: Behavior;
68
+ componentsMapOffset: number;
73
69
  };
74
70
 
75
71
  type State = {
@@ -184,6 +180,7 @@ export class TvOSCellComponent extends React.Component<Props, State> {
184
180
  groupId,
185
181
  component,
186
182
  index,
183
+ componentsMapOffset,
187
184
  } = this.props;
188
185
 
189
186
  this.setScreenLayout(componentAnchorPointY, screenLayout);
@@ -198,13 +195,11 @@ export class TvOSCellComponent extends React.Component<Props, State> {
198
195
  const extraAnchorPointYOffset =
199
196
  screenLayout?.extraAnchorPointYOffset || 0;
200
197
 
201
- const marginTop = screenLayout?.screenMarginTop || 0;
202
-
203
198
  const totalOffset =
204
199
  headerOffset +
205
- (componentAnchorPointY || 0) +
206
- extraAnchorPointYOffset -
207
- marginTop;
200
+ (componentAnchorPointY || 0) +
201
+ extraAnchorPointYOffset -
202
+ componentsMapOffset || 0;
208
203
 
209
204
  mainOffsetUpdater?.(
210
205
  { tag: this.target },
@@ -252,7 +247,7 @@ export class TvOSCellComponent extends React.Component<Props, State> {
252
247
 
253
248
  const focusableId = R.join("-", [component?.id, id, index]);
254
249
 
255
- const handleFocus = (arg1: any, index: number) => {
250
+ const handleFocus = (arg1: any, index?: number) => {
256
251
  const focusFn = onFocus || noop;
257
252
  focusFn(arg1, index);
258
253
 
@@ -285,7 +280,7 @@ export class TvOSCellComponent extends React.Component<Props, State> {
285
280
  <View onLayout={this.onLayout} style={styles.container}>
286
281
  <Focusable
287
282
  id={focusableId}
288
- groupId={groupId || component?.id}
283
+ groupId={String(groupId || component?.id)}
289
284
  onFocus={handleFocus}
290
285
  onBlur={onBlur || this.onBlur}
291
286
  isParallaxDisabled={this.layout?.width > 1740}
@@ -297,20 +292,18 @@ export class TvOSCellComponent extends React.Component<Props, State> {
297
292
  style={baseCellStyles}
298
293
  isFocusable={isFocusable}
299
294
  >
300
- {(focused) => {
301
- return (
302
- <FocusableCell
303
- {...{
304
- index,
305
- CellRenderer,
306
- item,
307
- focused: this.props.focused || selectedCell || focused,
308
- scrollTo: this.scrollTo,
309
- behavior,
310
- }}
311
- />
312
- );
313
- }}
295
+ {(focused) => (
296
+ <FocusableCell
297
+ {...{
298
+ index,
299
+ CellRenderer,
300
+ item,
301
+ focused: !!(this.props.focused || selectedCell || focused),
302
+ scrollTo: this.scrollTo,
303
+ behavior,
304
+ }}
305
+ />
306
+ )}
314
307
  </Focusable>
315
308
  </View>
316
309
  );
@@ -1,7 +1,7 @@
1
1
  import { View } from "react-native";
2
2
  import React from "react";
3
3
  import { act, render } from "@testing-library/react-native";
4
- import { CellWithFocusable } from "../CellWithFocusable";
4
+ import { CellWithFocusable } from "../CellWithFocusable.tsx";
5
5
 
6
6
  import { focusManager } from "@applicaster/zapp-react-native-utils/appUtils/focusManager";
7
7
 
@@ -23,7 +23,9 @@ describe("CellWithFocusable", () => {
23
23
 
24
24
  const wrapper = renderWith(props);
25
25
 
26
- expect(wrapper.UNSAFE_getByType("View").props.state).toBe("default");
26
+ const element = wrapper.getByTestId("cell-with-focusable-cell-renderer");
27
+
28
+ expect(element.props.state).toBe("default");
27
29
  });
28
30
 
29
31
  it("should render in default state", () => {
@@ -40,8 +42,9 @@ describe("CellWithFocusable", () => {
40
42
  focusManager.isGroupItemFocused = jest.fn(() => true);
41
43
 
42
44
  const wrapper = renderWith(props);
45
+ const element = wrapper.getByTestId("cell-with-focusable-cell-renderer");
43
46
 
44
- expect(wrapper.UNSAFE_getByType("View").props.state).toBe("default");
47
+ expect(element.props.state).toBe("default");
45
48
  });
46
49
 
47
50
  it("should render in focused state", () => {
@@ -55,13 +58,17 @@ describe("CellWithFocusable", () => {
55
58
  scrollTo: jest.fn(),
56
59
  };
57
60
 
58
- focusManager.isGroupItemFocused = jest.fn(() => true);
59
61
  const wrapper = renderWith(props);
60
62
 
63
+ const focusableGroupComponent = wrapper.getByTestId(
64
+ "cell-with-focusable-cell-renderer-focusable-group"
65
+ );
66
+
61
67
  act(() => {
62
- focusManager.on.mock.calls[focusManager.on.mock.calls.length - 1][1]();
68
+ focusableGroupComponent.props.onFocus();
63
69
  });
64
70
 
65
- expect(wrapper.UNSAFE_getByType("View").props.state).toBe("focused");
71
+ const element = wrapper.getByTestId("cell-with-focusable-cell-renderer");
72
+ expect(element.props.state).toBe("focused");
66
73
  });
67
74
  });
@@ -11,6 +11,7 @@ import { ScreenScrollingContext } from "../../Contexts/ScreenScrollingContext";
11
11
 
12
12
  import { ScreenLayoutContextConsumer } from "../../Contexts/ScreenLayoutContext";
13
13
  import { createContext } from "@applicaster/zapp-react-native-utils/reactUtils/createContext";
14
+ import { withComponentsMapOffsetContextConsumer } from "../../Contexts/ComponentsMapOffsetContext";
14
15
 
15
16
  // TODO | Gallery QB | Extract this
16
17
  export const ScrollInterceptorContext = createContext(
@@ -30,5 +31,6 @@ export const Cell = R.compose(
30
31
  RiverOffsetContext.withConsumer,
31
32
  HorizontalScrollContext.withConsumer,
32
33
  withConsumer,
33
- ScreenLayoutContextConsumer
34
+ ScreenLayoutContextConsumer,
35
+ withComponentsMapOffsetContextConsumer
34
36
  )(Component);