@applicaster/zapp-react-native-ui-components 14.0.0-alpha.5974411329 → 14.0.0-alpha.6000342231

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 (95) hide show
  1. package/Components/AnimatedInOut/index.tsx +69 -26
  2. package/Components/BaseFocusable/index.tsx +23 -12
  3. package/Components/Cell/Cell.tsx +91 -64
  4. package/Components/Cell/CellWithFocusable.tsx +3 -0
  5. package/Components/Cell/FocusableWrapper.tsx +44 -0
  6. package/Components/Cell/TvOSCellComponent.tsx +80 -14
  7. package/Components/Cell/__tests__/CellWIthFocusable.test.js +3 -2
  8. package/Components/FeedLoader/FeedLoader.tsx +7 -16
  9. package/Components/FeedLoader/FeedLoaderHOC.tsx +21 -0
  10. package/Components/FeedLoader/index.js +2 -8
  11. package/Components/Focusable/Focusable.tsx +10 -3
  12. package/Components/Focusable/FocusableTvOS.tsx +2 -2
  13. package/Components/Focusable/Touchable.tsx +5 -3
  14. package/Components/Focusable/index.android.tsx +8 -4
  15. package/Components/FocusableGroup/FocusableTvOS.tsx +1 -1
  16. package/Components/FocusableList/FocusableItem.tsx +4 -3
  17. package/Components/FocusableList/FocusableListItemWrapper.tsx +2 -1
  18. package/Components/FocusableList/hooks/useCellState.android.ts +13 -3
  19. package/Components/FocusableList/index.tsx +16 -9
  20. package/Components/FreezeWithCallback/__tests__/index.test.tsx +67 -43
  21. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +14 -17
  22. package/Components/HandlePlayable/HandlePlayable.tsx +14 -65
  23. package/Components/HandlePlayable/const.ts +3 -0
  24. package/Components/HandlePlayable/utils.ts +74 -0
  25. package/Components/Layout/TV/__tests__/index.test.tsx +0 -1
  26. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +6 -2
  27. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +0 -12
  28. package/Components/MasterCell/DefaultComponents/SecondaryImage/Image.tsx +65 -17
  29. package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/Image.test.tsx +21 -3
  30. package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/__snapshots__/Image.test.tsx.snap +6 -3
  31. package/Components/MasterCell/DefaultComponents/Text/index.tsx +26 -6
  32. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +10 -10
  33. package/Components/MasterCell/DefaultComponents/__tests__/text.test.tsx +18 -18
  34. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/index.test.tsx +10 -10
  35. package/Components/MasterCell/utils/behaviorProvider.ts +2 -2
  36. package/Components/MasterCell/utils/index.ts +1 -19
  37. package/Components/OfflineHandler/__tests__/index.test.tsx +6 -13
  38. package/Components/PlayerContainer/PlayerContainer.tsx +5 -17
  39. package/Components/PlayerImageBackground/index.tsx +3 -22
  40. package/Components/River/ComponentsMap/ComponentsMap.tsx +49 -42
  41. package/Components/River/ComponentsMap/ContextProviders/ComponentsMapHeightContext.ts +8 -0
  42. package/Components/River/ComponentsMap/ContextProviders/ComponentsMapRefContext.ts +8 -0
  43. package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +0 -1
  44. package/Components/River/RefreshControl.tsx +11 -19
  45. package/Components/River/__tests__/river.test.js +12 -26
  46. package/Components/Screen/TV/hooks/useInitialFocus.ts +14 -4
  47. package/Components/Screen/__tests__/Screen.test.tsx +5 -17
  48. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +2 -0
  49. package/Components/Screen/__tests__/navigationHandler.test.ts +133 -22
  50. package/Components/Screen/index.tsx +22 -5
  51. package/Components/Screen/navigationHandler.ts +20 -2
  52. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +2 -2
  53. package/Components/ScreenRevealManager/utils/index.ts +23 -0
  54. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +54 -24
  55. package/Components/Tabs/TV/Tabs.android.tsx +1 -1
  56. package/Components/Tabs/Tabs.tsx +2 -3
  57. package/Components/TextInputTv/__tests__/__snapshots__/TextInputTv.test.js.snap +13 -0
  58. package/Components/TextInputTv/index.tsx +11 -0
  59. package/Components/Touchable/__tests__/touchable.test.tsx +12 -17
  60. package/Components/VideoLive/__tests__/__snapshots__/PlayerLiveImageComponent.test.tsx.snap +1 -0
  61. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +117 -157
  62. package/Components/VideoModal/ModalAnimation/index.ts +2 -13
  63. package/Components/VideoModal/ModalAnimation/utils.ts +1 -327
  64. package/Components/VideoModal/PlayerDetails.tsx +5 -5
  65. package/Components/VideoModal/PlayerWrapper.tsx +14 -88
  66. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +5 -5
  67. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -0
  68. package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +9 -1
  69. package/Components/VideoModal/hooks/useDelayedPlayerDetails.ts +40 -15
  70. package/Components/VideoModal/hooks/useModalSize.ts +10 -5
  71. package/Components/VideoModal/hooks/utils/__tests__/showDetails.test.ts +2 -2
  72. package/Components/VideoModal/hooks/utils/index.ts +4 -0
  73. package/Components/VideoModal/playerWrapperStyle.ts +70 -0
  74. package/Components/VideoModal/playerWrapperUtils.ts +91 -0
  75. package/Contexts/CellFocusedStateContext/index.tsx +27 -0
  76. package/Contexts/ConfigutaionContext/__tests__/ConfigurationProvider.test.tsx +3 -3
  77. package/Contexts/ScreenContext/index.tsx +28 -32
  78. package/Decorators/ConfigurationWrapper/__tests__/withConfigurationProvider.test.tsx +3 -3
  79. package/Decorators/RiverFeedLoader/__tests__/__snapshots__/riverFeedLoader.test.tsx.snap +221 -209
  80. package/Decorators/RiverFeedLoader/__tests__/riverFeedLoader.test.tsx +14 -16
  81. package/Decorators/RiverFeedLoader/__tests__/utils.test.ts +0 -20
  82. package/Decorators/RiverFeedLoader/index.tsx +21 -13
  83. package/Decorators/RiverFeedLoader/utils/getDatasourceUrl.ts +6 -10
  84. package/Decorators/RiverFeedLoader/utils/index.ts +0 -35
  85. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +27 -27
  86. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +3 -5
  87. package/Decorators/ZappPipesDataConnector/utils/useFilter.tsx +68 -76
  88. package/events/index.ts +3 -0
  89. package/package.json +5 -5
  90. package/Components/River/__tests__/__snapshots__/river.test.js.snap +0 -27
  91. package/Components/VideoModal/ModalAnimation/AnimatedPlayerModalWrapper.tsx +0 -60
  92. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +0 -421
  93. package/Components/VideoModal/ModalAnimation/AnimatedVideoPlayerComponent.tsx +0 -176
  94. package/Components/VideoModal/ModalAnimation/AnimationComponent.tsx +0 -500
  95. package/Components/VideoModal/ModalAnimation/__tests__/getMoveUpValue.test.ts +0 -108
@@ -1,30 +1,11 @@
1
1
  import * as React from "react";
2
- import {
3
- Dimensions,
4
- Platform,
5
- StyleSheet,
6
- View,
7
- ViewStyle,
8
- } from "react-native";
2
+ import { View, ViewStyle } from "react-native";
9
3
  import { Edge, SafeAreaView } from "react-native-safe-area-context";
10
4
  import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
11
5
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
12
6
  import { playerDimensionsHack } from "./utils";
13
- import { getTabletWidth } from "@applicaster/zapp-react-native-utils/playerUtils";
14
-
15
- const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen");
16
-
17
- type DimensionsT = {
18
- width: number | string;
19
- height: number | string | undefined;
20
- aspectRatio?: number;
21
- };
22
-
23
- type Configuration = {
24
- [key: string]: any;
25
- tablet_landscape_sidebar_width?: string;
26
- tablet_landscape_player_container_background_color?: string;
27
- };
7
+ import { DimensionsT, Configuration, getEdges } from "./playerWrapperUtils";
8
+ import { defaultStyles, useStyle } from "./playerWrapperStyle";
28
9
 
29
10
  type Props = {
30
11
  entry: ZappEntry;
@@ -41,36 +22,12 @@ type Props = {
41
22
  playerContent: (styles: ViewStyle) => React.ReactNode;
42
23
  };
43
24
 
44
- const defaultStyles = StyleSheet.create({
45
- playerContainer: { position: "relative", alignSelf: "center", zIndex: 200 },
46
- });
47
-
48
- const getScreenAspectRatio = () => {
49
- const longEdge = Math.max(SCREEN_WIDTH, SCREEN_HEIGHT);
50
- const shortEdge = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT);
51
-
52
- return longEdge / shortEdge;
53
- };
54
-
55
- const getEdges = (isTablet: boolean, isInlineModal: boolean) => {
56
- if (isTablet) {
57
- return ["top"];
58
- }
59
-
60
- if (!isInlineModal && Platform.OS === "android") {
61
- return [];
62
- }
63
-
64
- return ["top"];
65
- };
66
-
67
25
  const PlayerWrapperComponent = (props: Props) => {
68
26
  const {
69
27
  entry,
70
28
  style,
71
29
  containerStyle,
72
30
  inline,
73
- docked,
74
31
  isModal,
75
32
  isTabletPortrait,
76
33
  configuration,
@@ -78,52 +35,21 @@ const PlayerWrapperComponent = (props: Props) => {
78
35
  playerContent,
79
36
  } = props;
80
37
 
38
+ const styles = useStyle({
39
+ style,
40
+ inline,
41
+ isModal,
42
+ isTabletPortrait,
43
+ configuration,
44
+ pip,
45
+ });
46
+
81
47
  const isTablet = useIsTablet();
82
48
 
83
49
  const isInlineModal = inline && isModal;
84
50
 
85
- const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
86
-
87
- const tabletWidth = getTabletWidth(
88
- configuration.tablet_landscape_sidebar_width,
89
- style
90
- );
91
-
92
- const baseDimensions: DimensionsT = React.useMemo(
93
- () => ({
94
- width: isInlineModal && isTabletLandscape ? tabletWidth : "100%",
95
- height: undefined,
96
- }),
97
- [isInlineModal, tabletWidth, docked]
98
- );
99
-
100
- const playerDimensions: DimensionsT = React.useMemo(
101
- () => ({
102
- ...baseDimensions,
103
- width: baseDimensions.width,
104
- aspectRatio: !isInlineModal && !pip ? getScreenAspectRatio() : 16 / 9,
105
- }),
106
- [baseDimensions, isInlineModal, pip]
107
- );
108
-
109
- const containerDimensions: DimensionsT = React.useMemo(
110
- () => ({
111
- ...baseDimensions,
112
- aspectRatio: playerDimensions.aspectRatio,
113
- }),
114
- [baseDimensions, isInlineModal, docked, playerDimensions.aspectRatio]
115
- );
116
-
117
51
  const WrapperView = React.useMemo(() => (isTV() ? View : SafeAreaView), []);
118
52
 
119
- const childrenStyles = React.useMemo(
120
- () => ({
121
- ...playerDimensions,
122
- ...playerDimensionsHack,
123
- }),
124
- [containerDimensions, playerDimensionsHack]
125
- );
126
-
127
53
  return (
128
54
  <WrapperView
129
55
  edges={getEdges(isTablet, isInlineModal) as readonly Edge[]}
@@ -134,11 +60,11 @@ const PlayerWrapperComponent = (props: Props) => {
134
60
  style={[
135
61
  defaultStyles.playerContainer,
136
62
  playerDimensionsHack,
137
- containerDimensions,
63
+ styles.containerDimensions,
138
64
  containerStyle,
139
65
  ]}
140
66
  >
141
- {playerContent(childrenStyles)}
67
+ {playerContent(styles.childrenStyles)}
142
68
  </View>
143
69
  </WrapperView>
144
70
  );
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import renderer from "react-test-renderer";
2
+ import { render } from "@testing-library/react-native";
3
3
 
4
4
  const props = {
5
5
  entry: {},
@@ -42,16 +42,16 @@ const { PlayerDetails } = require("../PlayerDetails");
42
42
 
43
43
  describe("PlayerDetails", () => {
44
44
  it("renders properly", () => {
45
- const element = renderer.create(<PlayerDetails {...props} />);
45
+ const { toJSON } = render(<PlayerDetails {...props} />);
46
46
 
47
- expect(element).toMatchSnapshot();
47
+ expect(toJSON()).toMatchSnapshot();
48
48
  });
49
49
 
50
50
  it("renders properly on tablet in landscape orientation", () => {
51
- const element = renderer.create(
51
+ const { toJSON } = render(
52
52
  <PlayerDetails {...props} isTabletLandscape={true} />
53
53
  );
54
54
 
55
- expect(element).toMatchSnapshot();
55
+ expect(toJSON()).toMatchSnapshot();
56
56
  });
57
57
  });
@@ -46,6 +46,7 @@ jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
46
46
 
47
47
  jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
48
48
  isTV: jest.fn(() => false),
49
+ isAndroidPlatform: jest.fn(() => false),
49
50
  isApplePlatform: jest.fn(() => true),
50
51
  platformSelect: jest.fn((props) => props.android),
51
52
  }));
@@ -2,6 +2,8 @@ import { renderHook } from "@testing-library/react-hooks";
2
2
  import { useDelayedPlayerDetails } from "../useDelayedPlayerDetails";
3
3
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
4
4
 
5
+ jest.useFakeTimers();
6
+
5
7
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
6
8
  useIsTablet: jest.fn().mockReturnValue(false),
7
9
  }));
@@ -11,11 +13,15 @@ describe("useDelayedPlayerDetails", () => {
11
13
  jest.clearAllMocks();
12
14
  });
13
15
 
14
- it("should return true initially", () => {
16
+ it("should return false initially, that changes after 1 second", () => {
15
17
  const { result } = renderHook(() =>
16
18
  useDelayedPlayerDetails({ isInline: true, isDocked: false, isPip: false })
17
19
  );
18
20
 
21
+ expect(result.current).toBe(false);
22
+
23
+ jest.advanceTimersByTime(1000);
24
+
19
25
  expect(result.current).toBe(true);
20
26
  });
21
27
 
@@ -46,6 +52,8 @@ describe("useDelayedPlayerDetails", () => {
46
52
  })
47
53
  );
48
54
 
55
+ jest.advanceTimersByTime(1000);
56
+
49
57
  expect(result.current).toBe(true);
50
58
  });
51
59
  });
@@ -1,22 +1,26 @@
1
+ // const showPlayerDetails = (
2
+ // isInline: boolean,
3
+ // isDocked: boolean,
4
+ // isPip: boolean,
5
+ // isTablet: boolean
6
+ // ) => {
7
+ // return showDetails({
8
+ // isMobile: !isTablet,
9
+ // isInline,
10
+ // isDocked,
11
+ // isPip,
12
+ // });
13
+ // };
14
+
15
+ import * as React from "react";
1
16
  import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
17
+ import { withTimeout$ } from "@applicaster/zapp-react-native-utils/idleUtils";
2
18
 
3
19
  import { showDetails } from "./utils";
4
20
 
5
- type Props = { isInline: boolean; isDocked: boolean; isPip: boolean };
21
+ const TIMEOUT = 1000; // ms
6
22
 
7
- const showPlayerDetails = (
8
- isInline: boolean,
9
- isDocked: boolean,
10
- isPip: boolean,
11
- isTablet: boolean
12
- ) => {
13
- return showDetails({
14
- isMobile: !isTablet,
15
- isInline,
16
- isDocked,
17
- isPip,
18
- });
19
- };
23
+ type Props = { isInline: boolean; isDocked: boolean; isPip: boolean };
20
24
 
21
25
  /**
22
26
  * Custom hook to determine whether to show player details with a delay.
@@ -32,7 +36,28 @@ export const useDelayedPlayerDetails = ({
32
36
  isDocked,
33
37
  isPip,
34
38
  }: Props): boolean => {
39
+ const [shouldShowDetails, setShouldShowDetails] = React.useState(false);
40
+
35
41
  const isTablet = useIsTablet();
36
42
 
37
- return showPlayerDetails(isInline, isDocked, isPip, isTablet);
43
+ React.useEffect(() => {
44
+ const subscription = withTimeout$(TIMEOUT).subscribe({
45
+ next: () => {
46
+ setShouldShowDetails(() => {
47
+ return showDetails({
48
+ isMobile: !isTablet,
49
+ isInline,
50
+ isDocked,
51
+ isPip,
52
+ });
53
+ });
54
+ },
55
+ });
56
+
57
+ return () => {
58
+ subscription.unsubscribe();
59
+ };
60
+ }, [isDocked, isTablet, isInline, isPip]);
61
+
62
+ return shouldShowDetails;
38
63
  };
@@ -33,8 +33,12 @@ const MODAL_SIZE_FOR_LANDSCAPE: Size = {
33
33
  height: "100%",
34
34
  };
35
35
 
36
+ const SAFE_AREA_BREAKING_API_VERSION = 35;
37
+
36
38
  const isOldAndroidDevice =
37
- isAndroidPlatform() && !isAndroidVersionAtLeast(35) && !isAndroidTablet();
39
+ isAndroidPlatform() &&
40
+ !isAndroidVersionAtLeast(SAFE_AREA_BREAKING_API_VERSION) &&
41
+ !isAndroidTablet();
38
42
 
39
43
  export const useModalSize = (): Size => {
40
44
  const frame = useSafeAreaFrame();
@@ -42,7 +46,7 @@ export const useModalSize = (): Size => {
42
46
  const [modalSize, setModalSize] = React.useState<Size>({
43
47
  width: frame.width,
44
48
  height: isOldAndroidDevice
45
- ? frame.height + StatusBar.currentHeight
49
+ ? frame.height + (StatusBar.currentHeight ?? 0)
46
50
  : frame.height,
47
51
  });
48
52
 
@@ -57,9 +61,10 @@ export const useModalSize = (): Size => {
57
61
 
58
62
  return {
59
63
  width: newSize.width,
60
- height: isOldAndroidDevice
61
- ? newSize.height + StatusBar.currentHeight
62
- : newSize.height,
64
+ height:
65
+ isOldAndroidDevice && newSize.height !== "100%"
66
+ ? newSize.height + (StatusBar.currentHeight ?? 0)
67
+ : newSize.height,
63
68
  };
64
69
  });
65
70
 
@@ -12,7 +12,7 @@ describe("showDetails", () => {
12
12
  expect(result).toBe(false);
13
13
  });
14
14
 
15
- it("should return false if isDocked is true", () => {
15
+ it("should return true if isDocked & mobile", () => {
16
16
  const result = showDetails({
17
17
  isMobile: true,
18
18
  isInline: true,
@@ -20,7 +20,7 @@ describe("showDetails", () => {
20
20
  isPip: false,
21
21
  });
22
22
 
23
- expect(result).toBe(false);
23
+ expect(result).toBe(true);
24
24
  });
25
25
 
26
26
  it("should return true if isMobile is true and isInline is true", () => {
@@ -52,6 +52,10 @@ export const showDetails = ({
52
52
  }
53
53
 
54
54
  if (isDocked) {
55
+ if (isMobile) {
56
+ return true;
57
+ }
58
+
55
59
  return false;
56
60
  }
57
61
 
@@ -0,0 +1,70 @@
1
+ import * as React from "react";
2
+ import { StyleSheet, ViewStyle } from "react-native";
3
+ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
4
+ import { useIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
5
+ import { playerDimensionsHack } from "./utils";
6
+ import { getTabletWidth } from "@applicaster/zapp-react-native-utils/playerUtils";
7
+ import {
8
+ getBaseDimensions,
9
+ calculateAspectRatio,
10
+ getPlayerDimensions,
11
+ getContainerDimensions,
12
+ } from "./playerWrapperUtils";
13
+
14
+ export const defaultStyles = StyleSheet.create({
15
+ playerContainer: { position: "relative", alignSelf: "center", zIndex: 200 },
16
+ });
17
+
18
+ export const useStyle = ({
19
+ style,
20
+ inline,
21
+ isModal,
22
+ isTabletPortrait,
23
+ configuration,
24
+ pip,
25
+ }) => {
26
+ const isTablet = useIsTablet();
27
+
28
+ const isInlineModal = inline && isModal;
29
+
30
+ const isTabletLandscape = !isTV() && isTablet && !isTabletPortrait;
31
+
32
+ const tabletWidth = getTabletWidth(
33
+ configuration.tablet_landscape_sidebar_width,
34
+ style
35
+ );
36
+
37
+ const baseDimensions: ViewStyle = React.useMemo(
38
+ () => getBaseDimensions(isInlineModal, isTabletLandscape, tabletWidth),
39
+ [isInlineModal, isTabletLandscape, tabletWidth]
40
+ );
41
+
42
+ const aspectRatio = React.useMemo(
43
+ () => calculateAspectRatio(isInlineModal, pip),
44
+ // ignoring insets - only initial needed
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ [isInlineModal, pip]
47
+ );
48
+
49
+ return React.useMemo(() => {
50
+ const playerDimensions: ViewStyle = getPlayerDimensions(
51
+ baseDimensions,
52
+ aspectRatio
53
+ );
54
+
55
+ const containerDimensions: ViewStyle = getContainerDimensions(
56
+ baseDimensions,
57
+ aspectRatio
58
+ );
59
+
60
+ const childrenStyles = {
61
+ ...playerDimensions,
62
+ ...playerDimensionsHack,
63
+ };
64
+
65
+ return StyleSheet.create({
66
+ containerDimensions,
67
+ childrenStyles,
68
+ });
69
+ }, [baseDimensions, aspectRatio]);
70
+ };
@@ -0,0 +1,91 @@
1
+ import { Dimensions, DimensionValue, Platform, ViewStyle } from "react-native";
2
+ import { Edge } from "react-native-safe-area-context";
3
+
4
+ export type DimensionsT = {
5
+ width: number | string;
6
+ height: number | string | undefined;
7
+ aspectRatio?: number;
8
+ };
9
+
10
+ export type Configuration = {
11
+ [key: string]: any;
12
+ tablet_landscape_sidebar_width?: string;
13
+ tablet_landscape_player_container_background_color?: string;
14
+ };
15
+
16
+ // This is safe, remembering screen dimensions once as they do not change during runtime
17
+ // TODO: consider sharing screen orientation as a shared function for the app
18
+ const { width: SCREEN_WIDTH, height: SCREEN_HEIGHT } = Dimensions.get("screen");
19
+
20
+ export const getWindowDimensions = () => {
21
+ const { width, height } = Dimensions.get("window");
22
+
23
+ return { width, height };
24
+ };
25
+
26
+ export const getMaxWindowDimension = () => {
27
+ const { width, height } = getWindowDimensions();
28
+
29
+ return Math.max(width, height);
30
+ };
31
+
32
+ export const getMinWindowDimension = () => {
33
+ const { width, height } = getWindowDimensions();
34
+
35
+ return Math.min(width, height);
36
+ };
37
+
38
+ export const getScreenAspectRatio = () => {
39
+ const longEdge = Math.max(SCREEN_WIDTH, SCREEN_HEIGHT);
40
+ const shortEdge = Math.min(SCREEN_WIDTH, SCREEN_HEIGHT);
41
+
42
+ return longEdge / shortEdge;
43
+ };
44
+
45
+ export const getEdges = (
46
+ isTablet: boolean,
47
+ isInlineModal: boolean
48
+ ): readonly Edge[] => {
49
+ if (isTablet) {
50
+ return ["top"];
51
+ }
52
+
53
+ if (!isInlineModal && Platform.OS === "android") {
54
+ return [];
55
+ }
56
+
57
+ return ["top"];
58
+ };
59
+
60
+ export const getBaseDimensions = (
61
+ isInlineModal: boolean,
62
+ isTabletLandscape: boolean,
63
+ tabletWidth: DimensionValue
64
+ ): ViewStyle => ({
65
+ width: isInlineModal && isTabletLandscape ? tabletWidth : "100%",
66
+ height: undefined,
67
+ });
68
+
69
+ export const calculateAspectRatio = (
70
+ isInlineModal: boolean,
71
+ pip?: boolean
72
+ ): number => {
73
+ return !isInlineModal && !pip ? getScreenAspectRatio() : 16 / 9;
74
+ };
75
+
76
+ export const getPlayerDimensions = (
77
+ baseDimensions: ViewStyle,
78
+ aspectRatio: number
79
+ ): ViewStyle => ({
80
+ ...(baseDimensions as any),
81
+ width: baseDimensions.width,
82
+ aspectRatio,
83
+ });
84
+
85
+ export const getContainerDimensions = (
86
+ baseDimensions: ViewStyle,
87
+ aspectRatio?: string | number
88
+ ): ViewStyle => ({
89
+ ...baseDimensions,
90
+ aspectRatio,
91
+ });
@@ -0,0 +1,27 @@
1
+ import React, { ReactNode } from "react";
2
+
3
+ export const CellFocusedStateContext = React.createContext<boolean>(false);
4
+
5
+ export const CellFocusedStateContextProvider = ({
6
+ cellFocused,
7
+ children,
8
+ }: {
9
+ cellFocused: boolean;
10
+ children: ReactNode;
11
+ }) => {
12
+ return (
13
+ <CellFocusedStateContext.Provider value={cellFocused}>
14
+ {children}
15
+ </CellFocusedStateContext.Provider>
16
+ );
17
+ };
18
+
19
+ export function withCellFocusedStateContext(
20
+ Component: React.ComponentType<any>
21
+ ) {
22
+ return function WithCellFocusedStateContextWrapper(props) {
23
+ const cellFocusedState = React.useContext(CellFocusedStateContext);
24
+
25
+ return <Component {...props} cellFocusedState={cellFocusedState} />;
26
+ };
27
+ }
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import TestRenderer from "react-test-renderer";
2
+ import { render } from "@testing-library/react-native";
3
3
  import { View } from "react-native";
4
4
  import { useConfiguration } from "@applicaster/zapp-react-native-utils/reactHooks/configuration";
5
5
 
@@ -14,12 +14,12 @@ describe("withConfigurationProvider", () => {
14
14
  };
15
15
 
16
16
  it("provides configuration to children", () => {
17
- const wrapper = TestRenderer.create(
17
+ const { toJSON } = render(
18
18
  <ConfigurationProvider configuration={{ target: "foobar" }}>
19
19
  <TestComponent />
20
20
  </ConfigurationProvider>
21
21
  );
22
22
 
23
- expect(wrapper.toJSON()).toMatchSnapshot();
23
+ expect(toJSON()).toMatchSnapshot();
24
24
  });
25
25
  });
@@ -13,7 +13,8 @@ import {
13
13
  } from "@applicaster/zapp-react-native-utils/reactHooks";
14
14
  import { useModalNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ModalNavigationContext";
15
15
  import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NestedNavigationContext";
16
- import { create, StoreApi, UseBoundStore } from "zustand";
16
+ import { create } from "zustand";
17
+ import { subscribeWithSelector } from "zustand/middleware";
17
18
  import { useShallow } from "zustand/react/shallow";
18
19
  import { Animated } from "react-native";
19
20
 
@@ -39,38 +40,26 @@ interface NavBarState {
39
40
  setSummary: (subtitle: string) => void;
40
41
  }
41
42
 
42
- type ScreenContextType = {
43
- _navBarStore: UseBoundStore<StoreApi<NavBarStoreState>>;
44
- _stateStore: UseBoundStore<StoreApi<StateStore>>;
45
- navBar: NavBarState;
46
- legacyFormatScreenData: LegacyNavigationScreenData | null;
47
- };
48
-
49
- interface StateStore {
50
- data: Record<string, any>;
51
- setValue: (key: string, value: any) => void;
52
- removeValue: (key: string) => void;
53
- }
54
-
55
- // possible replacement of screenStateStore, remove changes in this file if not needed
56
43
  const createStateStore = () =>
57
- create<StateStore>((set) => ({
58
- data: {},
59
- setValue: (key, value) =>
60
- set((state) => ({
61
- data: {
62
- ...state.data,
63
- [key]: value,
64
- },
65
- })),
66
- removeValue: (key) =>
67
- set((state) => {
68
- const newData = { ...state.data };
69
- delete newData[key];
70
-
71
- return { data: newData };
72
- }),
73
- }));
44
+ create(
45
+ subscribeWithSelector<ScreenStateStore>((set) => ({
46
+ data: {},
47
+ setValue: (key, value) =>
48
+ set((state) => ({
49
+ data: {
50
+ ...state.data,
51
+ [key]: value,
52
+ },
53
+ })),
54
+ removeValue: (key) =>
55
+ set((state) => {
56
+ const newData = { ...state.data };
57
+ delete newData[key];
58
+
59
+ return { data: newData };
60
+ }),
61
+ }))
62
+ );
74
63
 
75
64
  const createStore = () =>
76
65
  create<NavBarStoreState>((set) => ({
@@ -92,6 +81,13 @@ const createStore = () =>
92
81
  },
93
82
  }));
94
83
 
84
+ type ScreenContextType = {
85
+ _navBarStore: ReturnType<typeof createStore>;
86
+ _stateStore: ReturnType<typeof createStateStore>;
87
+ navBar: NavBarState;
88
+ legacyFormatScreenData: LegacyNavigationScreenData | null;
89
+ };
90
+
95
91
  export const ScreenContext = createContext<ScreenContextType>({
96
92
  _stateStore: createStateStore(),
97
93
  _navBarStore: createStore(),
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import TestRenderer from "react-test-renderer";
2
+ import { render } from "@testing-library/react-native";
3
3
  import { useConfiguration } from "@applicaster/zapp-react-native-utils/reactHooks/configuration";
4
4
  import { View } from "react-native";
5
5
  import { withConfigurationProvider } from "@applicaster/zapp-react-native-ui-components/Decorators/ConfigurationWrapper";
@@ -15,12 +15,12 @@ describe("withConfigurationProvider", () => {
15
15
  it("correctly passes all the configuration keys child component", () => {
16
16
  const Component = withConfigurationProvider(TestComponent);
17
17
 
18
- const wrapper = TestRenderer.create(
18
+ const { toJSON } = render(
19
19
  <Component
20
20
  screenData={{ styles: {}, general: {}, data: { source: "test" } }}
21
21
  />
22
22
  );
23
23
 
24
- expect(wrapper.toJSON()).toMatchSnapshot();
24
+ expect(toJSON()).toMatchSnapshot();
25
25
  });
26
26
  });