@applicaster/zapp-react-native-utils 14.0.0-alpha.4111088201 → 14.0.0-alpha.4138342511
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 +60 -84
- package/actionsExecutor/ScreenActions.ts +164 -0
- package/actionsExecutor/StorageActions.ts +110 -0
- package/actionsExecutor/feedDecorator.ts +171 -0
- package/actionsExecutor/screenResolver.ts +11 -0
- package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
- package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
- package/analyticsUtils/__tests__/analyticsUtils.test.js +3 -0
- package/analyticsUtils/events.ts +8 -0
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/index.ts +5 -5
- package/appUtils/contextKeysManager/contextResolver.ts +42 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -0
- package/appUtils/focusManager/index.ios.ts +10 -0
- package/appUtils/focusManager/index.ts +11 -0
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/appUtils/focusManagerAux/utils/index.ts +18 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +0 -15
- package/appUtils/playerManager/useChapterMarker.tsx +0 -1
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
- package/arrayUtils/index.ts +1 -1
- package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
- package/componentsUtils/index.ts +4 -1
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
- package/configurationUtils/manifestKeyParser.ts +57 -32
- package/focusManager/FocusManager.ts +26 -16
- package/focusManager/Tree.ts +25 -21
- package/focusManager/__tests__/FocusManager.test.ts +50 -8
- package/index.d.ts +0 -9
- package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +6 -4
- package/package.json +2 -3
- package/playerUtils/getPlayerActionButtons.ts +1 -1
- package/playerUtils/index.ts +51 -0
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +3 -1
- package/reactHooks/cell-click/__tests__/index.test.js +3 -0
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/debugging/__tests__/index.test.js +0 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +36 -15
- package/reactHooks/feed/index.ts +2 -0
- package/reactHooks/feed/useBatchLoading.ts +16 -9
- package/reactHooks/feed/useFeedLoader.tsx +36 -34
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +57 -0
- package/reactHooks/feed/usePipesCacheReset.ts +3 -3
- package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
- package/reactHooks/layout/__tests__/index.test.tsx +3 -1
- package/reactHooks/layout/isTablet/index.ts +12 -5
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
- package/reactHooks/layout/useLayoutVersion.ts +5 -5
- package/reactHooks/navigation/index.ts +7 -5
- package/reactHooks/navigation/useIsScreenActive.ts +9 -5
- package/reactHooks/navigation/useRoute.ts +7 -2
- package/reactHooks/navigation/useScreenStateStore.ts +8 -0
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
- package/reactHooks/screen/useScreenContext.ts +1 -1
- package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
- package/reactHooks/state/useRivers.ts +7 -8
- package/riverComponetsMeasurementProvider/index.tsx +1 -1
- package/services/js2native.ts +1 -0
- package/storage/ScreenSingleValueProvider.ts +204 -0
- package/storage/ScreenStateMultiSelectProvider.ts +293 -0
- package/storage/StorageMultiSelectProvider.ts +192 -0
- package/storage/StorageSingleSelectProvider.ts +108 -0
- package/time/BackgroundTimer.ts +6 -4
- package/utils/index.ts +6 -0
|
@@ -4,13 +4,11 @@ import * as zappPipesModule from "@applicaster/zapp-react-native-redux/ZappPipes
|
|
|
4
4
|
import * as reactReduxModules from "react-redux";
|
|
5
5
|
import { Provider } from "react-redux";
|
|
6
6
|
import * as React from "react";
|
|
7
|
-
import configureStore from "redux-mock-store";
|
|
8
|
-
import thunk from "redux-thunk";
|
|
9
7
|
import * as useRouteHook from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useRoute";
|
|
10
8
|
import * as useNavigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
|
|
11
9
|
import { useFeedLoader } from "../useFeedLoader";
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
import { WrappedWithProviders } from "../../../testUtils";
|
|
11
|
+
import { ScreenStateResolver } from "../../../appUtils/contextKeysManager/contextResolver";
|
|
14
12
|
|
|
15
13
|
jest.useFakeTimers({ legacyFakeTimers: true });
|
|
16
14
|
|
|
@@ -55,13 +53,15 @@ const mockZappPipesData = {
|
|
|
55
53
|
|
|
56
54
|
describe("useFeedLoader", () => {
|
|
57
55
|
describe("with cached feed url", () => {
|
|
58
|
-
const store =
|
|
56
|
+
const store = {
|
|
59
57
|
plugins: [],
|
|
60
58
|
zappPipes: { "test://testfakeurl": mockZappPipesData },
|
|
61
|
-
}
|
|
59
|
+
};
|
|
62
60
|
|
|
63
|
-
const wrapper: React.FC<any> = ({ children }) => (
|
|
64
|
-
<
|
|
61
|
+
const wrapper: React.FC<any> = ({ children, ...props }) => (
|
|
62
|
+
<WrappedWithProviders store={props.store || store}>
|
|
63
|
+
{children}
|
|
64
|
+
</WrappedWithProviders>
|
|
65
65
|
);
|
|
66
66
|
|
|
67
67
|
it("returns cached feed", () => {
|
|
@@ -110,8 +110,10 @@ describe("useFeedLoader", () => {
|
|
|
110
110
|
describe("without cached feeds", () => {
|
|
111
111
|
const feedUrl = "test://testfakeurl2";
|
|
112
112
|
|
|
113
|
-
const wrapper: React.FC<any> = ({ children,
|
|
114
|
-
<
|
|
113
|
+
const wrapper: React.FC<any> = ({ children, ...props }) => (
|
|
114
|
+
<WrappedWithProviders store={props.store}>
|
|
115
|
+
{children}
|
|
116
|
+
</WrappedWithProviders>
|
|
115
117
|
);
|
|
116
118
|
|
|
117
119
|
it("It loads data for new url and returns it", () => {
|
|
@@ -123,10 +125,10 @@ describe("useFeedLoader", () => {
|
|
|
123
125
|
.spyOn(zappPipesModule, "loadPipesData")
|
|
124
126
|
.mockImplementation(jest.fn());
|
|
125
127
|
|
|
126
|
-
const initialStore =
|
|
128
|
+
const initialStore = {
|
|
127
129
|
plugins: [],
|
|
128
130
|
zappPipes: { "test://testfakeurl": "foobar" },
|
|
129
|
-
}
|
|
131
|
+
};
|
|
130
132
|
|
|
131
133
|
const { result, rerender } = renderHook(
|
|
132
134
|
() => useFeedLoader({ feedUrl: "test://testfakeurl2" }),
|
|
@@ -135,15 +137,19 @@ describe("useFeedLoader", () => {
|
|
|
135
137
|
|
|
136
138
|
expect(result.current.data).toBeNull();
|
|
137
139
|
|
|
138
|
-
expect(loadPipesDataSpy).
|
|
140
|
+
expect(loadPipesDataSpy).toHaveBeenCalledWith(feedUrl, {
|
|
139
141
|
clearCache: true,
|
|
140
142
|
riverId: undefined,
|
|
143
|
+
callback: expect.any(Function),
|
|
144
|
+
resolvers: {
|
|
145
|
+
screen: expect.any(ScreenStateResolver),
|
|
146
|
+
},
|
|
141
147
|
});
|
|
142
148
|
|
|
143
|
-
const store2 =
|
|
149
|
+
const store2 = {
|
|
144
150
|
plugins: [],
|
|
145
151
|
zappPipes: { "test://testfakeurl2": mockZappPipesData },
|
|
146
|
-
}
|
|
152
|
+
};
|
|
147
153
|
|
|
148
154
|
rerender({ store: store2 });
|
|
149
155
|
|
|
@@ -179,6 +185,11 @@ describe("useFeedLoader", () => {
|
|
|
179
185
|
expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
|
|
180
186
|
clearCache: true,
|
|
181
187
|
riverId: undefined,
|
|
188
|
+
resolvers: {
|
|
189
|
+
screen: {
|
|
190
|
+
screenStateStore: undefined,
|
|
191
|
+
},
|
|
192
|
+
},
|
|
182
193
|
});
|
|
183
194
|
|
|
184
195
|
const store2 = mockStore({
|
|
@@ -228,6 +239,11 @@ describe("useFeedLoader", () => {
|
|
|
228
239
|
expect(loadPipesDataSpy).toBeCalledWith(feedUrl, {
|
|
229
240
|
clearCache: true,
|
|
230
241
|
silentRefresh: true,
|
|
242
|
+
resolvers: {
|
|
243
|
+
screen: {
|
|
244
|
+
screenStateStore: undefined,
|
|
245
|
+
},
|
|
246
|
+
},
|
|
231
247
|
});
|
|
232
248
|
|
|
233
249
|
loadPipesDataSpy.mockRestore();
|
|
@@ -267,6 +283,11 @@ describe("useFeedLoader", () => {
|
|
|
267
283
|
expect(loadPipesDataSpy).toBeCalledWith(nextUrl, {
|
|
268
284
|
parentFeed: feedUrlWithNext,
|
|
269
285
|
silentRefresh: true,
|
|
286
|
+
resolvers: {
|
|
287
|
+
screen: {
|
|
288
|
+
screenStateStore: undefined,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
270
291
|
});
|
|
271
292
|
|
|
272
293
|
loadPipesDataSpy.mockRestore();
|
package/reactHooks/feed/index.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { complement, compose, isNil, map, min, prop, take, uniq } from "ramda";
|
|
2
|
-
import { useDispatch } from "react-redux";
|
|
3
2
|
import * as React from "react";
|
|
4
|
-
import {
|
|
5
|
-
import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
3
|
+
import { useZappPipesFeed } from "@applicaster/zapp-react-native-redux";
|
|
6
4
|
import { isNilOrEmpty } from "../../reactUtils/helpers";
|
|
7
5
|
import { ZappPipesSearchContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
8
6
|
import {
|
|
9
7
|
getInflatedDataSourceUrl,
|
|
10
8
|
getSearchContext,
|
|
9
|
+
useLoadPipesDataDispatch,
|
|
11
10
|
} from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
12
11
|
import { isGallery } from "@applicaster/zapp-react-native-utils/componentsUtils";
|
|
13
|
-
import { useScreenContext } from "../screen
|
|
12
|
+
import { useScreenContext } from "../screen";
|
|
14
13
|
|
|
15
14
|
type Options = {
|
|
16
15
|
initialBatchSize?: number;
|
|
@@ -63,7 +62,6 @@ export const useBatchLoading = (
|
|
|
63
62
|
componentsToRender: { data?: ZappDataSource; component_type: string }[],
|
|
64
63
|
options: Options
|
|
65
64
|
) => {
|
|
66
|
-
const dispatch = useDispatch();
|
|
67
65
|
const { screen: screenContext, entry: entryContext } = useScreenContext();
|
|
68
66
|
const [searchContext] = ZappPipesSearchContext.useZappPipesContext();
|
|
69
67
|
const [hasEverBeenReady, setHasEverBeenReady] = React.useState(false);
|
|
@@ -118,7 +116,9 @@ export const useBatchLoading = (
|
|
|
118
116
|
[]
|
|
119
117
|
);
|
|
120
118
|
|
|
121
|
-
const feeds =
|
|
119
|
+
const feeds = useZappPipesFeed(feedUrls);
|
|
120
|
+
|
|
121
|
+
const loadPipesDataDispatcher = useLoadPipesDataDispatch();
|
|
122
122
|
|
|
123
123
|
// dispatch loadPipesData for each feed that is not loaded
|
|
124
124
|
const runBatchLoading = React.useCallback(() => {
|
|
@@ -138,13 +138,20 @@ export const useBatchLoading = (
|
|
|
138
138
|
|
|
139
139
|
if (mappedFeedUrl) {
|
|
140
140
|
// 4. load data
|
|
141
|
-
return
|
|
142
|
-
|
|
141
|
+
return loadPipesDataDispatcher(
|
|
142
|
+
mappedFeedUrl,
|
|
143
|
+
{
|
|
144
|
+
riverId: options.riverId,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
withResolvers: true,
|
|
148
|
+
withScreenRouteMapping: true,
|
|
149
|
+
}
|
|
143
150
|
);
|
|
144
151
|
}
|
|
145
152
|
}
|
|
146
153
|
});
|
|
147
|
-
}, [feedUrls, feeds]);
|
|
154
|
+
}, [feedUrls, feeds, loadPipesDataDispatcher]);
|
|
148
155
|
|
|
149
156
|
React.useEffect(() => {
|
|
150
157
|
runBatchLoading();
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import React, { useEffect } from "react";
|
|
2
|
-
import { useDispatch } from "react-redux";
|
|
3
2
|
|
|
4
|
-
import {
|
|
5
|
-
import { useZappPipesFeed } from "@applicaster/zapp-react-native-redux/hooks";
|
|
3
|
+
import { useZappPipesFeed } from "@applicaster/zapp-react-native-redux";
|
|
6
4
|
|
|
7
5
|
import { reactHooksLogger } from "../logger";
|
|
8
6
|
import { shouldDispatchData, useIsInitialRender } from "../utils";
|
|
9
7
|
import { useInflatedUrl } from "./useInflatedUrl";
|
|
10
|
-
import {
|
|
8
|
+
import { useLoadPipesDataDispatch } from "./useLoadPipesDataDispatch";
|
|
11
9
|
|
|
12
10
|
const logger = reactHooksLogger.addSubsystem("useFeedLoader");
|
|
13
11
|
|
|
@@ -49,29 +47,26 @@ export const useFeedLoader = ({
|
|
|
49
47
|
}, []);
|
|
50
48
|
|
|
51
49
|
const isInitialRender = useIsInitialRender();
|
|
52
|
-
const dispatch = useDispatch();
|
|
53
|
-
const { screenData } = useRoute();
|
|
54
50
|
|
|
55
51
|
const callableFeedUrl = useInflatedUrl({ feedUrl, mapping });
|
|
56
52
|
|
|
57
53
|
const currentFeed = useZappPipesFeed(callableFeedUrl);
|
|
58
54
|
|
|
59
|
-
const
|
|
60
|
-
(screenData as LegacyNavigationScreenData)?.targetScreen?.id ??
|
|
61
|
-
screenData?.id;
|
|
55
|
+
const loadPipesDataDispatcher = useLoadPipesDataDispatch();
|
|
62
56
|
|
|
63
57
|
const reloadData = React.useCallback<ReloadDataFunction>(
|
|
64
58
|
(silentRefresh = true, callback) => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
loadPipesDataDispatcher(
|
|
60
|
+
callableFeedUrl,
|
|
61
|
+
{
|
|
62
|
+
clearCache: true,
|
|
63
|
+
silentRefresh,
|
|
64
|
+
callback,
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
withResolvers: true,
|
|
68
|
+
}
|
|
69
|
+
);
|
|
75
70
|
},
|
|
76
71
|
[callableFeedUrl]
|
|
77
72
|
);
|
|
@@ -80,15 +75,16 @@ export const useFeedLoader = ({
|
|
|
80
75
|
if (callableFeedUrl) {
|
|
81
76
|
const nextFeed = currentFeed?.data?.next;
|
|
82
77
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
loadPipesDataDispatcher(
|
|
79
|
+
nextFeed,
|
|
80
|
+
{
|
|
81
|
+
silentRefresh: true,
|
|
82
|
+
parentFeed: callableFeedUrl,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
withResolvers: true,
|
|
86
|
+
}
|
|
87
|
+
);
|
|
92
88
|
}
|
|
93
89
|
}, [callableFeedUrl, currentFeed?.data?.next]);
|
|
94
90
|
|
|
@@ -97,12 +93,16 @@ export const useFeedLoader = ({
|
|
|
97
93
|
shouldDispatchData(callableFeedUrl, currentFeed, pipesOptions.clearCache)
|
|
98
94
|
) {
|
|
99
95
|
if (callableFeedUrl && !pipesOptions.skipLoading) {
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
loadPipesDataDispatcher(
|
|
97
|
+
callableFeedUrl,
|
|
98
|
+
{
|
|
102
99
|
...pipesOptions,
|
|
103
100
|
clearCache: true,
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
withResolvers: true,
|
|
104
|
+
withScreenRouteMapping: true,
|
|
105
|
+
}
|
|
106
106
|
);
|
|
107
107
|
} else if (!callableFeedUrl) {
|
|
108
108
|
logger.info({
|
|
@@ -131,9 +131,11 @@ export const useFeedLoader = ({
|
|
|
131
131
|
// Reload feed when feedUrl changes, unless skipLoading is true
|
|
132
132
|
useEffect(() => {
|
|
133
133
|
if (!isInitialRender && callableFeedUrl && !pipesOptions.skipLoading) {
|
|
134
|
-
|
|
134
|
+
loadPipesDataDispatcher(callableFeedUrl, pipesOptions, {
|
|
135
|
+
withResolvers: true,
|
|
136
|
+
});
|
|
135
137
|
}
|
|
136
|
-
}, [callableFeedUrl]);
|
|
138
|
+
}, [callableFeedUrl, isInitialRender, pipesOptions.skipLoading]);
|
|
137
139
|
|
|
138
140
|
return React.useMemo(() => {
|
|
139
141
|
if (!callableFeedUrl || !feedUrl) {
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAppDispatch,
|
|
3
|
+
ZappPipes,
|
|
4
|
+
} from "@applicaster/zapp-react-native-redux";
|
|
5
|
+
import { applyScreenRouteDefaults } from "@applicaster/zapp-react-native-redux/ZappPipes/feedProcessor";
|
|
6
|
+
import React from "react";
|
|
7
|
+
import { useScreenResolvers } from "../../actionsExecutor/screenResolver";
|
|
8
|
+
import { useRoute } from "../navigation";
|
|
9
|
+
import { useScreenStateStore } from "../navigation/useScreenStateStore";
|
|
10
|
+
|
|
11
|
+
export const useLoadPipesDataDispatch = () => {
|
|
12
|
+
const screenStateStore = useScreenStateStore();
|
|
13
|
+
const resolvers = useScreenResolvers();
|
|
14
|
+
const dispatch = useAppDispatch();
|
|
15
|
+
|
|
16
|
+
const { pathname, screenData } = useRoute();
|
|
17
|
+
|
|
18
|
+
const riverId =
|
|
19
|
+
(screenData as LegacyNavigationScreenData)?.targetScreen?.id ??
|
|
20
|
+
screenData?.id;
|
|
21
|
+
|
|
22
|
+
const onLoadCB = (options) => (data, _err) => {
|
|
23
|
+
options?.callback?.();
|
|
24
|
+
|
|
25
|
+
if (data) {
|
|
26
|
+
applyScreenRouteDefaults(data, screenStateStore, pathname);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return React.useCallback(
|
|
31
|
+
(
|
|
32
|
+
url: string,
|
|
33
|
+
options = {},
|
|
34
|
+
{
|
|
35
|
+
withResolvers = false,
|
|
36
|
+
withScreenRouteMapping = false,
|
|
37
|
+
}: {
|
|
38
|
+
withResolvers?: boolean;
|
|
39
|
+
withScreenRouteMapping?: boolean;
|
|
40
|
+
} = {}
|
|
41
|
+
) => {
|
|
42
|
+
if (url) {
|
|
43
|
+
dispatch(
|
|
44
|
+
ZappPipes.loadPipesData(url, {
|
|
45
|
+
riverId,
|
|
46
|
+
resolvers: withResolvers ? resolvers : undefined,
|
|
47
|
+
...options,
|
|
48
|
+
callback: withScreenRouteMapping
|
|
49
|
+
? onLoadCB(options)
|
|
50
|
+
: options?.callback,
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
[]
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { useDispatch } from "react-redux";
|
|
3
2
|
|
|
4
3
|
import { getDatasourceUrl } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/getDatasourceUrl";
|
|
5
4
|
import { usePipesContexts } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/usePipesContexts";
|
|
6
5
|
import { clearPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
7
6
|
|
|
8
|
-
import { useRoute } from "../navigation
|
|
7
|
+
import { useRoute } from "../navigation";
|
|
8
|
+
import { useAppDispatch } from "@applicaster/zapp-react-native-redux";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* reset river components cache when screen is unmounted
|
|
@@ -13,7 +13,7 @@ import { useRoute } from "../navigation/useRoute";
|
|
|
13
13
|
* @param {Array} riverComponents list of UI components
|
|
14
14
|
*/
|
|
15
15
|
export const usePipesCacheReset = (riverId, riverComponents) => {
|
|
16
|
-
const dispatch =
|
|
16
|
+
const dispatch = useAppDispatch();
|
|
17
17
|
const { screenData, pathname } = useRoute();
|
|
18
18
|
const pipesContexts = usePipesContexts(riverId, pathname);
|
|
19
19
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
|
-
import { View } from "react-native";
|
|
3
|
+
import { View, ViewStyle } from "react-native";
|
|
4
4
|
|
|
5
5
|
import { platformSelect } from "../../reactUtils";
|
|
6
6
|
|
|
@@ -49,13 +49,13 @@ export const useSequentialRenderItem = (data: Data) => {
|
|
|
49
49
|
const readyToDisplay =
|
|
50
50
|
index === 0 ? true : arePreviousComponentsReady(index);
|
|
51
51
|
|
|
52
|
-
const displayStyle = {
|
|
52
|
+
const displayStyle: ViewStyle = {
|
|
53
53
|
display: readyToDisplay ? "flex" : "none",
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
const readyStyle = {
|
|
57
57
|
visibility: readyToDisplay ? "visible" : "hidden",
|
|
58
|
-
};
|
|
58
|
+
} as ViewStyle;
|
|
59
59
|
|
|
60
60
|
const style = platformSelect({
|
|
61
61
|
tvos: readyStyle,
|
|
@@ -42,15 +42,17 @@ jest.mock("react-native-safe-area-context", () => ({
|
|
|
42
42
|
}));
|
|
43
43
|
|
|
44
44
|
jest.mock("../../../reactUtils", () => ({
|
|
45
|
+
...jest.requireActual("../../../reactUtils"),
|
|
45
46
|
platformSelect: jest.fn((specs) => specs[platform] || specs.default),
|
|
46
47
|
isTV: jest.fn(() => mock_tv_flag),
|
|
47
48
|
}));
|
|
48
49
|
|
|
49
50
|
jest.mock("../../navigation", () => ({
|
|
50
|
-
useNavigation: () => null,
|
|
51
51
|
useIsScreenActive: () => true,
|
|
52
52
|
}));
|
|
53
53
|
|
|
54
|
+
jest.mock("../../navigation/useNavigation");
|
|
55
|
+
|
|
54
56
|
const { Dimensions } = require("react-native");
|
|
55
57
|
const { useDimensions } = require("..");
|
|
56
58
|
|
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
import { NativeModules, Platform } from "react-native";
|
|
2
2
|
|
|
3
|
+
export const isAndroidTablet = () => {
|
|
4
|
+
const { initialProps } = NativeModules.QuickBrickCommunicationModule;
|
|
5
|
+
|
|
6
|
+
return initialProps?.is_tablet;
|
|
7
|
+
};
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* Determines wether the given device is a tablet based on dimensions, orientation, and platform
|
|
5
11
|
* @param {Object} dimensions - Dimensions object passed to the function
|
|
6
12
|
* @param {String} orientation - Orientation enum passed to the function
|
|
7
13
|
* @returns {Boolean} isTablet - returns whether the given device is a tablet
|
|
8
14
|
*/
|
|
9
|
-
export const isTablet = (
|
|
15
|
+
export const isTablet = (
|
|
16
|
+
dimensions?: { width: number; height: number },
|
|
17
|
+
orientation?: string
|
|
18
|
+
) => {
|
|
10
19
|
if (Platform?.OS === "ios") {
|
|
11
20
|
return Platform?.isPad;
|
|
12
21
|
} else if (Platform?.OS === "android") {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return initialProps?.is_tablet;
|
|
22
|
+
return isAndroidTablet();
|
|
16
23
|
}
|
|
17
24
|
|
|
18
|
-
const { width } = dimensions;
|
|
25
|
+
const { width } = dimensions || {};
|
|
19
26
|
|
|
20
27
|
if (width < 600) return false;
|
|
21
28
|
if (width >= 600 && width < 840) return orientation === "portrait";
|
|
@@ -1,46 +1,48 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react-hooks";
|
|
2
2
|
import { Dimensions, StatusBar } from "react-native";
|
|
3
|
+
import { useDimensions } from "../useDimensions";
|
|
4
|
+
import { usePickFromState } from "@applicaster/zapp-react-native-redux";
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
const mockUseIsScreenActive = jest.fn();
|
|
6
|
-
const mockGetInitialDimensions = jest.fn();
|
|
7
|
-
const mockGetDeviceInfo = jest.fn();
|
|
6
|
+
import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive";
|
|
8
7
|
|
|
9
|
-
jest.mock("@applicaster/zapp-react-native-redux/hooks", () =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
useIsScreenActive: mockUseIsScreenActive,
|
|
16
|
-
}));
|
|
8
|
+
jest.mock("@applicaster/zapp-react-native-redux/hooks", () => {
|
|
9
|
+
return {
|
|
10
|
+
...jest.requireActual("@applicaster/zapp-react-native-redux/hooks"),
|
|
11
|
+
usePickFromState: jest.fn(),
|
|
12
|
+
};
|
|
13
|
+
});
|
|
17
14
|
|
|
18
|
-
jest.mock(
|
|
19
|
-
|
|
15
|
+
jest.mock(
|
|
16
|
+
"@applicaster/zapp-react-native-utils/reactHooks/navigation/useIsScreenActive",
|
|
17
|
+
() => ({
|
|
18
|
+
useIsScreenActive: jest.fn().mockReturnValue(true),
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
jest.doMock("../helpers", () => ({
|
|
23
|
+
getInitialDimensions: jest
|
|
24
|
+
.fn()
|
|
25
|
+
.mockReturnValue({ width: 100, height: 200, scale: 1, fontScale: 1 }),
|
|
20
26
|
}));
|
|
21
27
|
|
|
22
28
|
jest.mock("../../getDeviceInfo", () => ({
|
|
23
|
-
getDeviceInfo:
|
|
29
|
+
getDeviceInfo: jest.fn().mockReturnValue({ deviceInfo: "testDeviceInfo" }),
|
|
24
30
|
}));
|
|
25
31
|
|
|
26
|
-
const {
|
|
32
|
+
const mockDimensions = { width: 100, height: 200, scale: 1, fontScale: 1 };
|
|
33
|
+
|
|
34
|
+
Dimensions.get = jest.fn().mockReturnValue(mockDimensions);
|
|
35
|
+
|
|
36
|
+
Dimensions.addEventListener = jest.fn().mockReturnValue({
|
|
37
|
+
remove: jest.fn(),
|
|
38
|
+
});
|
|
27
39
|
|
|
28
40
|
describe("useDimensions", () => {
|
|
29
|
-
const mockDimensions = { width: 100, height: 200, scale: 1, fontScale: 1 };
|
|
30
41
|
const mockAppData = { someData: "test" };
|
|
31
42
|
|
|
32
43
|
beforeEach(() => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
Dimensions.addEventListener = jest.fn().mockReturnValue({
|
|
37
|
-
remove: jest.fn(),
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
mockUsePickFromState.mockReturnValue({ appData: mockAppData });
|
|
41
|
-
mockUseIsScreenActive.mockReturnValue(true);
|
|
42
|
-
mockGetInitialDimensions.mockReturnValue(mockDimensions);
|
|
43
|
-
mockGetDeviceInfo.mockReturnValue({ deviceInfo: "testDeviceInfo" });
|
|
44
|
+
StatusBar.currentHeight = 20;
|
|
45
|
+
(usePickFromState as jest.Mock).mockReturnValue({ appData: mockAppData });
|
|
44
46
|
});
|
|
45
47
|
|
|
46
48
|
it("returns correct initial dimensions", () => {
|
|
@@ -48,12 +50,9 @@ describe("useDimensions", () => {
|
|
|
48
50
|
useDimensions("window", { fullDimensions: false })
|
|
49
51
|
);
|
|
50
52
|
|
|
51
|
-
expect(result.current).
|
|
52
|
-
...mockDimensions,
|
|
53
|
+
expect(result.current).toMatchObject({
|
|
53
54
|
statusBarHeight: StatusBar.currentHeight,
|
|
54
55
|
});
|
|
55
|
-
|
|
56
|
-
expect(mockGetInitialDimensions).toHaveBeenCalledWith("window");
|
|
57
56
|
});
|
|
58
57
|
|
|
59
58
|
it("calls handler on mount", () => {
|
|
@@ -70,7 +69,7 @@ describe("useDimensions", () => {
|
|
|
70
69
|
useDimensions("window", { fullDimensions: false })
|
|
71
70
|
);
|
|
72
71
|
|
|
73
|
-
|
|
72
|
+
(useIsScreenActive as jest.Mock).mockReturnValue(false);
|
|
74
73
|
rerender();
|
|
75
74
|
|
|
76
75
|
expect(Dimensions.addEventListener).toHaveBeenCalledWith(
|
|
@@ -84,8 +83,7 @@ describe("useDimensions", () => {
|
|
|
84
83
|
useDimensions("window", { fullDimensions: true })
|
|
85
84
|
);
|
|
86
85
|
|
|
87
|
-
expect(result.current).
|
|
88
|
-
...mockDimensions,
|
|
86
|
+
expect(result.current).toMatchObject({
|
|
89
87
|
scale: 1,
|
|
90
88
|
fontScale: 1,
|
|
91
89
|
statusBarHeight: StatusBar.currentHeight,
|
|
@@ -98,7 +96,7 @@ describe("useDimensions", () => {
|
|
|
98
96
|
);
|
|
99
97
|
|
|
100
98
|
expect(result.current.height).toBe(
|
|
101
|
-
mockDimensions.height - StatusBar
|
|
99
|
+
mockDimensions.height - (StatusBar?.currentHeight ?? 0)
|
|
102
100
|
);
|
|
103
101
|
});
|
|
104
102
|
|
|
@@ -10,7 +10,7 @@ import { isTV } from "../../../reactUtils";
|
|
|
10
10
|
import { Options, UseDimensions } from "../types";
|
|
11
11
|
import { getDeviceInfo } from "../getDeviceInfo";
|
|
12
12
|
import { getInitialDimensions } from "./helpers";
|
|
13
|
-
import { useIsScreenActive } from "../../navigation";
|
|
13
|
+
import { useIsScreenActive } from "../../navigation/useIsScreenActive";
|
|
14
14
|
|
|
15
15
|
function compensateForScaleIfNeeded(context) {
|
|
16
16
|
return function () {
|
|
@@ -24,8 +24,6 @@ const applyScaleToDimensions = R.unless(R.propEq("scale", 1), (dimensions) => ({
|
|
|
24
24
|
scale: 1,
|
|
25
25
|
}));
|
|
26
26
|
|
|
27
|
-
const statusBarHeight = StatusBar?.currentHeight;
|
|
28
|
-
|
|
29
27
|
/**
|
|
30
28
|
* Returns React-native Dimensions object and updates it on any dimension change
|
|
31
29
|
* @param {('screen'|'window')} [context=window] - Dimensions context passed to Dimensions.get method
|
|
@@ -37,6 +35,7 @@ export const useDimensions: UseDimensions = (
|
|
|
37
35
|
context = "window",
|
|
38
36
|
fullDimensions = { fullDimensions: false, updateForInactiveScreens: true }
|
|
39
37
|
) => {
|
|
38
|
+
const statusBarHeight = StatusBar?.currentHeight;
|
|
40
39
|
const isActive = useIsScreenActive();
|
|
41
40
|
const { appData } = usePickFromState(["appData"]);
|
|
42
41
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable no-redeclare */
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
useAppSelector,
|
|
4
|
+
selectLayoutVersion,
|
|
5
|
+
} from "@applicaster/zapp-react-native-redux";
|
|
4
6
|
|
|
5
7
|
export function useLayoutVersion(): ZappLayoutVersions;
|
|
6
8
|
|
|
@@ -23,9 +25,7 @@ export function useLayoutVersion({
|
|
|
23
25
|
isV2?: boolean;
|
|
24
26
|
isV1?: boolean;
|
|
25
27
|
} = {}): boolean | ZappLayoutVersions {
|
|
26
|
-
const layoutVersion =
|
|
27
|
-
R.path(["appData", "layoutVersion"])
|
|
28
|
-
);
|
|
28
|
+
const layoutVersion = useAppSelector(selectLayoutVersion);
|
|
29
29
|
|
|
30
30
|
if (isV2) {
|
|
31
31
|
return layoutVersion === "v2";
|
|
@@ -14,7 +14,7 @@ import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
|
|
|
14
14
|
import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
|
|
15
15
|
import { useConnectionInfo } from "../connection";
|
|
16
16
|
|
|
17
|
-
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
17
|
+
import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
18
18
|
import { useNavbarState } from "../screen";
|
|
19
19
|
|
|
20
20
|
export { useNavigation } from "./useNavigation";
|
|
@@ -127,11 +127,13 @@ export function isNavBarVisible(
|
|
|
127
127
|
|
|
128
128
|
export const useBackHandler = (cb: () => boolean) => {
|
|
129
129
|
useEffect(() => {
|
|
130
|
-
|
|
130
|
+
if (!isWeb()) {
|
|
131
|
+
const unsubscribe = BackHandler.addEventListener("hardwareBackPress", cb);
|
|
131
132
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
return () => {
|
|
134
|
+
unsubscribe.remove();
|
|
135
|
+
};
|
|
136
|
+
}
|
|
135
137
|
}, [cb]);
|
|
136
138
|
};
|
|
137
139
|
|