@applicaster/zapp-react-native-ui-components 16.0.0-rc.5 → 16.0.0-rc.50

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 (105) hide show
  1. package/Components/BackgroundImage/BackgroundImage.android.tv.tsx +28 -0
  2. package/Components/BackgroundImage/BackgroundImage.ios.tv.tsx +24 -0
  3. package/Components/BackgroundImage/BackgroundImage.tsx +42 -0
  4. package/Components/BackgroundImage/index.ts +1 -0
  5. package/Components/CellRendererResolver/index.ts +2 -2
  6. package/Components/ComponentResolver/__tests__/componentResolver.test.js +1 -1
  7. package/Components/FocusableGroup/FocusableTvOS.tsx +11 -7
  8. package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
  9. package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
  10. package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
  11. package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
  12. package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
  13. package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +124 -0
  14. package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
  15. package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
  16. package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
  17. package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +72 -0
  18. package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
  19. package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
  20. package/Components/GeneralContentScreen/index.ts +2 -0
  21. package/Components/Layout/FullWidthRow.tsx +38 -0
  22. package/Components/Layout/TV/ScreenContainer.tsx +5 -0
  23. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +0 -1
  24. package/Components/Layout/TV/index.tsx +3 -4
  25. package/Components/Layout/TV/index.web.tsx +2 -3
  26. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
  27. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +47 -21
  28. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +34 -6
  29. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +1 -1
  30. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts +420 -125
  31. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/index.ts +114 -19
  32. package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +19 -8
  33. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -3
  34. package/Components/MasterCell/DefaultComponents/PressableView.tsx +29 -9
  35. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +4 -0
  36. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +154 -100
  37. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +15 -4
  38. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +56 -22
  39. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
  40. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +3 -1
  41. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +32 -21
  42. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +15 -4
  43. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +23 -16
  44. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +8 -3
  45. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +2 -2
  46. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/insertButtonsBetweenLabels.test.ts +45 -13
  47. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +2 -2
  48. package/Components/MasterCell/contexts/PressedStateContext.ts +3 -0
  49. package/Components/MasterCell/dataAdapter.ts +15 -5
  50. package/Components/MasterCell/hooks/index.ts +2 -0
  51. package/Components/MasterCell/hooks/usePressedState.ts +4 -0
  52. package/Components/MasterCell/index.tsx +30 -5
  53. package/Components/MasterCell/utils/__tests__/resolveColor.test.js +169 -132
  54. package/Components/MasterCell/utils/__tests__/resolveColorForProp.test.js +92 -0
  55. package/Components/MasterCell/utils/index.ts +85 -46
  56. package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +332 -0
  57. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +402 -0
  58. package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +811 -0
  59. package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +671 -0
  60. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +878 -0
  61. package/Components/ModalComponent/AudioPlayer/Components/index.ts +9 -0
  62. package/Components/ModalComponent/BottomSheetDragArea.tsx +33 -0
  63. package/Components/ModalComponent/BottomSheetModalContent.tsx +49 -26
  64. package/Components/ModalComponent/__tests__/BottomSheetDragArea.test.tsx +74 -0
  65. package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +4 -85
  66. package/Components/OfflineHandler/__tests__/index.test.tsx +78 -18
  67. package/Components/OfflineHandler/hooks.ts +123 -0
  68. package/Components/OfflineHandler/index.tsx +51 -73
  69. package/Components/OfflineHandler/utils/index.ts +1 -13
  70. package/Components/PlayerContainer/PlayerContainer.tsx +23 -13
  71. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +285 -0
  72. package/Components/PreloaderWrapper/index.tsx +1 -1
  73. package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -2
  74. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +3 -15
  75. package/Components/Screen/TV/hooks/__tests__/useAfterPaint.test.ts +60 -0
  76. package/Components/Screen/TV/hooks/index.ts +2 -0
  77. package/Components/Screen/TV/hooks/useAfterPaint.ts +23 -0
  78. package/Components/Screen/TV/index.web.tsx +16 -7
  79. package/Components/Screen/index.tsx +8 -4
  80. package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +5 -3
  81. package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +1 -1
  82. package/Components/ScreenRevealManager/Overlay.tsx +34 -0
  83. package/Components/ScreenRevealManager/__tests__/Overlay.test.tsx +88 -0
  84. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +8 -19
  85. package/Components/TopCutoffOverlay/index.tsx +2 -2
  86. package/Components/Transitioner/Transitioner.tsx +28 -17
  87. package/Components/VideoLive/LiveImageManager.ts +56 -45
  88. package/Components/VideoLive/PlayerLiveImageComponent.tsx +4 -2
  89. package/Components/VideoModal/utils.ts +6 -1
  90. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +12 -5
  91. package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
  92. package/Contexts/CachedDimensionsContext/__tests__/index.test.ts +154 -0
  93. package/Contexts/CachedDimensionsContext/index.ts +17 -2
  94. package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
  95. package/Helpers/index.js +7 -40
  96. package/package.json +5 -5
  97. package/Components/Layout/TV/LayoutBackground.tsx +0 -31
  98. package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +0 -112
  99. package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +0 -107
  100. package/Components/OfflineHandler/NotificationView/NotificationView.tsx +0 -153
  101. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +0 -66
  102. package/Components/OfflineHandler/NotificationView/utils.ts +0 -34
  103. package/Components/Screen/utils.ts +0 -16
  104. package/Helpers/Analytics/index.js +0 -95
  105. /package/Components/MasterCell/DefaultComponents/ButtonContainerView/{index.tv.android.tsx → index.android.tv.tsx} +0 -0
@@ -0,0 +1,154 @@
1
+ import { renderHook, act } from "@testing-library/react-native";
2
+
3
+ type DimensionsStore = {
4
+ setState: (
5
+ partial: { dimensions: Record<string, unknown>; ids: string[] },
6
+ replace?: boolean
7
+ ) => void;
8
+ };
9
+
10
+ const createdStores: DimensionsStore[] = [];
11
+
12
+ jest.mock("zustand", () => {
13
+ const actual = jest.requireActual<typeof import("zustand")>("zustand");
14
+
15
+ return {
16
+ ...actual,
17
+ create: ((initializer: Parameters<typeof actual.create>[0]) => {
18
+ const store = actual.create(initializer);
19
+ createdStores.push(store);
20
+
21
+ return store;
22
+ }) as typeof actual.create,
23
+ };
24
+ });
25
+
26
+ import { useCachedDimensions } from "../index";
27
+
28
+ const resetStore = () => {
29
+ const store = createdStores[createdStores.length - 1];
30
+
31
+ act(() => {
32
+ store?.setState({ dimensions: {}, ids: [] });
33
+ });
34
+ };
35
+
36
+ describe("useCachedDimensions", () => {
37
+ beforeEach(() => {
38
+ resetStore();
39
+ });
40
+
41
+ describe("getCachedDimensions", () => {
42
+ it("returns default dimensions when id has no cached value", () => {
43
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
44
+
45
+ expect(result.current.getCachedDimensions()).toEqual({
46
+ width: undefined,
47
+ height: undefined,
48
+ });
49
+ });
50
+
51
+ it("returns cached dimensions after setCachedDimensions", () => {
52
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
53
+ const dimensions = { width: 100, height: 200 };
54
+
55
+ act(() => {
56
+ result.current.setCachedDimensions(dimensions);
57
+ });
58
+
59
+ expect(result.current.getCachedDimensions()).toEqual(dimensions);
60
+ });
61
+ });
62
+
63
+ describe("setCachedDimensions", () => {
64
+ it("updates dimensions for the hook id", () => {
65
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
66
+
67
+ act(() => {
68
+ result.current.setCachedDimensions({ width: 50, height: 75 });
69
+ });
70
+
71
+ expect(result.current.getCachedDimensions()).toEqual({
72
+ width: 50,
73
+ height: 75,
74
+ });
75
+ });
76
+
77
+ it("shares cached dimensions between hook instances with the same id", () => {
78
+ const { result: first } = renderHook(() =>
79
+ useCachedDimensions("shared-id")
80
+ );
81
+
82
+ const { result: second } = renderHook(() =>
83
+ useCachedDimensions("shared-id")
84
+ );
85
+
86
+ act(() => {
87
+ first.current.setCachedDimensions({ width: 10, height: 20 });
88
+ });
89
+
90
+ expect(second.current.getCachedDimensions()).toEqual({
91
+ width: 10,
92
+ height: 20,
93
+ });
94
+ });
95
+ });
96
+
97
+ describe("getLastCachedDimensions", () => {
98
+ it("returns undefined when no dimensions have been cached", () => {
99
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
100
+
101
+ expect(result.current.getLastCachedDimensions()).toBeUndefined();
102
+ });
103
+
104
+ it("returns the most recently cached dimensions across ids", () => {
105
+ const { result: first } = renderHook(() => useCachedDimensions("first"));
106
+
107
+ const { result: second } = renderHook(() =>
108
+ useCachedDimensions("second")
109
+ );
110
+
111
+ act(() => {
112
+ first.current.setCachedDimensions({ width: 100, height: 100 });
113
+ });
114
+
115
+ act(() => {
116
+ second.current.setCachedDimensions({ width: 200, height: 200 });
117
+ });
118
+
119
+ expect(first.current.getLastCachedDimensions()).toEqual({
120
+ width: 200,
121
+ height: 200,
122
+ });
123
+ });
124
+
125
+ it("returns the latest dimensions when the same id is updated multiple times", () => {
126
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
127
+
128
+ act(() => {
129
+ result.current.setCachedDimensions({ width: 100, height: 100 });
130
+ });
131
+
132
+ act(() => {
133
+ result.current.setCachedDimensions({ width: 300, height: 400 });
134
+ });
135
+
136
+ expect(result.current.getLastCachedDimensions()).toEqual({
137
+ width: 300,
138
+ height: 400,
139
+ });
140
+ });
141
+ });
142
+
143
+ describe("return value", () => {
144
+ it("exposes getCachedDimensions, setCachedDimensions, and getLastCachedDimensions", () => {
145
+ const { result } = renderHook(() => useCachedDimensions("component-1"));
146
+
147
+ expect(result.current).toEqual({
148
+ getCachedDimensions: expect.any(Function),
149
+ setCachedDimensions: expect.any(Function),
150
+ getLastCachedDimensions: expect.any(Function),
151
+ });
152
+ });
153
+ });
154
+ });
@@ -1,6 +1,7 @@
1
1
  import { create, useStore } from "zustand";
2
2
  import { produce } from "immer";
3
3
  import { useCallback, useMemo } from "react";
4
+ import { last } from "@applicaster/zapp-react-native-utils/utils";
4
5
 
5
6
  type Dimensions = {
6
7
  width: Option<number>;
@@ -10,14 +11,17 @@ type Dimensions = {
10
11
  type DimensionsState = {
11
12
  dimensions: Record<string, Dimensions>;
12
13
  setCachedDimensions: (id: string, dimensions: Dimensions) => void;
14
+ ids: string[];
13
15
  };
14
16
 
15
17
  const dimensionsStore = create<DimensionsState>((set) => ({
16
18
  dimensions: {},
19
+ ids: [],
17
20
  setCachedDimensions: (id, dimensions) =>
18
21
  set(
19
22
  produce((draft) => {
20
23
  draft.dimensions[id] = dimensions;
24
+ draft.ids.push(id);
21
25
  })
22
26
  ),
23
27
  }));
@@ -28,7 +32,7 @@ const initialDimensions = () => ({
28
32
  });
29
33
 
30
34
  export const useCachedDimensions = (id: string) => {
31
- const { dimensions, setCachedDimensions } = useStore(
35
+ const { dimensions, setCachedDimensions, ids } = useStore(
32
36
  dimensionsStore
33
37
  ) as DimensionsState;
34
38
 
@@ -40,11 +44,22 @@ export const useCachedDimensions = (id: string) => {
40
44
  setCachedDimensions(id, newDimensions);
41
45
  }, []);
42
46
 
47
+ const getLastCachedDimensions = useCallback(() => {
48
+ const previousId = last(ids);
49
+
50
+ if (!previousId) {
51
+ return undefined;
52
+ }
53
+
54
+ return dimensions[previousId];
55
+ }, [dimensions, ids]);
56
+
43
57
  return useMemo(
44
58
  () => ({
45
59
  getCachedDimensions,
46
60
  setCachedDimensions: handleSetCachedDimensions,
61
+ getLastCachedDimensions,
47
62
  }),
48
- [getCachedDimensions, handleSetCachedDimensions]
63
+ [getCachedDimensions, handleSetCachedDimensions, getLastCachedDimensions]
49
64
  );
50
65
  };
@@ -1,4 +1,3 @@
1
- import { sendTapCellEvent, sendTapMenuItem } from "../Analytics";
2
1
  import { getItemType } from "@applicaster/zapp-react-native-utils/navigationUtils";
3
2
  import { SCREEN_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/itemTypes";
4
3
 
@@ -12,7 +11,6 @@ export function onCellPress(
12
11
  itemIndex,
13
12
  layoutVersion = "v1"
14
13
  ) {
15
- sendTapCellEvent(entry, component, headerTitle, itemIndex);
16
14
  const componentScreenType = screenTypeFromComponent(component);
17
15
  const entryScreenType = screenTypeFromEntry(entry);
18
16
  const itemType = getItemType(entry, layoutVersion);
@@ -37,7 +35,3 @@ function screenTypeFromComponent(component) {
37
35
  function screenTypeFromEntry(entry) {
38
36
  return entry && entry.screen_type;
39
37
  }
40
-
41
- export function onMenuItemFocus({ item, index, isHome }) {
42
- sendTapMenuItem({ item, index, isHome });
43
- }
package/Helpers/index.js CHANGED
@@ -1,42 +1,9 @@
1
- export const ASSETS = {
2
- APP_BACKGROUND_IMAGE: "app_background_image",
3
- };
1
+ import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
4
2
 
5
- export const ANALYTICS_CORE_EVENTS = {
6
- TAP_CELL: "Tap Cell",
7
- PLAY_VOD_ITEM: "Play VOD Item",
8
- VOD_ITEM_PLAY_WAS_TRIGGERED: "VOD Item: Play Was Triggered",
9
- CHANNEL_ITEM_PLAY_WAS_TRIGGERED: "Channel Item: Play Was Triggered",
10
- PROGRAM_ITEM_PLAY_WAS_TRIGGERED: "Program Item: Play Was Triggered",
11
- TAP_MENU_ICON: "Tap Menu Item",
12
- HOME_SCREEN_VIEWED: "Home Screen: Viewed",
13
- ITEM_NOT_AVAILABLE: "N/A",
14
- };
15
-
16
- export const ANALYTICS_ENTRY_EVENTS = {
17
- ITEM_TYPE: "Item Type",
18
- ITEM_TITLE: "Item Name",
19
- ITEM_ID: "Item ID",
20
- ITEM_LINK: "Item Link",
21
- ITEM_INDEX: "Item Number",
22
- ITEM_TIME_PLAYED: "Item Total Time Played",
23
- ITEM_TOTAL_TIME_PLAYED: "Item Total Time Played",
24
- ITEM_PLAY_COMPLETED: "Completed",
25
- ITEM_CUSTOM_PROPERTY: "Custom Property",
26
- };
27
-
28
- export const ANALYTICS_COMPONENT_EVENTS = {
29
- COMPONENT_ID: "Component ID",
30
- COMPONENT_TYPE: "Component Type",
31
- CELL_STYLE: "Cell Style",
32
- HEADER_TITLE: "Header Name",
33
- COMPONENT_SOURCE: "Component Source",
34
- };
35
-
36
- export const ANALYTICS_MENU_ITEM_EVENTS = {
37
- ITEM_TYPE: "Item Type",
38
- ITEM_TITLE: "Item Name",
39
- ITEM_ID: "Item ID",
40
- ITEM_HOME_SCREEN: "Home Screen",
41
- ITEM_INDEX: "Item Number",
3
+ export const ASSETS = {
4
+ APP_BACKGROUND_IMAGE: platformSelect({
5
+ tvos: "app_background_image",
6
+ android_tv: "tv_app_background",
7
+ amazon: "tv_app_background",
8
+ }),
42
9
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "16.0.0-rc.5",
3
+ "version": "16.0.0-rc.50",
4
4
  "description": "Applicaster Zapp React Native ui components for the Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "16.0.0-rc.5",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-rc.5",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-rc.5",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-rc.5",
31
+ "@applicaster/applicaster-types": "16.0.0-rc.50",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-rc.50",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-rc.50",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-rc.50",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",
@@ -1,31 +0,0 @@
1
- import React from "react";
2
- import { getBackgroundImageUrl } from "../utils";
3
- import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
4
- import {
5
- selectRemoteConfigurations,
6
- useAppSelector,
7
- } from "@applicaster/zapp-react-native-redux";
8
-
9
- export const LayoutBackground = ({
10
- Background,
11
- children,
12
- }: {
13
- Background: React.ComponentType<any>;
14
- children: React.ReactNode;
15
- }) => {
16
- const theme = useTheme();
17
-
18
- const remoteConfigurations = useAppSelector(selectRemoteConfigurations);
19
-
20
- const backgroundColor = theme.app_background_color;
21
- const backgroundImageUrl = getBackgroundImageUrl(remoteConfigurations);
22
-
23
- return (
24
- <Background
25
- backgroundColor={backgroundColor}
26
- backgroundImageUrl={backgroundImageUrl}
27
- >
28
- {children}
29
- </Background>
30
- );
31
- };
@@ -1,112 +0,0 @@
1
- import * as React from "react";
2
- import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
3
- import { useNetworkStatusLocalizations } from "./utils";
4
-
5
- type Props = {
6
- children?: React.ReactNode;
7
- hidden?: boolean;
8
- online?: boolean;
9
- previousOnline?: boolean;
10
- dismiss: () => void;
11
- };
12
-
13
- const NOTIF_DURATION = 4500;
14
-
15
- const styles: Record<any, React.CSSProperties> = {
16
- body: {
17
- position: "absolute",
18
- bottom: 0,
19
- width: 1920,
20
- height: 200,
21
- background:
22
- "linear-gradient(180deg, rgba(17,17,17,0.9) 0%, rgba(17,17,17,1) 49%, rgba(0,0,0,0.85) 100%)",
23
- display: "flex",
24
- alignItems: "center",
25
- justifyContent: "center",
26
- flexDirection: "column",
27
- color: "#fff",
28
- paddingBottom: 15,
29
- },
30
- title: {
31
- fontSize: 28,
32
- margin: 0,
33
- padding: 0,
34
- },
35
- subtitle: {
36
- fontSize: 20,
37
- margin: 0,
38
- padding: 0,
39
- },
40
- };
41
-
42
- export const NotificationView = (props: Props) => {
43
- const { children, hidden, dismiss, previousOnline, online } = props;
44
-
45
- const theme = useTheme<BaseThemePropertiesTV>();
46
- const storedLocalizations = useNetworkStatusLocalizations();
47
-
48
- const [open, setOpen] = React.useState<boolean | null>(null);
49
-
50
- const timeout = React.useRef<NodeJS.Timeout>();
51
- const wentOnline = !previousOnline && props.online;
52
-
53
- const onClose = () => {
54
- setOpen(false);
55
- dismiss();
56
- };
57
-
58
- const closeNotification = () => {
59
- clearTimeout(timeout.current as NodeJS.Timeout);
60
-
61
- timeout.current = setTimeout(() => {
62
- setOpen(false);
63
- }, NOTIF_DURATION);
64
- };
65
-
66
- const openNotification = () => {
67
- if (!open && !hidden) {
68
- setOpen(true);
69
- }
70
- };
71
-
72
- const handleNotificationChange = () => {
73
- if (open !== null) {
74
- openNotification();
75
- }
76
-
77
- closeNotification();
78
- };
79
-
80
- React.useEffect(() => {
81
- handleNotificationChange();
82
- }, [hidden, online]);
83
-
84
- const showOnlineMsg = wentOnline || online;
85
-
86
- const MSG = showOnlineMsg
87
- ? (theme?.online_notification_title ??
88
- storedLocalizations?.online_notification_title)
89
- : (theme?.offline_notification_title ??
90
- storedLocalizations?.offline_notification_title);
91
-
92
- const EXTRA_MSG = showOnlineMsg
93
- ? (theme?.online_notification_subtitle ??
94
- storedLocalizations?.online_notification_subtitle)
95
- : (theme?.offline_notification_subtitle ??
96
- storedLocalizations?.offline_notification_subtitle);
97
-
98
- return (
99
- <div onClick={onClose}>
100
- {children}
101
- {open ? (
102
- <div style={styles.body}>
103
- <div style={styles.title}>
104
- <h2>{MSG}</h2>
105
- </div>
106
-
107
- <h4 style={styles.subtitle}>{EXTRA_MSG}</h4>
108
- </div>
109
- ) : null}
110
- </div>
111
- );
112
- };
@@ -1,107 +0,0 @@
1
- import * as React from "react";
2
- import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
3
- import { useNetworkStatusLocalizations } from "./utils";
4
-
5
- type Props = {
6
- children?: React.ReactNode;
7
- online?: boolean;
8
- previousOnline?: boolean;
9
- dismiss: () => void;
10
- };
11
-
12
- const DURATION_TO_HIDE_AFTER_BACK_TO_ONLINE = 4500; // ms
13
-
14
- const styles: Record<any, React.CSSProperties> = {
15
- body: {
16
- position: "absolute",
17
- top: 0,
18
- width: 1920,
19
- height: 200,
20
- background:
21
- "linear-gradient(180deg, rgba(17,17,17,0.9) 0%, rgba(17,17,17,1) 49%, rgba(0,0,0,0.85) 100%)",
22
- display: "flex",
23
- alignItems: "center",
24
- justifyContent: "center",
25
- flexDirection: "column",
26
- color: "#fff",
27
- paddingTop: 15,
28
- },
29
- title: {
30
- fontSize: 28,
31
- margin: 0,
32
- padding: 0,
33
- },
34
- subtitle: {
35
- fontSize: 20,
36
- margin: 0,
37
- padding: 0,
38
- },
39
- };
40
-
41
- let timer: NodeJS.Timeout;
42
-
43
- export const NotificationView = (props: Props) => {
44
- const { children, dismiss, previousOnline = true, online } = props;
45
-
46
- const theme = useTheme<BaseThemePropertiesTV>();
47
- const storedLocalizations = useNetworkStatusLocalizations();
48
-
49
- const [shown, setShown] = React.useState<boolean>(false);
50
-
51
- const onClose = () => {
52
- setShown(false);
53
- dismiss();
54
- };
55
-
56
- React.useEffect(() => {
57
- if (previousOnline && online) {
58
- return;
59
- }
60
-
61
- if (!previousOnline && !online) {
62
- return;
63
- }
64
-
65
- if (previousOnline && !online) {
66
- // went to offline
67
- clearTimeout(timer);
68
- setShown(true);
69
- }
70
-
71
- if (!previousOnline && online) {
72
- // back to online
73
- setShown(true);
74
-
75
- timer = setTimeout(() => {
76
- setShown(false);
77
- }, DURATION_TO_HIDE_AFTER_BACK_TO_ONLINE);
78
- }
79
- }, [online, previousOnline]);
80
-
81
- const title = online
82
- ? (theme?.online_notification_title ??
83
- storedLocalizations?.online_notification_title)
84
- : (theme?.offline_notification_title ??
85
- storedLocalizations?.offline_notification_title);
86
-
87
- const subtitle = online
88
- ? (theme?.online_notification_subtitle ??
89
- storedLocalizations?.online_notification_subtitle)
90
- : (theme?.offline_notification_subtitle ??
91
- storedLocalizations?.offline_notification_subtitle);
92
-
93
- return (
94
- <div onClick={onClose}>
95
- {children}
96
- {shown ? (
97
- <div style={styles.body}>
98
- <div style={styles.title}>
99
- <h2>{title}</h2>
100
- </div>
101
-
102
- <h4 style={styles.subtitle}>{subtitle}</h4>
103
- </div>
104
- ) : null}
105
- </div>
106
- );
107
- };