@applicaster/zapp-react-native-utils 13.0.0-rc.16 → 13.0.0-rc.17
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 +12 -1
- package/alertUtils/alert.ts +148 -0
- package/alertUtils/index.ts +1 -148
- package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
- package/analyticsUtils/helpers/hooks.ts +1 -1
- package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +7 -7
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +186 -186
- package/appUtils/contextKeysManager/contextResolver.ts +73 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +6 -6
- package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +1 -1
- package/appUtils/orientationHelper.ts +1 -1
- package/appUtils/playerManager/playerNative.ts +1 -1
- package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
- package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
- package/manifestUtils/__tests__/createConfig.test.js +18 -16
- package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +6 -6
- package/navigationUtils/__tests__/itemTypes.test.js +2 -2
- package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
- package/package.json +3 -2
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -1
- package/reactHooks/cell-click/__tests__/index.test.js +5 -2
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
- package/reactHooks/feed/usePipesCacheReset.ts +5 -5
- package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
- package/reactHooks/layout/__tests__/index.test.tsx +10 -10
- package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
- package/reactHooks/navigation/__tests__/index.test.tsx +0 -4
- package/reactHooks/navigation/index.ts +22 -214
- package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
- package/reactHooks/navigation/useGetTabBarHeight.ts +12 -0
- package/reactHooks/navigation/useIsScreenActive.ts +17 -0
- package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
- package/reactHooks/navigation/useNavigationType.ts +15 -0
- package/reactHooks/navigation/usePathname.ts +4 -0
- package/reactHooks/navigation/useRoute.ts +100 -0
- package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
- package/reactHooks/player/__tests__/useAutoSeek._test.tsx +2 -3
- package/reactUtils/__tests__/reactUtils.test.js +10 -28
- package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +19 -19
- package/reactUtils/createContext/__tests__/__snapshots__/index.test.js.snap +2 -2
- package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -3
- package/reactUtils/createContext/__tests__/helpers.test.js +8 -8
- package/theme/__mocks__/index.ts +4 -0
|
@@ -14,10 +14,10 @@ const mocked_return_value = (tv) => ({
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
const platform = "android";
|
|
17
|
-
let
|
|
17
|
+
let mock_tv_flag = false;
|
|
18
18
|
|
|
19
19
|
ReactNative.Dimensions.get = jest.fn(
|
|
20
|
-
(context) => mocked_return_value(
|
|
20
|
+
(context) => mocked_return_value(mock_tv_flag)[context]
|
|
21
21
|
);
|
|
22
22
|
|
|
23
23
|
const mockRemoveFn = jest.fn();
|
|
@@ -43,7 +43,7 @@ jest.mock("react-native-safe-area-context", () => ({
|
|
|
43
43
|
|
|
44
44
|
jest.mock("../../../reactUtils", () => ({
|
|
45
45
|
platformSelect: jest.fn((specs) => specs[platform] || specs.default),
|
|
46
|
-
isTV: jest.fn(() =>
|
|
46
|
+
isTV: jest.fn(() => mock_tv_flag),
|
|
47
47
|
}));
|
|
48
48
|
|
|
49
49
|
jest.mock("../../navigation", () => ({
|
|
@@ -134,20 +134,20 @@ describe("useDimensions", () => {
|
|
|
134
134
|
|
|
135
135
|
describe("it applies the scale to the width & height if needed", () => {
|
|
136
136
|
it("applies the scale on TV, and screen context", () => {
|
|
137
|
-
|
|
138
|
-
const { screen } = mocked_return_value(
|
|
137
|
+
mock_tv_flag = true;
|
|
138
|
+
const { screen } = mocked_return_value(mock_tv_flag);
|
|
139
139
|
const { dimensions } = testHook("screen");
|
|
140
140
|
|
|
141
141
|
expect(dimensions).toHaveProperty("height", screen.height * screen.scale);
|
|
142
142
|
expect(dimensions).toHaveProperty("width", screen.width * screen.scale);
|
|
143
143
|
expect(dimensions).toHaveProperty("scale", 1);
|
|
144
144
|
|
|
145
|
-
|
|
145
|
+
mock_tv_flag = false;
|
|
146
146
|
});
|
|
147
147
|
|
|
148
148
|
it("doesn't apply the scale on mobile with screen context", () => {
|
|
149
|
-
|
|
150
|
-
const { screen } = mocked_return_value(
|
|
149
|
+
mock_tv_flag = false;
|
|
150
|
+
const { screen } = mocked_return_value(mock_tv_flag);
|
|
151
151
|
const { dimensions } = testHook("screen");
|
|
152
152
|
|
|
153
153
|
expect(dimensions).toHaveProperty("height", screen.height);
|
|
@@ -156,8 +156,8 @@ describe("useDimensions", () => {
|
|
|
156
156
|
});
|
|
157
157
|
|
|
158
158
|
it("doesn't apply the scale on TV with window context", () => {
|
|
159
|
-
|
|
160
|
-
const { window } = mocked_return_value(
|
|
159
|
+
mock_tv_flag = true;
|
|
160
|
+
const { window } = mocked_return_value(mock_tv_flag);
|
|
161
161
|
const { dimensions } = testHook("window");
|
|
162
162
|
|
|
163
163
|
expect(dimensions).toHaveProperty("height", window.height);
|
package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
import * as ReactNative from "react-native";
|
|
2
|
+
import NativeDeviceInfo from "react-native/Libraries/Utilities/NativeDeviceInfo";
|
|
2
3
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
screen: { width: 360, height: 540 },
|
|
8
|
-
}[type])
|
|
9
|
-
);
|
|
4
|
+
const mockDimensions = {
|
|
5
|
+
window: { width: 1, height: 1 },
|
|
6
|
+
screen: { width: 360, height: 540 },
|
|
7
|
+
};
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const mockGetConstants = jest.fn().mockReturnValue({
|
|
14
|
-
Dimensions: {
|
|
15
|
-
window: { width: 360, height: 540 },
|
|
16
|
-
screen: { width: 360, height: 540 },
|
|
17
|
-
},
|
|
18
|
-
});
|
|
9
|
+
const mockDimensionsGet = jest.fn((type) => mockDimensions[type]);
|
|
19
10
|
|
|
20
|
-
|
|
21
|
-
getConstants: mockGetConstants,
|
|
22
|
-
}));
|
|
11
|
+
ReactNative.Dimensions.get = mockDimensionsGet;
|
|
23
12
|
|
|
24
13
|
const { Platform, Dimensions } = ReactNative;
|
|
25
14
|
|
|
@@ -34,27 +23,24 @@ describe("useDimensions > helpers ( native )", () => {
|
|
|
34
23
|
|
|
35
24
|
it("should call Dimensions.get for window context", () => {
|
|
36
25
|
getInitialDimensions("window");
|
|
37
|
-
expect(Dimensions.get).
|
|
26
|
+
expect(Dimensions.get).toHaveBeenCalled();
|
|
38
27
|
});
|
|
39
28
|
|
|
40
29
|
it("should call Dimensions.get for screen context", () => {
|
|
41
30
|
getInitialDimensions("screen");
|
|
42
|
-
expect(Dimensions.get).
|
|
31
|
+
expect(Dimensions.get).toHaveBeenCalled();
|
|
43
32
|
});
|
|
44
33
|
|
|
45
34
|
it("should call NativeDeviceInfo.getConstants for ios when width === height", () => {
|
|
46
35
|
Platform.OS = "ios";
|
|
47
36
|
|
|
48
|
-
jest
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
screen: { width: 360, height: 540 },
|
|
52
|
-
},
|
|
53
|
-
});
|
|
37
|
+
const mockGetConstants = jest
|
|
38
|
+
.spyOn(NativeDeviceInfo, "getConstants")
|
|
39
|
+
.mockReturnValue({ Dimensions: mockDimensions });
|
|
54
40
|
|
|
55
41
|
getInitialDimensions("window");
|
|
56
42
|
|
|
57
|
-
expect(Dimensions.get).
|
|
58
|
-
expect(mockGetConstants).
|
|
43
|
+
expect(Dimensions.get).toHaveBeenCalled();
|
|
44
|
+
expect(mockGetConstants).toHaveBeenCalled();
|
|
59
45
|
});
|
|
60
46
|
});
|
|
@@ -135,10 +135,6 @@ const hookModalWrapper = ({ children }) => (
|
|
|
135
135
|
</Provider>
|
|
136
136
|
);
|
|
137
137
|
|
|
138
|
-
jest.mock("../../../modalState", () => ({
|
|
139
|
-
useModalStore: jest.fn(),
|
|
140
|
-
}));
|
|
141
|
-
|
|
142
138
|
describe("navigation", () => {
|
|
143
139
|
describe("useRoute", () => {
|
|
144
140
|
describe("Main stack components", () => {
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint max-len: off */
|
|
3
|
-
|
|
4
|
-
import React, { useContext, useEffect, useMemo } from "react";
|
|
1
|
+
import React, { useEffect, useMemo } from "react";
|
|
5
2
|
import { BackHandler, InteractionManager, NativeModules } from "react-native";
|
|
6
|
-
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
7
3
|
|
|
8
4
|
import {
|
|
9
5
|
useContentTypes,
|
|
@@ -11,34 +7,36 @@ import {
|
|
|
11
7
|
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
12
8
|
import { HooksManager } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager";
|
|
13
9
|
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
LONG_KEY_PRESS_TIMEOUT,
|
|
17
|
-
QUICK_BRICK_NAVBAR,
|
|
18
|
-
QUICK_BRICK_CONTENT,
|
|
19
|
-
} from "@applicaster/quick-brick-core/const";
|
|
20
|
-
import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
|
|
10
|
+
import { LONG_KEY_PRESS_TIMEOUT } from "@applicaster/quick-brick-core/const";
|
|
21
11
|
import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
22
|
-
import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
|
|
23
12
|
import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
|
|
24
13
|
import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
|
|
25
|
-
import {
|
|
26
|
-
getNavigationProps,
|
|
27
|
-
getRiverFromRoute,
|
|
28
|
-
getTargetRoute,
|
|
29
|
-
} from "../../navigationUtils";
|
|
30
|
-
import { platformSelect } from "../../reactUtils";
|
|
14
|
+
import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
|
|
31
15
|
import { useConnectionInfo } from "../connection";
|
|
32
|
-
import { getTargetScreenData } from "../screen/useTargetScreenData";
|
|
33
16
|
|
|
34
|
-
import { isTV
|
|
17
|
+
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
35
18
|
import { useNavbarState } from "../screen";
|
|
36
|
-
import { useNavigation } from "./useNavigation";
|
|
37
|
-
import { useModalStore } from "../../modalState";
|
|
38
|
-
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
39
19
|
|
|
40
20
|
export { useNavigation } from "./useNavigation";
|
|
41
21
|
|
|
22
|
+
export { useRoute } from "./useRoute";
|
|
23
|
+
|
|
24
|
+
export { usePathname } from "./usePathname";
|
|
25
|
+
|
|
26
|
+
export { useNavigationPluginData } from "./useNavigationPluginData";
|
|
27
|
+
|
|
28
|
+
export { useNavigationType } from "./useNavigationType";
|
|
29
|
+
|
|
30
|
+
export { useGetBottomTabBarHeight } from "./useGetBottomTabBarHeight";
|
|
31
|
+
|
|
32
|
+
export { useIsScreenActive } from "./useIsScreenActive";
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
useUniqueRouteSuffix,
|
|
36
|
+
useNavbarId,
|
|
37
|
+
useContentId,
|
|
38
|
+
} from "./useUniqueRouteSuffix";
|
|
39
|
+
|
|
42
40
|
/**
|
|
43
41
|
* This function helps to decide wether the navbar should be presented on the screen
|
|
44
42
|
* based on route and / or screen Data
|
|
@@ -125,8 +123,6 @@ export function isNavBarVisible(
|
|
|
125
123
|
|
|
126
124
|
const { ProfilerBridge } = NativeModules;
|
|
127
125
|
|
|
128
|
-
export const usePathname = () => React.useContext(PathnameContext);
|
|
129
|
-
|
|
130
126
|
export const useBackHandler = (cb: () => boolean) => {
|
|
131
127
|
React.useEffect(() => {
|
|
132
128
|
BackHandler.addEventListener("hardwareBackPress", cb);
|
|
@@ -137,88 +133,6 @@ export const useBackHandler = (cb: () => boolean) => {
|
|
|
137
133
|
}, [cb]);
|
|
138
134
|
};
|
|
139
135
|
|
|
140
|
-
// starts with modal/
|
|
141
|
-
const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
|
|
142
|
-
|
|
143
|
-
const isVideoModalPathname = (pathname: string) =>
|
|
144
|
-
/^video-modal\//.test(pathname);
|
|
145
|
-
|
|
146
|
-
const isHookModalPathname = (pathname: string) =>
|
|
147
|
-
/^hooks-modal\//.test(pathname);
|
|
148
|
-
|
|
149
|
-
const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
150
|
-
|
|
151
|
-
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
152
|
-
|
|
153
|
-
export const useRoute = (): {
|
|
154
|
-
screenData: VariousScreenData;
|
|
155
|
-
pathname: string;
|
|
156
|
-
} => {
|
|
157
|
-
const pathname = usePathname() || "";
|
|
158
|
-
const navigator = useNavigation();
|
|
159
|
-
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
160
|
-
|
|
161
|
-
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
162
|
-
"plugins",
|
|
163
|
-
"rivers",
|
|
164
|
-
"contentTypes",
|
|
165
|
-
]);
|
|
166
|
-
|
|
167
|
-
const { modalState } = useModalStore();
|
|
168
|
-
const hookModalState = useZappHooksModalState();
|
|
169
|
-
|
|
170
|
-
const modalScreenData = modalState.screen;
|
|
171
|
-
|
|
172
|
-
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
173
|
-
|
|
174
|
-
const videoModalScreenData =
|
|
175
|
-
navigator.videoModalState?.item &&
|
|
176
|
-
legacyScreenData(
|
|
177
|
-
{
|
|
178
|
-
entry: navigator.videoModalState?.item as ZappEntry,
|
|
179
|
-
screen: getTargetScreenData(
|
|
180
|
-
navigator.videoModalState?.item as ZappEntry,
|
|
181
|
-
rivers,
|
|
182
|
-
contentTypes
|
|
183
|
-
),
|
|
184
|
-
},
|
|
185
|
-
plugins
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
// There are 4 route scenarios
|
|
189
|
-
// For regular screens take date from navigator stack.
|
|
190
|
-
// is path is model grab screenData from modal state
|
|
191
|
-
// if path is video modal grab screenData from video state
|
|
192
|
-
// if path is hook modal grab screenData from hook state
|
|
193
|
-
// if path is hook grab screenData from screenData
|
|
194
|
-
|
|
195
|
-
if (isModalPathname(pathname)) {
|
|
196
|
-
const screenData = modalScreenData ?? ({} as ZappEntry);
|
|
197
|
-
|
|
198
|
-
return { screenData, pathname };
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (isVideoModalPathname(pathname)) {
|
|
202
|
-
const screenData = videoModalScreenData as LegacyNavigationScreenData;
|
|
203
|
-
|
|
204
|
-
return { screenData, pathname };
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (isHookModalPathname(pathname)) {
|
|
208
|
-
const screenData = hookModalScreenData;
|
|
209
|
-
|
|
210
|
-
return { screenData, pathname };
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
if (isHookPathname(pathname)) {
|
|
214
|
-
return { screenData: screenDataContext, pathname };
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const screenData = screenDataContext;
|
|
218
|
-
|
|
219
|
-
return { screenData, pathname };
|
|
220
|
-
};
|
|
221
|
-
|
|
222
136
|
type Callbacks = Partial<{
|
|
223
137
|
handleHookPresent: ({
|
|
224
138
|
route,
|
|
@@ -342,34 +256,6 @@ export const useZappHooksForEntry = (
|
|
|
342
256
|
}, [entry.id]);
|
|
343
257
|
};
|
|
344
258
|
|
|
345
|
-
export enum MenuTypes {
|
|
346
|
-
drawer = "DRAWER",
|
|
347
|
-
bottomTabBar = "BOTTOM_TAB_BAR",
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
export const useNavigationPluginData = (): ZappNavigation | undefined => {
|
|
351
|
-
const {
|
|
352
|
-
screenData: useRouteScreenData,
|
|
353
|
-
}: { screenData: QuickBrickNavigationData | null } = useRoute();
|
|
354
|
-
|
|
355
|
-
const navigations = useRouteScreenData?.targetScreen
|
|
356
|
-
? (useRouteScreenData.targetScreen as ZappRiver).navigations
|
|
357
|
-
: (useRouteScreenData as ZappRiver).navigations;
|
|
358
|
-
|
|
359
|
-
const navigationMenu = navigations?.find((nav) => nav.category === "menu");
|
|
360
|
-
|
|
361
|
-
return navigationMenu;
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
export const useNavigationType = (): MenuTypes => {
|
|
365
|
-
const navigationMenu = useNavigationPluginData();
|
|
366
|
-
|
|
367
|
-
return !navigationMenu ||
|
|
368
|
-
navigationMenu.navigation_type === "quick_brick_side_menu"
|
|
369
|
-
? MenuTypes.drawer
|
|
370
|
-
: MenuTypes.bottomTabBar;
|
|
371
|
-
};
|
|
372
|
-
|
|
373
259
|
export const useProfilerLogging = () => {
|
|
374
260
|
const logTimestamp = (data: string) =>
|
|
375
261
|
InteractionManager.runAfterInteractions(() => {
|
|
@@ -414,81 +300,3 @@ export const useIsNavBarVisible = (): boolean => {
|
|
|
414
300
|
|
|
415
301
|
return useMemo(() => visible, [visible]);
|
|
416
302
|
};
|
|
417
|
-
|
|
418
|
-
const useGetNavBarTopBorderWidth = (): number => {
|
|
419
|
-
const navigator = useNavigation();
|
|
420
|
-
|
|
421
|
-
const navProps = getNavigationProps({
|
|
422
|
-
navigator,
|
|
423
|
-
title: "",
|
|
424
|
-
category: "menu",
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
|
|
428
|
-
};
|
|
429
|
-
|
|
430
|
-
const TAB_BAR_HEIGHT_IOS = 49;
|
|
431
|
-
const TAB_BAR_HEIGHT_ANDROID = 56;
|
|
432
|
-
|
|
433
|
-
const useGetTabBarHeight = () =>
|
|
434
|
-
platformSelect({
|
|
435
|
-
ios: TAB_BAR_HEIGHT_IOS + (useSafeAreaInsets().bottom ?? 0),
|
|
436
|
-
android: TAB_BAR_HEIGHT_ANDROID,
|
|
437
|
-
}) as number;
|
|
438
|
-
|
|
439
|
-
export const useGetBottomTabBarHeight = (): number => {
|
|
440
|
-
const topBorderWidth = useGetNavBarTopBorderWidth();
|
|
441
|
-
const tabBarHeight = useGetTabBarHeight();
|
|
442
|
-
|
|
443
|
-
const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
|
|
444
|
-
|
|
445
|
-
return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
// If current screen is active/focused (visible to the user)
|
|
449
|
-
export const useIsScreenActive = () => {
|
|
450
|
-
const pathname = usePathname();
|
|
451
|
-
const { currentRoute, videoModalState } = useNavigation();
|
|
452
|
-
|
|
453
|
-
if (
|
|
454
|
-
videoModalState.visible &&
|
|
455
|
-
["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
|
|
456
|
-
) {
|
|
457
|
-
return false;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
return pathname === currentRoute;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
type Return = (prefix: string) => string;
|
|
464
|
-
|
|
465
|
-
export const useUniqueRouteSuffix = (): Return => {
|
|
466
|
-
const pathname = usePathname();
|
|
467
|
-
const { currentRoute } = useNavigation();
|
|
468
|
-
|
|
469
|
-
const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
|
|
470
|
-
|
|
471
|
-
const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
|
|
472
|
-
if (isWeb()) {
|
|
473
|
-
// we should use extended route prefix only on Web, where we have stack-navigator
|
|
474
|
-
return `${prefix}___${suffix}`;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
// for other platforms use previous version
|
|
478
|
-
return prefix;
|
|
479
|
-
}, []);
|
|
480
|
-
|
|
481
|
-
return withUniqueRouteSuffix;
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
export const useNavbarId = () => {
|
|
485
|
-
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
486
|
-
|
|
487
|
-
return withUniqueRouteSuffix(QUICK_BRICK_NAVBAR);
|
|
488
|
-
};
|
|
489
|
-
|
|
490
|
-
export const useContentId = () => {
|
|
491
|
-
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
492
|
-
|
|
493
|
-
return withUniqueRouteSuffix(QUICK_BRICK_CONTENT);
|
|
494
|
-
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useGetNavBarTopBorderWidth } from "./useGetNavBarTopBorderWidth";
|
|
2
|
+
import { useGetTabBarHeight } from "./useGetTabBarHeight";
|
|
3
|
+
import { MenuTypes, useNavigationType } from "./useNavigationType";
|
|
4
|
+
|
|
5
|
+
export const useGetBottomTabBarHeight = (): number => {
|
|
6
|
+
const topBorderWidth = useGetNavBarTopBorderWidth();
|
|
7
|
+
const tabBarHeight = useGetTabBarHeight();
|
|
8
|
+
|
|
9
|
+
const isBottomBarNavigation = useNavigationType() === MenuTypes.bottomTabBar;
|
|
10
|
+
|
|
11
|
+
return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
|
|
12
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getNavigationProps } from "../../navigationUtils";
|
|
2
|
+
import { useNavigation } from "./useNavigation";
|
|
3
|
+
|
|
4
|
+
export const useGetNavBarTopBorderWidth = (): number => {
|
|
5
|
+
const navigator = useNavigation();
|
|
6
|
+
|
|
7
|
+
const navProps = getNavigationProps({
|
|
8
|
+
navigator,
|
|
9
|
+
title: "",
|
|
10
|
+
category: "menu",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
return Number(((navProps?.styles as any)?.top_border_width as number) ?? 0);
|
|
14
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
2
|
+
|
|
3
|
+
import { platformSelect } from "../../reactUtils";
|
|
4
|
+
|
|
5
|
+
const TAB_BAR_HEIGHT_IOS = 49;
|
|
6
|
+
const TAB_BAR_HEIGHT_ANDROID = 56;
|
|
7
|
+
|
|
8
|
+
export const useGetTabBarHeight = () =>
|
|
9
|
+
platformSelect({
|
|
10
|
+
ios: TAB_BAR_HEIGHT_IOS + (useSafeAreaInsets().bottom ?? 0),
|
|
11
|
+
android: TAB_BAR_HEIGHT_ANDROID,
|
|
12
|
+
}) as number;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useNavigation } from "./useNavigation";
|
|
2
|
+
import { usePathname } from "./usePathname";
|
|
3
|
+
|
|
4
|
+
// If current screen is active/focused (visible to the user)
|
|
5
|
+
export const useIsScreenActive = () => {
|
|
6
|
+
const pathname = usePathname();
|
|
7
|
+
const { currentRoute, videoModalState } = useNavigation();
|
|
8
|
+
|
|
9
|
+
if (
|
|
10
|
+
videoModalState.visible &&
|
|
11
|
+
["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
|
|
12
|
+
) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return pathname === currentRoute;
|
|
17
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useRoute } from "./useRoute";
|
|
2
|
+
|
|
3
|
+
export const useNavigationPluginData = (): ZappNavigation | undefined => {
|
|
4
|
+
const {
|
|
5
|
+
screenData: useRouteScreenData,
|
|
6
|
+
}: { screenData: QuickBrickNavigationData | null } = useRoute();
|
|
7
|
+
|
|
8
|
+
const navigations = useRouteScreenData?.targetScreen
|
|
9
|
+
? (useRouteScreenData.targetScreen as ZappRiver).navigations
|
|
10
|
+
: (useRouteScreenData as ZappRiver).navigations;
|
|
11
|
+
|
|
12
|
+
const navigationMenu = navigations?.find((nav) => nav.category === "menu");
|
|
13
|
+
|
|
14
|
+
return navigationMenu;
|
|
15
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useNavigationPluginData } from "./useNavigationPluginData";
|
|
2
|
+
|
|
3
|
+
export enum MenuTypes {
|
|
4
|
+
drawer = "DRAWER",
|
|
5
|
+
bottomTabBar = "BOTTOM_TAB_BAR",
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const useNavigationType = (): MenuTypes => {
|
|
9
|
+
const navigationMenu = useNavigationPluginData();
|
|
10
|
+
|
|
11
|
+
return !navigationMenu ||
|
|
12
|
+
navigationMenu.navigation_type === "quick_brick_side_menu"
|
|
13
|
+
? MenuTypes.drawer
|
|
14
|
+
: MenuTypes.bottomTabBar;
|
|
15
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
|
+
/* eslint max-len: off */
|
|
3
|
+
|
|
4
|
+
import { useContext } from "react";
|
|
5
|
+
|
|
6
|
+
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
7
|
+
|
|
8
|
+
import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
|
|
9
|
+
|
|
10
|
+
import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
|
|
11
|
+
|
|
12
|
+
import { getTargetScreenData } from "../screen/useTargetScreenData";
|
|
13
|
+
|
|
14
|
+
import { useNavigation } from "./useNavigation";
|
|
15
|
+
import { useModalStore } from "../../modalState";
|
|
16
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
17
|
+
import { usePathname } from "./usePathname";
|
|
18
|
+
|
|
19
|
+
// starts with modal/
|
|
20
|
+
const isModalPathname = (pathname: string) => /^modal\//.test(pathname);
|
|
21
|
+
|
|
22
|
+
const isVideoModalPathname = (pathname: string) =>
|
|
23
|
+
/^video-modal\//.test(pathname);
|
|
24
|
+
|
|
25
|
+
const isHookModalPathname = (pathname: string) =>
|
|
26
|
+
/^hooks-modal\//.test(pathname);
|
|
27
|
+
|
|
28
|
+
const isHookPathname = (pathname: string) => /^\/hooks\//.test(pathname);
|
|
29
|
+
|
|
30
|
+
type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
|
|
31
|
+
|
|
32
|
+
export const useRoute = (): {
|
|
33
|
+
screenData: VariousScreenData;
|
|
34
|
+
pathname: string;
|
|
35
|
+
} => {
|
|
36
|
+
const pathname = usePathname() || "";
|
|
37
|
+
const navigator = useNavigation();
|
|
38
|
+
|
|
39
|
+
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
40
|
+
|
|
41
|
+
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
42
|
+
"plugins",
|
|
43
|
+
"rivers",
|
|
44
|
+
"contentTypes",
|
|
45
|
+
]);
|
|
46
|
+
|
|
47
|
+
const { modalState } = useModalStore();
|
|
48
|
+
const hookModalState = useZappHooksModalState();
|
|
49
|
+
|
|
50
|
+
const modalScreenData = modalState.screen;
|
|
51
|
+
|
|
52
|
+
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
53
|
+
|
|
54
|
+
const videoModalScreenData =
|
|
55
|
+
navigator?.videoModalState?.item &&
|
|
56
|
+
legacyScreenData(
|
|
57
|
+
{
|
|
58
|
+
entry: navigator.videoModalState?.item as ZappEntry,
|
|
59
|
+
screen: getTargetScreenData(
|
|
60
|
+
navigator.videoModalState?.item as ZappEntry,
|
|
61
|
+
rivers,
|
|
62
|
+
contentTypes
|
|
63
|
+
),
|
|
64
|
+
},
|
|
65
|
+
plugins
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// There are 4 route scenarios
|
|
69
|
+
// For regular screens take date from navigator stack.
|
|
70
|
+
// is path is model grab screenData from modal state
|
|
71
|
+
// if path is video modal grab screenData from video state
|
|
72
|
+
// if path is hook modal grab screenData from hook state
|
|
73
|
+
// if path is hook grab screenData from screenData
|
|
74
|
+
|
|
75
|
+
if (isModalPathname(pathname)) {
|
|
76
|
+
const screenData = modalScreenData ?? ({} as ZappEntry);
|
|
77
|
+
|
|
78
|
+
return { screenData, pathname };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (isVideoModalPathname(pathname)) {
|
|
82
|
+
const screenData = videoModalScreenData as LegacyNavigationScreenData;
|
|
83
|
+
|
|
84
|
+
return { screenData, pathname };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (isHookModalPathname(pathname)) {
|
|
88
|
+
const screenData = hookModalScreenData;
|
|
89
|
+
|
|
90
|
+
return { screenData, pathname };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (isHookPathname(pathname)) {
|
|
94
|
+
return { screenData: screenDataContext, pathname };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const screenData = screenDataContext;
|
|
98
|
+
|
|
99
|
+
return { screenData, pathname };
|
|
100
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { isWeb } from "../../reactUtils";
|
|
3
|
+
import { useNavigation } from "./useNavigation";
|
|
4
|
+
import { usePathname } from "./usePathname";
|
|
5
|
+
import {
|
|
6
|
+
QUICK_BRICK_CONTENT,
|
|
7
|
+
QUICK_BRICK_NAVBAR,
|
|
8
|
+
} from "@applicaster/quick-brick-core/const";
|
|
9
|
+
|
|
10
|
+
type Return = (prefix: string) => string;
|
|
11
|
+
|
|
12
|
+
export const useUniqueRouteSuffix = (): Return => {
|
|
13
|
+
const pathname = usePathname();
|
|
14
|
+
const { currentRoute } = useNavigation();
|
|
15
|
+
|
|
16
|
+
const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
|
|
17
|
+
|
|
18
|
+
const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
|
|
19
|
+
if (isWeb()) {
|
|
20
|
+
// we should use extended route prefix only on Web, where we have stack-navigator
|
|
21
|
+
return `${prefix}___${suffix}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// for other platforms use previous version
|
|
25
|
+
return prefix;
|
|
26
|
+
}, []);
|
|
27
|
+
|
|
28
|
+
return withUniqueRouteSuffix;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const useNavbarId = () => {
|
|
32
|
+
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
33
|
+
|
|
34
|
+
return withUniqueRouteSuffix(QUICK_BRICK_NAVBAR);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const useContentId = () => {
|
|
38
|
+
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
39
|
+
|
|
40
|
+
return withUniqueRouteSuffix(QUICK_BRICK_CONTENT);
|
|
41
|
+
};
|
|
@@ -5,15 +5,14 @@ import { ON_HOLD_INTERVAL, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
|
|
|
5
5
|
|
|
6
6
|
import { useAutoSeek } from "../useAutoSeek";
|
|
7
7
|
|
|
8
|
-
jest.useFakeTimers();
|
|
8
|
+
jest.useFakeTimers({ legacyFakeTimers: true });
|
|
9
9
|
|
|
10
10
|
const rewind = jest.fn();
|
|
11
11
|
const forward = jest.fn();
|
|
12
12
|
|
|
13
13
|
jest
|
|
14
14
|
.spyOn(playerManager, "getInstanceController")
|
|
15
|
-
|
|
16
|
-
.mockImplementation(() => ({ rewind, forward }));
|
|
15
|
+
.mockReturnValue({ rewind, forward });
|
|
17
16
|
|
|
18
17
|
describe("useAutoSeek", () => {
|
|
19
18
|
beforeEach(() => {
|