@applicaster/zapp-react-native-ui-components 16.0.0-rc.37 → 16.0.0-rc.39

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.
@@ -1,88 +1,7 @@
1
1
  // Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
 
3
- exports[`OfflineHandler renders 1`] = `
4
- <View
5
- style={
6
- {
7
- "flex": 1,
8
- "position": "relative",
9
- }
10
- }
11
- >
12
- <View
13
- style={
14
- {
15
- "bottom": 0,
16
- "left": 0,
17
- "position": "absolute",
18
- "right": 0,
19
- "top": 0,
20
- }
21
- }
22
- >
23
- <View
24
- accessibilityState={
25
- {
26
- "busy": undefined,
27
- "checked": undefined,
28
- "disabled": undefined,
29
- "expanded": undefined,
30
- "selected": undefined,
31
- }
32
- }
33
- accessible={true}
34
- collapsable={false}
35
- focusable={true}
36
- onClick={[Function]}
37
- onResponderGrant={[Function]}
38
- onResponderMove={[Function]}
39
- onResponderRelease={[Function]}
40
- onResponderTerminate={[Function]}
41
- onResponderTerminationRequest={[Function]}
42
- onStartShouldSetResponder={[Function]}
43
- style={
44
- {
45
- "alignItems": "center",
46
- "backgroundColor": undefined,
47
- "flex": 1,
48
- "height": 88,
49
- "justifyContent": "center",
50
- "left": 0,
51
- "opacity": 0,
52
- "position": "absolute",
53
- "right": 0,
54
- "top": 0,
55
- "transform": [
56
- {
57
- "translateY": -88,
58
- },
59
- ],
60
- "width": "100%",
61
- }
62
- }
63
- >
64
- <View
65
- style={
66
- {
67
- "backgroundColor": undefined,
68
- "height": 44,
69
- }
70
- }
71
- />
72
- <Text
73
- style={
74
- {
75
- "color": undefined,
76
- "fontFamily": undefined,
77
- "fontSize": undefined,
78
- "letterSpacing": undefined,
79
- "lineHeight": undefined,
80
- }
81
- }
82
- >
83
- You are back online
84
- </Text>
85
- </View>
86
- </View>
87
- </View>
3
+ exports[`OfflineHandler renders its children without wrapping them in a notification view 1`] = `
4
+ <Text>
5
+ child content
6
+ </Text>
88
7
  `;
@@ -1,26 +1,26 @@
1
1
  import React from "react";
2
+ import { Text } from "react-native";
2
3
  import { render } from "@testing-library/react-native";
4
+ import { subscriberFor } from "@applicaster/zapp-react-native-utils/reactHooks/useSubscriberFor";
3
5
 
4
6
  jest.useFakeTimers({ legacyFakeTimers: true });
5
7
 
8
+ // `isOnline` (@applicaster/quick-brick-core/App/NetworkStatusProvider/utils)
9
+ // only treats connectionInfo as "ready" when it has NetInfoState-shaped
10
+ // isConnected/isInternetReachable/details fields, so the mock has to mirror
11
+ // that shape for online/offline to actually be distinguishable.
6
12
  let mockConnectionStatus = false;
7
- const mockPreviousValue = null;
8
13
 
9
14
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/connection", () => {
10
15
  return {
11
16
  ...jest.requireActual(
12
17
  "@applicaster/zapp-react-native-utils/reactHooks/connection"
13
18
  ),
14
- useConnectionInfo: jest.fn(() => mockConnectionStatus),
15
- };
16
- });
17
-
18
- jest.mock("@applicaster/zapp-react-native-utils/reactHooks/utils", () => {
19
- return {
20
- ...jest.requireActual(
21
- "@applicaster/zapp-react-native-utils/reactHooks/utils"
22
- ),
23
- usePrevious: jest.fn(() => mockPreviousValue),
19
+ useConnectionInfo: jest.fn(() => ({
20
+ details: {},
21
+ isConnected: mockConnectionStatus,
22
+ isInternetReachable: mockConnectionStatus,
23
+ })),
24
24
  };
25
25
  });
26
26
 
@@ -54,21 +54,81 @@ jest.mock("react-native-safe-area-context", () => ({
54
54
  }));
55
55
 
56
56
  describe("OfflineHandler", () => {
57
- const { OfflineHandler, NotificationView } = require("../");
57
+ const { OfflineHandler } = require("../");
58
+
59
+ beforeEach(() => {
60
+ mockConnectionStatus = false;
61
+ });
62
+
63
+ it("renders its children without wrapping them in a notification view", () => {
64
+ const { toJSON } = render(
65
+ <OfflineHandler>
66
+ <Text>child content</Text>
67
+ </OfflineHandler>
68
+ );
58
69
 
59
- it("renders", () => {
60
- const { toJSON } = render(<OfflineHandler />);
61
70
  expect(toJSON()).toMatchSnapshot();
62
71
  });
63
72
 
64
- it("renders Notification mode if component was rendered while online", () => {
73
+ it("emits a showToast event on mount when the device starts offline", () => {
74
+ mockConnectionStatus = false;
75
+
76
+ const handleShowToast = jest.fn();
77
+ const unsubscribe = subscriberFor("showToast", handleShowToast);
78
+
79
+ render(<OfflineHandler />);
80
+
81
+ expect(handleShowToast).toHaveBeenCalledWith(
82
+ expect.objectContaining({
83
+ id: "offline-status",
84
+ message: "No internet connection",
85
+ timeout: 5000,
86
+ }),
87
+ // the shared event bus appends a dispose fn as the last handler arg
88
+ expect.any(Function)
89
+ );
90
+
91
+ unsubscribe();
92
+ });
93
+
94
+ it("does not emit a showToast event on mount when the device starts online", () => {
65
95
  mockConnectionStatus = true;
66
96
 
67
- const { rerender, UNSAFE_getByType } = render(<OfflineHandler />);
97
+ const handleShowToast = jest.fn();
98
+ const unsubscribe = subscriberFor("showToast", handleShowToast);
99
+
100
+ render(<OfflineHandler />);
101
+
102
+ expect(handleShowToast).not.toHaveBeenCalled();
103
+
104
+ unsubscribe();
105
+ });
106
+
107
+ it("emits a showToast event when the device comes back online", () => {
108
+ mockConnectionStatus = false;
109
+
110
+ const handleShowToast = jest.fn();
111
+ const unsubscribe = subscriberFor("showToast", handleShowToast);
112
+
113
+ const { rerender } = render(<OfflineHandler />);
68
114
 
115
+ // ignore the offline toast emitted on mount; we only care about the
116
+ // offline -> online transition here
117
+ handleShowToast.mockClear();
118
+
119
+ mockConnectionStatus = true;
69
120
  rerender(<OfflineHandler />);
70
121
 
71
- const notificationsView = UNSAFE_getByType(NotificationView);
72
- expect(notificationsView).toBeDefined();
122
+ expect(handleShowToast).toHaveBeenCalledWith(
123
+ expect.objectContaining({
124
+ id: "offline-status",
125
+ message: "You are back online",
126
+ timeout: 2000,
127
+ }),
128
+ // the shared event bus appends a dispose fn as the last handler arg
129
+ expect.any(Function)
130
+ );
131
+
132
+ unsubscribe();
73
133
  });
74
134
  });
@@ -0,0 +1,123 @@
1
+ import React, { useMemo } from "react";
2
+
3
+ import {
4
+ isWeb,
5
+ platformSelect,
6
+ } from "@applicaster/zapp-react-native-utils/reactUtils";
7
+ import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
8
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
9
+
10
+ import { usePlugins } from "@applicaster/zapp-react-native-redux";
11
+ import { textTransform } from "@applicaster/zapp-react-native-utils/cellUtils";
12
+ import { findPluginByIdentifier } from "@applicaster/zapp-react-native-utils/pluginUtils";
13
+
14
+ import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
15
+
16
+ const OFFLINE_EXPERIENCE = "offline-experience";
17
+
18
+ const NETWORK_STATUS_LOCALIZATIONS_KEY = "network_status_localizations";
19
+
20
+ const THEME_STORAGE_NAMESPACE = "quick-brick-theme";
21
+
22
+ export const useNotificationHeight = () => {
23
+ const insets = useSafeAreaInsets();
24
+
25
+ const navBarHeight = platformSelect({ ios: 44, android: 56 });
26
+
27
+ const statusHeight = insets.top;
28
+ const notificationHeight = statusHeight + navBarHeight;
29
+
30
+ return { statusHeight, notificationHeight };
31
+ };
32
+
33
+ export function useNetworkStatusLocalizations() {
34
+ const [storedLocalizations, setStoredLocalizations] = React.useState<Record<
35
+ string,
36
+ string
37
+ > | null>(null);
38
+
39
+ React.useEffect(() => {
40
+ async function loadStoredLocalizations() {
41
+ try {
42
+ const stored = await sessionStorage.getItem(
43
+ NETWORK_STATUS_LOCALIZATIONS_KEY,
44
+ THEME_STORAGE_NAMESPACE
45
+ );
46
+
47
+ if (stored) {
48
+ setStoredLocalizations(stored);
49
+ }
50
+ } catch (error) {
51
+ console.error("Error loading network status localizations", error);
52
+ }
53
+ }
54
+
55
+ loadStoredLocalizations();
56
+ }, []);
57
+
58
+ return storedLocalizations;
59
+ }
60
+
61
+ export function useOfflineHandlerProps(online: boolean) {
62
+ const theme = useTheme<BaseThemePropertiesTV>();
63
+ const storedLocalizations = useNetworkStatusLocalizations();
64
+ const plugins = usePlugins();
65
+ const offlinePlugin = findPluginByIdentifier(OFFLINE_EXPERIENCE, plugins);
66
+ const { useOfflineExperienceConfiguration } = offlinePlugin?.module ?? {};
67
+
68
+ const {
69
+ configurationFields,
70
+ localizations,
71
+ }: {
72
+ configurationFields: OfflineExperiencePluginConfiguration;
73
+ localizations: OfflineExperienceLocalizations;
74
+ } = useOfflineExperienceConfiguration?.() ?? {};
75
+
76
+ let title, subtitle, style;
77
+
78
+ if (isWeb()) {
79
+ title = online
80
+ ? (theme?.online_notification_title ??
81
+ storedLocalizations?.online_notification_title)
82
+ : (theme?.offline_notification_title ??
83
+ storedLocalizations?.offline_notification_title);
84
+
85
+ subtitle = online
86
+ ? (theme?.online_notification_subtitle ??
87
+ storedLocalizations?.online_notification_subtitle)
88
+ : (theme?.offline_notification_subtitle ??
89
+ storedLocalizations?.offline_notification_subtitle);
90
+ } else {
91
+ title = textTransform(
92
+ configurationFields.offline_toast_message_text_transform,
93
+ online
94
+ ? localizations.online_toast_message
95
+ : localizations.offline_toast_message
96
+ );
97
+
98
+ style = {
99
+ color: online
100
+ ? configurationFields.offline_toast_message_online_font_color
101
+ : configurationFields.offline_toast_message_font_color,
102
+ backgroundColor: online
103
+ ? configurationFields.offline_toast_online_background_color
104
+ : configurationFields.offline_toast_offline_background_color,
105
+ fontFamily: platformSelect({
106
+ ios: configurationFields.offline_toast_message_ios_font_family,
107
+ android: configurationFields.offline_toast_message_android_font_family,
108
+ }),
109
+ fontSize: configurationFields.offline_toast_message_font_size,
110
+ lineHeight: configurationFields.offline_toast_message_line_height,
111
+ letterSpacing: platformSelect({
112
+ ios: configurationFields.offline_toast_message_letter_spacing_ios,
113
+ android:
114
+ configurationFields.offline_toast_message_letter_spacing_android,
115
+ }),
116
+ };
117
+ }
118
+
119
+ return useMemo(
120
+ () => ({ message: title, extraMessage: subtitle, style }),
121
+ [title, subtitle, style]
122
+ );
123
+ }
@@ -1,105 +1,83 @@
1
- import React, { useCallback, useEffect, useRef, useState } from "react";
2
- import { View, StyleSheet } from "react-native";
3
- import { NotificationView as NotificationViewNative } from "./NotificationView/NotificationView";
4
- import { NotificationView as NotificationViewSamsung } from "./NotificationView/NotificationView.samsung";
5
- import { NotificationView as NotificationViewLG } from "./NotificationView/NotificationView.lg";
6
-
1
+ import React, { useCallback, useEffect } from "react";
7
2
  import { useConnectionInfo } from "@applicaster/zapp-react-native-utils/reactHooks/connection";
8
3
  import { usePrevious } from "@applicaster/zapp-react-native-utils/reactHooks/utils";
9
- import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
4
+ import { useSubscriberFor } from "@applicaster/zapp-react-native-utils/reactHooks/useSubscriberFor";
10
5
 
6
+ import { useOfflineHandlerProps } from "./hooks";
11
7
  import { componentsLogger } from "../../Helpers/logger";
12
8
  import { parseConnectionInfo } from "./utils";
13
9
 
14
10
  const logger = componentsLogger.addSubsystem("OfflineHandler");
15
11
 
12
+ // mirrors NOTIFICATION_TOAST_EVENTS.SHOW_TOAST in
13
+ // @applicaster/quick-brick-core/App/NotificationToastRenderer/NotificationToastManager
14
+ // (kept as a literal here since this package must not depend on quick-brick-core)
15
+ const SHOW_TOAST_EVENT = "showToast";
16
+ const OFFLINE_STATUS_TOAST_ID = "offline-status";
17
+
16
18
  type Props = {
17
19
  children?: React.ReactElement<any>;
18
20
  };
19
21
 
20
- const styles = StyleSheet.create({
21
- container: {
22
- flex: 1,
23
- position: "relative",
24
- },
25
- });
26
-
27
22
  const timers = {
28
23
  goingOffline: 5000,
29
24
  goingOnline: 2000,
30
25
  };
31
26
 
32
- export const NotificationView = platformSelect({
33
- samsung_tv: NotificationViewSamsung,
34
- lg_tv: NotificationViewLG,
35
- default: NotificationViewNative,
36
- });
37
-
38
27
  export const OfflineHandler = ({ children }: Props) => {
39
28
  const connectionInfo = useConnectionInfo(false);
40
- const { online, deviceOnline } = parseConnectionInfo(connectionInfo);
29
+ const { online } = parseConnectionInfo(connectionInfo);
30
+ const prevOnline = usePrevious(online);
41
31
 
42
- const [hidden, setHidden] = useState<boolean>(true);
43
- const previousOnline: boolean = usePrevious(online);
44
- const timer = useRef<NodeJS.Timeout | null>(null);
45
- const initialRender = useRef(false);
32
+ const emitShowToast = useSubscriberFor(SHOW_TOAST_EVENT);
46
33
 
47
- const dismiss = useCallback(() => {
48
- setHidden(true);
34
+ const { message, extraMessage, style } = useOfflineHandlerProps(online);
49
35
 
50
- if (timer.current) {
51
- clearTimeout(timer.current);
52
- timer.current = null;
53
- }
54
- }, []);
36
+ const showOnlineToast = useCallback(() => {
37
+ logger.log("Device is back online, emit toast");
55
38
 
56
- const setTimer = useCallback((cb, duration) => {
57
- if (timer.current) {
58
- clearTimeout(timer.current);
59
- }
39
+ emitShowToast({
40
+ id: OFFLINE_STATUS_TOAST_ID,
41
+ message,
42
+ extraMessage,
43
+ style,
44
+ timeout: timers.goingOnline,
45
+ });
46
+ }, [emitShowToast, message, extraMessage, style]);
47
+
48
+ const showOfflineToast = useCallback(() => {
49
+ logger.log("Device went offline, emit toast");
60
50
 
61
- timer.current = setTimeout(cb, duration);
62
- }, []);
51
+ emitShowToast({
52
+ id: OFFLINE_STATUS_TOAST_ID,
53
+ message,
54
+ extraMessage,
55
+ style,
56
+ timeout: timers.goingOffline,
57
+ });
58
+ }, [emitShowToast, message, extraMessage, style]);
63
59
 
64
60
  useEffect(() => {
65
- if (initialRender.current) {
66
- const wentOffline = previousOnline && online === false;
67
- const wentOnline = !previousOnline && online;
68
- const renderedOffline = !online && previousOnline === null;
69
-
70
- if (!deviceOnline || wentOffline || renderedOffline) {
71
- logger.log("Device went offline");
72
- setTimer(() => setHidden(true), timers.goingOffline);
73
- setHidden(false);
61
+ // On mount there is no previous state yet: only surface the offline toast
62
+ // for a device that starts offline. Don't announce "back online" for a
63
+ // device that was online to begin with.
64
+ if (prevOnline === undefined) {
65
+ if (!online) {
66
+ showOfflineToast();
74
67
  }
75
68
 
76
- if (wentOnline) {
77
- logger.log("Device is back online");
78
- setHidden(false);
79
- setTimer(() => setHidden(true), timers.goingOnline);
80
- }
81
- } else {
82
- initialRender.current = true;
69
+ return;
83
70
  }
84
71
 
85
- return () => {
86
- if (timer.current) {
87
- clearTimeout(timer.current);
88
- timer.current = null;
72
+ // On subsequent renders, only emit a toast when the online/offline state changes.
73
+ if (prevOnline !== online) {
74
+ if (!online) {
75
+ showOfflineToast();
76
+ } else {
77
+ showOnlineToast();
89
78
  }
90
- };
91
- }, [connectionInfo]);
92
-
93
- return (
94
- <View style={styles.container}>
95
- <NotificationView
96
- hidden={hidden}
97
- online={online}
98
- previousOnline={previousOnline}
99
- dismiss={dismiss}
100
- >
101
- {children}
102
- </NotificationView>
103
- </View>
104
- );
79
+ }
80
+ }, [online, prevOnline, showOfflineToast, showOnlineToast]);
81
+
82
+ return children;
105
83
  };
@@ -1,9 +1,8 @@
1
1
  import * as R from "ramda";
2
-
3
2
  import { NetInfoState } from "@react-native-community/netinfo";
4
3
  import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
5
4
  import { isOnline as isOnlineUtils } from "@applicaster/quick-brick-core/App/NetworkStatusProvider/utils";
6
- import { useSafeAreaInsets } from "react-native-safe-area-context";
5
+
7
6
  import { Platform } from "react-native";
8
7
 
9
8
  type ConnectionInfo = NetInfoState & { deviceStatus: NetStatus };
@@ -51,14 +50,3 @@ export const parseConnectionInfo: typeof parseConnectionInfoForDefault =
51
50
  samsung_tv: parseConnectionInfoForSamsung,
52
51
  default: parseConnectionInfoForDefault,
53
52
  });
54
-
55
- export const useNotificationHeight = () => {
56
- const insets = useSafeAreaInsets();
57
-
58
- const navBarHeight = platformSelect({ ios: 44, android: 56 });
59
-
60
- const statusHeight = insets.top;
61
- const notificationHeight = statusHeight + navBarHeight;
62
-
63
- return { statusHeight, notificationHeight };
64
- };
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
- import { append, compose, identity, isNil, tail, take, update } from "ramda";
3
+ import { append, compose, identity, tail, take, update } from "ramda";
4
4
 
5
5
  import { AnimationManager } from "./AnimationManager";
6
6
  import { Scene } from "./Scene";
@@ -10,6 +10,7 @@ import {
10
10
  shouldSkipAnimationForPreviousWebViewScene,
11
11
  } from "./utils";
12
12
  import { v4 as uuid_v4 } from "uuid";
13
+ import { isScreenActiveForRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive";
13
14
 
14
15
  export const NAV_ACTION_PUSH = "PUSH";
15
16
 
@@ -50,16 +51,16 @@ function scenesForBackTransition(props: SceneProps, { scenes }) {
50
51
  : [prepareScene(props.children), scenes[0]];
51
52
  }
52
53
 
53
- const isModalClosed = (navigator) => {
54
- return !!isNil(navigator?.modalData);
55
- };
56
-
57
54
  type Props = {
58
55
  transitionConfig: any;
59
56
  children: React.ReactNode;
60
57
  navigator: {
61
58
  previousAction: string;
62
59
  currentRoute: string;
60
+ videoModalState?: {
61
+ visible?: boolean;
62
+ mode?: string;
63
+ };
63
64
  screenData: {
64
65
  [key: string]: any;
65
66
  };
@@ -283,8 +284,10 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
283
284
  // so only a single scene should be rendered,
284
285
  // instead of dangerous nulls or duplicates.
285
286
  renderSingleScene({ scenes, to }) {
286
- const { contentStyle } = this.props;
287
- const screenData = this.props.children.props.screenData;
287
+ const { contentStyle, navigator, children } = this.props;
288
+
289
+ const { currentRoute, videoModalState } = navigator;
290
+ const screenData = children.props.screenData;
288
291
  const pathname = scenes[to.index].key;
289
292
 
290
293
  return (
@@ -293,7 +296,11 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
293
296
  <Scene
294
297
  {...{ style: to?.style || {} }}
295
298
  pathname={pathname}
296
- isActive={pathname === this.props.navigator.currentRoute}
299
+ isActive={isScreenActiveForRoute(
300
+ pathname,
301
+ currentRoute,
302
+ videoModalState
303
+ )}
297
304
  contentStyle={contentStyle}
298
305
  key={scenes[to.index].key}
299
306
  screenUniqueId={scenes[to.index].screenUniqueId}
@@ -311,16 +318,19 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
311
318
  // Looks redundant, but when written like this
312
319
  // we do not need to pass or generate keys.
313
320
  renderScenes({ scenes, from, to }) {
314
- const { contentStyle } = this.props;
321
+ const { contentStyle, navigator } = this.props;
322
+
323
+ const { currentRoute, videoModalState } = navigator;
315
324
 
316
325
  const fromScene = scenes[from.index] && (
317
326
  <Scene
318
327
  key={scenes[from.index].key}
319
328
  pathname={scenes[from.index].key}
320
- isActive={
321
- scenes[from.index].key === this.props.navigator.currentRoute &&
322
- isModalClosed(this.props.navigator)
323
- }
329
+ isActive={isScreenActiveForRoute(
330
+ scenes[from.index].key,
331
+ currentRoute,
332
+ videoModalState
333
+ )}
324
334
  style={from.style}
325
335
  pointerEvents="none"
326
336
  overlayStyle={from.overlayStyle}
@@ -336,10 +346,11 @@ export class TransitionerComponent extends React.PureComponent<Props, State> {
336
346
  const toScene = scenes[to.index] && (
337
347
  <Scene
338
348
  pathname={scenes[to.index].key}
339
- isActive={
340
- scenes[to.index].key === this.props.navigator.currentRoute &&
341
- isModalClosed(this.props.navigator)
342
- }
349
+ isActive={isScreenActiveForRoute(
350
+ scenes[to.index].key,
351
+ currentRoute,
352
+ videoModalState
353
+ )}
343
354
  key={scenes[to.index].key}
344
355
  style={to.style}
345
356
  overlayStyle={to.overlayStyle}
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.37",
3
+ "version": "16.0.0-rc.39",
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.37",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-rc.37",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-rc.37",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-rc.37",
31
+ "@applicaster/applicaster-types": "16.0.0-rc.39",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-rc.39",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-rc.39",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-rc.39",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",
@@ -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
- };
@@ -1,153 +0,0 @@
1
- import React, { useRef, useState, useEffect } from "react";
2
- import * as R from "ramda";
3
- import {
4
- View,
5
- Text,
6
- Animated,
7
- StyleSheet,
8
- TouchableWithoutFeedback,
9
- } from "react-native";
10
-
11
- import { usePlugins } from "@applicaster/zapp-react-native-redux";
12
- import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
13
- import { textTransform } from "@applicaster/zapp-react-native-utils/cellUtils";
14
- import { useNotificationHeight } from "../utils";
15
-
16
- export const onlinePhrase = "You are back online";
17
-
18
- export const offlinePhrase = "No internet connection";
19
-
20
- const styles = StyleSheet.create({
21
- notificationView: {
22
- flex: 1,
23
- position: "absolute",
24
- alignItems: "center",
25
- justifyContent: "center",
26
- top: 0,
27
- left: 0,
28
- right: 0,
29
- },
30
- });
31
-
32
- type Props = {
33
- children?: React.ReactNode;
34
- hidden?: boolean;
35
- online?: boolean;
36
- dismiss: () => void;
37
- };
38
-
39
- type NumberBoolean = 0 | 1;
40
-
41
- const OFFLINE_EXPERIENCE = "offline-experience";
42
-
43
- export const NotificationView = ({
44
- children,
45
- hidden = true,
46
- online = true,
47
- dismiss,
48
- }: Props) => {
49
- const plugins = usePlugins();
50
- const { statusHeight, notificationHeight } = useNotificationHeight();
51
-
52
- const offlinePlugin = R.find(
53
- R.propEq("identifier", OFFLINE_EXPERIENCE),
54
- plugins
55
- );
56
-
57
- const { useOfflineExperienceConfiguration } = offlinePlugin.module;
58
-
59
- const {
60
- configurationFields,
61
- localizations,
62
- }: {
63
- configurationFields: OfflineExperiencePluginConfiguration;
64
- localizations: OfflineExperienceLocalizations;
65
- } = useOfflineExperienceConfiguration?.();
66
-
67
- const [notificationOpacity, setNotificationOpacity] =
68
- useState<NumberBoolean>(0);
69
-
70
- const yPosition = useRef(new Animated.Value(0)).current;
71
-
72
- const showNotification = () => {
73
- setNotificationOpacity(1);
74
-
75
- Animated.timing(yPosition, {
76
- toValue: 1,
77
- useNativeDriver: true,
78
- duration: 300,
79
- }).start();
80
- };
81
-
82
- const hideNotification = () => {
83
- Animated.timing(yPosition, {
84
- toValue: 0,
85
- useNativeDriver: true,
86
- duration: 300,
87
- }).start(() => {
88
- setNotificationOpacity(0);
89
- });
90
- };
91
-
92
- useEffect(() => {
93
- hidden ? hideNotification() : showNotification();
94
- }, [hidden]);
95
-
96
- const backgroundColor = online
97
- ? configurationFields.offline_toast_online_background_color
98
- : configurationFields.offline_toast_offline_background_color;
99
-
100
- const animatedViewStyles = {
101
- ...styles.notificationView,
102
- transform: [
103
- {
104
- translateY: yPosition.interpolate({
105
- inputRange: [0, 1],
106
- outputRange: [-notificationHeight, 0],
107
- }),
108
- },
109
- ],
110
- opacity: notificationOpacity,
111
- height: notificationHeight,
112
- width: "100%",
113
- backgroundColor,
114
- };
115
-
116
- const textStyles = {
117
- color: online
118
- ? configurationFields.offline_toast_message_online_font_color
119
- : configurationFields.offline_toast_message_font_color,
120
- fontFamily: platformSelect({
121
- ios: configurationFields.offline_toast_message_ios_font_family,
122
- android: configurationFields.offline_toast_message_android_font_family,
123
- }),
124
- fontSize: configurationFields.offline_toast_message_font_size,
125
- lineHeight: configurationFields.offline_toast_message_line_height,
126
- letterSpacing: platformSelect({
127
- ios: configurationFields.offline_toast_message_letter_spacing_ios,
128
- android: configurationFields.offline_toast_message_letter_spacing_android,
129
- }),
130
- };
131
-
132
- const message = textTransform(
133
- configurationFields.offline_toast_message_text_transform,
134
- online
135
- ? localizations.online_toast_message
136
- : localizations.offline_toast_message
137
- );
138
-
139
- return (
140
- <View style={StyleSheet.absoluteFill}>
141
- {children}
142
- <TouchableWithoutFeedback
143
- style={styles.notificationView}
144
- onPress={dismiss}
145
- >
146
- <Animated.View style={animatedViewStyles}>
147
- <View style={{ height: statusHeight, backgroundColor }} />
148
- <Text style={textStyles}>{message}</Text>
149
- </Animated.View>
150
- </TouchableWithoutFeedback>
151
- </View>
152
- );
153
- };
@@ -1,66 +0,0 @@
1
- import React from "react";
2
- import { Text, Animated } from "react-native";
3
- import { render } from "@testing-library/react-native";
4
-
5
- import {
6
- NotificationView,
7
- onlinePhrase,
8
- offlinePhrase,
9
- } from "../NotificationView";
10
-
11
- jest.mock("@applicaster/zapp-react-native-redux", () => ({
12
- ...jest.requireActual("@applicaster/zapp-react-native-redux"),
13
- usePlugins: () => [
14
- {
15
- name: "offline experience",
16
- identifier: "offline-experience",
17
- type: "general",
18
- module: {
19
- useOfflineExperienceConfiguration: () => ({
20
- configurationFields: {},
21
- localizations: {
22
- offline_toast_message: "No internet connection",
23
- online_toast_message: "You are back online",
24
- },
25
- }),
26
- },
27
- },
28
- ],
29
- }));
30
-
31
- jest.mock("react-native-safe-area-context", () => ({
32
- useSafeAreaInsets: () => ({ top: 44 }),
33
- }));
34
-
35
- const dismiss = jest.fn();
36
-
37
- describe("NotificationView", () => {
38
- it("Show online message when Online", () => {
39
- const component = render(<NotificationView online dismiss={dismiss} />);
40
-
41
- expect(component.UNSAFE_getByType(Text).props.children).toBe(onlinePhrase);
42
- });
43
-
44
- it("Show offline message when Online", () => {
45
- const component = render(
46
- <NotificationView online={false} dismiss={dismiss} />
47
- );
48
-
49
- expect(component.UNSAFE_getByType(Text).props.children).toBe(offlinePhrase);
50
- });
51
-
52
- it("When hidden is false to true notification is visible", () => {
53
- const component = render(
54
- <NotificationView online={false} hidden={false} dismiss={dismiss} />
55
- );
56
-
57
- component.rerender(
58
- <NotificationView online={false} hidden={true} dismiss={dismiss} />
59
- );
60
-
61
- const animatedView = component.UNSAFE_getByType(Animated.View);
62
- const animatedViewStyles = animatedView.props.style;
63
-
64
- expect(animatedViewStyles.opacity).toBe(1);
65
- });
66
- });
@@ -1,34 +0,0 @@
1
- import * as React from "react";
2
- import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
3
-
4
- export const NETWORK_STATUS_LOCALIZATIONS_KEY = "network_status_localizations";
5
-
6
- export const THEME_STORAGE_NAMESPACE = "quick-brick-theme";
7
-
8
- export function useNetworkStatusLocalizations() {
9
- const [storedLocalizations, setStoredLocalizations] = React.useState<Record<
10
- string,
11
- string
12
- > | null>(null);
13
-
14
- React.useEffect(() => {
15
- async function loadStoredLocalizations() {
16
- try {
17
- const stored = await sessionStorage.getItem(
18
- NETWORK_STATUS_LOCALIZATIONS_KEY,
19
- THEME_STORAGE_NAMESPACE
20
- );
21
-
22
- if (stored) {
23
- setStoredLocalizations(stored);
24
- }
25
- } catch (error) {
26
- console.error("Error loading network status localizations", error);
27
- }
28
- }
29
-
30
- loadStoredLocalizations();
31
- }, []);
32
-
33
- return storedLocalizations;
34
- }