@applicaster/zapp-react-native-utils 12.0.0-alpha.4337072244 → 12.0.0-alpha.4342066143
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/analyticsUtils/analyticsPlugins.ts +25 -0
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -3
- package/appUtils/focusManager/__tests__/focusManager.test.js +24 -4
- package/appUtils/focusManager/__tests__/index.test.ts +3 -3
- package/appUtils/focusManager/index.ts +56 -141
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +43 -73
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -1
- package/arrayUtils/index.ts +0 -5
- package/numberUtils/__tests__/isLikeNumber.test.ts +0 -18
- package/numberUtils/index.ts +18 -5
- package/package.json +2 -2
- package/reactHooks/cell-click/__tests__/index.test.js +7 -10
- package/reactHooks/cell-click/index.ts +12 -12
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +70 -30
- package/reactHooks/feed/useBuildPipesUrl.ts +10 -7
- package/reactHooks/navigation/__tests__/index.test.tsx +11 -8
- package/reactHooks/navigation/index.ts +21 -80
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +23 -21
- package/reactHooks/screen/index.ts +0 -2
- package/reactHooks/screen/useScreenContext.ts +3 -3
- package/appUtils/focusManager/utils/index.ts +0 -94
- package/arrayUtils/__tests__/isFilledArray.test.ts +0 -63
- package/reactHooks/screen/useScreenBackgroundColor.ts +0 -23
|
@@ -1,13 +1,12 @@
|
|
|
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 { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutorContext";
|
|
5
|
-
|
|
6
4
|
import { waitFor } from "@testing-library/react-native";
|
|
7
5
|
|
|
8
6
|
const navigator = {
|
|
9
7
|
getPathname: () => "pathnameMock",
|
|
10
8
|
push: jest.fn(),
|
|
9
|
+
data: {},
|
|
11
10
|
};
|
|
12
11
|
|
|
13
12
|
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation", () => ({
|
|
@@ -30,7 +29,11 @@ jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
|
30
29
|
},
|
|
31
30
|
}));
|
|
32
31
|
|
|
33
|
-
|
|
32
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
|
|
33
|
+
useScreenContext: jest.fn(() => navigator.data),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
const { useCellClick } = require("../");
|
|
34
37
|
|
|
35
38
|
const mockProps = {
|
|
36
39
|
item: {},
|
|
@@ -44,15 +47,9 @@ const mockProps = {
|
|
|
44
47
|
|
|
45
48
|
const onCellTap = jest.fn();
|
|
46
49
|
|
|
47
|
-
const actionExecutor = {
|
|
48
|
-
handleEntryActions: jest.fn(() => Promise.resolve()),
|
|
49
|
-
};
|
|
50
|
-
|
|
51
50
|
const wrapper = ({ children }) => (
|
|
52
51
|
<CellTapContext.Provider value={onCellTap}>
|
|
53
|
-
|
|
54
|
-
{children}
|
|
55
|
-
</ActionExecutorContext.Provider>
|
|
52
|
+
{children}
|
|
56
53
|
</CellTapContext.Provider>
|
|
57
54
|
);
|
|
58
55
|
|
|
@@ -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";
|
|
@@ -11,9 +12,8 @@ import {
|
|
|
11
12
|
} from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
12
13
|
import { ZappPipesEntryContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
13
14
|
import { toBooleanWithDefaultTrue } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
import { isFunction, noop } from "../../functionUtils";
|
|
15
|
+
import { noop } from "../../functionUtils";
|
|
16
|
+
import { ActionExecutorContext } from "../../actionsExecutor/ActionExecutorContext";
|
|
17
17
|
import { useSendAnalyticsOnPress } from "../analytics";
|
|
18
18
|
import { logOnPress, warnEmptyContentType } from "./helpers";
|
|
19
19
|
|
|
@@ -30,12 +30,12 @@ type Props = {
|
|
|
30
30
|
zappPipesData?: ZappPipesData;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export const useCellClick = (
|
|
33
|
+
export const useCellClick = (props: Props) => {
|
|
34
|
+
const { component, zappPipesData } = props;
|
|
34
35
|
const { push, currentRoute } = useNavigation();
|
|
35
36
|
const { pathname } = useRoute();
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const actionExecutor = React.useContext(ActionExecutorContext);
|
|
37
|
+
const onCellTap = React.useContext(CellTapContext);
|
|
38
|
+
const actionExecutor = useContext(ActionExecutorContext);
|
|
39
39
|
|
|
40
40
|
const cellSelectable = toBooleanWithDefaultTrue(
|
|
41
41
|
component?.rules?.component_cells_selectable
|
|
@@ -47,7 +47,7 @@ export const useCellClick = ({ component, zappPipesData, item }: Props) => {
|
|
|
47
47
|
const logTimestamp = useProfilerLogging();
|
|
48
48
|
|
|
49
49
|
const sendAnalyticsOnPress = useSendAnalyticsOnPress(
|
|
50
|
-
item,
|
|
50
|
+
props.item,
|
|
51
51
|
component,
|
|
52
52
|
zappPipesData
|
|
53
53
|
);
|
|
@@ -56,7 +56,7 @@ export const useCellClick = ({ component, zappPipesData, item }: Props) => {
|
|
|
56
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
|
-
const selectedItem = isZappEntry ? _item : item;
|
|
59
|
+
const selectedItem = isZappEntry ? _item : props.item;
|
|
60
60
|
setEntryContext?.(selectedItem);
|
|
61
61
|
|
|
62
62
|
if (!selectedItem?.type?.value) {
|
|
@@ -80,10 +80,10 @@ export const useCellClick = ({ component, zappPipesData, item }: Props) => {
|
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
} else {
|
|
83
|
-
if (
|
|
84
|
-
onCellTap
|
|
83
|
+
if (typeof onCellTap === "function") {
|
|
84
|
+
onCellTap(selectedItem, _index);
|
|
85
85
|
} else {
|
|
86
|
-
if (currentRoute === pathname || pathname
|
|
86
|
+
if (currentRoute === pathname || pathname.includes("video-modal")) {
|
|
87
87
|
const targetScreen = component?.data?.target;
|
|
88
88
|
|
|
89
89
|
push(
|
|
@@ -1,26 +1,77 @@
|
|
|
1
|
+
import React from "react";
|
|
1
2
|
import { renderHook } from "@testing-library/react-hooks";
|
|
3
|
+
import configureStore from "redux-mock-store";
|
|
4
|
+
import thunk from "redux-thunk";
|
|
5
|
+
import { Provider } from "react-redux";
|
|
6
|
+
|
|
2
7
|
import { encodeParams } from "@applicaster/zapp-pipes-v2-client/src/utils";
|
|
3
8
|
|
|
9
|
+
const mockStore = configureStore([thunk]);
|
|
10
|
+
|
|
11
|
+
jest.useFakeTimers();
|
|
12
|
+
|
|
4
13
|
const appData = {
|
|
5
14
|
platform: "foo",
|
|
6
15
|
version_name: "1.2.0",
|
|
7
16
|
sdk_version: "2.0.0",
|
|
8
17
|
};
|
|
9
18
|
|
|
10
|
-
|
|
19
|
+
const pipesEndpoints = {
|
|
20
|
+
"http://foo.com/show": {
|
|
21
|
+
context_obj: [
|
|
22
|
+
{ type: "ctx", key: "platform" },
|
|
23
|
+
{ type: "query", mapper: "version", key: "appVersion" },
|
|
24
|
+
{ type: "header", mapper: "SDK", key: "sdkVersion" },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const store_mock = { appData, pipesEndpoints };
|
|
30
|
+
|
|
31
|
+
const defaultStore = mockStore({
|
|
32
|
+
pipesEndpoints,
|
|
33
|
+
appData,
|
|
34
|
+
});
|
|
11
35
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
() => ({
|
|
15
|
-
useInflatedUrl: () => INFLATED_URL,
|
|
16
|
-
})
|
|
36
|
+
const wrapper: React.FC<any> = ({ children, store }) => (
|
|
37
|
+
<Provider store={store}>{children}</Provider>
|
|
17
38
|
);
|
|
18
39
|
|
|
40
|
+
const navigator = {
|
|
41
|
+
currentRoute: "/river/A1234",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
jest.mock("../../navigation", () => ({
|
|
45
|
+
useNavigation: jest.fn(() => navigator),
|
|
46
|
+
useRoute: jest.fn(() => ({})),
|
|
47
|
+
}));
|
|
48
|
+
|
|
49
|
+
const contexts = {
|
|
50
|
+
entry: { id: "show-1" },
|
|
51
|
+
search: {},
|
|
52
|
+
screen: {},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const contextMock = (type) => ({
|
|
56
|
+
useZappPipesContext: () => [contexts[type] || {}],
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
60
|
+
ZappPipesEntryContext: contextMock("entry"),
|
|
61
|
+
ZappPipesSearchContext: contextMock("search"),
|
|
62
|
+
ZappPipesScreenContext: contextMock("screen"),
|
|
63
|
+
}));
|
|
64
|
+
|
|
65
|
+
jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
|
|
66
|
+
appStore: {
|
|
67
|
+
get: jest.fn((prop) => store_mock[prop]),
|
|
68
|
+
},
|
|
69
|
+
}));
|
|
70
|
+
|
|
19
71
|
const { useBuildPipesUrl } = require("../useBuildPipesUrl");
|
|
20
72
|
|
|
21
73
|
describe("useBuildPipesUrl", () => {
|
|
22
74
|
it("returns the proper url", async () => {
|
|
23
|
-
INFLATED_URL = "http://foo.com/show/show-1";
|
|
24
75
|
const url = "http://foo.com/show/{{showId}}";
|
|
25
76
|
|
|
26
77
|
const mapping = {
|
|
@@ -30,20 +81,12 @@ describe("useBuildPipesUrl", () => {
|
|
|
30
81
|
},
|
|
31
82
|
};
|
|
32
83
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const mockedRequestBuilder = {
|
|
42
|
-
build: jest.fn(() => Promise.resolve(buildResult)),
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const { result, waitForNextUpdate } = renderHook(() =>
|
|
46
|
-
useBuildPipesUrl({ url, mapping, requestBuilder: mockedRequestBuilder })
|
|
84
|
+
const { result, waitForNextUpdate } = renderHook(
|
|
85
|
+
() => useBuildPipesUrl({ url, mapping }),
|
|
86
|
+
{
|
|
87
|
+
wrapper,
|
|
88
|
+
initialProps: { store: defaultStore },
|
|
89
|
+
}
|
|
47
90
|
);
|
|
48
91
|
|
|
49
92
|
expect(result.current.url).toBe("http://foo.com/show/show-1");
|
|
@@ -65,7 +108,6 @@ describe("useBuildPipesUrl", () => {
|
|
|
65
108
|
});
|
|
66
109
|
|
|
67
110
|
it("returns empty object if url is not in endpoints", async () => {
|
|
68
|
-
INFLATED_URL = "http://foobar.com/show-1";
|
|
69
111
|
const url = "http://foobar.com/{{showId}}";
|
|
70
112
|
|
|
71
113
|
const mapping = {
|
|
@@ -75,14 +117,12 @@ describe("useBuildPipesUrl", () => {
|
|
|
75
117
|
},
|
|
76
118
|
};
|
|
77
119
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const { result, waitForNextUpdate } = renderHook(() =>
|
|
85
|
-
useBuildPipesUrl({ url, mapping, requestBuilder: mockedRequestBuilder })
|
|
120
|
+
const { result, waitForNextUpdate } = renderHook(
|
|
121
|
+
() => useBuildPipesUrl({ url, mapping }),
|
|
122
|
+
{
|
|
123
|
+
wrapper,
|
|
124
|
+
initialProps: { store: defaultStore },
|
|
125
|
+
}
|
|
86
126
|
);
|
|
87
127
|
|
|
88
128
|
expect(result.current.url).toBe("http://foobar.com/show-1");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
// @ts-ignore
|
|
1
2
|
import { RequestBuilder } from "@applicaster/zapp-pipes-v2-client";
|
|
2
|
-
import
|
|
3
|
-
import { useInflatedUrl } from "
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { useInflatedUrl } from "./useInflatedUrl";
|
|
4
5
|
import { reactHooksLogger } from "../logger";
|
|
5
6
|
|
|
6
7
|
export const logger = reactHooksLogger.addSubsystem("build-pipes-url");
|
|
@@ -14,16 +15,18 @@ type PipesBuildRequestObject = {
|
|
|
14
15
|
export function useBuildPipesUrl({
|
|
15
16
|
url,
|
|
16
17
|
mapping = {},
|
|
17
|
-
requestBuilder = new RequestBuilder(),
|
|
18
18
|
}): PipesBuildRequestObject {
|
|
19
|
-
const [requestParams, setRequestParams] =
|
|
19
|
+
const [requestParams, setRequestParams] = useState<object | null>(null);
|
|
20
|
+
const [error, setError] = useState(null);
|
|
20
21
|
|
|
21
|
-
const [error, setError] = React.useState(null);
|
|
22
22
|
const inflatedUrl = useInflatedUrl({ feedUrl: url, mapping });
|
|
23
23
|
|
|
24
|
+
const requestBuilder = new RequestBuilder();
|
|
25
|
+
|
|
24
26
|
const buildRequest = async (_url) => {
|
|
25
27
|
try {
|
|
26
28
|
const result = await requestBuilder.build(_url);
|
|
29
|
+
|
|
27
30
|
setRequestParams(result);
|
|
28
31
|
} catch (e) {
|
|
29
32
|
setError(e);
|
|
@@ -31,7 +34,7 @@ export function useBuildPipesUrl({
|
|
|
31
34
|
}
|
|
32
35
|
};
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
useEffect(() => {
|
|
35
38
|
if (inflatedUrl && !requestParams) {
|
|
36
39
|
buildRequest(inflatedUrl);
|
|
37
40
|
}
|
|
@@ -39,7 +42,7 @@ export function useBuildPipesUrl({
|
|
|
39
42
|
|
|
40
43
|
return {
|
|
41
44
|
url: inflatedUrl || "",
|
|
42
|
-
requestParams, // TODO should it be: || {} ?
|
|
45
|
+
requestParams: requestParams, // TODO should it be: || {} ?
|
|
43
46
|
error: error || undefined,
|
|
44
47
|
};
|
|
45
48
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
|
|
3
3
|
import { renderHook } from "@testing-library/react-hooks";
|
|
4
|
-
import {
|
|
4
|
+
import { isNavBarVisible, useRoute } from "../";
|
|
5
5
|
import { Provider } from "react-redux";
|
|
6
6
|
import configureMockStore from "redux-mock-store";
|
|
7
7
|
import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
|
|
8
8
|
import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
9
9
|
import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
|
|
10
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
10
11
|
|
|
11
12
|
const plugins = [];
|
|
12
13
|
|
|
@@ -100,13 +101,15 @@ const mainStackWrapper = ({
|
|
|
100
101
|
pathname = homeStack.route,
|
|
101
102
|
}) => (
|
|
102
103
|
<Provider store={store}>
|
|
103
|
-
<
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
{
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
<ScreenDataContext.Provider value={homeStack.state}>
|
|
105
|
+
<NavigationContext.Provider
|
|
106
|
+
value={{ ...mainStackNavigator, ...navigator, currentRoute: pathname }}
|
|
107
|
+
>
|
|
108
|
+
<PathnameContext.Provider value={pathname}>
|
|
109
|
+
{children}
|
|
110
|
+
</PathnameContext.Provider>
|
|
111
|
+
</NavigationContext.Provider>
|
|
112
|
+
</ScreenDataContext.Provider>
|
|
110
113
|
</Provider>
|
|
111
114
|
);
|
|
112
115
|
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
2
|
/* eslint max-len: off */
|
|
3
3
|
|
|
4
|
-
import React, { useEffect, useMemo } from "react";
|
|
4
|
+
import React, { useContext, useEffect, useMemo } from "react";
|
|
5
5
|
import { BackHandler, InteractionManager, NativeModules } from "react-native";
|
|
6
6
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
7
|
+
import { isEmpty } from "ramda";
|
|
7
8
|
|
|
8
9
|
import {
|
|
9
10
|
useContentTypes,
|
|
@@ -31,6 +32,7 @@ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
|
31
32
|
import { useNavbarState } from "../screen";
|
|
32
33
|
import { useNavigation } from "./useNavigation";
|
|
33
34
|
import { useModalStore } from "../../modalState";
|
|
35
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
34
36
|
|
|
35
37
|
export { useNavigation } from "./useNavigation";
|
|
36
38
|
|
|
@@ -146,16 +148,8 @@ export const useRoute = (): {
|
|
|
146
148
|
pathname: string;
|
|
147
149
|
} => {
|
|
148
150
|
const pathname = usePathname() || "";
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* compose `useRoute()` output data
|
|
152
|
-
*/
|
|
153
|
-
const composeRouteData = (screenData: VariousScreenData) => ({
|
|
154
|
-
screenData,
|
|
155
|
-
pathname,
|
|
156
|
-
});
|
|
157
|
-
|
|
158
151
|
const navigator = useNavigation();
|
|
152
|
+
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
159
153
|
|
|
160
154
|
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
161
155
|
"plugins",
|
|
@@ -163,10 +157,11 @@ export const useRoute = (): {
|
|
|
163
157
|
"contentTypes",
|
|
164
158
|
]);
|
|
165
159
|
|
|
166
|
-
const currentStack = navigator.getStackForPathname(pathname);
|
|
167
160
|
const { modalState } = useModalStore();
|
|
168
161
|
const hookModalState = useZappHooksModalState();
|
|
162
|
+
|
|
169
163
|
const modalScreenData = modalState.screen;
|
|
164
|
+
|
|
170
165
|
const hookModalScreenData = hookModalState.state.screenData?.payload;
|
|
171
166
|
|
|
172
167
|
const videoModalScreenData =
|
|
@@ -183,15 +178,6 @@ export const useRoute = (): {
|
|
|
183
178
|
plugins
|
|
184
179
|
);
|
|
185
180
|
|
|
186
|
-
const currentRouteScreenData = legacyScreenData(
|
|
187
|
-
{
|
|
188
|
-
screen: currentStack?.state?.screen ?? navigator.data?.screen ?? {},
|
|
189
|
-
entry: currentStack?.state?.entry ?? {},
|
|
190
|
-
} as NavigationScreenData,
|
|
191
|
-
|
|
192
|
-
plugins
|
|
193
|
-
);
|
|
194
|
-
|
|
195
181
|
// There are 4 route scenarios
|
|
196
182
|
// For regular screens take date from navigator stack.
|
|
197
183
|
// is path is model grab screenData from modal state
|
|
@@ -200,63 +186,33 @@ export const useRoute = (): {
|
|
|
200
186
|
// if path is hook grab screenData from screenData
|
|
201
187
|
|
|
202
188
|
if (isModalPathname(pathname)) {
|
|
203
|
-
|
|
189
|
+
const screenData = modalScreenData ?? ({} as ZappEntry);
|
|
190
|
+
|
|
191
|
+
return { screenData, pathname };
|
|
204
192
|
}
|
|
205
193
|
|
|
206
194
|
if (isVideoModalPathname(pathname)) {
|
|
207
|
-
|
|
195
|
+
const screenData = videoModalScreenData as LegacyNavigationScreenData;
|
|
196
|
+
|
|
197
|
+
return { screenData, pathname };
|
|
208
198
|
}
|
|
209
199
|
|
|
210
200
|
if (isHookModalPathname(pathname)) {
|
|
211
|
-
|
|
201
|
+
const screenData = hookModalScreenData;
|
|
202
|
+
|
|
203
|
+
return { screenData, pathname };
|
|
212
204
|
}
|
|
213
205
|
|
|
214
206
|
if (isHookPathname(pathname)) {
|
|
215
|
-
|
|
216
|
-
* HACK
|
|
217
|
-
*
|
|
218
|
-
* This condition relies on hacky approach to get the current hook screen data
|
|
219
|
-
* using navigator.screenData for some cases.
|
|
220
|
-
* This is used when hook is in sequence.
|
|
221
|
-
*/
|
|
222
|
-
|
|
223
|
-
// case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
|
|
224
|
-
if (!currentStack) {
|
|
225
|
-
return composeRouteData(navigator.screenData);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
const isValidHookInCurrentRouteScreenData =
|
|
229
|
-
"hookPlugin" in currentRouteScreenData &&
|
|
230
|
-
!!currentRouteScreenData.hookPlugin?.module;
|
|
231
|
-
|
|
232
|
-
let screenData;
|
|
233
|
-
|
|
234
|
-
// case 2: stack has valid hook data
|
|
235
|
-
if (isValidHookInCurrentRouteScreenData) {
|
|
236
|
-
screenData = currentRouteScreenData;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const navigatorScreenData = navigator.screenData as NavigatorEntry;
|
|
240
|
-
|
|
241
|
-
// case 3: current hookPlugin is missing weight, but navigator.screenData has weight, use navigator.screenData
|
|
242
|
-
if (
|
|
243
|
-
screenData.hookPlugin.identifier ===
|
|
244
|
-
navigatorScreenData?.hookPlugin?.identifier &&
|
|
245
|
-
!screenData.hookPlugin?.weight &&
|
|
246
|
-
navigatorScreenData?.hookPlugin?.weight
|
|
247
|
-
) {
|
|
248
|
-
screenData = navigator.screenData;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return composeRouteData(screenData);
|
|
207
|
+
return { screenData: screenDataContext, pathname };
|
|
252
208
|
}
|
|
253
209
|
|
|
254
|
-
//
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
210
|
+
// Cover cases where screenContext is used before navigation is initialized
|
|
211
|
+
const screenData = isEmpty(screenDataContext)
|
|
212
|
+
? navigator.screenData
|
|
213
|
+
: screenDataContext;
|
|
258
214
|
|
|
259
|
-
return
|
|
215
|
+
return { screenData, pathname };
|
|
260
216
|
};
|
|
261
217
|
|
|
262
218
|
type Callbacks = Partial<{
|
|
@@ -496,18 +452,3 @@ export const useIsScreenActive = () => {
|
|
|
496
452
|
|
|
497
453
|
return pathname === currentRoute;
|
|
498
454
|
};
|
|
499
|
-
|
|
500
|
-
type Return = (prefix: string) => string;
|
|
501
|
-
|
|
502
|
-
export const useUniqueRouteSuffix = (): Return => {
|
|
503
|
-
const pathname = usePathname();
|
|
504
|
-
const { currentRoute } = useNavigation();
|
|
505
|
-
|
|
506
|
-
const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
|
|
507
|
-
|
|
508
|
-
const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
|
|
509
|
-
return `${prefix}___${suffix}`;
|
|
510
|
-
}, []);
|
|
511
|
-
|
|
512
|
-
return withUniqueRouteSuffix;
|
|
513
|
-
};
|
|
@@ -3,28 +3,23 @@ import { Provider } from "react-redux";
|
|
|
3
3
|
import { renderHook } from "@testing-library/react-hooks";
|
|
4
4
|
import configureStore from "redux-mock-store";
|
|
5
5
|
import thunk from "redux-thunk";
|
|
6
|
+
import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
|
|
6
7
|
|
|
7
8
|
const mockStore = configureStore([thunk]);
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}),
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
|
-
const { useCurrentScreenData } = require("../useCurrentScreenData");
|
|
26
|
-
|
|
27
|
-
describe("useScreenData", () => {
|
|
10
|
+
import { useCurrentScreenData } from "../useCurrentScreenData";
|
|
11
|
+
|
|
12
|
+
describe("useScreenData", function () {
|
|
13
|
+
const river_id_2: ZappRiver = {
|
|
14
|
+
name: "River 2",
|
|
15
|
+
id: "A1234",
|
|
16
|
+
home: false,
|
|
17
|
+
home_offline: false,
|
|
18
|
+
supports_offline: false,
|
|
19
|
+
navigations: [],
|
|
20
|
+
hooks: { preload_plugins: [] },
|
|
21
|
+
};
|
|
22
|
+
|
|
28
23
|
const river_id_1 = { id: "B5678" };
|
|
29
24
|
|
|
30
25
|
const store = mockStore({
|
|
@@ -32,10 +27,17 @@ describe("useScreenData", () => {
|
|
|
32
27
|
});
|
|
33
28
|
|
|
34
29
|
const wrapper: React.FC<any> = ({ children }) => (
|
|
35
|
-
<Provider
|
|
30
|
+
<NavigationContext.Provider
|
|
31
|
+
value={{
|
|
32
|
+
currentRoute: "/river/river_id_1/river/river_id_2",
|
|
33
|
+
data: { screen: river_id_2 },
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<Provider store={store}>{children}</Provider>
|
|
37
|
+
</NavigationContext.Provider>
|
|
36
38
|
);
|
|
37
39
|
|
|
38
|
-
it("should return river data for the current screen/route", ()
|
|
40
|
+
it("should return river data for the current screen/route", function () {
|
|
39
41
|
const { result } = renderHook(() => useCurrentScreenData(), { wrapper });
|
|
40
42
|
|
|
41
43
|
expect(result.current).toBe(river_id_2);
|
|
@@ -5,7 +5,7 @@ import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-co
|
|
|
5
5
|
import { useNavigation } from "../navigation/useNavigation";
|
|
6
6
|
|
|
7
7
|
import { ScreenContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext";
|
|
8
|
-
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/
|
|
8
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
9
9
|
|
|
10
10
|
export function useScreenContextV2() {
|
|
11
11
|
return useContext(ScreenContext);
|
|
@@ -45,8 +45,8 @@ export function useSetNavbarState() {
|
|
|
45
45
|
|
|
46
46
|
export function useScreenContext(): NavigationScreenData {
|
|
47
47
|
const navigator = useNavigation();
|
|
48
|
-
|
|
49
|
-
const screenData = useContext(ScreenDataContext);
|
|
48
|
+
// Cover cases where screenContext is used before navigation is initialized
|
|
49
|
+
const screenData = useContext(ScreenDataContext) || navigator.data;
|
|
50
50
|
|
|
51
51
|
const modalScreenData = navigator?.modalData;
|
|
52
52
|
|