@applicaster/zapp-react-native-utils 15.0.0-rc.14 → 15.0.0-rc.140

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.
Files changed (177) hide show
  1. package/README.md +0 -6
  2. package/actionsExecutor/ActionExecutorContext.tsx +86 -12
  3. package/actionsExecutor/feedDecorator.ts +6 -6
  4. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  5. package/adsUtils/index.ts +2 -2
  6. package/analyticsUtils/README.md +1 -1
  7. package/analyticsUtils/analyticsMapper.ts +10 -2
  8. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  9. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  10. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  11. package/appUtils/HooksManager/index.ts +45 -10
  12. package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
  13. package/appUtils/accessibilityManager/__tests__/utils.test.ts +360 -0
  14. package/appUtils/accessibilityManager/const.ts +4 -0
  15. package/appUtils/accessibilityManager/hooks.ts +20 -13
  16. package/appUtils/accessibilityManager/index.ts +28 -1
  17. package/appUtils/accessibilityManager/utils.ts +59 -8
  18. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  19. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  20. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  21. package/appUtils/contextKeysManager/index.ts +65 -10
  22. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -0
  23. package/appUtils/focusManager/index.ios.ts +43 -4
  24. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  25. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  26. package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
  27. package/appUtils/focusManagerAux/utils/index.ts +13 -7
  28. package/appUtils/focusManagerAux/utils/utils.ios.ts +202 -3
  29. package/appUtils/keyCodes/keys/keys.web.ts +1 -4
  30. package/appUtils/localizationsHelper.ts +4 -0
  31. package/appUtils/orientationHelper.ts +2 -4
  32. package/appUtils/platform/platformUtils.ts +117 -18
  33. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +94 -4
  34. package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
  35. package/appUtils/playerManager/index.ts +9 -0
  36. package/appUtils/playerManager/player.ts +5 -1
  37. package/appUtils/playerManager/playerNative.ts +31 -17
  38. package/appUtils/playerManager/usePlayer.tsx +5 -3
  39. package/appUtils/playerManager/usePlayerState.tsx +14 -2
  40. package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
  41. package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
  42. package/arrayUtils/index.ts +5 -0
  43. package/cellUtils/__tests__/cellUtils.test.ts +39 -0
  44. package/cellUtils/index.ts +43 -1
  45. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  46. package/cloudEventsUtils/index.ts +65 -1
  47. package/componentsUtils/index.ts +8 -0
  48. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  49. package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
  50. package/configurationUtils/index.ts +17 -11
  51. package/dateUtils/__tests__/dayjs.test.ts +327 -0
  52. package/dateUtils/index.ts +2 -0
  53. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  54. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  55. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  56. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  57. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  58. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  59. package/errorUtils/__tests__/invariant.test.ts +112 -0
  60. package/focusManager/aux/index.ts +1 -1
  61. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  62. package/headersUtils/index.ts +2 -1
  63. package/manifestUtils/_internals/__tests__/index.test.js +41 -0
  64. package/manifestUtils/_internals/index.js +33 -0
  65. package/manifestUtils/defaultManifestConfigurations/player.js +115 -11
  66. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +49 -0
  67. package/manifestUtils/fieldUtils/index.js +54 -0
  68. package/manifestUtils/index.js +2 -0
  69. package/manifestUtils/keys.js +249 -0
  70. package/manifestUtils/mobileAction/button/__tests__/mobileActionButton.test.js +168 -0
  71. package/manifestUtils/mobileAction/button/index.js +140 -0
  72. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +102 -0
  73. package/manifestUtils/mobileAction/container/index.js +73 -0
  74. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +127 -0
  75. package/manifestUtils/mobileAction/groups/defaults.js +76 -0
  76. package/manifestUtils/mobileAction/groups/index.js +80 -0
  77. package/manifestUtils/platformIsTV.js +13 -0
  78. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
  79. package/manifestUtils/tvAction/container/index.js +1 -1
  80. package/navigationUtils/index.ts +15 -5
  81. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  82. package/numberUtils/__tests__/toPositiveNumber.test.ts +193 -0
  83. package/numberUtils/index.ts +23 -1
  84. package/package.json +4 -4
  85. package/playerUtils/usePlayerTTS.ts +8 -3
  86. package/pluginUtils/index.ts +4 -0
  87. package/reactHooks/advertising/index.ts +2 -2
  88. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  89. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  90. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  91. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  92. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  93. package/reactHooks/cell-click/index.ts +2 -1
  94. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  95. package/reactHooks/connection/__tests__/index.test.js +1 -1
  96. package/reactHooks/debugging/__tests__/index.test.js +4 -4
  97. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  98. package/reactHooks/device/useIsTablet.tsx +14 -19
  99. package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
  100. package/reactHooks/events/index.ts +20 -0
  101. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  102. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  103. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +4 -1
  104. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  105. package/reactHooks/feed/__tests__/{useInflatedUrl.test.ts → useInflatedUrl.test.tsx} +62 -7
  106. package/reactHooks/feed/index.ts +0 -2
  107. package/reactHooks/feed/useBatchLoading.ts +7 -1
  108. package/reactHooks/feed/useEntryScreenId.ts +2 -2
  109. package/reactHooks/feed/useInflatedUrl.ts +44 -18
  110. package/reactHooks/feed/usePipesCacheReset.ts +3 -1
  111. package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +13 -16
  112. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  113. package/reactHooks/index.ts +2 -0
  114. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  115. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  116. package/reactHooks/layout/index.ts +1 -1
  117. package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.ts → useDimensions.test.tsx} +105 -25
  118. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
  119. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  120. package/reactHooks/navigation/index.ts +27 -11
  121. package/reactHooks/navigation/useRoute.ts +11 -7
  122. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +27 -10
  123. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  124. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  125. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  126. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  127. package/reactHooks/resolvers/useCellResolver.ts +6 -2
  128. package/reactHooks/resolvers/useComponentResolver.ts +19 -3
  129. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
  130. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  131. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  132. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +12 -4
  133. package/reactHooks/screen/useTargetScreenData.ts +4 -2
  134. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  135. package/reactHooks/state/index.ts +2 -0
  136. package/reactHooks/state/useComponentScreenState.ts +45 -0
  137. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  138. package/reactHooks/state/useRivers.ts +1 -1
  139. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  140. package/reactHooks/usePluginConfiguration.ts +2 -2
  141. package/reactHooks/utils/__tests__/index.test.js +1 -1
  142. package/rectUtils/__tests__/index.test.ts +549 -0
  143. package/rectUtils/index.ts +2 -2
  144. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +206 -0
  145. package/refreshUtils/RefreshCoordinator/index.ts +245 -0
  146. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  147. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  148. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  149. package/screenPickerUtils/index.ts +5 -0
  150. package/screenState/__tests__/index.test.ts +1 -1
  151. package/screenUtils/index.ts +3 -0
  152. package/searchUtils/const.ts +7 -0
  153. package/searchUtils/index.ts +3 -0
  154. package/services/storageServiceSync.web.ts +1 -1
  155. package/stringUtils/index.ts +1 -1
  156. package/testUtils/index.tsx +30 -21
  157. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  158. package/time/__tests__/Timer.test.ts +236 -0
  159. package/typeGuards/__tests__/isString.test.ts +21 -0
  160. package/typeGuards/index.ts +4 -0
  161. package/utils/__tests__/clone.test.ts +158 -0
  162. package/utils/__tests__/mapAccum.test.ts +73 -0
  163. package/utils/__tests__/mergeRight.test.ts +48 -0
  164. package/utils/__tests__/path.test.ts +7 -0
  165. package/utils/__tests__/selectors.test.ts +124 -0
  166. package/utils/clone.ts +7 -0
  167. package/utils/index.ts +21 -1
  168. package/utils/mapAccum.ts +23 -0
  169. package/utils/mergeRight.ts +5 -0
  170. package/utils/path.ts +6 -3
  171. package/utils/pathOr.ts +5 -1
  172. package/utils/selectors.ts +46 -0
  173. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +49 -12
  174. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
  175. package/reactHooks/componentsMap/index.ts +0 -55
  176. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  177. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -92,22 +92,26 @@ export const prefetchImage = (playableItem: ZappEntry, config: any = {}) => {
92
92
  }
93
93
  };
94
94
 
95
- export const loadFeedAndPrefetchThumbnailImage = async (
96
- playNextFeedUrl: string,
97
- entry: ZappEntry,
98
- playNextPlugin
99
- ) => {
95
+ /**
96
+ * Loads a feed entry from the given feed URL using the provided Zapp entry as context.
97
+ *
98
+ * @param {string} feedUrl - The URL of the feed to load the entry from.
99
+ * @param {ZappEntry} entry - The Zapp entry to use as context for the request.
100
+ * @returns {Promise<ZappEntry>} A promise that resolves to the loaded Zapp entry.
101
+ * @throws {Error} If the feed loading fails or no entry is found in the response.
102
+ */
103
+ export const loadFeedEntry = async (feedUrl: string, entry: ZappEntry) => {
100
104
  const requestBuilder = new RequestBuilder()
101
105
  .setEntryContext(entry)
102
106
  .setScreenContext({} as ZappRiver)
103
- .setUrl(playNextFeedUrl);
107
+ .setUrl(feedUrl);
104
108
 
105
109
  const responseObject = await requestBuilder.call<ZappEntry>();
106
110
  const responseHelper = new PipesClientResponseHelper(responseObject);
107
111
 
108
112
  if (responseHelper.error) {
109
113
  log_error(
110
- `loadFeedAndPrefetchThumbnailImage: loading failed with error: ${responseHelper.error.message}. Play next observer, will not be executed`,
114
+ `loadFeedEntry: loading failed with error: ${responseHelper.error.message}. Observer will not be executed`,
111
115
  {
112
116
  response: responseHelper.getLogsData(),
113
117
  }
@@ -116,29 +120,37 @@ export const loadFeedAndPrefetchThumbnailImage = async (
116
120
  throw responseHelper.error;
117
121
  } else {
118
122
  log_info(
119
- `loadFeedAndPrefetchThumbnailImage: Play next url was successfully loaded for url: ${playNextFeedUrl}. Prefetching image`,
123
+ `loadFeedEntry: Feed was successfully loaded for url: ${feedUrl}`,
120
124
  responseHelper.getLogsData()
121
125
  );
122
126
 
123
- const playNextEntry = responseHelper.responseData?.entry[0];
127
+ const entry = responseHelper.responseData?.entry[0];
124
128
 
125
- if (!playNextEntry) {
126
- log_error(
127
- "loadFeedAndPrefetchThumbnailImage: Can not retrieve play next entry, feed was loaded but no entry was found",
128
- responseHelper.getLogsData()
129
- );
129
+ if (!entry) {
130
+ const error =
131
+ "loadFeedEntry: Can not retrieve entry, feed was loaded but no entry was found";
130
132
 
131
- throw new Error(
132
- "Can not retrieve play next entry, feed was loaded but no entry was found"
133
- );
134
- }
133
+ log_error(error, responseHelper.getLogsData());
135
134
 
136
- prefetchImage(playNextEntry, playNextPlugin?.configuration);
135
+ throw new Error(error);
136
+ }
137
137
 
138
- return playNextEntry;
138
+ return entry;
139
139
  }
140
140
  };
141
141
 
142
+ export const loadFeedAndPrefetchThumbnailImage = async (
143
+ playNextFeedUrl: string,
144
+ entry: ZappEntry,
145
+ playNextPlugin
146
+ ) => {
147
+ const playNextEntry = await loadFeedEntry(playNextFeedUrl, entry);
148
+
149
+ prefetchImage(playNextEntry, playNextPlugin?.configuration);
150
+
151
+ return playNextEntry;
152
+ };
153
+
142
154
  export const findPluginByIdentifier = (
143
155
  identifier: string,
144
156
  plugins: ZappPlugin[]
@@ -33,6 +33,7 @@ function deprecationWarning(method) {
33
33
  export interface PlayerLifecycleListener {
34
34
  onRegistered?: (player: Player) => void;
35
35
  onUnRegistered?: (player: Player) => void;
36
+ onCastingChanged?: (isCasting: boolean) => void;
36
37
  }
37
38
 
38
39
  type PlayersMap = {
@@ -253,10 +254,18 @@ export class PlayerManager {
253
254
 
254
255
  public registerCastingReceiver(receiver: Player) {
255
256
  this.castingReceiver = receiver;
257
+
258
+ this.lifecycleListeners.forEach((listener) => {
259
+ listener.onCastingChanged?.(true);
260
+ });
256
261
  }
257
262
 
258
263
  public unregisterCastingReceiver() {
259
264
  this.castingReceiver = null;
265
+
266
+ this.lifecycleListeners.forEach((listener) => {
267
+ listener.onCastingChanged?.(false);
268
+ });
260
269
  }
261
270
 
262
271
  /**
@@ -250,11 +250,15 @@ 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
 
256
260
  isAd = () => {
257
- return !!this.playerState.adState || this.playerState.isInAdBreak;
261
+ return !!this.playerState.adState || !!this.playerState.isInAdBreak;
258
262
  };
259
263
 
260
264
  isSeeking = () => {
@@ -15,6 +15,22 @@ const logger = createLogger({
15
15
 
16
16
  const { log_warning } = logger;
17
17
 
18
+ interface PlayerMethods {
19
+ seeking?: (position: number) => void;
20
+ forward?: (deltaTime: number) => void;
21
+ rewind?: (deltaTime: number) => void;
22
+ startSleepTimer?: (sleepTimestamp: number) => void;
23
+ selectTrack?: (
24
+ selected: QuickBrickPlayer.TextTrack | QuickBrickPlayer.AudioTrack
25
+ ) => void;
26
+ setPlaybackRate?: (rate: number) => void;
27
+ appStateChange?: (appState: string, previousAppState: string) => void;
28
+ closeNativePlayer?: () => void;
29
+ togglePlayPause?: () => void;
30
+ }
31
+
32
+ type PlayerComponent = ReactComponent<PlayerRefProps> & PlayerMethods;
33
+
18
34
  type PlayerPlugnId = "QuickBrickPlayerPlugin" | "KalturaPlayerPlugin";
19
35
 
20
36
  type Props = {
@@ -62,7 +78,7 @@ export class PlayerNative extends Player {
62
78
  return this.playerState.contentPosition;
63
79
  };
64
80
 
65
- currentPlayerComponent = (): ReactComponent<PlayerRefProps> =>
81
+ currentPlayerComponent = (): PlayerComponent | null =>
66
82
  this.playerComponent?.current;
67
83
 
68
84
  getState = () => this.playerState;
@@ -121,7 +137,7 @@ export class PlayerNative extends Player {
121
137
 
122
138
  this.playerState.seekPosition = newPosition;
123
139
 
124
- this.currentPlayerComponent()?.["seeking"](this.playerState.seekPosition);
140
+ this.currentPlayerComponent()?.seeking?.(this.playerState.seekPosition);
125
141
  }
126
142
 
127
143
  this.logState(PlayerModuleFuncNames.seekTo, { position });
@@ -135,7 +151,7 @@ export class PlayerNative extends Player {
135
151
  if (!this.invokeNativeFunction(PlayerModuleFuncNames.forward, deltaTime)) {
136
152
  // Kaltura does not have yet this implementation, use legacy code
137
153
 
138
- this.currentPlayerComponent()?.["forward"](deltaTime);
154
+ this.currentPlayerComponent()?.forward?.(deltaTime);
139
155
  }
140
156
 
141
157
  this.notifyPlayHeadPositionUpdate();
@@ -151,7 +167,7 @@ export class PlayerNative extends Player {
151
167
  if (!this.invokeNativeFunction(PlayerModuleFuncNames.rewind, deltaTime)) {
152
168
  // Kaltura does not have yet this implementation, use legacy code
153
169
 
154
- this.currentPlayerComponent()?.["rewind"](deltaTime);
170
+ this.currentPlayerComponent()?.rewind?.(deltaTime);
155
171
  }
156
172
 
157
173
  this.notifyPlayHeadPositionUpdate();
@@ -178,7 +194,7 @@ export class PlayerNative extends Player {
178
194
  sleepTimestamp
179
195
  )
180
196
  ) {
181
- this.currentPlayerComponent()?.["startSleepTimer"](sleepTimestamp);
197
+ this.currentPlayerComponent()?.startSleepTimer?.(sleepTimestamp);
182
198
  }
183
199
  };
184
200
 
@@ -195,11 +211,11 @@ export class PlayerNative extends Player {
195
211
  selectTrack = (
196
212
  selected: QuickBrickPlayer.TextTrack | QuickBrickPlayer.AudioTrack
197
213
  ) => {
198
- this.currentPlayerComponent()?.["selectTrack"]?.(selected);
214
+ this.currentPlayerComponent()?.selectTrack?.(selected);
199
215
  };
200
216
 
201
217
  setPlaybackRate = (rate: number) => {
202
- this.currentPlayerComponent()?.["setPlaybackRate"]?.(rate);
218
+ this.currentPlayerComponent()?.setPlaybackRate?.(rate);
203
219
  };
204
220
 
205
221
  getPluginConfiguration = () => {
@@ -209,19 +225,17 @@ export class PlayerNative extends Player {
209
225
  getProps = () => (this.currentPlayerComponent() as any)?.props;
210
226
 
211
227
  appStateChange = (appState, previousAppState) => {
212
- this.currentPlayerComponent()?.["appStateChange"]?.(
213
- appState,
214
- previousAppState
215
- );
228
+ this.currentPlayerComponent()?.appStateChange?.(appState, previousAppState);
216
229
  };
217
230
 
218
231
  closeNativePlayer = () => {
219
- // TODO: Delete does not work
220
- this.currentPlayerComponent()?.["closeNativePlayer"]?.();
232
+ // TODO: Delete, does not work (component is null)
233
+ this.currentPlayerComponent()?.closeNativePlayer?.();
234
+ this.getPlayerModule()?.stopBackgroundPlayback?.();
221
235
  };
222
236
 
223
237
  togglePlayPause = () => {
224
- this.currentPlayerComponent()?.["togglePlayPause"]?.();
238
+ this.currentPlayerComponent()?.togglePlayPause?.();
225
239
  };
226
240
 
227
241
  onVideoLoad = (event) => {
@@ -289,19 +303,19 @@ export class PlayerNative extends Player {
289
303
  isFullScreenSupported = (): boolean => {
290
304
  const config = this.getConfig();
291
305
 
292
- const disableFullScreen = config?.["disable_fullscreen"];
306
+ const disableFullScreen = config?.disable_fullscreen;
293
307
 
294
308
  if (disableFullScreen) {
295
309
  return false;
296
310
  }
297
311
 
298
- const isFullScreenAudioPlayer = config?.["full_screen_audio_player"];
312
+ const isFullScreenAudioPlayer = config?.full_screen_audio_player;
299
313
 
300
314
  return !(isFullScreenAudioPlayer && this.isAudioItem());
301
315
  };
302
316
 
303
317
  supportsNativeControls = (): boolean =>
304
- toBooleanWithDefaultFalse(this.getConfig()?.["supports_native_controls"]);
318
+ toBooleanWithDefaultFalse(this.getConfig()?.supports_native_controls);
305
319
 
306
320
  supportNativeCast = (): boolean =>
307
321
  toBooleanWithDefaultFalse(
@@ -22,7 +22,6 @@ export const usePlayer = (playerId?: string): Player => {
22
22
 
23
23
  const isCasting = playerManager.isCasting();
24
24
 
25
- // TODO: We need to prerender when we start/stop casting, fix this
26
25
  const getPlayer = (playerId, isCasting) =>
27
26
  getControlledPlayer(playerId, isCasting);
28
27
 
@@ -46,7 +45,7 @@ export const usePlayer = (playerId?: string): Player => {
46
45
  return playerManager.addLifecycleListener({
47
46
  onRegistered: (player) => {
48
47
  if (playerIdToUse === player.playerId) {
49
- setPlayer(getPlayer(playerIdToUse, isCasting));
48
+ setPlayer(getPlayer(playerIdToUse, playerManager.isCasting()));
50
49
  }
51
50
  },
52
51
  onUnRegistered: (player) => {
@@ -54,8 +53,11 @@ export const usePlayer = (playerId?: string): Player => {
54
53
  setPlayer(null);
55
54
  }
56
55
  },
56
+ onCastingChanged: () => {
57
+ setPlayer(getPlayer(playerIdToUse, playerManager.isCasting()));
58
+ },
57
59
  } as PlayerLifecycleListener);
58
- }, [playerIdToUse, isCasting]);
60
+ }, [playerIdToUse]);
59
61
 
60
62
  return player;
61
63
  };
@@ -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
  };
@@ -0,0 +1,24 @@
1
+ import { allTruthy } from "..";
2
+
3
+ describe("allTruthy", () => {
4
+ it("should return true when all values are true", () => {
5
+ expect(allTruthy([true, true, true])).toBe(true);
6
+ });
7
+
8
+ it("should return false when at least one value is false", () => {
9
+ expect(allTruthy([true, false, true])).toBe(false);
10
+ });
11
+
12
+ it("should return false when all values are false", () => {
13
+ expect(allTruthy([false, false, false])).toBe(false);
14
+ });
15
+
16
+ it("should return false for an empty array", () => {
17
+ expect(allTruthy([])).toBe(false);
18
+ });
19
+
20
+ it("should handle single-element arrays correctly", () => {
21
+ expect(allTruthy([true])).toBe(true);
22
+ expect(allTruthy([false])).toBe(false);
23
+ });
24
+ });
@@ -0,0 +1,24 @@
1
+ import { anyTruthy } from "..";
2
+
3
+ describe("anyTruthy", () => {
4
+ it("should return true when at least one value is true", () => {
5
+ expect(anyTruthy([false, true, false])).toBe(true);
6
+ });
7
+
8
+ it("should return false when all values are false", () => {
9
+ expect(anyTruthy([false, false, false])).toBe(false);
10
+ });
11
+
12
+ it("should return true when all values are true", () => {
13
+ expect(anyTruthy([true, true, true])).toBe(true);
14
+ });
15
+
16
+ it("should return false for an empty array", () => {
17
+ expect(anyTruthy([])).toBe(false);
18
+ });
19
+
20
+ it("should handle single-element arrays correctly", () => {
21
+ expect(anyTruthy([true])).toBe(true);
22
+ expect(anyTruthy([false])).toBe(false);
23
+ });
24
+ });
@@ -116,3 +116,8 @@ export const sample = (xs: unknown[]): unknown => {
116
116
 
117
117
  return xs[index];
118
118
  };
119
+
120
+ export const allTruthy = (xs: boolean[]) =>
121
+ isFilledArray(xs) && xs.every(Boolean);
122
+
123
+ export const anyTruthy = (xs: boolean[]) => xs.some(Boolean);
@@ -3,6 +3,7 @@ import {
3
3
  ifEmptyUseFallback,
4
4
  textTransform,
5
5
  getKeyForLabel,
6
+ getDataTransformForLabel,
6
7
  getLabel,
7
8
  getAspectRatio,
8
9
  getCellWidth,
@@ -56,6 +57,44 @@ describe("getKeyForLabel", () => {
56
57
  });
57
58
  });
58
59
 
60
+ describe("getDataTransformForLabel", () => {
61
+ it("returns dataKey when dataKey is not other", () => {
62
+ expect(getDataTransformForLabel(VAL.dataKey, VAL.customKey)).toEqual(
63
+ VAL.dataKey
64
+ );
65
+ });
66
+
67
+ it("returns customKey when dataKey is other", () => {
68
+ expect(getDataTransformForLabel(VAL.other, VAL.customKey)).toEqual(
69
+ VAL.customKey
70
+ );
71
+ });
72
+
73
+ it("preserves full date formats containing dots", () => {
74
+ expect(getDataTransformForLabel(VAL.other, "DD.MM.YYYY")).toEqual(
75
+ "DD.MM.YYYY"
76
+ );
77
+ });
78
+
79
+ it("returns default date format when selected key is null or undefined", () => {
80
+ expect(getDataTransformForLabel(EMPTY.nulls, VAL.customKey)).toEqual(
81
+ "DD/MM/YYYY"
82
+ );
83
+
84
+ expect(getDataTransformForLabel(EMPTY.undef, VAL.customKey)).toEqual(
85
+ "DD/MM/YYYY"
86
+ );
87
+
88
+ expect(getDataTransformForLabel(VAL.other, EMPTY.nulls)).toEqual(
89
+ "DD/MM/YYYY"
90
+ );
91
+
92
+ expect(getDataTransformForLabel(VAL.other, EMPTY.undef)).toEqual(
93
+ "DD/MM/YYYY"
94
+ );
95
+ });
96
+ });
97
+
59
98
  describe("getLabel", () => {
60
99
  it("returns a string from dataKey's path", () => {
61
100
  expect(getLabel(VAL.dataKey, VAL.customKey)(entry)).toEqual(entry.id);
@@ -1,5 +1,5 @@
1
1
  import * as R from "ramda";
2
- import dayjs from "dayjs";
2
+ import { dayjs } from "../dateUtils";
3
3
  import validateColor from "validate-color";
4
4
 
5
5
  import { transformColorCode as fixColorHexCode } from "@applicaster/zapp-react-native-utils/transform";
@@ -31,6 +31,16 @@ export const getKeyForLabel = (dataKey, customKey) => {
31
31
  return keyToUse.split(".");
32
32
  };
33
33
 
34
+ /**
35
+ * Provides `format` for date formatting. Returns customKey if dataKey is "other", otherwise it returns dataKey.
36
+ * Should consist of valid dayjs tokens - https://day.js.org/docs/en/parse/string-format#list-of-all-available-parsing-tokens
37
+ */
38
+ export const getDataTransformForLabel = (dataKey, customKey) => {
39
+ const keyToUse = dataKey === CUSTOM_KEY ? customKey : dataKey;
40
+
41
+ return keyToUse ?? "DD/MM/YYYY";
42
+ };
43
+
34
44
  /**
35
45
  * This method will return true if the argument passed to it is either empty or nil
36
46
  * The method prevents zero from being evaluated as falsey in an || condition
@@ -505,3 +515,35 @@ export const getImageContainerMarginStyles = ({ value }: { value: any }) => {
505
515
  marginRight: value("image_margin_right"),
506
516
  };
507
517
  };
518
+
519
+ export const isTextLabel = (key: string): boolean =>
520
+ key.includes("text_label_") && key.endsWith("_switch");
521
+
522
+ export const hasTextLabelsEnabled = (
523
+ configuration: Record<string, any>
524
+ ): boolean => {
525
+ const textLabelsKeys = Object.keys(configuration).filter(isTextLabel);
526
+
527
+ const picked = textLabelsKeys.reduce(
528
+ (acc, key) => {
529
+ acc[key] = configuration[key];
530
+
531
+ return acc;
532
+ },
533
+ {} as Record<string, any>
534
+ );
535
+
536
+ const pickedValues = Object.values(picked);
537
+
538
+ return pickedValues.some((value) => {
539
+ if (typeof value === "boolean") {
540
+ return value === true;
541
+ }
542
+
543
+ if (typeof value === "string") {
544
+ return value !== "" && value.toLowerCase() !== "false";
545
+ }
546
+
547
+ return Boolean(value);
548
+ });
549
+ };