@applicaster/zapp-react-native-utils 14.0.0-rc.91 → 15.0.0-alpha.1017526116

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.
@@ -31,6 +31,10 @@ export const BUTTON_ACCESSIBILITY_KEYS = {
31
31
  hint: "accessibility_close_mini_hint",
32
32
  },
33
33
  },
34
+ back_to_live: {
35
+ label: "back_to_live_label",
36
+ hint: "",
37
+ },
34
38
  maximize: {
35
39
  label: "accessibility_maximize_label",
36
40
  hint: "accessibility_maximize_hint",
@@ -250,6 +250,10 @@ export class Player {
250
250
  return false;
251
251
  }
252
252
 
253
+ if (!Number.isFinite(duration)) {
254
+ return this.getSeekableDuration() > 0;
255
+ }
256
+
253
257
  return duration > 0;
254
258
  };
255
259
 
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import { Player } from "./player";
3
3
  import { usePlayer } from "./usePlayer";
4
4
 
5
- type PlayerState = {
5
+ export type PlayerState = {
6
6
  currentTime: number;
7
7
  duration: number;
8
8
  seekableDuration: number;
@@ -10,6 +10,8 @@ type PlayerState = {
10
10
  isPaused: boolean;
11
11
  isBuffering: boolean;
12
12
  isReadyToPlay: boolean;
13
+ trackState?: QuickBrickPlayer.TracksState;
14
+ isAd: boolean;
13
15
  };
14
16
 
15
17
  export const usePlayerState = (
@@ -24,6 +26,8 @@ export const usePlayerState = (
24
26
  isPaused: null,
25
27
  isBuffering: false,
26
28
  isReadyToPlay: false,
29
+ trackState: null,
30
+ isAd: false,
27
31
  });
28
32
 
29
33
  const player: Player = usePlayer(playerId);
@@ -37,6 +41,8 @@ export const usePlayerState = (
37
41
  isPaused: player.isPaused(),
38
42
  isBuffering: player.isBuffering(),
39
43
  isReadyToPlay: player.isReadyToPlay(),
44
+ trackState: player.getTracksState(),
45
+ isAd: player.isAd(),
40
46
  });
41
47
  }, [player]);
42
48
 
@@ -54,10 +60,16 @@ export const usePlayerState = (
54
60
  onPlayerPause: onPlayerChangeState,
55
61
  onPlayerResume: onPlayerChangeState,
56
62
  onPlayerSeekComplete: onPlayerChangeState,
63
+ onTracksChanged: onPlayerChangeState,
64
+ onAdBreakBegin: onPlayerChangeState,
65
+ onAdBreakEnd: onPlayerChangeState,
66
+ onAdBegin: onPlayerChangeState,
67
+ onAdEnd: onPlayerChangeState,
68
+ onAdError: onPlayerChangeState,
57
69
  },
58
70
  });
59
71
  }
60
- }, [player]);
72
+ }, [listenerId, onPlayerChangeState, player]);
61
73
 
62
74
  return state;
63
75
  };
@@ -335,6 +335,13 @@ function getPlayerConfiguration({ platform, version }) {
335
335
  };
336
336
 
337
337
  if (isTV(platform)) {
338
+ localizations.fields.push({
339
+ key: "back_to_live_label",
340
+ label: "Back to live label",
341
+ initial_value: "Back To Live",
342
+ type: "text_input",
343
+ });
344
+
338
345
  styles.fields.push(
339
346
  fieldsGroup("Always Show Scrub Bar & Timestamp", "", [
340
347
  {
@@ -447,7 +454,7 @@ function getPlayerConfiguration({ platform, version }) {
447
454
  ),
448
455
  fieldsGroup(
449
456
  "Skip Button",
450
- "This section allows you to configure the skip button styles for tv",
457
+ "This section allows you to configure the skip button behaviour",
451
458
  [
452
459
  {
453
460
  type: "switch",
@@ -464,6 +471,12 @@ function getPlayerConfiguration({ platform, version }) {
464
471
  label: "Persistent Button Toggle",
465
472
  initial_value: true,
466
473
  },
474
+ ]
475
+ ),
476
+ fieldsGroup(
477
+ "Labeled Button Style",
478
+ "This section allows you to configure the labeled button styles",
479
+ [
467
480
  {
468
481
  type: "color_picker_rgba",
469
482
  label_tooltip: "",
@@ -619,6 +632,32 @@ function getPlayerConfiguration({ platform, version }) {
619
632
  );
620
633
  }
621
634
 
635
+ if (isTV(platform)) {
636
+ general.fields.push(
637
+ {
638
+ key: "liveSeekingEnabled",
639
+ label: "Live Seeking Enabled",
640
+ initial_value: false,
641
+ type: "switch",
642
+ label_tooltip: "Enable Live Seek",
643
+ },
644
+ {
645
+ key: "minimumAllowedSeekableDurationInSeconds",
646
+ label: "Minimum allowed seekable duration in seconds",
647
+ initial_value: 300,
648
+ type: "number_input",
649
+ label_tooltip:
650
+ "If duration less that this value, player will disable 'liveSeekingEnabled' value",
651
+ },
652
+ {
653
+ key: "live_image",
654
+ label: "Live badge",
655
+ type: "uploader",
656
+ label_tooltip: "Override default live badge / icon",
657
+ }
658
+ );
659
+ }
660
+
622
661
  if (isMobile(platform)) {
623
662
  general.fields.push(
624
663
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "14.0.0-rc.91",
3
+ "version": "15.0.0-alpha.1017526116",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "14.0.0-rc.91",
30
+ "@applicaster/applicaster-types": "15.0.0-alpha.1017526116",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -151,7 +151,13 @@ export const useBatchLoading = (
151
151
  }
152
152
  }
153
153
  });
154
- }, [feedUrls, feeds, loadPipesDataDispatcher]);
154
+ }, [
155
+ batchComponents,
156
+ feeds,
157
+ getUrl,
158
+ loadPipesDataDispatcher,
159
+ options.riverId,
160
+ ]);
155
161
 
156
162
  React.useEffect(() => {
157
163
  runBatchLoading();
@@ -34,7 +34,9 @@ export const usePipesCacheReset = (riverId, riverComponents) => {
34
34
  component
35
35
  );
36
36
 
37
- dispatch(clearPipesData(url, { riverId }));
37
+ if (url) {
38
+ dispatch(clearPipesData(url, { riverId }));
39
+ }
38
40
  }
39
41
  });
40
42
  };
@@ -147,17 +147,34 @@ export class TVSeekController
147
147
 
148
148
  let targetPos = currentPos;
149
149
 
150
- if (this.currentSeekType === SEEK_TYPE.FORWARD) {
151
- targetPos = Math.min(
152
- currentPos + offset,
153
- this.playerController.getSeekableDuration()
154
- );
155
- } else if (this.currentSeekType === SEEK_TYPE.REWIND) {
156
- targetPos = Math.max(0, currentPos - offset);
150
+ const isLive = this.playerController.isLive();
151
+
152
+ if (isLive) {
153
+ if (this.currentSeekType === SEEK_TYPE.REWIND) {
154
+ targetPos = Math.min(
155
+ currentPos + offset,
156
+ this.playerController.getSeekableDuration()
157
+ );
158
+ } else if (this.currentSeekType === SEEK_TYPE.FORWARD) {
159
+ targetPos = Math.max(0, currentPos - offset);
160
+ } else {
161
+ log_warning(
162
+ `TVSeekController: handleDelayedSeek - invalid seek type: ${this.currentSeekType}`
163
+ );
164
+ }
157
165
  } else {
158
- log_warning(
159
- `TVSeekController: handleDelayedSeek - invalid seek type: ${this.currentSeekType}`
160
- );
166
+ if (this.currentSeekType === SEEK_TYPE.FORWARD) {
167
+ targetPos = Math.min(
168
+ currentPos + offset,
169
+ this.playerController.getSeekableDuration()
170
+ );
171
+ } else if (this.currentSeekType === SEEK_TYPE.REWIND) {
172
+ targetPos = Math.max(0, currentPos - offset);
173
+ } else {
174
+ log_warning(
175
+ `TVSeekController: handleDelayedSeek - invalid seek type: ${this.currentSeekType}`
176
+ );
177
+ }
161
178
  }
162
179
 
163
180
  log_debug(
package/utils/index.ts CHANGED
@@ -36,6 +36,8 @@ export {
36
36
  last,
37
37
  toLower,
38
38
  isEqual as equals,
39
+ uniq,
40
+ uniqWith,
39
41
  flowRight as compose,
40
42
  partial,
41
43
  reverse,
@@ -0,0 +1,231 @@
1
+ import { useNavigation, useRivers, useScreenContext } from "../../reactHooks";
2
+ import { createLogger } from "../../logger";
3
+ import { useCallback, useMemo } from "react";
4
+
5
+ export enum NavigationCallbackOptions {
6
+ DEFAULT = "default",
7
+ GO_HOME = "go_home",
8
+ GO_BACK = "go_back",
9
+ GO_TO_SCREEN = "go_to_screen",
10
+ }
11
+
12
+ export enum ResultType {
13
+ login = "login",
14
+ logout = "logout",
15
+ }
16
+
17
+ export type CallbackResult = hookCallbackArgs & {
18
+ options?: {
19
+ resultType?: ResultType;
20
+ };
21
+ };
22
+
23
+ export type ScreenResultCallback = (args: CallbackResult) => void | undefined;
24
+
25
+ export const CALLBACK_NAVIGATION_KEY = "completion_action";
26
+
27
+ export const CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY =
28
+ "completion_action_navigation_go_to_screen";
29
+
30
+ type NavKeys = {
31
+ action: NavigationCallbackOptions;
32
+ targetScreenId: string | null;
33
+ } | null;
34
+
35
+ type General = Record<string, unknown>;
36
+
37
+ const LogPrefix = "useCallbackNavigationAction:";
38
+
39
+ const { log_info, log_verbose, log_debug } = createLogger({
40
+ subsystem: "hook-navigation-callback",
41
+ });
42
+
43
+ const legacyMappingKeys = {
44
+ "quick-brick-login-flow": {
45
+ actionType: "login_completion_action",
46
+ targetScreen: "navigate_to_login_screen",
47
+ },
48
+ "quick-brick-user-account-ui-component": {
49
+ actionType: "callbackAction",
50
+ },
51
+ "quick-brick-login-multi-login-providers.login": {
52
+ actionType: "login_completion_action",
53
+ targetScreen: "navigate_to_login_screen",
54
+ },
55
+ "quick-brick-login-multi-login-providers.logout": {
56
+ actionType: "logout_completion_action",
57
+ targetScreen: "navigate_to_logout_screen",
58
+ },
59
+ "quick-brick-storefront": {
60
+ actionType: "purchase_completion_action",
61
+ targetScreen: "navigate_to_screen_after_purchase",
62
+ },
63
+ "zapp_login_plugin_oauth_tv_2_0.login": {
64
+ actionType: "login_completion_action",
65
+ targetScreen: "navigate_to_login_screen",
66
+ },
67
+ "zapp_login_plugin_oauth_tv_2_0.logout": {
68
+ actionType: "logout_completion_action",
69
+ targetScreen: "navigate_to_logout_screen",
70
+ },
71
+ };
72
+
73
+ const NAV_ACTIONS = (
74
+ Object.values(NavigationCallbackOptions) as string[]
75
+ ).filter((value) => value !== NavigationCallbackOptions.DEFAULT);
76
+
77
+ const isNavAction = (v: unknown): v is NavigationCallbackOptions =>
78
+ typeof v === "string" && NAV_ACTIONS.includes(v);
79
+
80
+ export const getNavigationKeys = (
81
+ item?: ZappUIComponent | ZappRiver,
82
+ resultType: ResultType | null = null
83
+ ): NavKeys => {
84
+ const general = (item?.general ?? {}) as General;
85
+
86
+ const pluginIdentifier = (item as any).identifier ?? item?.type ?? "";
87
+
88
+ const legacy =
89
+ legacyMappingKeys[`${pluginIdentifier}.${resultType}`] ??
90
+ legacyMappingKeys[pluginIdentifier] ??
91
+ {};
92
+
93
+ const actionKey = resultType
94
+ ? `${resultType}_${CALLBACK_NAVIGATION_KEY}`
95
+ : CALLBACK_NAVIGATION_KEY;
96
+
97
+ const rawAction =
98
+ (general as General)[actionKey] ??
99
+ (legacy.actionType ? (general as General)[legacy.actionType] : undefined);
100
+
101
+ const action: NavigationCallbackOptions | null = isNavAction(rawAction)
102
+ ? rawAction
103
+ : null;
104
+
105
+ if (!action) return null;
106
+
107
+ let targetScreenId: string | null = null;
108
+
109
+ if (action === NavigationCallbackOptions.GO_TO_SCREEN) {
110
+ const screenKey = resultType
111
+ ? `${resultType}_${CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY}`
112
+ : CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY;
113
+
114
+ const screenId: string | null =
115
+ ((general as General)[screenKey] as string) ??
116
+ (legacy.targetScreen
117
+ ? ((general as General)[legacy.targetScreen] as string)
118
+ : undefined);
119
+
120
+ if (screenId) {
121
+ targetScreenId = screenId.length > 0 ? screenId : null;
122
+ }
123
+ }
124
+
125
+ return { action, targetScreenId };
126
+ };
127
+
128
+ export const useCallbackNavigationAction = (
129
+ item?: ZappUIComponent | ZappRiver
130
+ ): ((
131
+ args: CallbackResult,
132
+ hookCallback?: hookCallback
133
+ ) => void | undefined) => {
134
+ const navigation = useNavigation();
135
+ const rivers = useRivers();
136
+ const screenContext = useScreenContext();
137
+
138
+ const overrideCallbackFromComponent = useMemo(() => {
139
+ log_verbose(`${LogPrefix}: overridden callbackAction by component`);
140
+
141
+ // TODO: Check if we have better option where to store overridden callback action
142
+ return screenContext?.options?.callback;
143
+ }, [screenContext?.options?.callback]);
144
+
145
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
146
+ log_verbose(`${LogPrefix} screenContext`, { screenContext, item });
147
+ }
148
+
149
+ const callbackAction = useCallback<hookCallback>(
150
+ (args: CallbackResult, hookCallback: hookCallback = null) => {
151
+ if (!args.success) {
152
+ log_debug(
153
+ `${LogPrefix} callback called with no success, use original callback`
154
+ );
155
+
156
+ hookCallback?.(args);
157
+
158
+ return;
159
+ }
160
+
161
+ if (args.cancelled) {
162
+ log_debug(
163
+ `${LogPrefix} callback called but cancelled, use original callback`
164
+ );
165
+
166
+ hookCallback?.(args);
167
+
168
+ return;
169
+ }
170
+
171
+ const data = getNavigationKeys(item, args.options?.resultType ?? null);
172
+
173
+ if (!data) {
174
+ hookCallback?.(args);
175
+
176
+ return;
177
+ }
178
+
179
+ hookCallback?.({ ...args, success: false, cancelled: true });
180
+
181
+ switch (data.action) {
182
+ case NavigationCallbackOptions.GO_BACK: {
183
+ if (navigation.canGoBack()) {
184
+ navigation.goBack();
185
+ log_info(`${LogPrefix} performing 'GO BACK' action`);
186
+ } else {
187
+ log_info(`${LogPrefix} cannot perform 'GO BACK' action — ignoring`);
188
+ }
189
+
190
+ break;
191
+ }
192
+
193
+ case NavigationCallbackOptions.GO_HOME: {
194
+ navigation.goHome();
195
+ log_info(`${LogPrefix} performing 'GO HOME' action`);
196
+ break;
197
+ }
198
+
199
+ case NavigationCallbackOptions.GO_TO_SCREEN: {
200
+ const screenId = data.targetScreenId;
201
+
202
+ if (!screenId) {
203
+ log_info(`${LogPrefix} no screenId provided — ignoring`);
204
+ break;
205
+ }
206
+
207
+ const screen = rivers[screenId];
208
+
209
+ if (screen) {
210
+ navigation.replace(screen);
211
+
212
+ log_info(
213
+ `${LogPrefix} performing 'GO TO SCREEN' action to screen: ${screenId}`
214
+ );
215
+ } else {
216
+ log_info(`${LogPrefix} no screen provided — ignoring`);
217
+ }
218
+
219
+ break;
220
+ }
221
+
222
+ default: {
223
+ break;
224
+ }
225
+ }
226
+ },
227
+ [item, navigation, rivers]
228
+ );
229
+
230
+ return overrideCallbackFromComponent || callbackAction;
231
+ };
@@ -0,0 +1,76 @@
1
+ const NavigationCallbackOptions = {
2
+ DEFAULT: "default",
3
+ GO_HOME: "go_home",
4
+ GO_BACK: "go_back",
5
+ GO_TO_SCREEN: "go_to_screen",
6
+ };
7
+
8
+ const ResultType = {
9
+ login: "login",
10
+ logout: "logout",
11
+ };
12
+
13
+ const CALLBACK_NAVIGATION_KEY = "completion_action";
14
+
15
+ const CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY =
16
+ "completion_action_navigation_go_to_screen";
17
+
18
+ const callbackKeyPrefix = (key, prefix, keySeparator = "_") =>
19
+ prefix ? `${prefix}${keySeparator}${key}` : key;
20
+
21
+ const extendManifestWithHookCallback = (prefix = null) => ({
22
+ group: true,
23
+ label: "CallBack Navigation",
24
+ folded: true,
25
+ fields: [
26
+ {
27
+ type: "select",
28
+ key: callbackKeyPrefix(CALLBACK_NAVIGATION_KEY, prefix),
29
+ label: callbackKeyPrefix(
30
+ "Callback Navigation",
31
+ prefix?.toUpperCase(),
32
+ " "
33
+ ),
34
+ label_tooltip:
35
+ "Defines what navigation action should be performed after the callback is called.",
36
+ options: [
37
+ {
38
+ text: "Use default flow",
39
+ value: NavigationCallbackOptions.DEFAULT,
40
+ },
41
+ {
42
+ text: "Go Back to home screen",
43
+ value: NavigationCallbackOptions.GO_HOME,
44
+ },
45
+ {
46
+ text: "Go Back to previous screen",
47
+ value: NavigationCallbackOptions.GO_BACK,
48
+ },
49
+ {
50
+ text: "Move to specific screen",
51
+ value: NavigationCallbackOptions.GO_TO_SCREEN,
52
+ },
53
+ ],
54
+ initial_value: "default",
55
+ },
56
+ {
57
+ type: "screen_selector",
58
+ key: callbackKeyPrefix(CALLBACK_NAVIGATION_GO_TO_SCREEN_KEY, prefix),
59
+ label: callbackKeyPrefix(
60
+ "Navigate to screen",
61
+ prefix?.toUpperCase(),
62
+ " "
63
+ ),
64
+ label_tooltip: "Screen you wish to navigate to after success purchase",
65
+ rules: "conditional",
66
+ conditional_fields: [
67
+ {
68
+ key: `general/${callbackKeyPrefix(CALLBACK_NAVIGATION_KEY, prefix)}`,
69
+ condition_value: NavigationCallbackOptions.GO_TO_SCREEN,
70
+ },
71
+ ],
72
+ },
73
+ ],
74
+ });
75
+
76
+ module.exports = { extendManifestWithHookCallback, ResultType };
@@ -0,0 +1,19 @@
1
+ import { useCallback } from "react";
2
+ import {
3
+ CallbackResult,
4
+ useCallbackNavigationAction,
5
+ } from "./callbackNavigationAction";
6
+
7
+ export const useCallbackActions = (
8
+ item?: ZappUIComponent | ZappRiver,
9
+ hookCallback?: hookCallback
10
+ ): hookCallback => {
11
+ const navigationAction = useCallbackNavigationAction(item);
12
+
13
+ return useCallback(
14
+ async (data: CallbackResult) => {
15
+ navigationAction(data, hookCallback);
16
+ },
17
+ [navigationAction, hookCallback]
18
+ );
19
+ };
@@ -20,7 +20,7 @@ const isAuthenticationRequired = ({ payload, logs }) => {
20
20
 
21
21
  if (!payload) {
22
22
  log_info(
23
- "isAuthenticationRequired: No payload exist, authentefication required"
23
+ "isAuthenticationRequired: No payload exist, authentication required"
24
24
  );
25
25
 
26
26
  return true;