@applicaster/zapp-react-native-utils 12.0.0-alpha.5606245605 → 12.0.0-alpha.5624518702

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 (58) hide show
  1. package/analyticsUtils/AnalyticPlayerListener.ts +155 -0
  2. package/analyticsUtils/AnalyticsEvents/index.ts +6 -0
  3. package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
  4. package/analyticsUtils/PlayerAnalyticsManager.ts +90 -0
  5. package/analyticsUtils/analyticsPlugins.ts +25 -0
  6. package/analyticsUtils/events.ts +6 -0
  7. package/analyticsUtils/index.tsx +6 -0
  8. package/analyticsUtils/{analyticsTracker.ts → playerAnalyticsTracker.ts} +19 -10
  9. package/appUtils/HooksManager/index.js +3 -1
  10. package/appUtils/playerManager/DelayedSeekPlayerWrapper.tsx +239 -0
  11. package/appUtils/playerManager/conts.ts +5 -0
  12. package/appUtils/playerManager/index.ts +9 -27
  13. package/appUtils/playerManager/player.ts +46 -4
  14. package/appUtils/playerManager/playerFactory.ts +12 -10
  15. package/appUtils/playerManager/playerNative.ts +11 -2
  16. package/appUtils/playerManager/usePlayerControllerSetup.tsx +23 -4
  17. package/cellUtils/__tests__/cellUtils.test.ts +9 -20
  18. package/cellUtils/index.ts +10 -14
  19. package/dateUtils/index.ts +11 -0
  20. package/headersUtils/index.ts +1 -0
  21. package/inflatedUrlUtils/index.ts +4 -4
  22. package/localizationUtils/__tests__/localizationUtils.test.ts +72 -53
  23. package/localizationUtils/index.ts +13 -22
  24. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  25. package/manifestUtils/defaultManifestConfigurations/player.js +2 -1
  26. package/manifestUtils/index.js +5 -1
  27. package/manifestUtils/secondaryImage/index.js +18 -15
  28. package/navigationUtils/index.ts +8 -4
  29. package/numberUtils/index.ts +4 -0
  30. package/package.json +2 -2
  31. package/playerUtils/configurationGenerator.ts +3 -1
  32. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
  33. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
  34. package/reactHooks/cell-click/__tests__/index.test.js +5 -0
  35. package/reactHooks/cell-click/index.ts +2 -2
  36. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  37. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  38. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +44 -29
  39. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  40. package/reactHooks/layout/types/index.ts +2 -0
  41. package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
  42. package/reactHooks/navigation/__mocks__/index.ts +15 -0
  43. package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
  44. package/reactHooks/navigation/__tests__/index.test.tsx +26 -8
  45. package/reactHooks/navigation/index.ts +21 -19
  46. package/reactHooks/player/__tests__/useAutoSeek.test.tsx +8 -1
  47. package/reactHooks/player/useAutoSeek.tsx +23 -7
  48. package/reactHooks/player/useTapSeek.tsx +13 -8
  49. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
  50. package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
  51. package/reactHooks/screen/useScreenContext.ts +5 -4
  52. package/reactHooks/screen/useTargetScreenData.ts +7 -0
  53. package/reactHooks/useListenEventBusEvent.ts +1 -4
  54. package/screenState/index.ts +0 -8
  55. package/stringUtils/index.ts +5 -0
  56. package/testUtils/getByTestId.ts +14 -0
  57. package/testUtils/index.tsx +38 -23
  58. package/types.ts +4 -0
@@ -1,10 +1,9 @@
1
1
  import * as R from "ramda";
2
2
  import { ViewStyle } from "react-native";
3
- import { useSelector } from "react-redux";
4
3
 
5
- import { getDeviceLocales } from "./deviceLocales";
6
4
  import { useMemo } from "react";
7
5
  import { getUILanguage } from "../appUtils/localizationsHelper";
6
+ import { utilsLogger } from "../logger";
8
7
 
9
8
  export {
10
9
  getLocale,
@@ -45,34 +44,26 @@ export function useLocalizedStrings({ localizations }) {
45
44
  return result;
46
45
  }
47
46
 
48
- function getLocaleToUse(languageCodes, localizations) {
49
- const matchingLanguages = languageCodes.filter(
50
- R.contains(R.__, localizations)
51
- );
47
+ export function getIsRTL(): boolean {
48
+ const uiLanguage = getUILanguage();
49
+
50
+ if (!uiLanguage) {
51
+ utilsLogger.error({ message: "getUILanguage returned null or undefined" });
52
52
 
53
- if (matchingLanguages?.length) {
54
- return R.head(matchingLanguages);
53
+ return false;
55
54
  }
56
55
 
57
- return R.head(localizations);
58
- }
56
+ const [languageCode] = uiLanguage.split("-");
59
57
 
60
- export function getIsRTLFromLocalizations(localizations): boolean {
61
- const deviceLocales = getDeviceLocales() || [];
62
- const localeToUse = getLocaleToUse(deviceLocales, R.keys(localizations));
58
+ const lowerCaseLanguageCode = languageCode.toLocaleLowerCase();
63
59
 
64
- return R.contains(localeToUse, RTL_LOCALES);
65
- }
60
+ const isRTL = R.contains(lowerCaseLanguageCode, RTL_LOCALES);
66
61
 
67
- const remoteConfigLocalizationSelector = R.path([
68
- "remoteConfigurations",
69
- "localizations",
70
- ]);
62
+ return isRTL;
63
+ }
71
64
 
72
65
  export function useIsRTL(): boolean {
73
- const localizations = useSelector(remoteConfigLocalizationSelector);
74
-
75
- return getIsRTLFromLocalizations(localizations);
66
+ return getIsRTL();
76
67
  }
77
68
 
78
69
  export const applyRTLStylesIfNeeded = (
@@ -245,6 +245,12 @@ const generalContent = () => ({
245
245
  ],
246
246
  initial_value: "reloading...",
247
247
  },
248
+ {
249
+ type: "text_input",
250
+ label: "Navigation Bar Screen Title",
251
+ key: "screen_title",
252
+ initial_value: null,
253
+ },
248
254
  ],
249
255
  },
250
256
  advertising: {
@@ -1663,7 +1663,8 @@ function getPlayerConfiguration({ platform }) {
1663
1663
  platform.includes("lg") ||
1664
1664
  platform.includes("samsung") ||
1665
1665
  platform.includes("android_tv") ||
1666
- platform.includes("amazon")
1666
+ platform.includes("amazon") ||
1667
+ platform.includes("vizio")
1667
1668
  ) {
1668
1669
  styles.fields.push(
1669
1670
  // Captions Menu
@@ -22,7 +22,11 @@ const {
22
22
  const { buttonKey } = require("./buttons");
23
23
  const { tvBadges } = require("./tvBadges");
24
24
  const { mobileProgressBar, tvProgressBar } = require("./progressBar");
25
- const { secondaryImage, getUpdatedSecondaryImageKeys } = require("./secondaryImage");
25
+
26
+ const {
27
+ secondaryImage,
28
+ getUpdatedSecondaryImageKeys,
29
+ } = require("./secondaryImage");
26
30
 
27
31
  module.exports = {
28
32
  fontKey,
@@ -132,29 +132,32 @@ function secondaryImage({
132
132
 
133
133
  const POSITION_OVER_IMAGE = toSnakeCase(position_over_image);
134
134
 
135
- const getUpdatedSecondaryImageKeys = (secondaryImageManifest) => secondaryImageManifest.fields.reduce((acc, item) => {
136
- const key = item.key;
135
+ const getUpdatedSecondaryImageKeys = (secondaryImageManifest) =>
136
+ secondaryImageManifest.fields.reduce((acc, item) => {
137
+ const key = item.key;
137
138
 
138
- const conditionalFields = (item.conditional_fields || []).map((field) => field.key);
139
+ const conditionalFields = (item.conditional_fields || []).map(
140
+ (field) => field.key
141
+ );
139
142
 
140
- const updatedConditionalFields = conditionalFields.reduce((acc, field) => {
141
- const updatedKey = field.replace("secondary_image_", "nested_image_");
143
+ const updatedConditionalFields = conditionalFields.reduce((acc, field) => {
144
+ const updatedKey = field.replace("secondary_image_", "nested_image_");
145
+
146
+ return {
147
+ ...acc,
148
+ [updatedKey]: field,
149
+ };
150
+ }, {});
151
+
152
+ const updatedKey = key.replace("secondary_image_", "nested_image_");
142
153
 
143
154
  return {
144
155
  ...acc,
145
- [updatedKey]: field,
156
+ ...updatedConditionalFields,
157
+ [updatedKey]: key,
146
158
  };
147
159
  }, {});
148
160
 
149
- const updatedKey = key.replace("secondary_image_", "nested_image_");
150
-
151
- return {
152
- ...acc,
153
- ...updatedConditionalFields,
154
- [updatedKey]: key,
155
- };
156
- }, {});
157
-
158
161
  module.exports = {
159
162
  secondaryImage,
160
163
  getUpdatedSecondaryImageKeys,
@@ -114,7 +114,11 @@ export function getNavigationProps({
114
114
  } | null {
115
115
  const { activeRiver } = navigator;
116
116
  const { navigations, id: selected, home } = activeRiver; // use useRiver hook instead
117
- const navigation = R.find(R.propEq("category", category), navigations);
117
+
118
+ const navigation: ZappNavigation = R.find(
119
+ R.propEq("category", category),
120
+ navigations
121
+ );
118
122
 
119
123
  if (!navigation) {
120
124
  return null;
@@ -127,9 +131,9 @@ export function getNavigationProps({
127
131
  title,
128
132
  home,
129
133
  styles,
130
- assets,
131
- nav_items,
132
- rules,
134
+ assets: assets as ZappNavBarAssets,
135
+ nav_items: nav_items as any as NavBarItem[],
136
+ rules: rules as any as ZappNavBarRules,
133
137
  };
134
138
  }
135
139
 
@@ -75,3 +75,7 @@ export const isLikeNumber = (value: any): boolean => {
75
75
 
76
76
  export const isZero = (value: unknown): boolean =>
77
77
  Object.is(value, -0) || Object.is(value, 0);
78
+
79
+ export const isMinusZero = (value: number) => {
80
+ return 1 / value === -Infinity;
81
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "12.0.0-alpha.5606245605",
3
+ "version": "12.0.0-alpha.5624518702",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "12.0.0-alpha.5606245605",
31
+ "@applicaster/applicaster-types": "12.0.0-alpha.5624518702",
32
32
  "buffer": "^5.2.1",
33
33
  "camelize": "^1.0.0",
34
34
  "create-react-context": "^0.2.3",
@@ -22,6 +22,7 @@ function getDevice(platform) {
22
22
  case "android_tv_for_quickbrick":
23
23
  case "lg_tv":
24
24
  case "samsung_tv":
25
+ case "vizio":
25
26
  case "web":
26
27
  return "tv";
27
28
  }
@@ -1659,7 +1660,8 @@ function getPlayerConfiguration({ platform }) {
1659
1660
  platform.includes("lg") ||
1660
1661
  platform.includes("samsung") ||
1661
1662
  platform.includes("android_tv") ||
1662
- platform.includes("amazon")
1663
+ platform.includes("amazon") ||
1664
+ platform.includes("vizio")
1663
1665
  ) {
1664
1666
  styles.fields.push(
1665
1667
  // Captions Menu for TV
@@ -12,6 +12,8 @@ jest.mock(
12
12
  })
13
13
  );
14
14
 
15
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
16
+
15
17
  jest.useFakeTimers();
16
18
 
17
19
  const {
@@ -1,4 +1,8 @@
1
+ import React from "react";
2
+
1
3
  import { act, renderHook } from "@testing-library/react-hooks";
4
+ import { Provider } from "react-redux";
5
+ import configureStore from "redux-mock-store";
2
6
 
3
7
  const mockUpdateComponentsPositions = jest.fn();
4
8
 
@@ -17,11 +21,24 @@ jest.mock(
17
21
 
18
22
  jest.useFakeTimers();
19
23
 
24
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
25
+
26
+ const mockStore = configureStore();
27
+
28
+ const store = mockStore({ appData: {} });
29
+
30
+ const Wrapper = ({ children }: { children: React.ReactChild }) => (
31
+ /* @ts-ignore */
32
+ <Provider store={store}>{children}</Provider>
33
+ );
34
+
20
35
  const { useTrackedView } = require("../useTrackedView");
21
36
 
22
37
  describe("useTrackCurrentAutoScrollingElement", () => {
23
38
  it("should update position for selected component", async () => {
24
- const { result } = renderHook(() => useTrackedView("123"));
39
+ const { result } = renderHook(() => useTrackedView("123"), {
40
+ wrapper: Wrapper,
41
+ });
25
42
 
26
43
  // Fast-forward until all timers have been executed
27
44
  jest.advanceTimersByTime(3000);
@@ -6,6 +6,7 @@ import { waitFor } from "@testing-library/react-native";
6
6
  const navigator = {
7
7
  getPathname: () => "pathnameMock",
8
8
  push: jest.fn(),
9
+ data: {},
9
10
  };
10
11
 
11
12
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
@@ -28,6 +29,10 @@ jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
28
29
  },
29
30
  }));
30
31
 
32
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
33
+ useScreenContext: jest.fn(() => navigator.data),
34
+ }));
35
+
31
36
  const { useCellClick } = require("../");
32
37
 
33
38
  const mockProps = {
@@ -1,6 +1,7 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
 
3
3
  import * as React from "react";
4
+ import { useContext } from "react";
4
5
  import * as R from "ramda";
5
6
  import { handleActionSchemeUrl } from "@applicaster/quick-brick-core/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useUrlSchemeHandler";
6
7
  import { CellTapContext } from "@applicaster/zapp-react-native-ui-components/Contexts/CellTapContext";
@@ -12,7 +13,6 @@ import {
12
13
  import { ZappPipesEntryContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
13
14
  import { toBooleanWithDefaultTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
14
15
  import { noop } from "../../functionUtils";
15
- import { useContext } from "react";
16
16
  import { ActionExecutorContext } from "../../actionsExecutor/ActionExecutorContext";
17
17
  import { useSendAnalyticsOnPress } from "../analytics";
18
18
  import { logOnPress, warnEmptyContentType } from "./helpers";
@@ -83,7 +83,7 @@ export const useCellClick = (props: Props) => {
83
83
  if (typeof onCellTap === "function") {
84
84
  onCellTap(selectedItem, _index);
85
85
  } else {
86
- if (currentRoute === pathname || pathname === "videoModal") {
86
+ if (currentRoute === pathname || pathname.includes("video-modal")) {
87
87
  const targetScreen = component?.data?.target;
88
88
 
89
89
  push(
@@ -12,9 +12,21 @@ const {
12
12
 
13
13
  const { reactHooksLogger } = require("../../logger");
14
14
 
15
+ let mockStore;
16
+
15
17
  describe("getInflatedDataSourceUrl", () => {
16
18
  beforeEach(() => {
17
19
  reactHooksLogger.warning.mockClear();
20
+
21
+ const {
22
+ appStore,
23
+ } = require("@applicaster/zapp-react-native-redux/AppStore");
24
+
25
+ mockStore = {
26
+ getState: jest.fn().mockReturnValue({ pipesEndpoints: {} }),
27
+ };
28
+
29
+ appStore.set(mockStore);
18
30
  });
19
31
 
20
32
  it("returns the url inflated with the right params", () => {
@@ -72,7 +84,8 @@ describe("getInflatedDataSourceUrl", () => {
72
84
  expect(reactHooksLogger.warning).toHaveBeenCalledTimes(1);
73
85
 
74
86
  expect(reactHooksLogger.warning).toHaveBeenCalledWith({
75
- message: "Not enough data to fully inflate url",
87
+ message:
88
+ "Not enough data to fully inflate url: {{entry.id}} source: http://foo.com/show/seriesId={{seriesId}}",
76
89
  data: { source, contexts, mapping },
77
90
  });
78
91
  });
@@ -107,7 +120,8 @@ describe("getInflatedDataSourceUrl", () => {
107
120
  expect(reactHooksLogger.warning).toHaveBeenCalledTimes(1);
108
121
 
109
122
  expect(reactHooksLogger.warning).toHaveBeenCalledWith({
110
- message: "Not enough data to fully inflate url",
123
+ message:
124
+ "Not enough data to fully inflate url: {{entry.extensions.groupName}} source: https://zapp-1689-emmys.web.app/emmys/group-categories/{{groupName}}",
111
125
  data: { source, contexts, mapping },
112
126
  });
113
127
  });
@@ -148,7 +162,8 @@ describe("getInflatedDataSourceUrl", () => {
148
162
  expect(reactHooksLogger.warning).toHaveBeenCalledTimes(1);
149
163
 
150
164
  expect(reactHooksLogger.warning).toHaveBeenCalledWith({
151
- message: "Not enough data to fully inflate url",
165
+ message:
166
+ "Not enough data to fully inflate url: {{entry.extensions.groupName2}} source: https://zapp-1689-emmys.web.app/emmys/group-categories/{{groupName1}}?test={{groupName2}}",
152
167
  data: { source, contexts, mapping },
153
168
  });
154
169
  });
@@ -9,9 +9,15 @@ import {
9
9
 
10
10
  import { inflateString } from "../../stringUtils";
11
11
  import { useRoute } from "../navigation";
12
- import { isEnoughDataToInflateString } from "../../inflatedUrlUtils";
12
+ import { getMissingValues } from "../../inflatedUrlUtils";
13
13
  import { reactHooksLogger as logger } from "../logger";
14
14
  import { isTV } from "../../reactUtils";
15
+ import {
16
+ findEndpointForURL,
17
+ HTTP_METHODS,
18
+ } from "@applicaster/zapp-pipes-v2-client";
19
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
20
+ import { ENDPOINT_TAGS } from "../../types";
15
21
 
16
22
  /**
17
23
  * will match any occurrence in a string of one or more word characters
@@ -105,24 +111,47 @@ export const getInflatedDataSourceUrl: GetInflatedDataSourceUrl = ({
105
111
  R.keys(mapping)
106
112
  );
107
113
 
108
- if (!isEnoughDataToInflateString(contexts, string)) {
109
- const message = "Not enough data to fully inflate url";
114
+ const missingValues = getMissingValues(contexts, string);
110
115
 
111
- // todo: add js only payload instead
112
- if (__DEV__) {
113
- logger.warning({
114
- message,
115
- data: { source, contexts, mapping },
116
- });
116
+ if (missingValues && missingValues.length > 0) {
117
+ const pipesEndpoints = appStore.get("pipesEndpoints");
118
+
119
+ const endpointURL = findEndpointForURL(
120
+ source,
121
+ pipesEndpoints,
122
+ HTTP_METHODS.GET
123
+ );
124
+
125
+ const tags = pipesEndpoints?.[endpointURL]?.tags;
126
+ const allowMissingKeys = tags?.includes(ENDPOINT_TAGS.allow_missing_keys);
127
+
128
+ if (!allowMissingKeys) {
129
+ const message = `Not enough data to fully inflate url: ${missingValues.join(
130
+ ","
131
+ )} source: ${source}`;
132
+
133
+ // todo: add js only payload instead
134
+ if (__DEV__) {
135
+ logger.warning({
136
+ message,
137
+ data: { source, contexts, mapping },
138
+ });
139
+ } else {
140
+ // todo: log values we've failed to resolve
141
+ logger.warning({
142
+ message,
143
+ });
144
+ }
145
+
146
+ // return null in order to prevent start fetching data with invalid url
147
+ return null;
117
148
  } else {
118
- // todo: log values we've failed to resolve
119
- logger.warning({
120
- message,
149
+ logger.debug({
150
+ message: `Ignoring missing values in url because ${
151
+ ENDPOINT_TAGS.allow_missing_keys
152
+ } endpoint tag, keys: ${missingValues.join(",")}`,
121
153
  });
122
154
  }
123
-
124
- // return null in order to prevent start fetching data with invalid url
125
- return null;
126
155
  }
127
156
 
128
157
  return inflateString({ string, data: contexts });
@@ -1,4 +1,8 @@
1
+ import React from "react";
2
+
1
3
  import { cleanup, renderHook } from "@testing-library/react-hooks";
4
+ import { Provider } from "react-redux";
5
+ import configureStore from "redux-mock-store";
2
6
 
3
7
  import * as ReactNative from "react-native";
4
8
 
@@ -44,22 +48,47 @@ jest.mock("../../../reactUtils", () => ({
44
48
 
45
49
  jest.mock("../../navigation", () => ({
46
50
  useNavigation: () => null,
51
+ useIsScreenActive: () => true,
47
52
  }));
48
53
 
49
54
  const { Dimensions } = require("react-native");
50
- const { useDimensions } = require("../");
55
+ const { useDimensions } = require("..");
56
+
57
+ const mockStore = configureStore();
58
+
59
+ const getWrapper = () => {
60
+ const store = mockStore({ appData: {} });
61
+
62
+ const Wrapper = ({ children }: { children: React.ReactChild }) => (
63
+ /* @ts-ignore */
64
+ <Provider store={store}>{children}</Provider>
65
+ );
66
+
67
+ return Wrapper;
68
+ };
69
+
70
+ const testHook = (context, params?) => {
71
+ const wrapper = getWrapper();
72
+
73
+ const {
74
+ result,
75
+ result: { current: dimensions },
76
+ } = renderHook(() => useDimensions(context, params), {
77
+ wrapper,
78
+ });
79
+
80
+ return { result, dimensions };
81
+ };
51
82
 
52
83
  describe("useDimensions", () => {
53
84
  it("renders", () => {
54
- const { result } = renderHook(() =>
55
- useDimensions("window", { fullDimensions: true })
56
- );
85
+ const { result } = testHook("window", { fullDimensions: true });
57
86
 
58
87
  expect(result).toBeDefined();
59
88
  });
60
89
 
61
90
  it("sets event listener", () => {
62
- renderHook(() => useDimensions("window", { fullDimensions: true }));
91
+ testHook("window", { fullDimensions: true });
63
92
 
64
93
  expect(Dimensions.addEventListener).toBeCalledWith(
65
94
  "change",
@@ -68,16 +97,14 @@ describe("useDimensions", () => {
68
97
  });
69
98
 
70
99
  it("removes event listener", () => {
71
- renderHook(() => useDimensions("window", { fullDimensions: true }));
100
+ testHook("window", { fullDimensions: true });
72
101
  cleanup();
73
102
 
74
103
  expect(mockRemoveFn).toBeCalled();
75
104
  });
76
105
 
77
106
  it("Returns full dimensions object", () => {
78
- const {
79
- result: { current: dimensions },
80
- } = renderHook(() => useDimensions("window", { fullDimensions: true }));
107
+ const { dimensions } = testHook("window", { fullDimensions: true });
81
108
 
82
109
  expect(dimensions).toHaveProperty("height");
83
110
  expect(dimensions).toHaveProperty("width");
@@ -86,20 +113,17 @@ describe("useDimensions", () => {
86
113
  });
87
114
 
88
115
  it("Returns shorthand dimensions object", () => {
89
- const {
90
- result: { current: dimensions },
91
- } = renderHook(() => useDimensions("window"));
116
+ const { dimensions } = testHook("window");
92
117
 
93
118
  expect(dimensions).toHaveProperty("height");
94
119
  expect(dimensions).toHaveProperty("width");
95
120
  });
96
121
 
97
122
  it("Returns the device info object", () => {
98
- const {
99
- result: { current: dimensions },
100
- } = renderHook(() =>
101
- useDimensions("window", { fullDimensions: true, deviceInfo: true })
102
- );
123
+ const { dimensions } = testHook("window", {
124
+ fullDimensions: true,
125
+ deviceInfo: true,
126
+ });
103
127
 
104
128
  expect(dimensions).toHaveProperty("height");
105
129
  expect(dimensions).toHaveProperty("width");
@@ -112,10 +136,7 @@ describe("useDimensions", () => {
112
136
  it("applies the scale on TV, and screen context", () => {
113
137
  tv_flag = true;
114
138
  const { screen } = mocked_return_value(tv_flag);
115
-
116
- const {
117
- result: { current: dimensions },
118
- } = renderHook(() => useDimensions("screen"));
139
+ const { dimensions } = testHook("screen");
119
140
 
120
141
  expect(dimensions).toHaveProperty("height", screen.height * screen.scale);
121
142
  expect(dimensions).toHaveProperty("width", screen.width * screen.scale);
@@ -127,10 +148,7 @@ describe("useDimensions", () => {
127
148
  it("doesn't apply the scale on mobile with screen context", () => {
128
149
  tv_flag = false;
129
150
  const { screen } = mocked_return_value(tv_flag);
130
-
131
- const {
132
- result: { current: dimensions },
133
- } = renderHook(() => useDimensions("screen"));
151
+ const { dimensions } = testHook("screen");
134
152
 
135
153
  expect(dimensions).toHaveProperty("height", screen.height);
136
154
  expect(dimensions).toHaveProperty("width", screen.width);
@@ -140,10 +158,7 @@ describe("useDimensions", () => {
140
158
  it("doesn't apply the scale on TV with window context", () => {
141
159
  tv_flag = true;
142
160
  const { window } = mocked_return_value(tv_flag);
143
-
144
- const {
145
- result: { current: dimensions },
146
- } = renderHook(() => useDimensions("window"));
161
+ const { dimensions } = testHook("window");
147
162
 
148
163
  expect(dimensions).toHaveProperty("height", window.height);
149
164
  expect(dimensions).toHaveProperty("width", window.width);
@@ -3,13 +3,15 @@ import { isTablet } from "../isTablet";
3
3
  /**
4
4
  * Returns an object with additional device info that can be used to determine if tablet
5
5
  * @param {Number} dimensions - Dimensions object passed to the function
6
+ * @param {Object} appData - application data object passed to the function
6
7
  * @returns {DeviceInfo} deviceInfo - returns an object with scale, isTablet, and orientation
7
8
  */
8
- export const getDeviceInfo = (dimensions) => {
9
+ export const getDeviceInfo = (dimensions, appData) => {
9
10
  const scale = dimensions?.scale;
10
11
  const isLandscape = dimensions?.width > dimensions?.height;
11
12
  const orientation = isLandscape ? "landscape" : "portrait";
12
13
  const tablet = isTablet(dimensions, orientation) || false;
14
+ const isTabletLandscape = tablet && !appData?.isTabletPortrait;
13
15
 
14
- return { scale, isTablet: tablet, orientation };
16
+ return { scale, isTablet: tablet, orientation, isTabletLandscape };
15
17
  };
@@ -2,6 +2,7 @@ type DeviceInfo = {
2
2
  isTablet: boolean;
3
3
  scale: number;
4
4
  orientation: string;
5
+ isTabletLandscape: boolean;
5
6
  };
6
7
 
7
8
  type RNDimensions = {
@@ -20,6 +21,7 @@ export type Options = {
20
21
  excludeStatusBar?: boolean;
21
22
  rounded?: boolean;
22
23
  deviceInfo?: boolean;
24
+ updateForInactiveScreens?: boolean;
23
25
  };
24
26
 
25
27
  export type Context = "window" | "screen";