@applicaster/zapp-react-native-utils 13.0.0-alpha.6179233127 → 13.0.0-alpha.6234681660

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,6 +1,6 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
3
- import React, { createContext, useMemo } from "react";
3
+ import React, { createContext, useEffect, useMemo } from "react";
4
4
  import {
5
5
  actionExecutor as _actionExecutor,
6
6
  ActionResult,
@@ -19,8 +19,15 @@ import {
19
19
  EntryResolver,
20
20
  resolveObjectValues,
21
21
  } from "../appUtils/contextKeysManager/contextResolver";
22
+ import { useNavigation } from "../reactHooks";
23
+ import { get } from "lodash";
22
24
 
23
- const { log_error, log_info } = createLogger({
25
+ import {
26
+ useContentTypes,
27
+ usePickFromState,
28
+ } from "@applicaster/zapp-react-native-redux/hooks";
29
+
30
+ export const { log_error, log_info, log_debug } = createLogger({
24
31
  subsystem: "ActionExecutorContext",
25
32
  category: "General",
26
33
  });
@@ -51,6 +58,22 @@ type Props = {
51
58
  children: React.ReactNode;
52
59
  };
53
60
 
61
+ function findParentComponent(
62
+ childId: string,
63
+ parent: ZappRiver | ZappUIComponent
64
+ ): ZappRiver | ZappUIComponent | null {
65
+ for (const child of parent.ui_components) {
66
+ if (child.id === childId) return parent;
67
+
68
+ if (child.ui_components) {
69
+ const found = findParentComponent(childId, child);
70
+ if (found) return found;
71
+ }
72
+ }
73
+
74
+ return null;
75
+ }
76
+
54
77
  const prepareDefaultActions = (actionExecutor) => {
55
78
  actionExecutor.registerAction("localStorageSet", async (action) => {
56
79
  const namespaces = action.options.content;
@@ -65,11 +88,13 @@ const prepareDefaultActions = (actionExecutor) => {
65
88
  async (_action, context) => {
66
89
  const dispatch = appStore.getDispatch();
67
90
 
68
- log_info("handleAction: refreshComponent event");
91
+ const dataSource =
92
+ context?.component?.data?.source ||
93
+ findParentComponent(context?.component.id, context?.screenData)?.data
94
+ ?.source;
69
95
 
70
- const dataSource = context?.component?.data?.source;
96
+ log_info(`handleAction: refreshComponent for dataSource:${dataSource}`);
71
97
 
72
- // TODO: Later we can pass component ids to do refresh instead of current one
73
98
  // TODO: In theory we should wait callback to complete, before completing the action, but now it's not needed
74
99
  // TODO: handle focused item removal
75
100
  dispatch(
@@ -169,8 +194,29 @@ const prepareDefaultActions = (actionExecutor) => {
169
194
  action: ActionType,
170
195
  context?: Record<string, any>
171
196
  ): Promise<ActionResult> => {
197
+ if (!context) {
198
+ log_error(
199
+ "handleAction: localStorageToggleFlag action missing context"
200
+ );
201
+
202
+ return ActionResult.Error;
203
+ }
204
+
205
+ const entry = context?.entry as ZappEntry;
206
+
207
+ if (!entry) {
208
+ log_error(
209
+ "handleAction: localStorageToggleFlag action missing entry. Entry is required to get the tag."
210
+ );
211
+
212
+ return ActionResult.Error;
213
+ }
214
+
215
+ const tag = action.options?.selector
216
+ ? get(entry, action.options.selector)
217
+ : (entry.extensions?.tag ?? entry.id);
218
+
172
219
  const keyNamespace = action.options?.key;
173
- const tag = context?.entry?.extensions?.tag;
174
220
 
175
221
  if (keyNamespace && tag) {
176
222
  const multiSelectProvider =
@@ -211,6 +257,10 @@ export function withActionExecutor(Component) {
211
257
  prepareDefaultActions(_actionExecutor);
212
258
 
213
259
  return function ActionExecutorComponent(props: Props) {
260
+ const navigator = useNavigation();
261
+ const { rivers } = usePickFromState(["rivers"]);
262
+ const contentTypes = useContentTypes();
263
+
214
264
  const handlers = useMemo(() => {
215
265
  return {
216
266
  unregisterAction: _actionExecutor.unregisterAction,
@@ -221,6 +271,43 @@ export function withActionExecutor(Component) {
221
271
  };
222
272
  }, []);
223
273
 
274
+ useEffect(() => {
275
+ return _actionExecutor.registerAction(
276
+ "navigateToScreen",
277
+ async (action: ActionType, _context?: Record<string, any>) => {
278
+ const screenType = action.options?.typeMapping;
279
+
280
+ if (!screenType) {
281
+ log_error("navigateToScreen: typeMapping option is missing");
282
+
283
+ return ActionResult.Error;
284
+ }
285
+
286
+ const screenId = contentTypes?.[screenType]?.screen_id || null;
287
+
288
+ if (!screenId) {
289
+ log_error(
290
+ `navigateToScreen: can not resolve screen type mapping: ${screenType}`
291
+ );
292
+
293
+ return ActionResult.Error;
294
+ }
295
+
296
+ const river = rivers[screenId];
297
+
298
+ if (!river) {
299
+ log_error("navigateToScreen: can not resolve river");
300
+
301
+ return ActionResult.Error;
302
+ }
303
+
304
+ navigator.replace(river);
305
+
306
+ return ActionResult.Success;
307
+ }
308
+ );
309
+ }, [navigator, rivers, contentTypes]);
310
+
224
311
  return (
225
312
  <ActionExecutorContext.Provider value={handlers}>
226
313
  <Component {...props} />
@@ -1,12 +1,6 @@
1
- import { createLogger } from "../../logger";
2
1
  import { ContextKeysManager } from "./index";
3
2
  import * as R from "ramda";
4
3
 
5
- const { log_error } = createLogger({
6
- subsystem: "contextResolver",
7
- category: "General",
8
- });
9
-
10
4
  interface IResolver {
11
5
  resolve: (string) => Promise<string | number | object>;
12
6
  }
@@ -64,12 +58,7 @@ export const resolveObjectValues = async (
64
58
  return [key, resolvedValue];
65
59
  }
66
60
 
67
- log_error("resolveObjectValues: invalid context string", {
68
- key,
69
- value,
70
- });
71
-
72
- return [key, null];
61
+ return [key, value];
73
62
  })
74
63
  );
75
64
 
@@ -97,7 +97,7 @@ export class Player {
97
97
  this.onVideoLoad = this.onVideoLoad.bind(this);
98
98
  this.isFullScreenSupported = this.isFullScreenSupported.bind(this);
99
99
  this.onPlayerSeekComplete = this.onPlayerSeekComplete.bind(this);
100
-
100
+ this.onAdBreakEnd = this.onAdBreakEnd.bind(this);
101
101
  this.entryObservable = null;
102
102
  }
103
103
 
@@ -201,17 +201,25 @@ export class Player {
201
201
  adPosition: currentTime,
202
202
  };
203
203
  } else {
204
- if (!isEmptyOrNil(seekableDuration) && seekableDuration >= 0) {
205
- this.playerState.seekableDuration = seekableDuration;
206
- }
204
+ this.updateContentDuration({ seekableDuration, duration, currentTime });
205
+ }
206
+ };
207
207
 
208
- if (!isEmptyOrNil(duration) && duration >= 0) {
209
- this.playerState.contentDuration = duration;
210
- }
208
+ protected updateContentDuration = ({
209
+ seekableDuration = null,
210
+ duration = null,
211
+ currentTime = null,
212
+ }) => {
213
+ if (!isEmptyOrNil(seekableDuration) && seekableDuration >= 0) {
214
+ this.playerState.seekableDuration = seekableDuration;
215
+ }
211
216
 
212
- if (!isEmptyOrNil(currentTime) && currentTime >= 0) {
213
- this.playerState.contentPosition = currentTime;
214
- }
217
+ if (!isEmptyOrNil(duration) && duration >= 0) {
218
+ this.playerState.contentDuration = duration;
219
+ }
220
+
221
+ if (!isEmptyOrNil(currentTime) && currentTime >= 0) {
222
+ this.playerState.contentPosition = currentTime;
215
223
  }
216
224
  };
217
225
 
@@ -559,7 +567,7 @@ export class Player {
559
567
  });
560
568
  };
561
569
 
562
- onAdBreakEnd = (event) => {
570
+ onAdBreakEnd(event) {
563
571
  this.playerState.adState = null;
564
572
  this.playerState.isInAdBreak = false;
565
573
 
@@ -567,7 +575,7 @@ export class Player {
567
575
  callbackName: SharedPlayerCallBacksKeys.OnAdBreakEnd,
568
576
  event,
569
577
  });
570
- };
578
+ }
571
579
 
572
580
  onAdEnd = (event) => {
573
581
  this.playerState.adState = null;
@@ -225,7 +225,9 @@ export class PlayerNative extends Player {
225
225
  };
226
226
 
227
227
  onVideoLoad = (event) => {
228
- if (this.startPosition) {
228
+ this.updateContentDuration(event);
229
+
230
+ if (this.startPosition && !this.playerState.isInAdBreak) {
229
231
  super.onVideoLoad({ ...event, ignoreContinueWatching: true });
230
232
 
231
233
  this.seekTo(this.startPosition);
@@ -253,6 +255,15 @@ export class PlayerNative extends Player {
253
255
  }
254
256
  };
255
257
 
258
+ onAdBreakEnd = (event) => {
259
+ super.onAdBreakEnd(event);
260
+
261
+ if (this.startPosition) {
262
+ this.seekTo(this.startPosition);
263
+ this.startPosition = null;
264
+ }
265
+ };
266
+
256
267
  // This function is called when native player used directly without wrapped component,
257
268
  // Since event from native comes with wrapped in NativeEvent property
258
269
  getNativeViewListener = (): QuickBrickPlayer.SharedPlayerCallBacks => {
@@ -117,17 +117,25 @@ export const useIsFocusable = (props: Props): void => {
117
117
  isNilOrEmpty(zappPipesData?.data) ||
118
118
  isNilOrEmpty(zappPipesData?.data?.entry);
119
119
 
120
+ const hasNoUIComponents = isNilOrEmpty(component?.ui_components);
121
+
120
122
  const hasDataError = !!zappPipesData?.error;
121
123
 
122
124
  const hasEmptyGroup = shouldShowEmptyGroup(component);
123
125
 
124
126
  const isGallery = component?.component_type === "gallery-qb";
125
127
 
128
+ const isGroup = component?.component_type === "group-qb";
129
+
126
130
  const isHiddenDueToEmptyData =
127
131
  !isLoadingData && hasNoData && hideIfDataEmpty && !hasEmptyGroup;
128
132
 
133
+ const isEmptyGroup = isGroup && hasNoUIComponents;
134
+
129
135
  const defaultFocusableLogic =
130
- componentCellsFocusable && (!hasNoData || !hideIfDataEmpty);
136
+ componentCellsFocusable &&
137
+ (!hasNoData || !hideIfDataEmpty) &&
138
+ !isEmptyGroup;
131
139
 
132
140
  React.useEffect(() => {
133
141
  if (isAndroidTVPlatform()) {
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "13.0.0-alpha.6179233127",
3
+ "version": "13.0.0-alpha.6234681660",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
8
- "test": "jest -w=2",
9
8
  "build": "echo skipping hybrid ts build in main packages for now"
10
9
  },
11
10
  "publishConfig": {
@@ -28,7 +27,7 @@
28
27
  },
29
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
29
  "dependencies": {
31
- "@applicaster/applicaster-types": "13.0.0-alpha.6179233127",
30
+ "@applicaster/applicaster-types": "13.0.0-alpha.6234681660",
32
31
  "buffer": "^5.2.1",
33
32
  "camelize": "^1.0.0",
34
33
  "dayjs": "^1.11.10",
@@ -5,7 +5,7 @@ import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
5
5
  import { useZappPipesFeed } from "@applicaster/zapp-react-native-redux/hooks";
6
6
 
7
7
  import { reactHooksLogger } from "../logger";
8
- import { useIsInitialRender, shouldDispatchData } from "../utils";
8
+ import { shouldDispatchData, useIsInitialRender } from "../utils";
9
9
  import { useInflatedUrl } from "./useInflatedUrl";
10
10
  import { useRoute } from "../navigation";
11
11
 
@@ -55,7 +55,9 @@ export const useFeedLoader = ({
55
55
 
56
56
  const currentFeed = useZappPipesFeed(callableFeedUrl);
57
57
 
58
- const riverId = screenData?.id;
58
+ const riverId =
59
+ (screenData as LegacyNavigationScreenData)?.targetScreen?.id ??
60
+ screenData?.id;
59
61
 
60
62
  const reloadData = React.useCallback<ReloadDataFunction>(
61
63
  (silentRefresh = true, callback) => {
@@ -0,0 +1,39 @@
1
+ import { reactHooksLogger } from "../../logger";
2
+ import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
3
+
4
+ const logger = reactHooksLogger.addSubsystem("useHookModalScreenData");
5
+
6
+ type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
7
+
8
+ export const useHookModalScreenData = (): VariousScreenData | undefined => {
9
+ const hookModalState = useZappHooksModalState();
10
+
11
+ if (!hookModalState.state?.screenData) {
12
+ return;
13
+ }
14
+
15
+ try {
16
+ const screenData = hookModalState.state.screenData?.payload;
17
+ const hookPlugin = hookModalState.state.screenData.hookPlugin;
18
+
19
+ if (hookPlugin?.screen_id) {
20
+ return {
21
+ ...screenData,
22
+ targetScreen: hookPlugin,
23
+ };
24
+ }
25
+
26
+ return hookModalState.state.screenData?.payload;
27
+ } catch (error) {
28
+ logger.error({
29
+ message: "Hook modal screen data creation failed",
30
+ data: {
31
+ error,
32
+ hookModalState,
33
+ },
34
+ jsOnly: true,
35
+ });
36
+
37
+ return hookModalState.state.screenData?.payload;
38
+ }
39
+ };
@@ -108,9 +108,11 @@ export function isNavBarVisible(
108
108
  return false;
109
109
  }
110
110
 
111
- const showSecondaryLevel = screenData?.navigations?.some(
112
- (navigation) => navigation.styles?.show_secondary_level_menu
113
- );
111
+ const showSecondaryLevel =
112
+ !isTV() ||
113
+ screenData?.navigations?.some(
114
+ (navigation) => navigation.styles?.show_secondary_level_menu
115
+ );
114
116
 
115
117
  if (canGoBack && !showSecondaryLevel) {
116
118
  return false;
@@ -7,9 +7,8 @@ import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
7
7
 
8
8
  import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
9
9
 
10
- import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
11
-
12
10
  import { getTargetScreenData } from "../screen/useTargetScreenData";
11
+ import { useHookModalScreenData } from "../hookModal/hooks/useHookModalScreenData";
13
12
 
14
13
  import { useNavigation } from "./useNavigation";
15
14
  import { useModalStore } from "../../modalState";
@@ -45,11 +44,10 @@ export const useRoute = (): {
45
44
  ]);
46
45
 
47
46
  const { modalState } = useModalStore();
48
- const hookModalState = useZappHooksModalState();
49
47
 
50
48
  const modalScreenData = modalState.screen;
51
49
 
52
- const hookModalScreenData = hookModalState.state.screenData?.payload;
50
+ const hookModalScreenData = useHookModalScreenData();
53
51
 
54
52
  const videoModalScreenData =
55
53
  navigator?.videoModalState?.item &&
@@ -89,11 +89,15 @@ const runInBackground = async ({
89
89
  const shouldPresent = await hookPresentPolicy.shouldPresentScreen();
90
90
 
91
91
  if (!shouldPresent) {
92
+ const isRefreshed = await checkUserAuthenticated();
93
+
92
94
  log_info(
93
- "runInBackground: Background mode finished, hook plugin will be skipped"
95
+ `runInBackground: Background mode finished, ${isRefreshed ? "finish hook with completion true" : "refresh failed will presentUI"}`
94
96
  );
95
97
 
96
- await checkUserAuthenticated();
98
+ isRefreshed
99
+ ? callback({ success: isRefreshed, payload: item })
100
+ : presentUI();
97
101
 
98
102
  return;
99
103
  }