@applicaster/zapp-react-native-utils 12.0.0-rc.3 → 12.0.0-rc.31
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.
- package/actionsExecutor/ActionExecutorContext.tsx +16 -8
- package/analyticsUtils/__tests__/analyticsManager.test.js +75 -73
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +12 -3
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +1 -1
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +80 -85
- package/appUtils/keyCodes/keys.web.js +1 -0
- package/appUtils/orientationHelper.ts +1 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +53 -0
- package/appUtils/playerManager/player.ts +12 -4
- package/appUtils/playerManager/playerFactory.ts +13 -1
- package/appUtils/playerManager/playerNative.ts +26 -0
- package/appUtils/playerManager/usePlayerState.tsx +13 -1
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +50 -0
- package/cellUtils/__tests__/cellUtils.test.ts +59 -0
- package/cellUtils/__tests__/fixtures.ts +13 -0
- package/cellUtils/index.ts +42 -0
- package/focusManager/index.ts +1 -1
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +2 -2
- package/functionUtils/__tests__/functionUtils.test.js +244 -248
- package/localizationUtils/__tests__/localizationUtils.test.ts +17 -13
- package/localizationUtils/index.ts +6 -3
- package/logger/index.ts +1 -1
- package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
- package/modalState/index.ts +57 -0
- package/navigationUtils/index.ts +52 -7
- package/package.json +3 -2
- package/playerUtils/configurationGenerator.ts +8 -0
- package/pluginUtils/index.ts +11 -7
- package/reactHooks/cell-click/__tests__/index.test.js +6 -2
- package/reactHooks/cell-click/index.ts +2 -2
- package/reactHooks/device/index.ts +0 -1
- package/reactHooks/device/useIsTablet.tsx +28 -3
- package/reactHooks/device/useMemoizedIsTablet.ts +1 -1
- package/reactHooks/device/useOrientation.tsx +3 -1
- package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -9
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/__tests__/index.test.js +22 -30
- package/reactHooks/layout/index.ts +2 -1
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +11 -16
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +12 -14
- package/reactHooks/navigation/__tests__/index.test.tsx +216 -75
- package/reactHooks/navigation/index.ts +201 -85
- package/reactHooks/screen/index.ts +2 -0
- package/reactHooks/screen/useScreenData.ts +1 -1
- package/reactHooks/state/useRivers.ts +3 -1
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +10 -9
- package/riverComponetsMeasurementProvider/index.tsx +2 -2
- package/screenState/index.ts +8 -0
- package/zappFrameworkUtils/loginPluginUtils.ts +12 -2
- package/reactHooks/device/useIsTablet.android.tsx +0 -14
- package/reactHooks/device/useIsTablet.ios.tsx +0 -7
- package/reactHooks/device/useIsTablet.web.tsx +0 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
|
|
3
|
+
interface ModalState {
|
|
4
|
+
visible: boolean;
|
|
5
|
+
screen: any;
|
|
6
|
+
options: Record<string, unknown>;
|
|
7
|
+
props: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ModalStore {
|
|
11
|
+
modalState: ModalState;
|
|
12
|
+
setModalState: (newState: Partial<ModalState>) => void;
|
|
13
|
+
openModal: (
|
|
14
|
+
item: any,
|
|
15
|
+
options?: Record<string, unknown>,
|
|
16
|
+
props?: Record<string, unknown>
|
|
17
|
+
) => void;
|
|
18
|
+
dismissModal: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const initialModalState: ModalState = {
|
|
22
|
+
visible: false,
|
|
23
|
+
screen: null,
|
|
24
|
+
options: {},
|
|
25
|
+
props: {},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const useModalStore = create<ModalStore>((set) => ({
|
|
29
|
+
modalState: initialModalState,
|
|
30
|
+
setModalState: (newState) =>
|
|
31
|
+
set((state) => ({
|
|
32
|
+
modalState: { ...state.modalState, ...newState },
|
|
33
|
+
})),
|
|
34
|
+
openModal: ({
|
|
35
|
+
item,
|
|
36
|
+
options = {},
|
|
37
|
+
props = { screenData: {} },
|
|
38
|
+
}: OpenModalArg) =>
|
|
39
|
+
set({
|
|
40
|
+
modalState: {
|
|
41
|
+
visible: true,
|
|
42
|
+
screen: item,
|
|
43
|
+
options: {
|
|
44
|
+
animated: true,
|
|
45
|
+
animationType: "slide",
|
|
46
|
+
onShow: () => {},
|
|
47
|
+
presentationStyle: "overFullScreen",
|
|
48
|
+
transparent: true,
|
|
49
|
+
...options,
|
|
50
|
+
onDismiss: () => set({ modalState: initialModalState }),
|
|
51
|
+
onRequestClose: () => set({ modalState: initialModalState }),
|
|
52
|
+
},
|
|
53
|
+
props,
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
dismissModal: () => set(() => ({ modalState: initialModalState })),
|
|
57
|
+
}));
|
package/navigationUtils/index.ts
CHANGED
|
@@ -93,19 +93,64 @@ export function resolveNavigationPlugin({
|
|
|
93
93
|
* @param {Object} navigator to look for navigation props
|
|
94
94
|
* @param {String} category to look for in screen navigations
|
|
95
95
|
* @returns {Object} props
|
|
96
|
+
* @deprecated use getNavigationPropsV2 instead
|
|
96
97
|
*/
|
|
97
98
|
export function getNavigationProps({
|
|
98
|
-
navigator
|
|
99
|
+
navigator,
|
|
99
100
|
title = "",
|
|
100
101
|
category,
|
|
101
102
|
}: {
|
|
102
103
|
navigator: QuickBrickAppNavigator;
|
|
103
104
|
title: string;
|
|
104
105
|
category: string;
|
|
105
|
-
}):
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
}): {
|
|
107
|
+
selected: string;
|
|
108
|
+
title: string;
|
|
109
|
+
home: boolean;
|
|
110
|
+
styles: unknown;
|
|
111
|
+
assets: ZappNavBarAssets;
|
|
112
|
+
rules: ZappNavBarRules;
|
|
113
|
+
nav_items: NavBarItem[];
|
|
114
|
+
} | null {
|
|
115
|
+
const { activeRiver } = navigator;
|
|
116
|
+
const { navigations, id: selected, home } = activeRiver; // use useRiver hook instead
|
|
117
|
+
const navigation = R.find(R.propEq("category", category), navigations);
|
|
118
|
+
|
|
119
|
+
if (!navigation) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const { styles, assets, nav_items, rules } = navigation;
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
selected,
|
|
127
|
+
title,
|
|
128
|
+
home,
|
|
129
|
+
styles,
|
|
130
|
+
assets,
|
|
131
|
+
nav_items,
|
|
132
|
+
rules,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export function getNavigationPropsV2({
|
|
137
|
+
currentRiver,
|
|
138
|
+
title = "",
|
|
139
|
+
category,
|
|
140
|
+
}: {
|
|
141
|
+
currentRiver: ZappRiver;
|
|
142
|
+
title: string;
|
|
143
|
+
category: string;
|
|
144
|
+
}): {
|
|
145
|
+
selected: string;
|
|
146
|
+
title: string;
|
|
147
|
+
home: boolean;
|
|
148
|
+
styles: unknown;
|
|
149
|
+
assets: ZappNavBarAssets;
|
|
150
|
+
rules: ZappNavBarRules;
|
|
151
|
+
nav_items: NavBarItem[];
|
|
152
|
+
} | null {
|
|
153
|
+
const { navigations, id: selected, home } = currentRiver; // use useRiver hook instead
|
|
109
154
|
const navigation = R.find(R.propEq("category", category), navigations);
|
|
110
155
|
|
|
111
156
|
if (!navigation) {
|
|
@@ -170,7 +215,7 @@ export function getScreenIdForContentType(payload, contentTypes) {
|
|
|
170
215
|
export function getItemTargetId(
|
|
171
216
|
item: ZappEntry | ZappRiver,
|
|
172
217
|
screenType?: string, // todo: creat screen types enum
|
|
173
|
-
contentTypes?: ZappContentTypes,
|
|
218
|
+
contentTypes?: ZappContentTypes | null,
|
|
174
219
|
rivers?: Record<string, ZappRiver>
|
|
175
220
|
) {
|
|
176
221
|
// Pipes v2 resolution
|
|
@@ -217,7 +262,7 @@ export function getTargetRoute(
|
|
|
217
262
|
layoutVersion = undefined,
|
|
218
263
|
rivers = {},
|
|
219
264
|
}: {
|
|
220
|
-
contentTypes?: ZappContentTypes;
|
|
265
|
+
contentTypes?: ZappContentTypes | null;
|
|
221
266
|
layoutVersion?: Maybe<ZappLayoutVersions>;
|
|
222
267
|
rivers?: Record<string, ZappRiver>;
|
|
223
268
|
} = {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "12.0.0-rc.
|
|
3
|
+
"version": "12.0.0-rc.31",
|
|
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-rc.
|
|
31
|
+
"@applicaster/applicaster-types": "12.0.0-rc.31",
|
|
32
32
|
"buffer": "^5.2.1",
|
|
33
33
|
"camelize": "^1.0.0",
|
|
34
34
|
"create-react-context": "^0.2.3",
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
"immer": "*",
|
|
45
45
|
"react": "17.0.2",
|
|
46
46
|
"react-native": "0.68.6",
|
|
47
|
+
"validate-color": "*",
|
|
47
48
|
"zustand": "*"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
@@ -46,6 +46,14 @@ function getPlayerConfiguration({ platform }) {
|
|
|
46
46
|
label_tooltip:
|
|
47
47
|
"Enable if you want to have adaptive background gradient based on audio background image.",
|
|
48
48
|
},
|
|
49
|
+
{
|
|
50
|
+
key: "audio_player_background_image_query",
|
|
51
|
+
label: "Audio Player Image Query",
|
|
52
|
+
initial_value: "",
|
|
53
|
+
type: "text_input",
|
|
54
|
+
label_tooltip:
|
|
55
|
+
"Set the query params which control the size of the image e.g width, height. This will help to optimize the loading time, when magic background is enabled.",
|
|
56
|
+
},
|
|
49
57
|
],
|
|
50
58
|
};
|
|
51
59
|
|
package/pluginUtils/index.ts
CHANGED
|
@@ -20,14 +20,14 @@ type Plugin = {
|
|
|
20
20
|
* returns the component module for a specific type
|
|
21
21
|
* Will look in components first, then in plugins
|
|
22
22
|
*/
|
|
23
|
-
function getComponentModule({
|
|
23
|
+
export function getComponentModule({
|
|
24
24
|
componentType,
|
|
25
25
|
components,
|
|
26
26
|
plugins,
|
|
27
27
|
}: {
|
|
28
28
|
componentType: string;
|
|
29
29
|
components: ComponentsMap;
|
|
30
|
-
plugins: Plugin[];
|
|
30
|
+
plugins: Plugin[] | QuickBrickPlugin[];
|
|
31
31
|
}) {
|
|
32
32
|
const component = R.compose(
|
|
33
33
|
R.prop(R.__, components),
|
|
@@ -68,11 +68,13 @@ export function findComponentByType({
|
|
|
68
68
|
* Returns the plugin for a given identifier, if found
|
|
69
69
|
* @param identifier of the plugin to look for
|
|
70
70
|
* @param plugins map of the available plugins
|
|
71
|
+
* @param doNotWarn if set to true, will not log a warning if plugin is not found
|
|
71
72
|
* @return whole plugin if found, undefined otherwise
|
|
72
73
|
*/
|
|
73
74
|
export function findPluginByIdentifier(
|
|
74
75
|
identifier: string,
|
|
75
|
-
plugins: (QuickBrickPlugin | ZappPlugin | Plugin)[]
|
|
76
|
+
plugins: (QuickBrickPlugin | ZappPlugin | Plugin)[],
|
|
77
|
+
doNotWarn: boolean = false
|
|
76
78
|
): (QuickBrickPlugin | ZappPlugin | Plugin) | undefined {
|
|
77
79
|
if (!identifier) {
|
|
78
80
|
return undefined;
|
|
@@ -84,10 +86,12 @@ export function findPluginByIdentifier(
|
|
|
84
86
|
)(plugins);
|
|
85
87
|
|
|
86
88
|
if (!plugin && identifier !== "river" && identifier !== "hooks") {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
if (!doNotWarn) {
|
|
90
|
+
pluginUtilsLogger.warning({
|
|
91
|
+
message: `Could not find plugin for identifier ${identifier}`,
|
|
92
|
+
data: { identifier },
|
|
93
|
+
});
|
|
94
|
+
}
|
|
91
95
|
}
|
|
92
96
|
|
|
93
97
|
return plugin;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { cleanup, renderHook } from "@testing-library/react-hooks";
|
|
3
3
|
import { CellTapContext } from "@applicaster/zapp-react-native-ui-components/Contexts/CellTapContext";
|
|
4
|
+
import { waitFor } from "@testing-library/react-native";
|
|
4
5
|
|
|
5
6
|
const navigator = {
|
|
6
7
|
getPathname: () => "pathnameMock",
|
|
@@ -64,13 +65,16 @@ describe("useCellClick", () => {
|
|
|
64
65
|
cleanup();
|
|
65
66
|
});
|
|
66
67
|
|
|
67
|
-
it("runs onCellTap", () => {
|
|
68
|
+
it("runs onCellTap", async () => {
|
|
68
69
|
const { result } = renderHook(() => useCellClick(mockProps), { wrapper });
|
|
69
70
|
const useCellClickHook = result.current;
|
|
70
71
|
|
|
71
72
|
useCellClickHook();
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
await waitFor(() => {
|
|
75
|
+
expect(onCellTap).toHaveBeenCalled();
|
|
76
|
+
});
|
|
77
|
+
|
|
74
78
|
cleanup();
|
|
75
79
|
});
|
|
76
80
|
});
|
|
@@ -53,7 +53,7 @@ export const useCellClick = (props: Props) => {
|
|
|
53
53
|
);
|
|
54
54
|
|
|
55
55
|
const onPress = React.useCallback(
|
|
56
|
-
(_item?: ZappEntry | any, _index?: number) => {
|
|
56
|
+
async (_item?: ZappEntry | any, _index?: number) => {
|
|
57
57
|
// Making sure we are not getting GestureResponderEvent in here.
|
|
58
58
|
const isZappEntry = _item?.id && _item?.type;
|
|
59
59
|
const selectedItem = isZappEntry ? _item : props.item;
|
|
@@ -70,7 +70,7 @@ export const useCellClick = (props: Props) => {
|
|
|
70
70
|
logOnPress(selectedItem, pathname, component, onCellTap);
|
|
71
71
|
|
|
72
72
|
if (selectedItem) {
|
|
73
|
-
actionExecutor?.handleEntryActions(selectedItem);
|
|
73
|
+
await actionExecutor?.handleEntryActions(selectedItem);
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
if (selectedItem?.type?.value === "action") {
|
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/* eslint react-native/split-platform-components: off */
|
|
2
|
+
|
|
3
|
+
import { Platform, PlatformIOSStatic, NativeModules } from "react-native";
|
|
4
|
+
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
5
|
+
import { F as alwaysFalse } from "ramda";
|
|
6
|
+
import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
7
|
+
|
|
8
|
+
const useIsTabletIos = (): boolean => {
|
|
9
|
+
const { isPad } = Platform as PlatformIOSStatic;
|
|
10
|
+
|
|
11
|
+
return isPad;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const useIsTabletAndroid = (): boolean => {
|
|
15
|
+
const { initialProps } = NativeModules.QuickBrickCommunicationModule;
|
|
16
|
+
|
|
17
|
+
return toBooleanWithDefaultFalse(initialProps?.is_tablet);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const useIsTablet = platformSelect({
|
|
21
|
+
ios: useIsTabletIos,
|
|
22
|
+
android: useIsTabletAndroid,
|
|
23
|
+
lg_tv: alwaysFalse,
|
|
24
|
+
samsung_tv: alwaysFalse,
|
|
25
|
+
android_tv: alwaysFalse,
|
|
26
|
+
tvos: alwaysFalse,
|
|
27
|
+
default: alwaysFalse,
|
|
28
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
3
|
-
import { useIsTablet } from "./
|
|
3
|
+
import { useIsTablet } from "./useIsTablet";
|
|
4
4
|
|
|
5
5
|
export const useMemoizedIsTablet = () => {
|
|
6
6
|
const isTablet = useIsTablet();
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useWindowDimensions } from "react-native";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
type Return = "landscape" | "portrait";
|
|
4
|
+
|
|
5
|
+
export const useOrientation = (): Return => {
|
|
4
6
|
const { width, height } = useWindowDimensions();
|
|
5
7
|
const isLandscape = width > height;
|
|
6
8
|
|
|
@@ -5,27 +5,34 @@ type Return = (index: number) => void;
|
|
|
5
5
|
|
|
6
6
|
type Predicate = (
|
|
7
7
|
entry: ZappUIComponentProps["zappPipesData"]["data"]["entry"],
|
|
8
|
-
index: number
|
|
8
|
+
index: number,
|
|
9
|
+
numberOfColumns: number
|
|
9
10
|
) => boolean;
|
|
10
11
|
|
|
11
12
|
type Props = {
|
|
12
13
|
ifNeeded: Predicate;
|
|
13
14
|
loadNextData: () => void;
|
|
14
15
|
entry: ZappUIComponentProps["zappPipesData"]["data"]["entry"];
|
|
16
|
+
numberOfColumns?: number;
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
const handleLoadNextPage =
|
|
18
20
|
(
|
|
19
|
-
ifNeeded: (
|
|
21
|
+
ifNeeded: (
|
|
22
|
+
entry: ZappEntry[],
|
|
23
|
+
index: number,
|
|
24
|
+
numberOfColumns?: number
|
|
25
|
+
) => boolean,
|
|
20
26
|
loadNextData: () => void,
|
|
21
|
-
entry: ZappEntry[]
|
|
27
|
+
entry: ZappEntry[],
|
|
28
|
+
numberOfColumns
|
|
22
29
|
) =>
|
|
23
30
|
(index: number) => {
|
|
24
31
|
/**
|
|
25
32
|
* Lazy-Loading, invoke nextLoadData if we reach the end of the List
|
|
26
33
|
*/
|
|
27
34
|
|
|
28
|
-
if (ifNeeded(entry, index)) {
|
|
35
|
+
if (ifNeeded(entry, index, numberOfColumns)) {
|
|
29
36
|
loadNextData();
|
|
30
37
|
}
|
|
31
38
|
};
|
|
@@ -34,10 +41,10 @@ export const useLoadNextPageIfNeeded = ({
|
|
|
34
41
|
ifNeeded,
|
|
35
42
|
loadNextData = noop,
|
|
36
43
|
entry,
|
|
44
|
+
numberOfColumns = 0,
|
|
37
45
|
}: Props): Return => {
|
|
38
|
-
return React.useCallback(
|
|
39
|
-
ifNeeded,
|
|
40
|
-
loadNextData,
|
|
41
|
-
|
|
42
|
-
]);
|
|
46
|
+
return React.useCallback(
|
|
47
|
+
handleLoadNextPage(ifNeeded, loadNextData, entry, numberOfColumns),
|
|
48
|
+
[ifNeeded, loadNextData, entry, numberOfColumns]
|
|
49
|
+
);
|
|
43
50
|
};
|
package/reactHooks/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { cleanup, renderHook } from "@testing-library/react-hooks";
|
|
2
2
|
|
|
3
|
+
import * as ReactNative from "react-native";
|
|
4
|
+
|
|
3
5
|
const mocked_return_value = (tv) => ({
|
|
4
6
|
screen: tv
|
|
5
7
|
? { width: 50, height: 50, scale: 2, fontScale: 1 }
|
|
@@ -10,41 +12,31 @@ const mocked_return_value = (tv) => ({
|
|
|
10
12
|
const platform = "android";
|
|
11
13
|
let tv_flag = false;
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
ReactNative.Dimensions.get = jest.fn(
|
|
16
|
+
(context) => mocked_return_value(tv_flag)[context]
|
|
17
|
+
);
|
|
16
18
|
|
|
17
19
|
const mockRemoveFn = jest.fn();
|
|
18
20
|
|
|
19
|
-
jest.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const Dims = {
|
|
23
|
-
get: jest.fn((context) => mocked_return_value(tv_flag)[context]),
|
|
24
|
-
addEventListener: jest.fn().mockReturnValue({
|
|
25
|
-
remove: mockRemoveFn,
|
|
26
|
-
}),
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const QuickBrickCommunicationModule = {
|
|
30
|
-
initialProps: {
|
|
31
|
-
is_tablet: false,
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
...RNMock,
|
|
37
|
-
Dimensions: Dims,
|
|
38
|
-
Platform: {
|
|
39
|
-
OS: platform,
|
|
40
|
-
},
|
|
41
|
-
NativeModules: {
|
|
42
|
-
...RNMock.NativeModules,
|
|
43
|
-
QuickBrickCommunicationModule,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
21
|
+
ReactNative.Dimensions.addEventListener = jest.fn().mockReturnValue({
|
|
22
|
+
remove: mockRemoveFn,
|
|
46
23
|
});
|
|
47
24
|
|
|
25
|
+
ReactNative.Platform.OS = platform;
|
|
26
|
+
|
|
27
|
+
const QuickBrickCommunicationModule = {
|
|
28
|
+
initialProps: {
|
|
29
|
+
is_tablet: false,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
ReactNative.NativeModules.QuickBrickCommunicationModule =
|
|
34
|
+
QuickBrickCommunicationModule;
|
|
35
|
+
|
|
36
|
+
jest.mock("react-native-safe-area-context", () => ({
|
|
37
|
+
useSafeAreaInsets: () => ({ top: 50 }),
|
|
38
|
+
}));
|
|
39
|
+
|
|
48
40
|
jest.mock("../../../reactUtils", () => ({
|
|
49
41
|
platformSelect: jest.fn((specs) => specs[platform] || specs.default),
|
|
50
42
|
isTV: jest.fn(() => tv_flag),
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import { StatusBar, Platform } from "react-native";
|
|
3
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
3
4
|
|
|
4
5
|
import { platformSelect, isTV } from "../../reactUtils";
|
|
5
6
|
import { useIsNavBarVisible } from "../navigation";
|
|
6
|
-
|
|
7
|
+
|
|
7
8
|
import { isTablet } from "./isTablet";
|
|
8
9
|
|
|
9
10
|
export { isTablet } from "./isTablet";
|
package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import * as ReactNative from "react-native";
|
|
2
2
|
|
|
3
|
-
jest.
|
|
4
|
-
|
|
5
|
-
(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
);
|
|
3
|
+
const mockDimensionsGet = jest.fn(
|
|
4
|
+
(type) =>
|
|
5
|
+
({
|
|
6
|
+
window: { width: 1, height: 1 },
|
|
7
|
+
screen: { width: 360, height: 540 },
|
|
8
|
+
}[type])
|
|
9
|
+
);
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
Platform: jest.fn(() => ({ OS: mockPlatformOS })),
|
|
14
|
-
Dimensions: { get: mockDimensionsGet },
|
|
15
|
-
};
|
|
16
|
-
});
|
|
11
|
+
ReactNative.Dimensions.get = mockDimensionsGet;
|
|
17
12
|
|
|
18
13
|
const mockGetConstants = jest.fn().mockReturnValue({
|
|
19
14
|
Dimensions: {
|
|
@@ -26,9 +21,10 @@ jest.mock("react-native/Libraries/Utilities/NativeDeviceInfo", () => ({
|
|
|
26
21
|
getConstants: mockGetConstants,
|
|
27
22
|
}));
|
|
28
23
|
|
|
29
|
-
const { Platform, Dimensions } =
|
|
24
|
+
const { Platform, Dimensions } = ReactNative;
|
|
30
25
|
|
|
31
26
|
Platform.OS = "android";
|
|
27
|
+
|
|
32
28
|
const { getInitialDimensions } = require("../getInitialDimensions.native.ts");
|
|
33
29
|
|
|
34
30
|
describe("useDimensions > helpers ( native )", () => {
|
|
@@ -48,7 +44,6 @@ describe("useDimensions > helpers ( native )", () => {
|
|
|
48
44
|
|
|
49
45
|
it("should call NativeDeviceInfo.getConstants for ios when width === height", () => {
|
|
50
46
|
Platform.OS = "ios";
|
|
51
|
-
mockPlatformOS = "ios";
|
|
52
47
|
|
|
53
48
|
jest.fn().mockReturnValue({
|
|
54
49
|
Dimensions: {
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
const mockDimensionsGet = jest.fn(
|
|
3
|
-
(type) =>
|
|
4
|
-
({
|
|
5
|
-
window: { width: 1, height: 1 },
|
|
6
|
-
screen: { width: 360, height: 540 },
|
|
7
|
-
}[type])
|
|
8
|
-
);
|
|
1
|
+
import * as ReactNative from "react-native";
|
|
9
2
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
3
|
+
const mockDimensionsGet = jest.fn(
|
|
4
|
+
(type) =>
|
|
5
|
+
({
|
|
6
|
+
window: { width: 1, height: 1 },
|
|
7
|
+
screen: { width: 360, height: 540 },
|
|
8
|
+
}[type])
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
ReactNative.Dimensions.get = mockDimensionsGet;
|
|
15
12
|
|
|
16
|
-
const { Platform, Dimensions } =
|
|
13
|
+
const { Platform, Dimensions } = ReactNative;
|
|
17
14
|
|
|
18
15
|
Platform.OS = "web";
|
|
16
|
+
|
|
19
17
|
const { getInitialDimensions } = require("../getInitialDimensions.ts");
|
|
20
18
|
|
|
21
19
|
describe("useDimensions > helpers (web)", () => {
|