@applicaster/zapp-react-native-ui-components 13.0.0-alpha.5771418585 → 13.0.0-alpha.5814285061

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 (143) hide show
  1. package/Components/AppContainer/__tests__/AppContainer.test.js +4 -6
  2. package/Components/AudioPlayer/AudioPlayer.tsx +7 -4
  3. package/Components/AudioPlayer/__tests__/Runtime.test.js +5 -8
  4. package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayer.test.js.snap +54 -111
  5. package/Components/AudioPlayer/__tests__/__snapshots__/audioPlayerLayout.test.js.snap +36 -20
  6. package/Components/AudioPlayer/__tests__/artWork.test.js +3 -5
  7. package/Components/AudioPlayer/__tests__/audioPlayer.test.js +3 -5
  8. package/Components/AudioPlayer/__tests__/audioPlayerLayout.test.js +7 -8
  9. package/Components/AudioPlayer/__tests__/channel.test.js +3 -5
  10. package/Components/AudioPlayer/__tests__/summary.test.js +3 -5
  11. package/Components/AudioPlayer/__tests__/title.test.js +3 -5
  12. package/Components/AudioPlayer/helpers.tsx +1 -1
  13. package/Components/BaseFocusable/index.tsx +1 -2
  14. package/Components/Cell/Cell.tsx +4 -13
  15. package/Components/Cell/CellWithFocusable.tsx +22 -15
  16. package/Components/Cell/CellWrapper.tsx +18 -0
  17. package/Components/Cell/TvOSCellComponent.tsx +20 -22
  18. package/Components/Cell/index.js +3 -1
  19. package/Components/Cell/styles.ts +17 -0
  20. package/Components/CellRendererResolver/__tests__/cellRendererResolver.test.js +46 -48
  21. package/Components/CellRendererResolver/index.ts +2 -1
  22. package/Components/ComponentResolver/__tests__/__snapshots__/componentResolver.test.js.snap +1 -42
  23. package/Components/ComponentResolver/__tests__/componentResolver.test.js +16 -22
  24. package/Components/ContentScreen/__tests__/contentScreen.test.js +3 -3
  25. package/Components/ErrorScreen/index.tsx +8 -0
  26. package/Components/Focusable/FocusableTvOS.tsx +5 -1
  27. package/Components/Focusable/index.android.tsx +10 -3
  28. package/Components/FocusableCell/index.tsx +1 -1
  29. package/Components/FocusableGroup/FocusableTvOS.tsx +34 -86
  30. package/Components/FocusableGroup/index.tsx +0 -3
  31. package/Components/FocusableList/index.tsx +26 -9
  32. package/Components/FocusableScrollView/index.tsx +43 -13
  33. package/Components/GeneralContentScreen/GeneralContentScreen.tsx +3 -0
  34. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +4 -2
  35. package/Components/GeneralContentScreen/utils/useEventAlerts.ts +30 -0
  36. package/Components/HandlePlayable/HandlePlayable.tsx +21 -27
  37. package/Components/Layout/TV/LayoutBackground.tsx +28 -0
  38. package/Components/Layout/TV/NavBarContainer.tsx +19 -23
  39. package/Components/Layout/TV/ScreenContainer.tsx +8 -2
  40. package/Components/Layout/TV/ScreenLayoutContextProvider.tsx +5 -0
  41. package/Components/Layout/TV/__tests__/ScreenContainer.test.tsx +2 -1
  42. package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +3 -2
  43. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +3 -2
  44. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +15 -10
  45. package/Components/Layout/TV/__tests__/index.test.tsx +8 -2
  46. package/Components/Layout/TV/index.tsx +6 -20
  47. package/Components/Layout/TV/index.web.tsx +4 -1
  48. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +2 -3
  49. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +4 -3
  50. package/Components/MasterCell/DefaultComponents/Image/hooks/useImage.ts +11 -7
  51. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/const.ts +3 -0
  52. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +6 -6
  53. package/Components/MasterCell/SharedUI/ProgressBar/hooks/useFillInPercent.ts +2 -8
  54. package/Components/MasterCell/__tests__/__snapshots__/elementMapper.test.js.snap +4 -12
  55. package/Components/MasterCell/__tests__/__snapshots__/masterCell.test.js.snap +0 -229
  56. package/Components/MasterCell/__tests__/elementMapper.test.js +18 -5
  57. package/Components/MasterCell/__tests__/masterCell.test.js +26 -26
  58. package/Components/MasterCell/utils/behaviorProvider.ts +136 -0
  59. package/Components/MasterCell/utils/index.ts +8 -134
  60. package/Components/ModalComponent/BottomSheetModalContent.tsx +59 -43
  61. package/Components/ModalComponent/Button/Item.tsx +6 -5
  62. package/Components/ModalComponent/Button/assets.ts +1 -1
  63. package/Components/ModalComponent/Button/index.tsx +45 -62
  64. package/Components/ModalComponent/Header/index.tsx +9 -8
  65. package/Components/ModalComponent/utils.ts +55 -7
  66. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +0 -5
  67. package/Components/OfflineHandler/utils/index.ts +1 -1
  68. package/Components/PlayerContainer/PlayerContainer.tsx +34 -7
  69. package/Components/PlayerImageBackground/index.tsx +1 -1
  70. package/Components/River/ComponentsMap/ComponentsMap.tsx +3 -0
  71. package/Components/River/ComponentsMap/hooks/useLoadingState.ts +3 -3
  72. package/Components/River/RiverItem.tsx +2 -1
  73. package/Components/River/TV/index.tsx +6 -1
  74. package/Components/River/__tests__/__snapshots__/river.test.js.snap +20 -82
  75. package/Components/River/__tests__/river.test.js +75 -40
  76. package/Components/RouteManager/__tests__/__snapshots__/routeManager.test.js.snap +11 -4
  77. package/Components/RouteManager/__tests__/routeManager.test.js +29 -14
  78. package/Components/RouteManager/__tests__/testId.test.js +8 -6
  79. package/Components/Screen/TV/__tests__/index.web.test.tsx +26 -0
  80. package/Components/Screen/TV/index.web.tsx +5 -6
  81. package/Components/Screen/__tests__/Screen.test.tsx +22 -14
  82. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +2 -2
  83. package/Components/Screen/hooks.ts +3 -6
  84. package/Components/ScreenResolver/__tests__/screenResolver.test.js +91 -70
  85. package/Components/TopMarginApplicator/TopMarginApplicator.tsx +2 -3
  86. package/Components/TrackedView/index.tsx +1 -0
  87. package/Components/Transitioner/AnimationManager.js +15 -15
  88. package/Components/Transitioner/__tests__/Scene.test.js +25 -14
  89. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +12 -68
  90. package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +2 -2
  91. package/Components/Transitioner/__tests__/transitioner.test.js +13 -4
  92. package/Components/VideoLive/PlayerLiveImageComponent.tsx +4 -0
  93. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +1 -0
  94. package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +1 -1
  95. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +35 -19
  96. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +3 -3
  97. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +38 -14
  98. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +10 -3
  99. package/Components/VideoModal/ModalAnimation/__tests__/getMoveUpValue.test.ts +108 -0
  100. package/Components/VideoModal/ModalAnimation/const.ts +5 -0
  101. package/Components/VideoModal/ModalAnimation/index.ts +2 -0
  102. package/Components/VideoModal/ModalAnimation/utils.ts +30 -0
  103. package/Components/VideoModal/PlayerDetails.tsx +13 -5
  104. package/Components/VideoModal/PlayerWrapper.tsx +35 -22
  105. package/Components/VideoModal/VideoModal.tsx +19 -4
  106. package/Components/VideoModal/__tests__/__snapshots__/PlayerDetails.test.tsx.snap +2 -40
  107. package/Components/VideoModal/utils.ts +3 -4
  108. package/Components/Viewport/ViewportAware/__tests__/__snapshots__/viewportAware.test.js.snap +24 -36
  109. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +12 -18
  110. package/Components/Viewport/__tests__/utils.test.js +5 -4
  111. package/Components/ZappUIComponent/Placeholder.tsx +3 -1
  112. package/Components/ZappUIComponent/__tests__/{ZappUIComponent.test.js → ZappUIComponent.test.tsx} +26 -10
  113. package/Components/ZappUIComponent/index.tsx +4 -17
  114. package/Components/default-cell-renderer/__tests__/defaultCellRenderer.test.tsx +20 -17
  115. package/Components/default-cell-renderer/viewTrees/tv/DefaultCell/__tests__/DefaultCell.test.tsx +15 -11
  116. package/Contexts/ComponentsMapOffsetContext/index.tsx +49 -0
  117. package/Contexts/FocusableGroupContext/withFocusableContext.tsx +4 -10
  118. package/Contexts/HeaderOffsetContext/index.tsx +4 -6
  119. package/Contexts/ScreenContext/index.tsx +3 -10
  120. package/Contexts/ScreenLayoutContext/index.tsx +5 -3
  121. package/Decorators/Navigator/__tests__/navigator.test.js +16 -16
  122. package/Decorators/Navigator/index.tsx +1 -1
  123. package/Decorators/RiverResolver/__tests__/riverResolver.test.tsx +18 -24
  124. package/Decorators/RiverResolver/index.tsx +6 -8
  125. package/Decorators/ZappPipesDataConnector/__tests__/zappPipesDataConnector.test.js +29 -22
  126. package/Decorators/ZappPipesDataConnector/index.tsx +4 -30
  127. package/package.json +7 -11
  128. package/tsconfig.json +2 -3
  129. package/.babelrc +0 -8
  130. package/Components/Cell/CellStyles/FallbackCellStyle/index.js +0 -157
  131. package/Components/Cell/CellStyles/Hero/index.js +0 -111
  132. package/Components/Cell/CellStyles/ScreenSelector/index.js +0 -68
  133. package/Components/Cell/CellStyles/cellStylesResolver.ts +0 -19
  134. package/Components/Cell/CellStyles/colors.js +0 -40
  135. package/Components/Cell/CellStyles/index.js +0 -15
  136. package/Components/Cell/CellWithFocusable.ios.tsx +0 -126
  137. package/Components/CellRendererResolver/__tests__/__snapshots__/cellRendererResolver.test.js.snap +0 -53
  138. package/Components/RouteManager/__tests__/__snapshots__/testId.test.js.snap +0 -17
  139. package/Components/ScreenResolver/__tests__/__snapshots__/screenResolver.test.js.snap +0 -17
  140. package/Components/ZappUIComponent/__tests__/__snapshots__/ZappUIComponent.test.js.snap +0 -91
  141. package/Components/default-cell-renderer/__tests__/__snapshots__/defaultCellRenderer.test.tsx.snap +0 -338
  142. package/Decorators/Navigator/__tests__/__snapshots__/navigator.test.js.snap +0 -18
  143. package/Decorators/RiverResolver/__tests__/__snapshots__/riverResolver.test.tsx.snap +0 -28
@@ -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";
@@ -65,6 +65,7 @@ type Props = {
65
65
  isFocusable: boolean;
66
66
  shouldUpdate: boolean;
67
67
  behavior: Behavior;
68
+ componentsMapOffset: number;
68
69
  };
69
70
 
70
71
  type State = {
@@ -179,6 +180,7 @@ export class TvOSCellComponent extends React.Component<Props, State> {
179
180
  groupId,
180
181
  component,
181
182
  index,
183
+ componentsMapOffset,
182
184
  } = this.props;
183
185
 
184
186
  this.setScreenLayout(componentAnchorPointY, screenLayout);
@@ -193,13 +195,11 @@ export class TvOSCellComponent extends React.Component<Props, State> {
193
195
  const extraAnchorPointYOffset =
194
196
  screenLayout?.extraAnchorPointYOffset || 0;
195
197
 
196
- const marginTop = screenLayout?.screenMarginTop || 0;
197
-
198
198
  const totalOffset =
199
199
  headerOffset +
200
- (componentAnchorPointY || 0) +
201
- extraAnchorPointYOffset -
202
- marginTop;
200
+ (componentAnchorPointY || 0) +
201
+ extraAnchorPointYOffset -
202
+ componentsMapOffset || 0;
203
203
 
204
204
  mainOffsetUpdater?.(
205
205
  { tag: this.target },
@@ -247,7 +247,7 @@ export class TvOSCellComponent extends React.Component<Props, State> {
247
247
 
248
248
  const focusableId = R.join("-", [component?.id, id, index]);
249
249
 
250
- const handleFocus = (arg1: any, index: number) => {
250
+ const handleFocus = (arg1: any, index?: number) => {
251
251
  const focusFn = onFocus || noop;
252
252
  focusFn(arg1, index);
253
253
 
@@ -280,7 +280,7 @@ export class TvOSCellComponent extends React.Component<Props, State> {
280
280
  <View onLayout={this.onLayout} style={styles.container}>
281
281
  <Focusable
282
282
  id={focusableId}
283
- groupId={groupId || component?.id}
283
+ groupId={String(groupId || component?.id)}
284
284
  onFocus={handleFocus}
285
285
  onBlur={onBlur || this.onBlur}
286
286
  isParallaxDisabled={this.layout?.width > 1740}
@@ -292,20 +292,18 @@ export class TvOSCellComponent extends React.Component<Props, State> {
292
292
  style={baseCellStyles}
293
293
  isFocusable={isFocusable}
294
294
  >
295
- {(focused) => {
296
- return (
297
- <FocusableCell
298
- {...{
299
- index,
300
- CellRenderer,
301
- item,
302
- focused: this.props.focused || selectedCell || focused,
303
- scrollTo: this.scrollTo,
304
- behavior,
305
- }}
306
- />
307
- );
308
- }}
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
+ )}
309
307
  </Focusable>
310
308
  </View>
311
309
  );
@@ -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);
@@ -0,0 +1,17 @@
1
+ import { StyleSheet } from "react-native";
2
+
3
+ export const styles = StyleSheet.create({
4
+ cellWrapper: {
5
+ flex: 0,
6
+ height: "100%",
7
+ },
8
+ baseCell: {
9
+ height: "100%",
10
+ display: "flex",
11
+ flex: 1,
12
+ },
13
+ touchableCell: {
14
+ flex: 1,
15
+ height: "100%",
16
+ },
17
+ });
@@ -1,6 +1,7 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
- import { shallow } from "enzyme";
3
+ import { render } from "@testing-library/react-native";
4
+ import { CellRendererResolver } from "../";
4
5
 
5
6
  jest.mock("../../default-cell-renderer", () => {
6
7
  const View = jest.requireActual("react-native").View;
@@ -8,8 +9,6 @@ jest.mock("../../default-cell-renderer", () => {
8
9
  return jest.fn((prop) => <View whoAmI="default renderer" someProp={prop} />);
9
10
  });
10
11
 
11
- const { CellRendererResolver } = require("../index");
12
-
13
12
  const component = {
14
13
  styles: {
15
14
  cell_plugin_configuration_id: "ABCDE-123456",
@@ -45,17 +44,9 @@ describe("CellRendererResolver", () => {
45
44
  cellStyles,
46
45
  });
47
46
 
48
- it("renders correctly", () => {
49
- const result = shallow(
50
- getResult({ component, plugins, styles, cellStyles })
51
- );
52
-
53
- expect(result).toMatchSnapshot();
54
- });
55
-
56
47
  describe("with a default renderer plugin", () => {
57
48
  it("renders correctly", () => {
58
- const result = shallow(
49
+ const { UNSAFE_root } = render(
59
50
  getResult({
60
51
  component,
61
52
  plugins,
@@ -64,56 +55,63 @@ describe("CellRendererResolver", () => {
64
55
  })
65
56
  );
66
57
 
67
- expect(result).toMatchSnapshot();
58
+ expect(UNSAFE_root).toBeDefined();
68
59
  });
69
60
 
70
61
  it("returns default plugin if component has no cell_plugin_configuration_id", () => {
71
- const result = getResult({
72
- component: {},
73
- plugins,
74
- styles,
75
- cellStyles,
76
- });
77
-
78
- expect(result).toBeDefined();
79
- expect(result.props.whoAmI).toEqual("default renderer");
62
+ const { UNSAFE_getByProps } = render(
63
+ getResult({
64
+ component: {},
65
+ plugins,
66
+ styles,
67
+ cellStyles,
68
+ })
69
+ );
70
+
71
+ expect(UNSAFE_getByProps({ whoAmI: "default renderer" })).toBeTruthy();
80
72
  });
81
73
 
82
74
  it("returns default plugin if requested cell plugin configuration does not exist", () => {
83
- const result = getResult({
84
- component: { styles: { cell_plugin_configuration_id: "wrong-id" } },
85
- plugins,
86
- styles,
87
- cellStyles,
88
- });
89
-
90
- expect(result.props.whoAmI).toEqual("default renderer");
75
+ const { UNSAFE_getByProps } = render(
76
+ getResult({
77
+ component: { styles: { cell_plugin_configuration_id: "wrong-id" } },
78
+ plugins,
79
+ styles,
80
+ cellStyles,
81
+ })
82
+ );
83
+
84
+ expect(UNSAFE_getByProps({ whoAmI: "default renderer" })).toBeTruthy();
91
85
  });
92
86
 
93
87
  it("returns default plugin if cellStyles store is empty", () => {
94
- const result = getResult({
95
- component,
96
- plugins,
97
- styles,
98
- cellStyles: {},
99
- });
100
-
101
- expect(result.props.whoAmI).toEqual("default renderer");
88
+ const { UNSAFE_getByProps } = render(
89
+ getResult({
90
+ component,
91
+ plugins,
92
+ styles,
93
+ cellStyles: {},
94
+ })
95
+ );
96
+
97
+ expect(UNSAFE_getByProps({ whoAmI: "default renderer" })).toBeTruthy();
102
98
  });
103
99
 
104
100
  it("returns null if requested renderer plugin does not exist", () => {
105
- const result = getResult({
106
- component: {
107
- styles: {
108
- cell_plugin_configuration_id: "FGHIJ-123456",
101
+ const { UNSAFE_getByProps } = render(
102
+ getResult({
103
+ component: {
104
+ styles: {
105
+ cell_plugin_configuration_id: "FGHIJ-123456",
106
+ },
109
107
  },
110
- },
111
- plugins,
112
- styles,
113
- cellStyles,
114
- });
108
+ plugins,
109
+ styles,
110
+ cellStyles,
111
+ })
112
+ );
115
113
 
116
- expect(result.props.whoAmI).toEqual("default renderer");
114
+ expect(UNSAFE_getByProps({ whoAmI: "default renderer" })).toBeTruthy();
117
115
  });
118
116
  });
119
117
  });
@@ -1,4 +1,5 @@
1
1
  import { findPluginByIdentifier } from "@applicaster/zapp-react-native-utils/pluginUtils";
2
+ import { isGroup } from "@applicaster/zapp-react-native-utils/componentsUtils";
2
3
 
3
4
  import { componentsLogger } from "../../Helpers/logger";
4
5
  import defaultCellRenderer from "../default-cell-renderer";
@@ -80,7 +81,7 @@ export function CellRendererResolver({
80
81
  }: Props) {
81
82
  const cellRendererPlugin = getRendererPlugin(component, plugins, cellStyles);
82
83
 
83
- if (!cellRendererPlugin && component.component_type !== "group-qb") {
84
+ if (!cellRendererPlugin && !isGroup(component)) {
84
85
  logger.warning({
85
86
  message: "Could not resolve cell builder plugin",
86
87
  data: { component },
@@ -1,48 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`ComponentResolver renders correctly 1`] = `
4
- <ContextProvider
5
- value={null}
6
- >
7
- <Memo(ComponentResolver)
8
- cellStyles={{}}
9
- component={
10
- {
11
- "component_type": "some_component",
12
- }
13
- }
14
- components={
15
- {
16
- "SomeComponent": [MockFunction],
17
- }
18
- }
19
- decorators={[MockFunction]}
20
- dispatch={[Function]}
21
- plugins={[]}
22
- store={
23
- {
24
- "clearActions": [Function],
25
- "dispatch": [Function],
26
- "getActions": [Function],
27
- "getState": [Function],
28
- "replaceReducer": [Function],
29
- "subscribe": [Function],
30
- }
31
- }
32
- />
33
- </ContextProvider>
34
- `;
35
-
36
3
  exports[`ComponentResolverComponent initializes the cell renderer plugin module if matching plugin exists 1`] = `
37
- <mockConstructor
4
+ <View
38
5
  rendered={true}
39
6
  />
40
7
  `;
41
-
42
- exports[`ComponentResolverComponent renders the Component if it exists 1`] = `
43
- <mockConstructor
44
- rendered={true}
45
- />
46
- `;
47
-
48
- exports[`ComponentResolverComponent returns null if the component doesn't exist 1`] = `""`;
@@ -1,7 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
- import { shallow } from "enzyme";
4
- import { shallowToJson } from "enzyme-to-json";
3
+ import { render } from "@testing-library/react-native";
5
4
  import configureStore from "redux-mock-store";
6
5
 
7
6
  const mockLogger = {
@@ -43,37 +42,36 @@ const store = configureStore()({
43
42
  });
44
43
 
45
44
  const component = { component_type: "some_component" };
46
- const decorators = jest.fn((x) => x);
45
+ const decorators = (x) => x;
47
46
  const renderFunction = jest.fn((Comp) => <Comp rendered />);
48
47
 
49
48
  function clearAllMocks() {
50
- SomeComponent.mockClear();
51
- decorators.mockClear();
52
- renderFunction.mockClear();
53
- mockLogger.warning.mockClear();
49
+ jest.clearAllMocks();
54
50
  }
55
51
 
56
52
  describe("ComponentResolver", () => {
57
53
  beforeEach(clearAllMocks);
58
54
 
59
55
  it("renders correctly", () => {
60
- const wrapper = shallow(
56
+ const { toJSON } = render(
61
57
  <ComponentResolver
62
58
  component={component}
63
59
  decorators={decorators}
64
60
  store={store}
65
- />
61
+ >
62
+ {() => null}
63
+ </ComponentResolver>
66
64
  );
67
65
 
68
- expect(shallowToJson(wrapper)).toMatchSnapshot();
66
+ expect(toJSON()).toBeNull();
69
67
  });
70
68
  });
71
69
 
72
70
  describe("ComponentResolverComponent", () => {
73
71
  beforeEach(clearAllMocks);
74
72
 
75
- const getWrapper = (component, plugins) =>
76
- shallow(
73
+ const renderComponent = (component, plugins) =>
74
+ render(
77
75
  <ComponentResolverComponent
78
76
  components={components}
79
77
  component={component}
@@ -87,9 +85,9 @@ describe("ComponentResolverComponent", () => {
87
85
  );
88
86
 
89
87
  it("renders the Component if it exists", () => {
90
- const wrapper = getWrapper(component, plugins);
88
+ const { toJSON } = renderComponent(component, plugins);
91
89
 
92
- expect(shallowToJson(wrapper)).toMatchSnapshot();
90
+ expect(toJSON()).not.toBeNull();
93
91
 
94
92
  expect(renderFunction).toHaveBeenCalledWith(
95
93
  SomeComponent,
@@ -98,14 +96,12 @@ describe("ComponentResolverComponent", () => {
98
96
  });
99
97
 
100
98
  it("returns null if the component doesn't exist", () => {
101
- const wrapper = getWrapper({ component_type: "foo" }, plugins);
99
+ const { UNSAFE_root } = renderComponent({ component_type: "foo" }, plugins);
102
100
 
103
101
  const warningMessage =
104
102
  "Component foo cannot be found - it is skipped from rendering";
105
103
 
106
- expect(shallowToJson(wrapper)).toMatchSnapshot();
107
- expect(wrapper.isEmptyRender()).toBe(true);
108
-
104
+ expect(UNSAFE_root.children.length).toBe(0);
109
105
  expect(mockLogger.warning).toHaveBeenCalledTimes(2);
110
106
 
111
107
  expect(mockLogger.warning).toHaveBeenNthCalledWith(
@@ -124,11 +120,9 @@ describe("ComponentResolverComponent", () => {
124
120
  });
125
121
 
126
122
  it("initializes the cell renderer plugin module if matching plugin exists", () => {
127
- const plugins = [];
128
-
129
- const wrapper = getWrapper(component, plugins);
123
+ const { toJSON } = renderComponent(component, plugins);
130
124
 
131
- expect(shallowToJson(wrapper)).toMatchSnapshot();
125
+ expect(toJSON()).toMatchSnapshot();
132
126
 
133
127
  expect(renderFunction).toHaveBeenCalledWith(
134
128
  SomeComponent,
@@ -1,10 +1,10 @@
1
1
  import React from "react";
2
- import { shallow } from "enzyme";
2
+ import { render } from "@testing-library/react-native";
3
3
 
4
- import { ContentScreen } from "../index";
4
+ import { ContentScreen } from "../";
5
5
 
6
6
  describe("<ContentScreen />", () => {
7
7
  it("renders correctly", () => {
8
- expect(() => shallow(<ContentScreen />)).toThrowErrorMatchingSnapshot();
8
+ expect(() => render(<ContentScreen />)).toThrowErrorMatchingSnapshot();
9
9
  });
10
10
  });
@@ -105,6 +105,11 @@ const defaultProps = {
105
105
  alignItems: "center",
106
106
  justifyContent: "center",
107
107
  },
108
+ focusedButton: {
109
+ backgroundColor: "#3a3a3a",
110
+ borderColor: "#ffffff",
111
+ borderWidth: 2,
112
+ },
108
113
  buttonText: {
109
114
  fontFamily: platformSelect({
110
115
  ios: "SFProText-Medium",
@@ -116,6 +121,9 @@ const defaultProps = {
116
121
  color: "rgba(255, 255, 255, 1)",
117
122
  textTransform: "uppercase",
118
123
  },
124
+ focusedText: {
125
+ color: "#ffffff",
126
+ },
119
127
  },
120
128
  };
121
129
 
@@ -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> {
@@ -33,6 +33,8 @@ type Props = {
33
33
  onLongPress?: (ref: FocusManager.FocusableRef) => void;
34
34
  onRegister?: () => void;
35
35
  isFocusableCell?: boolean;
36
+ /** only for FocusableScrollView */
37
+ onSetIsFocusable?: (isFocusable: boolean) => void;
36
38
  } & ParentFocus;
37
39
 
38
40
  export const FocusableContext = React.createContext<
@@ -67,6 +69,7 @@ function FocusableComponent(props: Props, forwardedRef) {
67
69
  onLongPress,
68
70
  onRegister = noop,
69
71
  isFocusableCell = true,
72
+ onSetIsFocusable,
70
73
  } = props;
71
74
 
72
75
  const isRTL = useIsRTL();
@@ -137,9 +140,13 @@ function FocusableComponent(props: Props, forwardedRef) {
137
140
  [onBlur]
138
141
  );
139
142
 
140
- const setIsFocusable = React.useCallback((blockFocus) => {
141
- setDisableFocus(!blockFocus);
142
- }, []);
143
+ const setIsFocusable = React.useCallback(
144
+ (blockFocus) => {
145
+ onSetIsFocusable?.(blockFocus);
146
+ setDisableFocus(!blockFocus);
147
+ },
148
+ [onSetIsFocusable]
149
+ );
143
150
 
144
151
  const parentFocus = React.useMemo(
145
152
  () => ({
@@ -23,7 +23,7 @@ export function FocusableCell(props: Props) {
23
23
  behavior,
24
24
  } = props;
25
25
 
26
- const state = useCellState({ id: item.id, behavior, focused });
26
+ const state = useCellState({ item, behavior, focused });
27
27
 
28
28
  React.useEffect(() => {
29
29
  if (focused && scrollTo && !isAndroid) {
@@ -1,17 +1,30 @@
1
1
  import * as React from "react";
2
2
  import { FocusableGroupNative } from "@applicaster/zapp-react-native-ui-components/Components/NativeFocusables";
3
3
  import { BaseFocusable } from "@applicaster/zapp-react-native-ui-components/Components/BaseFocusable";
4
-
5
- function noop() {}
4
+ import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
5
+
6
+ const { log_verbose } = createLogger({
7
+ subsystem: "General",
8
+ category: "FocusableGroup",
9
+ });
10
+
11
+ type FocusableGroupNativeEvent = {
12
+ nativeEvent: {
13
+ focusHeading: FocusManager.Direction;
14
+ groupId: string;
15
+ isActive: boolean;
16
+ isFocusDisabled: boolean;
17
+ isFocusingByUser: boolean;
18
+ itemId: string;
19
+ target: number;
20
+ };
21
+ };
6
22
 
7
23
  type Props = {
8
24
  id: string;
9
25
  children: (arg1: boolean) => React.ComponentType<any>;
10
- onWillUpdateFocus: (nativeEvent: any) => void;
11
- onDidUpdateFocus: (nativeEvent: any) => void;
12
26
  isFocusDisabled: boolean;
13
- initialItemId: string;
14
- resetFocusToInitialValue: boolean;
27
+ isWithMemory: boolean;
15
28
  focusGroupRef: React.Component;
16
29
  shouldUsePreferredFocus: boolean;
17
30
  groupId: string;
@@ -21,86 +34,26 @@ type Props = {
21
34
  };
22
35
 
23
36
  export class FocusableGroup extends BaseFocusable<Props> {
24
- focusableGroupNativeRef: React.Component | null;
25
- constructor(props) {
26
- super(props);
27
- this.focusableGroupNativeRef = null;
28
-
29
- this.state = {
30
- isActive: false,
31
- };
32
-
33
- this.onWillUpdateFocus = this.onWillUpdateFocus.bind(this);
34
- this.onDidUpdateFocus = this.onDidUpdateFocus.bind(this);
35
- this.isGroup = true;
36
-
37
- this.shouldUsePreferredFocus = this.shouldUsePreferredFocus.bind(this);
38
- this.measureView = this.measureView.bind(this);
39
- }
40
-
41
- connectedScreenId() {
42
- const {
43
- screenData: { screenId, parentScreenId },
44
- } = this.props;
45
-
46
- if (screenId) {
47
- return null;
48
- }
49
-
50
- return parentScreenId ? `${parentScreenId}-${screenId}` : screenId;
51
- }
52
-
53
- /**
54
- * tells whether the group should give focus to a preferred item when it gains focus from another
55
- * group
56
- * @returns {boolean}
57
- */
58
- shouldUsePreferredFocus() {
59
- return this.props.shouldUsePreferredFocus || false;
60
- }
61
-
62
- /**
63
- * indicates whether the underlying component should claim preferred focus
64
- * when navigating into the group of this item
65
- * @returns {boolean}
66
- */
67
- isPreferredFocus() {
68
- return this.props.preferredFocus || false;
69
- }
70
-
71
- onWillUpdateFocus({ nativeEvent }) {
72
- const { isActive } = nativeEvent;
73
- this.setState({ isActive });
74
- const { onWillUpdateFocus = noop } = this.props;
75
- onWillUpdateFocus(nativeEvent);
76
- }
77
-
78
- onDidUpdateFocus({ nativeEvent }) {
79
- const { onDidUpdateFocus = noop } = this.props;
80
- onDidUpdateFocus(nativeEvent);
81
- }
82
-
83
- setFocusDisabled(isFocusDisabled) {
84
- if (this.ref) {
85
- this.ref.current.setNativeProps({
86
- isFocusDisabled,
87
- });
88
- }
89
- }
90
-
91
37
  render() {
92
38
  const {
93
39
  children,
94
40
  id,
95
41
  isFocusDisabled,
96
- initialItemId,
97
- resetFocusToInitialValue,
98
- style,
42
+ isWithMemory,
43
+ style = {},
99
44
  groupId,
100
45
  ...otherProps
101
46
  } = this.props;
102
47
 
103
- const focusableStyles = style || {};
48
+ const onGroupFocus = ({ nativeEvent }: FocusableGroupNativeEvent) => {
49
+ log_verbose("FOCUSABLE_GROUP: onGroupFocus", { nativeEvent });
50
+ this.onFocus(this.ref, nativeEvent.focusHeading);
51
+ };
52
+
53
+ const onGroupBlur = ({ nativeEvent }: FocusableGroupNativeEvent) => {
54
+ log_verbose("FOCUSABLE_GROUP: onGroupBlur", { nativeEvent });
55
+ this.onBlur(this.ref, nativeEvent.focusHeading);
56
+ };
104
57
 
105
58
  return (
106
59
  <FocusableGroupNative
@@ -108,16 +61,11 @@ export class FocusableGroup extends BaseFocusable<Props> {
108
61
  itemId={id}
109
62
  ref={this.ref}
110
63
  isFocusDisabled={isFocusDisabled}
111
- initialItemId={initialItemId}
112
- resetFocusToInitialValue={resetFocusToInitialValue}
113
- onLayout={this.measureView}
114
- onViewFocus={this.onFocus}
115
- onViewPress={this.onPress}
116
- onViewBlur={this.onBlur}
117
- style={focusableStyles}
64
+ isWithMemory={isWithMemory}
65
+ onGroupFocus={onGroupFocus}
66
+ onGroupBlur={onGroupBlur}
67
+ style={style}
118
68
  {...otherProps}
119
- onWillUpdateFocus={this.onWillUpdateFocus}
120
- onDidUpdateFocus={this.onDidUpdateFocus}
121
69
  >
122
70
  {children}
123
71
  </FocusableGroupNative>