@applicaster/zapp-react-native-ui-components 13.0.0-alpha.6714678893 → 13.0.0-alpha.7100577251

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 (123) 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.ios.ts +1 -1
  10. package/Components/BaseFocusable/index.tsx +66 -29
  11. package/Components/Cell/Cell.tsx +7 -3
  12. package/Components/Cell/TvOSCellComponent.tsx +4 -8
  13. package/Components/CellRendererResolver/__tests__/__snapshots__/cellRendererResolver.test.js.snap +20 -20
  14. package/Components/CellRendererResolver/__tests__/cellRendererResolver.test.js +5 -3
  15. package/Components/ComponentResolver/__tests__/__snapshots__/componentResolver.test.js.snap +5 -5
  16. package/Components/ComponentResolver/__tests__/componentResolver.test.js +11 -9
  17. package/Components/DisplayState/__tests__/__snapshots__/displayState.test.js.snap +2 -2
  18. package/Components/Focusable/Focusable.tsx +0 -54
  19. package/Components/Focusable/FocusableTvOS.tsx +1 -5
  20. package/Components/Focusable/Touchable.tsx +19 -20
  21. package/Components/FocusableList/index.tsx +0 -1
  22. package/Components/FocusableScrollView/index.tsx +12 -39
  23. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +9 -0
  24. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +1 -1
  25. package/Components/Layout/TV/__tests__/ScreenContainer.test.tsx +1 -0
  26. package/Components/Layout/TV/__tests__/__snapshots__/LayoutContainer.test.tsx.snap +1 -1
  27. package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +3 -3
  28. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +9 -9
  29. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +1 -1
  30. package/Components/Layout/TV/__tests__/index.test.tsx +7 -3
  31. package/Components/MasterCell/DefaultComponents/BorderContainerView/__tests__/index.test.tsx +66 -0
  32. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +4 -1
  33. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +6 -12
  34. package/Components/MasterCell/DefaultComponents/ImageBorderContainer/__tests__/index.test.ts +93 -0
  35. package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/__snapshots__/Image.test.tsx.snap +3 -3
  36. package/Components/MasterCell/DefaultComponents/SecondaryImage/utils.ts +1 -1
  37. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
  38. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/__snapshots__/index.test.tsx.snap +1 -1
  39. package/Components/MasterCell/__tests__/__snapshots__/dataAdapter.test.js.snap +180 -180
  40. package/Components/MasterCell/__tests__/__snapshots__/elementMapper.test.js.snap +7 -7
  41. package/Components/MasterCell/__tests__/__snapshots__/masterCell.test.js.snap +34 -34
  42. package/Components/MasterCell/hooks/useAsyncRendering/MasterCellAsyncRenderManager.ts +2 -2
  43. package/Components/MasterCell/hooks/useAsyncRendering/index.ts +2 -2
  44. package/Components/MasterCell/utils/index.ts +1 -1
  45. package/Components/ModalComponent/Header/index.tsx +3 -3
  46. package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +7 -7
  47. package/Components/OfflineHandler/__tests__/index.test.tsx +28 -25
  48. package/Components/PlayerContainer/PlayerContainer.tsx +5 -11
  49. package/Components/PlayerContainer/PlayerContainerContext.tsx +9 -0
  50. package/Components/PlayerImageBackground/index.tsx +23 -3
  51. package/Components/River/ComponentsMap/ComponentsMap.tsx +39 -65
  52. package/Components/River/ComponentsMap/hooks/useLoadingState.ts +78 -51
  53. package/Components/River/RefreshControl.tsx +1 -1
  54. package/Components/River/RiverFooter.tsx +39 -9
  55. package/Components/River/RiverItem.tsx +37 -2
  56. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +114 -45
  57. package/Components/River/__tests__/__snapshots__/river.test.js.snap +12 -12
  58. package/Components/River/__tests__/componentsMap.test.js +64 -17
  59. package/Components/RouteManager/__tests__/__snapshots__/routeManager.test.js.snap +1 -1
  60. package/Components/RouteManager/__tests__/__snapshots__/testId.test.js.snap +1 -1
  61. package/Components/Screen/__tests__/Screen.test.tsx +41 -27
  62. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +4 -4
  63. package/Components/Screen/hooks.ts +56 -0
  64. package/Components/Screen/index.tsx +13 -39
  65. package/Components/ScreenResolver/__tests__/__snapshots__/screenResolver.test.js.snap +2 -2
  66. package/Components/ScreenResolver/__tests__/screenResolver.test.js +31 -27
  67. package/Components/Tabs/Tab.tsx +7 -6
  68. package/Components/TextInputTv/__tests__/TextInputTv.test.js +42 -42
  69. package/Components/TextInputTv/__tests__/__snapshots__/TextInputTv.test.js.snap +7 -0
  70. package/Components/TextInputTv/index.tsx +4 -4
  71. package/Components/Touchable/__tests__/__snapshots__/touchable.test.tsx.snap +2 -2
  72. package/Components/Transitioner/AnimationManager.js +8 -8
  73. package/Components/Transitioner/Scene.tsx +52 -23
  74. package/Components/Transitioner/__tests__/__snapshots__/AnimationManager.test.js.snap +26 -26
  75. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +62 -46
  76. package/Components/Transitioner/__tests__/__snapshots__/config.test.js.snap +20 -20
  77. package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +4 -4
  78. package/Components/Transitioner/index.js +8 -4
  79. package/Components/VideoLive/LiveImageManager.ts +27 -1
  80. package/Components/VideoLive/PlayerLiveImageComponent.tsx +29 -21
  81. package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +63 -8
  82. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +5 -10
  83. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +5 -1
  84. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +5 -1
  85. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +8 -7
  86. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +4 -10
  87. package/Components/VideoModal/ModalAnimation/index.ts +2 -1
  88. package/Components/VideoModal/ModalAnimation/useModalAnimationContext.ts +6 -0
  89. package/Components/VideoModal/ModalAnimation/utils.ts +2 -2
  90. package/Components/VideoModal/OpaqueLayer.tsx +33 -0
  91. package/Components/VideoModal/PlayerDetails.tsx +4 -1
  92. package/Components/VideoModal/PlayerWrapper.tsx +16 -35
  93. package/Components/VideoModal/VideoModal.tsx +14 -23
  94. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +5 -2
  95. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +13 -10
  96. package/Components/VideoModal/__tests__/__snapshots__/PlayerDetails.test.tsx.snap +4 -4
  97. package/Components/VideoModal/__tests__/__snapshots__/PlayerWrapper.test.tsx.snap +66 -156
  98. package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +89 -0
  99. package/Components/VideoModal/hooks/index.ts +7 -0
  100. package/Components/VideoModal/hooks/useDelayedPlayerDetails.ts +49 -0
  101. package/Components/VideoModal/hooks/utils/__tests__/showDetails.test.ts +91 -0
  102. package/Components/VideoModal/hooks/utils/index.ts +33 -0
  103. package/Components/VideoModal/utils.ts +3 -5
  104. package/Components/Viewport/ViewportAware/__tests__/__snapshots__/viewportAware.test.js.snap +2 -2
  105. package/Components/Viewport/ViewportTracker/__tests__/__snapshots__/viewportTracker.test.js.snap +1 -1
  106. package/Components/ZappUIComponent/__tests__/__snapshots__/ZappUIComponent.test.js.snap +11 -11
  107. package/Components/default-cell-renderer/__tests__/__snapshots__/defaultCellRenderer.test.tsx.snap +30 -30
  108. package/Contexts/ConfigutaionContext/__tests__/__snapshots__/ConfigurationProvider.test.tsx.snap +1 -1
  109. package/Contexts/ScreenContext/index.tsx +3 -2
  110. package/Decorators/Navigator/__tests__/__snapshots__/navigator.test.js.snap +2 -2
  111. package/Decorators/RiverFeedLoader/__tests__/__snapshots__/riverFeedLoader.test.tsx.snap +77 -77
  112. package/Decorators/RiverFeedLoader/__tests__/riverFeedLoader.test.tsx +34 -39
  113. package/Decorators/RiverFeedLoader/__tests__/utils.test.ts +0 -9
  114. package/Decorators/RiverFeedLoader/index.tsx +1 -1
  115. package/Decorators/RiverFeedLoader/utils/getDatasourceUrl.ts +39 -0
  116. package/Decorators/RiverFeedLoader/utils/index.ts +29 -0
  117. package/Decorators/RiverFeedLoader/utils/usePipesContexts.ts +40 -0
  118. package/Decorators/RiverResolver/__tests__/__snapshots__/riverResolver.test.tsx.snap +5 -5
  119. package/Decorators/RiverResolver/__tests__/riverResolver.test.tsx +16 -10
  120. package/Decorators/ZappPipesDataConnector/__tests__/Hero.js +1 -1
  121. package/Decorators/ZappPipesDataConnector/index.tsx +32 -2
  122. package/package.json +12 -6
  123. package/Decorators/RiverFeedLoader/utils.ts +0 -100
@@ -2,10 +2,6 @@
2
2
  import React from "react";
3
3
  import { View } from "react-native";
4
4
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
5
- import {
6
- isOrientationCompatible,
7
- useGetScreenOrientation,
8
- } from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
9
5
 
10
6
  import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
11
7
  import { getComponentModule } from "@applicaster/zapp-react-native-utils/pluginUtils";
@@ -15,7 +11,6 @@ import {
15
11
  getScreenId,
16
12
  } from "@applicaster/zapp-react-native-utils/navigationUtils";
17
13
  import {
18
- useDimensions,
19
14
  useRoute,
20
15
  useCurrentScreenData,
21
16
  useNavbarState,
@@ -27,6 +22,7 @@ import { getNavigationPluginModule } from "@applicaster/zapp-react-native-app/Ap
27
22
  import { RouteManager } from "../RouteManager";
28
23
  import { useScreenConfiguration } from "../River/useScreenConfiguration";
29
24
  import { isValidColor } from "./utils";
25
+ import { useWaitForValidOrientation } from "./hooks";
30
26
 
31
27
  const screenStyles = {
32
28
  flex: 1,
@@ -50,14 +46,6 @@ export function Screen(_props: Props) {
50
46
  const currentScreenData = useCurrentScreenData();
51
47
  const { backgroundColor } = useScreenConfiguration(currentScreenData.id);
52
48
 
53
- const {
54
- width: screenWidth,
55
- height,
56
- deviceInfo,
57
- } = useDimensions("screen", {
58
- fullDimensions: true,
59
- });
60
-
61
49
  const { screenData, pathname } = useRoute();
62
50
 
63
51
  const currentRiver = useScreenData(
@@ -66,13 +54,6 @@ export function Screen(_props: Props) {
66
54
 
67
55
  const { title } = useNavbarState();
68
56
 
69
- const isTablet = deviceInfo?.isTablet;
70
-
71
- const { appData } = usePickFromState(["appData"]);
72
- const isTabletPortrait = appData?.isTabletPortrait;
73
-
74
- const layoutData = { isTablet, isTabletPortrait, width: screenWidth, height };
75
-
76
57
  const hasMenu = shouldNavBarDisplayMenu(currentRiver, plugins);
77
58
 
78
59
  const navBarProps = React.useMemo<MobileNavBarPluginProps | null>(
@@ -108,30 +89,23 @@ export function Screen(_props: Props) {
108
89
  [theme.app_background_color, backgroundColor]
109
90
  );
110
91
 
111
- const targetScreenData =
112
- currentScreenData || (screenData as any)?.targetScreen || screenData;
113
-
114
- const orientation = useGetScreenOrientation(targetScreenData);
92
+ // Set ready state when screen is rotated to desired orientation
93
+ const isReady = useWaitForValidOrientation();
115
94
 
116
95
  // We prevent rendering of the screen until UI is actually rotated to screen desired orientation.
117
96
  // This saves unnecessary re-renders and user will not see distorted aspect screen.
118
- if (
119
- !isOrientationCompatible({
120
- orientation,
121
- layoutData,
122
- })
123
- ) {
124
- return <View style={style} />;
125
- }
126
-
127
97
  return (
128
98
  <View style={style}>
129
- {navBarProps && <NavBar {...navBarProps} hasMenu={hasMenu} />}
130
-
131
- <OfflineFallbackScreen>
132
- {/* @TODO RouteManager doesn't use props, can they be removed ? */}
133
- <RouteManager pathname={pathname} screenData={screenData} />
134
- </OfflineFallbackScreen>
99
+ {isReady ? (
100
+ <>
101
+ {navBarProps && <NavBar {...navBarProps} hasMenu={hasMenu} />}
102
+
103
+ <OfflineFallbackScreen>
104
+ {/* @TODO RouteManager doesn't use props, can they be removed ? */}
105
+ <RouteManager pathname={pathname} screenData={screenData} />
106
+ </OfflineFallbackScreen>
107
+ </>
108
+ ) : null}
135
109
  </View>
136
110
  );
137
111
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  exports[`<ScreenResolver /> renders correctly 1`] = `
4
4
  <mockConstructor
5
- screenData={Object {}}
5
+ screenData={{}}
6
6
  screenId="1234"
7
7
  screenType="screen_type_1"
8
8
  />
@@ -11,7 +11,7 @@ exports[`<ScreenResolver /> renders correctly 1`] = `
11
11
  exports[`<ScreenResolver /> wraps the player with the playerController component when the screenType is playable 1`] = `
12
12
  <HandlePlayable
13
13
  isModal={false}
14
- item={Object {}}
14
+ item={{}}
15
15
  mode="FULLSCREEN"
16
16
  />
17
17
  `;
@@ -2,42 +2,39 @@ import React from "react";
2
2
  import { View } from "react-native";
3
3
  import { shallow } from "enzyme";
4
4
  import { shallowToJson } from "enzyme-to-json";
5
- import { connect as realConnect } from "react-redux";
6
-
7
5
  const pluginConfiguration = { foo: "bar" };
8
6
 
9
7
  const ScreenType1 = jest.fn(() => <View />);
10
8
  const ScreenType2 = jest.fn(() => <View />);
9
+ const PlayerController = jest.fn(() => <View />);
11
10
 
12
- const ScreenType3 = {
11
+ const mockScreenType3 = {
13
12
  module: jest.fn(() => <View />),
14
13
  name: "ScreenType3",
15
14
  type: "screen_type_3",
16
15
  configuration: pluginConfiguration,
17
16
  };
18
17
 
19
- const ScreenType4 = {
18
+ const mockScreenType4 = {
20
19
  module: jest.fn(() => <View />),
21
20
  name: "ScreenType4",
22
21
  type: "screen_type_4",
23
22
  };
24
23
 
25
- const PlayerController = jest.fn(() => <View />);
26
-
27
- const playerPlugin = {
24
+ const mockPlayerPlugin = {
28
25
  module: jest.fn(() => <View />),
29
26
  name: "playerPlugin",
30
27
  type: "player",
31
28
  };
32
29
 
33
- const ScreenPlugin = {
30
+ const mockScreenPlugin = {
34
31
  module: jest.fn(() => <View />),
35
32
  type: "general",
36
33
  name: "Screen plugin",
37
34
  identifier: "screen-plugin",
38
35
  };
39
36
 
40
- const PluginWithConfig = {
37
+ const mockPluginWithConfig = {
41
38
  module: jest.fn(() => <View />),
42
39
  type: "general",
43
40
  name: "Plugin with config",
@@ -47,15 +44,7 @@ const PluginWithConfig = {
47
44
 
48
45
  const components = { ScreenType1, ScreenType2, PlayerController };
49
46
 
50
- const plugins = {
51
- ScreenType3,
52
- ScreenType4,
53
- playerPlugin,
54
- ScreenPlugin,
55
- PluginWithConfig,
56
- };
57
-
58
- const withAnalytics = {
47
+ const mockWithAnalytics = {
59
48
  sendOnClickEvent: jest.fn(),
60
49
  sendMenuClickEvent: jest.fn(),
61
50
  sendMenuToggleEvent: jest.fn(),
@@ -66,24 +55,39 @@ const withAnalytics = {
66
55
  sendScreenEvent: jest.fn(),
67
56
  };
68
57
 
58
+ const mockUsePickFromState = jest.fn(() => {
59
+ return {
60
+ components,
61
+ plugins: {
62
+ ScreenType3: mockScreenType3,
63
+ ScreenType4: mockScreenType4,
64
+ playerPlugin: mockPlayerPlugin,
65
+ ScreenPlugin: mockScreenPlugin,
66
+ PluginWithConfig: mockPluginWithConfig,
67
+ },
68
+ };
69
+ });
70
+
69
71
  jest.mock("@applicaster/zapp-react-native-utils/analyticsUtils", () => ({
70
- useAnalytics: jest.fn().mockReturnValue(withAnalytics),
72
+ useAnalytics: jest.fn().mockReturnValue(mockWithAnalytics),
71
73
  }));
72
74
 
73
75
  jest.mock("@applicaster/zapp-react-native-redux/hooks", () => ({
74
- usePickFromState: jest.fn(() => ({ components, plugins })),
76
+ usePickFromState: mockUsePickFromState,
75
77
  }));
76
78
 
79
+ const mockUseScreenAnalytics = jest.fn();
80
+
77
81
  jest.mock(
78
82
  "@applicaster/zapp-react-native-utils/analyticsUtils/helpers/hooks",
79
83
  () => ({
80
- useScreenAnalytics: jest.fn(() => {}),
84
+ useScreenAnalytics: mockUseScreenAnalytics,
81
85
  })
82
86
  );
83
87
 
84
88
  jest.mock("react-redux", () => ({
89
+ ...jest.requireActual("react-redux"),
85
90
  useDispatch: jest.fn(() => () => {}),
86
- connect: realConnect,
87
91
  }));
88
92
 
89
93
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
@@ -118,13 +122,13 @@ describe("<ScreenResolver />", () => {
118
122
  it("picks screen from plugins if it exists", () => {
119
123
  const wrapper = getWrapper("A1234", "screen_type_3", {});
120
124
 
121
- expect(wrapper.find(ScreenType3.module)).toHaveProperty("length", 1);
125
+ expect(wrapper.find(mockScreenType3.module)).toHaveProperty("length", 1);
122
126
  });
123
127
 
124
128
  it("picks the screen from its identifier if it exists", () => {
125
129
  const wrapper = getWrapper("A1234", "screen-plugin", {});
126
130
 
127
- expect(wrapper.find(ScreenPlugin.module)).toHaveProperty("length", 1);
131
+ expect(wrapper.find(mockScreenPlugin.module)).toHaveProperty("length", 1);
128
132
  });
129
133
 
130
134
  it("picks screen from components if it doesn't exist in plugins", () => {
@@ -136,7 +140,7 @@ describe("<ScreenResolver />", () => {
136
140
  it("renders the screen and passes screenId & locationState as props", () => {
137
141
  const wrapper = getWrapper("A1234", "screen_type_3", "foo");
138
142
 
139
- const screenWrapper = wrapper.find(ScreenType3.module);
143
+ const screenWrapper = wrapper.find(mockScreenType3.module);
140
144
 
141
145
  expect(screenWrapper.prop("screenId")).toEqual("A1234");
142
146
  expect(screenWrapper.prop("screenData")).toEqual("foo");
@@ -151,7 +155,7 @@ describe("<ScreenResolver />", () => {
151
155
  it("injects the plugin configuration if it exists", () => {
152
156
  const wrapper = getWrapper("A1234", "plugin-with-config", {});
153
157
 
154
- expect(wrapper.find(PluginWithConfig.module).props()).toHaveProperty(
158
+ expect(wrapper.find(mockPluginWithConfig.module).props()).toHaveProperty(
155
159
  "configuration",
156
160
  expect.objectContaining(pluginConfiguration)
157
161
  );
@@ -160,7 +164,7 @@ describe("<ScreenResolver />", () => {
160
164
  it("injects the plugin configuration if it exists, even when plugin is resolved by type", () => {
161
165
  const wrapper = getWrapper("A1234", "screen_type_3", {});
162
166
 
163
- expect(wrapper.find(ScreenType3.module).props()).toHaveProperty(
167
+ expect(wrapper.find(mockScreenType3.module).props()).toHaveProperty(
164
168
  "configuration",
165
169
  expect.objectContaining(pluginConfiguration)
166
170
  );
@@ -69,8 +69,8 @@ const getStyles = (configuration, selected, focused) => {
69
69
  ? tab_cell_background_color_selected_active
70
70
  : tab_cell_background_color_selected_default
71
71
  : focused
72
- ? tab_cell_background_color_active
73
- : tab_cell_background_color_default,
72
+ ? tab_cell_background_color_active
73
+ : tab_cell_background_color_default,
74
74
  justifyContent: "center",
75
75
  alignItems: "center",
76
76
  position: "relative",
@@ -85,8 +85,8 @@ const getStyles = (configuration, selected, focused) => {
85
85
  ? tab_cell_border_color_active_focused
86
86
  : tab_cell_border_color_active
87
87
  : focused
88
- ? tab_cell_border_color_default_focused
89
- : tab_cell_border_color_default,
88
+ ? tab_cell_border_color_default_focused
89
+ : tab_cell_border_color_default,
90
90
  },
91
91
  label: {
92
92
  fontFamily: text_label_font_family,
@@ -98,8 +98,8 @@ const getStyles = (configuration, selected, focused) => {
98
98
  ? text_label_selected_active_font_color
99
99
  : text_label_selected_default_font_color
100
100
  : focused
101
- ? text_label_active_font_color
102
- : text_label_default_font_color,
101
+ ? text_label_active_font_color
102
+ : text_label_default_font_color,
103
103
  },
104
104
  underline: {
105
105
  position: "absolute",
@@ -138,6 +138,7 @@ const Tab = ({ title, selected, handleOnPress }: Props, ref: any) => {
138
138
 
139
139
  return (
140
140
  <TouchableWithoutFeedback
141
+ testID="tab-touchable"
141
142
  onPressIn={handleOnPressIn}
142
143
  onPressOut={handleOnPressOut}
143
144
  onPress={handleOnPress}
@@ -1,18 +1,13 @@
1
1
  import React from "react";
2
- import TestRenderer from "react-test-renderer";
3
-
4
- jest.mock("react-native", () => {
5
- const RNMock = jest.genMockFromModule("react-native");
6
- const { TextInput } = jest.requireActual("react-native");
7
-
8
- return {
9
- ...RNMock,
10
- TextInput,
11
- Platform: {
12
- OS: "samsung_tv",
13
- isTV: true,
14
- },
15
- };
2
+ import { Platform } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+
5
+ Platform.OS = "samsung_tv";
6
+
7
+ Object.defineProperty(Platform, "isTV", {
8
+ get() {
9
+ return true;
10
+ },
16
11
  });
17
12
 
18
13
  jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
@@ -20,12 +15,12 @@ jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
20
15
  }));
21
16
 
22
17
  const { TextInputTv } = require("../");
23
- const { Platform, TextInput } = require("react-native");
18
+ const testIDToTest = "TextInput-tv";
24
19
 
25
20
  describe("<TextInputTv />", () => {
26
21
  it("renders", () => {
27
- const testInstance = TestRenderer.create(<TextInputTv />);
28
- expect(testInstance.toJSON).toBeTruthy();
22
+ const { toJSON } = render(<TextInputTv />);
23
+ expect(toJSON()).toMatchSnapshot();
29
24
  });
30
25
 
31
26
  describe("on native", () => {
@@ -34,8 +29,8 @@ describe("<TextInputTv />", () => {
34
29
  });
35
30
 
36
31
  it("returns React-Native TextInput component if not on samsung", () => {
37
- const testInstance = TestRenderer.create(<TextInputTv />);
38
- expect(testInstance.root.findByType(TextInput)).toBeTruthy();
32
+ const { getByTestId } = render(<TextInputTv />);
33
+ expect(getByTestId(testIDToTest)).toBeTruthy();
39
34
  });
40
35
  });
41
36
 
@@ -45,29 +40,30 @@ describe("<TextInputTv />", () => {
45
40
  });
46
41
 
47
42
  it("returns React input component if on samsung", () => {
48
- const testInstance = TestRenderer.create(<TextInputTv type="samsung" />);
49
- expect(testInstance.root.findByType("input")).toBeTruthy();
43
+ const { getByTestId } = render(<TextInputTv type="samsung" />);
44
+ expect(getByTestId(testIDToTest)).toBeTruthy();
50
45
  });
51
46
 
52
47
  it("flattens styles", () => {
53
48
  Platform.OS = "samsung_tv";
54
49
  const style = [{ width: 200 }, { height: 200 }];
55
- const testInstance = TestRenderer.create(<TextInputTv style={style} />);
56
50
 
57
- expect(typeof testInstance.root.findByType("input").props.style).toBe(
58
- "object"
51
+ const { getByTestId } = render(
52
+ <TextInputTv type="samsung" style={style} />
59
53
  );
54
+
55
+ expect(getByTestId(testIDToTest).props.style).toBeObject();
60
56
  });
61
57
 
62
58
  it("maps onChangeText to onChange", () => {
63
59
  Platform.OS = "samsung_tv";
64
60
  const onChangeText = jest.fn();
65
61
 
66
- const testInstance = TestRenderer.create(
67
- <TextInputTv onChangeText={onChangeText} />
62
+ const { getByTestId } = render(
63
+ <TextInputTv type="samsung" onChangeText={onChangeText} />
68
64
  );
69
65
 
70
- const inputInstance = testInstance.root.findByType("input");
66
+ const inputInstance = getByTestId(testIDToTest);
71
67
  expect(inputInstance.props.onChange).toBeDefined();
72
68
  expect(inputInstance.props.onChangeText).toBeUndefined();
73
69
  });
@@ -76,11 +72,11 @@ describe("<TextInputTv />", () => {
76
72
  Platform.OS = "samsung_tv";
77
73
  const onChangeText = jest.fn();
78
74
 
79
- const testInstance = TestRenderer.create(
80
- <TextInputTv onChangeText={onChangeText} />
75
+ const { getByTestId } = render(
76
+ <TextInputTv type="samsung" onChangeText={onChangeText} />
81
77
  );
82
78
 
83
- const inputInstance = testInstance.root.findByType("input");
79
+ const inputInstance = getByTestId(testIDToTest);
84
80
  const value = "foobar";
85
81
  inputInstance.props.onChange({ target: { value: value } });
86
82
  expect(onChangeText).toBeCalledWith(value);
@@ -89,11 +85,12 @@ describe("<TextInputTv />", () => {
89
85
  it("maps onEndEditing to onBlur", () => {
90
86
  Platform.OS = "samsung_tv";
91
87
 
92
- const testInstance = TestRenderer.create(
93
- <TextInputTv onEndEditing={() => null} />
88
+ const { getByTestId } = render(
89
+ <TextInputTv type="samsung" onEndEditing={() => null} />
94
90
  );
95
91
 
96
- const inputInstance = testInstance.root.findByType("input");
92
+ const inputInstance = getByTestId(testIDToTest);
93
+
97
94
  expect(inputInstance.props.onBlur).toBeDefined();
98
95
  expect(inputInstance.props.onEndEditing).toBeUndefined();
99
96
  });
@@ -101,11 +98,12 @@ describe("<TextInputTv />", () => {
101
98
  it("maps onPress to onClick", () => {
102
99
  Platform.OS = "samsung_tv";
103
100
 
104
- const testInstance = TestRenderer.create(
105
- <TextInputTv onPress={() => null} />
101
+ const { getByTestId } = render(
102
+ <TextInputTv type="samsung" onPress={() => null} />
106
103
  );
107
104
 
108
- const inputInstance = testInstance.root.findByType("input");
105
+ const inputInstance = getByTestId(testIDToTest);
106
+
109
107
  expect(inputInstance.props.onClick).toBeDefined();
110
108
  expect(inputInstance.props.onPress).toBeUndefined();
111
109
  });
@@ -113,22 +111,24 @@ describe("<TextInputTv />", () => {
113
111
  it("replaces secureTextEntry with type:'password'", () => {
114
112
  Platform.OS = "samsung_tv";
115
113
 
116
- const testInstance = TestRenderer.create(
117
- <TextInputTv secureTextEntry={true} />
114
+ const { getByTestId } = render(
115
+ <TextInputTv type="samsung" secureTextEntry />
118
116
  );
119
117
 
120
- const inputInstance = testInstance.root.findByType("input");
118
+ const inputInstance = getByTestId(testIDToTest);
119
+
121
120
  expect(inputInstance.props.type).toBe("password");
122
121
  });
123
122
 
124
123
  it("removes 'onChangeText', 'secureTextEntry', 'onEndEditing', 'onPress' props", () => {
125
124
  Platform.OS = "samsung_tv";
126
125
 
127
- const testInstance = TestRenderer.create(
128
- <TextInputTv onChangeText secureTextEntry onEndEditing />
126
+ const { getByTestId } = render(
127
+ <TextInputTv type="samsung" onChangeText secureTextEntry onEndEditing />
129
128
  );
130
129
 
131
- const inputInstance = testInstance.root.findByType("input");
130
+ const inputInstance = getByTestId(testIDToTest);
131
+
132
132
  expect(inputInstance.props.onChangeText).toBeUndefined();
133
133
  expect(inputInstance.props.secureTextEntry).toBeUndefined();
134
134
  expect(inputInstance.props.onEndEditing).toBeUndefined();
@@ -0,0 +1,7 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`<TextInputTv /> renders 1`] = `
4
+ <input
5
+ testID="TextInput-tv"
6
+ />
7
+ `;
@@ -94,8 +94,8 @@ function TextInputTV(props: Props, ref) {
94
94
  styles.textAlign === "center"
95
95
  ? styles.textAlign
96
96
  : styles.textAlign === "left"
97
- ? "right"
98
- : "left";
97
+ ? "right"
98
+ : "left";
99
99
 
100
100
  return { style: { ...styles, textAlign } };
101
101
  }
@@ -175,10 +175,10 @@ function TextInputTV(props: Props, ref) {
175
175
  return isWebPlatform ? (
176
176
  <>
177
177
  {additional && additional()}
178
- <input ref={ref} {...inputProps} />
178
+ <input testID="TextInput-tv" ref={ref} {...inputProps} />
179
179
  </>
180
180
  ) : (
181
- <TextInput ref={ref} {...inputProps} />
181
+ <TextInput testID="TextInput-tv" ref={ref} {...inputProps} />
182
182
  );
183
183
  }
184
184
 
@@ -14,7 +14,7 @@ exports[`<Touchable /> when not running in automated tests environment renders c
14
14
  onResponderTerminationRequest={[Function]}
15
15
  onStartShouldSetResponder={[Function]}
16
16
  style={
17
- Object {
17
+ {
18
18
  "opacity": 1,
19
19
  }
20
20
  }
@@ -40,7 +40,7 @@ exports[`<Touchable /> when running in automated tests environment has accessibl
40
40
  onResponderTerminationRequest={[Function]}
41
41
  onStartShouldSetResponder={[Function]}
42
42
  style={
43
- Object {
43
+ {
44
44
  "opacity": 1,
45
45
  }
46
46
  }
@@ -3,19 +3,19 @@ import { Animated } from "react-native";
3
3
  import { NAV_ACTION_PUSH, NAV_ACTION_BACK } from "./Transitioner";
4
4
 
5
5
  type TransitionConfig = {
6
- duration: number,
7
- easing: any,
6
+ duration: number;
7
+ easing: any;
8
8
  from: {
9
- style: any,
10
- },
9
+ style: any;
10
+ };
11
11
  to: {
12
- style: any,
13
- },
12
+ style: any;
13
+ };
14
14
  };
15
15
 
16
16
  type Props = {
17
- transitionConfig: TransitionConfig,
18
- contentStyle: { [string]: any },
17
+ transitionConfig: TransitionConfig;
18
+ contentStyle: { [string]: any };
19
19
  };
20
20
 
21
21
  /**
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import { equals } from "ramda";
2
3
  import { Animated, ViewProps, ViewStyle } from "react-native";
3
4
  import { useSafeAreaFrame } from "react-native-safe-area-context";
4
5
 
@@ -8,6 +9,11 @@ import { PathnameContext } from "../../Contexts/PathnameContext";
8
9
  import { ScreenDataContext } from "../../Contexts/ScreenDataContext";
9
10
  import { ScreenContextProvider } from "../../Contexts/ScreenContext";
10
11
 
12
+ const fullWidthDimensions = {
13
+ height: "100%",
14
+ width: "100%",
15
+ };
16
+
11
17
  type Props = {
12
18
  children: any;
13
19
  style: any;
@@ -20,6 +26,47 @@ type Props = {
20
26
  screenData: NavigationScreenData;
21
27
  };
22
28
 
29
+ export function CurrentScreenContextProvider({
30
+ children,
31
+ ...props
32
+ }: {
33
+ children: any;
34
+ pathname: string;
35
+ isActive: boolean;
36
+ screenData: NavigationScreenData;
37
+ }) {
38
+ const { pathname, isActive = false, screenData } = props;
39
+
40
+ const [initialScreenData, setInitialScreenData] = React.useState(screenData);
41
+
42
+ React.useLayoutEffect(() => {
43
+ const screenDataChanged = !equals(initialScreenData, screenData);
44
+
45
+ if (isActive && screenDataChanged) {
46
+ setInitialScreenData(screenData);
47
+ }
48
+ }, [initialScreenData, screenData, isActive]);
49
+
50
+ return (
51
+ <ScreenDataContext.Provider value={initialScreenData}>
52
+ <PathnameContext.Provider value={pathname}>
53
+ <ScreenContextProvider pathname={pathname}>
54
+ {children}
55
+ </ScreenContextProvider>
56
+ </PathnameContext.Provider>
57
+ </ScreenDataContext.Provider>
58
+ );
59
+ }
60
+
61
+ const withCurrentScreenContext = (Component) =>
62
+ function SceneComponent(props: Props) {
63
+ return (
64
+ <CurrentScreenContextProvider {...props}>
65
+ <Component {...props} />
66
+ </CurrentScreenContextProvider>
67
+ );
68
+ };
69
+
23
70
  /**
24
71
  * Animated View container for any purpose.
25
72
  * Renders given children with given style object.
@@ -32,53 +79,35 @@ type Props = {
32
79
  * @param contentStyle
33
80
  * @param screenUniqueId
34
81
  */
35
- export function Scene({
82
+ function SceneComponent({
36
83
  children,
37
84
  style,
38
85
  pointerEvents = "auto",
39
86
  overlayStyle,
40
87
  animating,
41
88
  contentStyle,
42
- pathname,
43
89
  isActive = false,
44
90
  screenData,
45
91
  }: Props) {
46
- const [initialScreenData, setInitialScreenData] = React.useState(screenData);
47
-
48
92
  useScreenOrientationHandler({
49
93
  screenData,
50
94
  isActive,
51
95
  });
52
96
 
53
- React.useLayoutEffect(() => {
54
- if (isActive) {
55
- setInitialScreenData(screenData);
56
- }
57
- }, [screenData, isActive]);
58
-
59
97
  const frame = useSafeAreaFrame();
60
98
  const isAnimating = animating && overlayStyle;
61
99
 
62
- const dimensions = isAnimating
63
- ? {
64
- width: "100%",
65
- height: "100%",
66
- }
67
- : frame;
100
+ const dimensions = isAnimating ? fullWidthDimensions : frame;
68
101
 
69
102
  return (
70
103
  <Animated.View
71
104
  pointerEvents={pointerEvents}
72
105
  style={[style, contentStyle, dimensions]}
73
106
  >
74
- <ScreenDataContext.Provider value={initialScreenData}>
75
- <PathnameContext.Provider value={pathname}>
76
- <ScreenContextProvider pathname={pathname}>
77
- {children}
78
- </ScreenContextProvider>
79
- </PathnameContext.Provider>
80
- </ScreenDataContext.Provider>
107
+ {children}
81
108
  {isAnimating && <Animated.View style={overlayStyle} />}
82
109
  </Animated.View>
83
110
  );
84
111
  }
112
+
113
+ export const Scene = withCurrentScreenContext(SceneComponent);