@applicaster/zapp-react-native-utils 12.0.0-alpha.5350212300 → 12.0.0-alpha.5400461972

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.
@@ -1,7 +1,7 @@
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
7
 
@@ -31,6 +31,7 @@ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
31
31
  import { useNavbarState } from "../screen";
32
32
  import { useNavigation } from "./useNavigation";
33
33
  import { useModalStore } from "../../modalState";
34
+ import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
34
35
 
35
36
  export { useNavigation } from "./useNavigation";
36
37
 
@@ -146,16 +147,8 @@ export const useRoute = (): {
146
147
  pathname: string;
147
148
  } => {
148
149
  const pathname = usePathname() || "";
149
-
150
- /**
151
- * compose `useRoute()` output data
152
- */
153
- const composeRouteData = (screenData: VariousScreenData) => ({
154
- screenData,
155
- pathname,
156
- });
157
-
158
150
  const navigator = useNavigation();
151
+ const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
159
152
 
160
153
  const { plugins, contentTypes, rivers } = usePickFromState([
161
154
  "plugins",
@@ -163,10 +156,11 @@ export const useRoute = (): {
163
156
  "contentTypes",
164
157
  ]);
165
158
 
166
- const currentStack = navigator.getStackForPathname(pathname);
167
159
  const { modalState } = useModalStore();
168
160
  const hookModalState = useZappHooksModalState();
161
+
169
162
  const modalScreenData = modalState.screen;
163
+
170
164
  const hookModalScreenData = hookModalState.state.screenData?.payload;
171
165
 
172
166
  const videoModalScreenData =
@@ -183,15 +177,6 @@ export const useRoute = (): {
183
177
  plugins
184
178
  );
185
179
 
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
180
  // There are 4 route scenarios
196
181
  // For regular screens take date from navigator stack.
197
182
  // is path is model grab screenData from modal state
@@ -200,63 +185,30 @@ export const useRoute = (): {
200
185
  // if path is hook grab screenData from screenData
201
186
 
202
187
  if (isModalPathname(pathname)) {
203
- return composeRouteData(modalScreenData ?? ({} as ZappEntry));
188
+ const screenData = modalScreenData ?? ({} as ZappEntry);
189
+
190
+ return { screenData, pathname };
204
191
  }
205
192
 
206
193
  if (isVideoModalPathname(pathname)) {
207
- return composeRouteData(videoModalScreenData as LegacyNavigationScreenData);
194
+ const screenData = videoModalScreenData as LegacyNavigationScreenData;
195
+
196
+ return { screenData, pathname };
208
197
  }
209
198
 
210
199
  if (isHookModalPathname(pathname)) {
211
- return composeRouteData(hookModalScreenData);
200
+ const screenData = hookModalScreenData;
201
+
202
+ return { screenData, pathname };
212
203
  }
213
204
 
214
205
  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);
206
+ return { screenData: screenDataContext, pathname };
252
207
  }
253
208
 
254
- // case 1: stack not yet updated in navigator context, but navigator.screenData is updated already.
255
- if (!currentStack) {
256
- return composeRouteData(navigator.screenData);
257
- }
209
+ const screenData = screenDataContext;
258
210
 
259
- return composeRouteData(currentRouteScreenData);
211
+ return { screenData, pathname };
260
212
  };
261
213
 
262
214
  type Callbacks = Partial<{
@@ -496,18 +448,3 @@ export const useIsScreenActive = () => {
496
448
 
497
449
  return pathname === currentRoute;
498
450
  };
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
- };
@@ -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/Components/Layout/TV";
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
 
@@ -7,7 +7,7 @@ export const isAnyNil = R.any(R.isNil);
7
7
 
8
8
  export const isNilOrEmpty = R.either(R.isNil, R.isEmpty);
9
9
 
10
- export const isNotEmpty = R.both(isNotNil, R.complement(R.isEmpty));
10
+ export const isNotEmpty = R.complement(R.isEmpty);
11
11
 
12
12
  export const withoutNil = R.reject(R.isNil);
13
13
 
package/types.ts CHANGED
@@ -5,3 +5,7 @@ export type ManifestField<T> = {
5
5
  group?: boolean;
6
6
  fields?: ManifestField<any>[];
7
7
  };
8
+
9
+ export enum ENDPOINT_TAGS {
10
+ allow_missing_keys = "allow_missing_keys",
11
+ }
@@ -1,65 +0,0 @@
1
- import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
2
- import { find, last, startsWith } from "ramda";
3
-
4
- // run check each 300 ms
5
- // run this check too often could lead to performance penalty on low-end devices
6
- const HOW_OFTEN_TO_CHECK_CONDITION = 300; //ms
7
-
8
- type Props = {
9
- maxTimeout: number;
10
- conditionFn: () => boolean;
11
- };
12
-
13
- export const waitUntil = ({ maxTimeout, conditionFn }: Props) => {
14
- let interval;
15
- return new Promise((resolve, reject) => {
16
- interval = setInterval(() => {
17
- if (conditionFn()) {
18
- clearInterval(interval);
19
- resolve(undefined);
20
- }
21
- }, HOW_OFTEN_TO_CHECK_CONDITION);
22
-
23
- setTimeout(() => {
24
- reject();
25
- }, maxTimeout);
26
- });
27
- };
28
-
29
- export const waitForActiveScreen = (currentRoute: string, focusableTree) => {
30
- const isActiveScreenAvailableToFocus = (): boolean => {
31
- const routes = focusableTree.root.children;
32
-
33
- const route = find((route) => route.id === currentRoute, routes);
34
- return isNotNil(route);
35
- };
36
-
37
- return waitUntil({
38
- maxTimeout: 2500, //ms
39
- conditionFn: isActiveScreenAvailableToFocus,
40
- });
41
- };
42
-
43
- export const getActiveScreen = (focusableTree) => {
44
- return last(focusableTree.root.children);
45
- };
46
-
47
- export const getContentNode = (focusableTree) => {
48
- const content = find(
49
- (child) => startsWith("content", child.id),
50
- getActiveScreen(focusableTree)?.children
51
- );
52
-
53
- return content;
54
- };
55
-
56
- export const waitForContent = (focusableTree) => {
57
- const contentHasAnyChildren = (): boolean => {
58
- return getContentNode(focusableTree)?.children.length > 0;
59
- };
60
-
61
- return waitUntil({
62
- maxTimeout: 2500, //ms
63
- conditionFn: contentHasAnyChildren,
64
- });
65
- };