@applicaster/zapp-react-native-ui-components 13.0.0-alpha.7192404241 → 13.0.0-alpha.7196055925

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 (35) hide show
  1. package/Components/BaseFocusable/index.ios.ts +1 -1
  2. package/Components/BaseFocusable/index.tsx +1 -1
  3. package/Components/Focusable/Touchable.tsx +19 -20
  4. package/Components/MasterCell/DefaultComponents/BorderContainerView/__tests__/index.test.tsx +66 -0
  5. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +4 -1
  6. package/Components/MasterCell/DefaultComponents/Image/Image.ios.tsx +5 -11
  7. package/Components/MasterCell/DefaultComponents/ImageBorderContainer/__tests__/index.test.ts +93 -0
  8. package/Components/MasterCell/DefaultComponents/SecondaryImage/utils.ts +1 -1
  9. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +1 -1
  10. package/Components/MasterCell/utils/index.ts +1 -1
  11. package/Components/ModalComponent/Header/index.tsx +3 -3
  12. package/Components/River/ComponentsMap/ComponentsMap.tsx +39 -65
  13. package/Components/River/ComponentsMap/hooks/useLoadingState.ts +78 -51
  14. package/Components/River/RiverFooter.tsx +39 -9
  15. package/Components/River/RiverItem.tsx +37 -2
  16. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +148 -31
  17. package/Components/River/__tests__/componentsMap.test.js +3 -4
  18. package/Components/Screen/hooks.ts +56 -0
  19. package/Components/Screen/index.tsx +13 -39
  20. package/Components/Tabs/Tab.tsx +6 -6
  21. package/Components/TextInputTv/index.tsx +2 -2
  22. package/Components/Transitioner/AnimationManager.js +8 -8
  23. package/Components/Transitioner/Scene.tsx +52 -23
  24. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +59 -43
  25. package/Components/Transitioner/__tests__/__snapshots__/transitioner.test.js.snap +2 -2
  26. package/Components/Transitioner/index.js +8 -4
  27. package/Components/VideoLive/LiveImageManager.ts +27 -1
  28. package/Components/VideoLive/PlayerLiveImageComponent.tsx +29 -21
  29. package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +51 -1
  30. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +0 -5
  31. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +7 -6
  32. package/Components/VideoModal/ModalAnimation/utils.ts +2 -2
  33. package/Contexts/ScreenContext/index.tsx +3 -2
  34. package/Decorators/ZappPipesDataConnector/__tests__/Hero.js +1 -1
  35. package/package.json +5 -5
@@ -1,11 +1,23 @@
1
- import React from "react";
1
+ import React, { useCallback } from "react";
2
2
  import { StyleSheet, View } from "react-native";
3
3
  import { Spinner } from "@applicaster/zapp-react-native-ui-components/Components/Spinner";
4
+ import type { Subject } from "rxjs";
5
+ import { useStateFromSubscribe } from "@applicaster/zapp-react-native-utils/reactHooks/state/useStateFromSubscribe";
6
+
7
+ type LoadingState = {
8
+ waitForAllComponents: boolean;
9
+ index: number;
10
+ done: boolean;
11
+ };
12
+
13
+ type State = {
14
+ visible: boolean;
15
+ isAnyLoaded: boolean;
16
+ };
4
17
 
5
18
  type Props = {
6
- visible?: boolean;
7
19
  flatListHeight?: number;
8
- isAnyLoaded: boolean;
20
+ loadingState: Subject<LoadingState>;
9
21
  };
10
22
 
11
23
  const FOOTER_COMPONENT_HEIGHT = 200;
@@ -19,17 +31,35 @@ const footerStyles = StyleSheet.create({
19
31
  });
20
32
 
21
33
  function RiverFooterComponent(props: Props) {
22
- const { visible = true, flatListHeight, isAnyLoaded } = props;
34
+ const { flatListHeight, loadingState } = props;
35
+
36
+ const { visible, isAnyLoaded } = useStateFromSubscribe<LoadingState, State>(
37
+ loadingState,
38
+ useCallback(
39
+ ({ index, done, waitForAllComponents }, setState) =>
40
+ setState(() => ({
41
+ visible: !done,
42
+ isAnyLoaded: index >= 0 || waitForAllComponents,
43
+ })),
44
+ []
45
+ ),
46
+ {
47
+ visible: true,
48
+ isAnyLoaded: false,
49
+ }
50
+ );
23
51
 
24
52
  if (!visible) return null;
25
53
 
26
54
  return (
27
55
  <View
28
- renderToHardwareTextureAndroid={true}
29
- style={{
30
- ...footerStyles.container,
31
- height: isAnyLoaded ? FOOTER_COMPONENT_HEIGHT : flatListHeight,
32
- }}
56
+ renderToHardwareTextureAndroid
57
+ style={[
58
+ footerStyles.container,
59
+ {
60
+ height: isAnyLoaded ? FOOTER_COMPONENT_HEIGHT : flatListHeight,
61
+ },
62
+ ]}
33
63
  >
34
64
  <Spinner size={isAnyLoaded ? "small" : "large"} />
35
65
  </View>
@@ -1,4 +1,4 @@
1
- import React from "react";
1
+ import React, { useEffect } from "react";
2
2
  import * as R from "ramda";
3
3
 
4
4
  import { applyDecorators } from "../../Decorators";
@@ -11,6 +11,7 @@ import {
11
11
  import { riverLogger } from "./logger";
12
12
  import { tvPluginsWithCellRenderer } from "../../const";
13
13
  import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
14
+ import type { BehaviorSubject } from "rxjs";
14
15
 
15
16
  export type RiverItemType = {
16
17
  item: ZappUIComponent;
@@ -24,6 +25,7 @@ export type RiverItemType = {
24
25
  getStaticComponentFeed: GeneralContentScreenProps["getStaticComponentFeed"];
25
26
  readyToBeDisplayed?: boolean;
26
27
  isLast: boolean;
28
+ loadingState: BehaviorSubject<{ index: number }>;
27
29
  };
28
30
 
29
31
  function getFeedUrl(feed: ZappFeed, index: number) {
@@ -36,6 +38,33 @@ function getFeedUrl(feed: ZappFeed, index: number) {
36
38
  }
37
39
  }
38
40
 
41
+ /**
42
+ * useLoadingState for RiverItemComponent
43
+ * takes currentIndex and loadingState as arguments
44
+ **/
45
+ const useLoadingState = (
46
+ currentIndex: number,
47
+ loadingState: RiverItemType["loadingState"]
48
+ ) => {
49
+ const [readyToBeDisplayed, setReadyToBeDisplayed] = React.useState(
50
+ loadingState.getValue().index + 1 === currentIndex
51
+ );
52
+
53
+ useEffect(() => {
54
+ const subscription = loadingState.subscribe(({ index }) => {
55
+ if (index + 1 === currentIndex) {
56
+ setReadyToBeDisplayed(true);
57
+ }
58
+ });
59
+
60
+ return () => {
61
+ subscription.unsubscribe();
62
+ };
63
+ }, [loadingState, currentIndex]);
64
+
65
+ return readyToBeDisplayed;
66
+ };
67
+
39
68
  function RiverItemComponent(props: RiverItemType) {
40
69
  const {
41
70
  item,
@@ -47,10 +76,12 @@ function RiverItemComponent(props: RiverItemType) {
47
76
  onLoadFinished,
48
77
  onLoadFailed,
49
78
  getStaticComponentFeed,
50
- readyToBeDisplayed,
51
79
  isLast,
80
+ loadingState,
52
81
  } = props;
53
82
 
83
+ const readyToBeDisplayed = useLoadingState(index, loadingState);
84
+
54
85
  const feedUrl = getFeedUrl(feed, index);
55
86
 
56
87
  const Component = useComponentResolver(
@@ -90,6 +121,10 @@ function RiverItemComponent(props: RiverItemType) {
90
121
  }
91
122
  }, []);
92
123
 
124
+ if (!readyToBeDisplayed) {
125
+ return null;
126
+ }
127
+
93
128
  if (Component === null || typeof Component === "undefined") {
94
129
  riverLogger.warning({
95
130
  message: `Component ${item.component_type} is null - skipping rendering`,
@@ -17,7 +17,138 @@ exports[`componentsMap renders renders components map correctly 1`] = `
17
17
  }
18
18
  >
19
19
  <RCTScrollView
20
- ListFooterComponent={[Function]}
20
+ ListFooterComponent={
21
+ <Memo(RiverFooterComponent)
22
+ flatListHeight={null}
23
+ loadingState={
24
+ BehaviorSubject {
25
+ "_isScalar": false,
26
+ "_value": {
27
+ "done": false,
28
+ "index": -1,
29
+ "waitForAllComponents": false,
30
+ },
31
+ "closed": false,
32
+ "hasError": false,
33
+ "isStopped": false,
34
+ "observers": [
35
+ Subscriber {
36
+ "_parentOrParents": null,
37
+ "_subscriptions": [
38
+ SubjectSubscription {
39
+ "_parentOrParents": [Circular],
40
+ "_subscriptions": null,
41
+ "closed": false,
42
+ "subject": [Circular],
43
+ "subscriber": [Circular],
44
+ },
45
+ ],
46
+ "closed": false,
47
+ "destination": SafeSubscriber {
48
+ "_complete": undefined,
49
+ "_context": [Circular],
50
+ "_error": undefined,
51
+ "_next": [Function],
52
+ "_parentOrParents": null,
53
+ "_parentSubscriber": [Circular],
54
+ "_subscriptions": null,
55
+ "closed": false,
56
+ "destination": {
57
+ "closed": true,
58
+ "complete": [Function],
59
+ "error": [Function],
60
+ "next": [Function],
61
+ },
62
+ "isStopped": false,
63
+ "syncErrorThrowable": false,
64
+ "syncErrorThrown": false,
65
+ "syncErrorValue": null,
66
+ },
67
+ "isStopped": false,
68
+ "syncErrorThrowable": true,
69
+ "syncErrorThrown": false,
70
+ "syncErrorValue": null,
71
+ },
72
+ Subscriber {
73
+ "_parentOrParents": null,
74
+ "_subscriptions": [
75
+ SubjectSubscription {
76
+ "_parentOrParents": [Circular],
77
+ "_subscriptions": null,
78
+ "closed": false,
79
+ "subject": [Circular],
80
+ "subscriber": [Circular],
81
+ },
82
+ ],
83
+ "closed": false,
84
+ "destination": SafeSubscriber {
85
+ "_complete": undefined,
86
+ "_context": [Circular],
87
+ "_error": undefined,
88
+ "_next": [Function],
89
+ "_parentOrParents": null,
90
+ "_parentSubscriber": [Circular],
91
+ "_subscriptions": null,
92
+ "closed": false,
93
+ "destination": {
94
+ "closed": true,
95
+ "complete": [Function],
96
+ "error": [Function],
97
+ "next": [Function],
98
+ },
99
+ "isStopped": false,
100
+ "syncErrorThrowable": false,
101
+ "syncErrorThrown": false,
102
+ "syncErrorValue": null,
103
+ },
104
+ "isStopped": false,
105
+ "syncErrorThrowable": true,
106
+ "syncErrorThrown": false,
107
+ "syncErrorValue": null,
108
+ },
109
+ Subscriber {
110
+ "_parentOrParents": null,
111
+ "_subscriptions": [
112
+ SubjectSubscription {
113
+ "_parentOrParents": [Circular],
114
+ "_subscriptions": null,
115
+ "closed": false,
116
+ "subject": [Circular],
117
+ "subscriber": [Circular],
118
+ },
119
+ ],
120
+ "closed": false,
121
+ "destination": SafeSubscriber {
122
+ "_complete": undefined,
123
+ "_context": [Circular],
124
+ "_error": undefined,
125
+ "_next": [Function],
126
+ "_parentOrParents": null,
127
+ "_parentSubscriber": [Circular],
128
+ "_subscriptions": null,
129
+ "closed": false,
130
+ "destination": {
131
+ "closed": true,
132
+ "complete": [Function],
133
+ "error": [Function],
134
+ "next": [Function],
135
+ },
136
+ "isStopped": false,
137
+ "syncErrorThrowable": false,
138
+ "syncErrorThrown": false,
139
+ "syncErrorValue": null,
140
+ },
141
+ "isStopped": false,
142
+ "syncErrorThrowable": true,
143
+ "syncErrorThrown": false,
144
+ "syncErrorValue": null,
145
+ },
146
+ ],
147
+ "thrownError": null,
148
+ }
149
+ }
150
+ />
151
+ }
21
152
  contentContainerStyle={
22
153
  {
23
154
  "paddingBottom": undefined,
@@ -80,22 +211,14 @@ exports[`componentsMap renders renders components map correctly 1`] = `
80
211
  style={null}
81
212
  >
82
213
  <View
214
+ onLayout={[Function]}
83
215
  style={
84
216
  {
85
- "display": "flex",
217
+ "flex": 1,
86
218
  }
87
219
  }
88
220
  >
89
- <View
90
- onLayout={[Function]}
91
- style={
92
- {
93
- "flex": 1,
94
- }
95
- }
96
- >
97
- <View />
98
- </View>
221
+ <View />
99
222
  </View>
100
223
  </View>
101
224
  <View
@@ -103,23 +226,13 @@ exports[`componentsMap renders renders components map correctly 1`] = `
103
226
  style={null}
104
227
  >
105
228
  <View
229
+ onLayout={[Function]}
106
230
  style={
107
231
  {
108
- "display": "none",
232
+ "flex": 1,
109
233
  }
110
234
  }
111
- >
112
- <View
113
- onLayout={[Function]}
114
- style={
115
- {
116
- "flex": 1,
117
- }
118
- }
119
- >
120
- <View />
121
- </View>
122
- </View>
235
+ />
123
236
  </View>
124
237
  <View
125
238
  onLayout={[Function]}
@@ -127,12 +240,16 @@ exports[`componentsMap renders renders components map correctly 1`] = `
127
240
  <View
128
241
  renderToHardwareTextureAndroid={true}
129
242
  style={
130
- {
131
- "alignItems": "center",
132
- "height": null,
133
- "justifyContent": "center",
134
- "width": "100%",
135
- }
243
+ [
244
+ {
245
+ "alignItems": "center",
246
+ "justifyContent": "center",
247
+ "width": "100%",
248
+ },
249
+ {
250
+ "height": null,
251
+ },
252
+ ]
136
253
  }
137
254
  >
138
255
  <ActivityIndicator
@@ -1,6 +1,5 @@
1
1
  import React from "react";
2
- import TestRenderer from "react-test-renderer";
3
- import { cleanup } from "@testing-library/react-native";
2
+ import { cleanup, render } from "@testing-library/react-native";
4
3
  import { Provider } from "react-redux";
5
4
  import configureStore from "redux-mock-store";
6
5
 
@@ -183,12 +182,12 @@ describe("componentsMap", () => {
183
182
  .spyOn(themeUtils, "useTheme")
184
183
  .mockImplementation(() => () => theme);
185
184
 
186
- const wrapper = TestRenderer.create(
185
+ const { toJSON } = render(
187
186
  <Provider store={store}>
188
187
  <ComponentsMap {...props} />
189
188
  </Provider>
190
189
  );
191
190
 
192
- expect(wrapper.toJSON()).toMatchSnapshot();
191
+ expect(toJSON()).toMatchSnapshot();
193
192
  });
194
193
  });
@@ -0,0 +1,56 @@
1
+ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
2
+ import {
3
+ useGetScreenOrientation,
4
+ isOrientationCompatible,
5
+ } from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
6
+ import {
7
+ useCurrentScreenData,
8
+ useDimensions,
9
+ useRoute,
10
+ } from "@applicaster/zapp-react-native-utils/reactHooks";
11
+ import { useMemo, useEffect, useState } from "react";
12
+
13
+ export const useWaitForValidOrientation = () => {
14
+ const {
15
+ width: screenWidth,
16
+ height,
17
+ deviceInfo,
18
+ } = useDimensions("screen", {
19
+ fullDimensions: true,
20
+ updateForInactiveScreens: false,
21
+ });
22
+
23
+ const currentScreenData = useCurrentScreenData();
24
+
25
+ const { screenData } = useRoute();
26
+
27
+ const [readyState, setReadyState] = useState(false);
28
+
29
+ const isTablet = deviceInfo?.isTablet;
30
+
31
+ const { appData } = usePickFromState(["appData"]);
32
+ const isTabletPortrait = appData?.isTabletPortrait;
33
+
34
+ const layoutData = useMemo(
35
+ () => ({ isTablet, isTabletPortrait, width: screenWidth, height }),
36
+ [isTablet, isTabletPortrait, screenWidth, height]
37
+ );
38
+
39
+ const targetScreenData =
40
+ currentScreenData || (screenData as any)?.targetScreen || screenData;
41
+
42
+ const orientation = useGetScreenOrientation(targetScreenData);
43
+
44
+ const isReadyForDisplay = isOrientationCompatible({
45
+ orientation,
46
+ layoutData,
47
+ });
48
+
49
+ useEffect(() => {
50
+ if (isReadyForDisplay && !readyState) {
51
+ setReadyState(true);
52
+ }
53
+ }, [readyState, orientation, layoutData]);
54
+
55
+ return readyState;
56
+ };
@@ -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
  }
@@ -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",
@@ -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
  }
@@ -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
  /**