@applicaster/zapp-react-native-utils 16.0.0-rc.99 → 17.0.0-alpha.1201533844

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 (156) hide show
  1. package/actionUtils/index.ts +3 -1
  2. package/actionsExecutor/ActionExecutor.ts +2 -2
  3. package/actionsExecutor/ActionExecutorContext.tsx +2 -2
  4. package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
  5. package/actionsExecutor/__tests__/feedDecorator.test.ts +30 -0
  6. package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
  7. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +186 -5
  8. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +72 -0
  10. package/actionsExecutor/actions/appRestart.ts +2 -2
  11. package/actionsExecutor/actions/confirmDialog.ts +2 -2
  12. package/actionsExecutor/actions/dismissBottomSheet.ts +2 -2
  13. package/actionsExecutor/actions/goBack.ts +2 -2
  14. package/actionsExecutor/actions/goHome.ts +2 -2
  15. package/actionsExecutor/actions/navigateToScreen.ts +35 -45
  16. package/actionsExecutor/actions/openBottomSheet.ts +4 -2
  17. package/actionsExecutor/actions/presentScreen.ts +2 -2
  18. package/actionsExecutor/actions/refreshComponent.ts +2 -2
  19. package/actionsExecutor/actions/screenToggleFlag.ts +1 -3
  20. package/actionsExecutor/actions/sendCloudEvent.ts +2 -2
  21. package/actionsExecutor/actions/showAlert.ts +2 -2
  22. package/actionsExecutor/actions/switchLayout.ts +2 -2
  23. package/actionsExecutor/feedDecorator.ts +8 -2
  24. package/actionsExecutor/types.ts +7 -0
  25. package/analyticsUtils/__tests__/playerAnalyticsSafeguard.test.ts +62 -0
  26. package/analyticsUtils/logger.ts +9 -4
  27. package/analyticsUtils/playerAnalyticsTracker.ts +1 -0
  28. package/appUtils/HooksManager/logger.ts +5 -2
  29. package/appUtils/accessibilityManager/logger.ts +2 -4
  30. package/appUtils/accessibilityManager/utils.ts +1 -1
  31. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -22
  32. package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
  33. package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
  34. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +0 -25
  35. package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
  36. package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
  37. package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
  38. package/appUtils/contextKeysManager/index.ts +30 -131
  39. package/appUtils/focusManager/__tests__/focusManager.test.js +33 -0
  40. package/appUtils/focusManager/__tests__/focusToolbox.test.ts +357 -0
  41. package/appUtils/focusManager/focusToolbox.ts +223 -0
  42. package/appUtils/focusManager/index.ios.ts +7 -1
  43. package/appUtils/focusManager/index.ts +3 -3
  44. package/appUtils/focusManager/logger.ts +2 -2
  45. package/appUtils/focusManagerAux/index.ts +2 -2
  46. package/appUtils/orientationHelper.ts +2 -2
  47. package/appUtils/platform/platformUtils.ts +6 -22
  48. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +1 -1
  49. package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
  50. package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
  51. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  52. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
  53. package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
  54. package/appUtils/playerManager/const.ts +13 -0
  55. package/appUtils/playerManager/index.ts +9 -2
  56. package/appUtils/playerManager/player.ts +26 -1
  57. package/appUtils/playerManager/playerNative.ts +23 -1
  58. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  59. package/appUtils/playerManager/playerToolbox.ts +196 -0
  60. package/appUtils/playerManager/usePlayNextOverlay.tsx +2 -2
  61. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
  62. package/appUtils/playerManager/userCellPlayerMutedPreference.ts +1 -1
  63. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  64. package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
  65. package/arrayUtils/index.ts +26 -43
  66. package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
  67. package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
  68. package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
  69. package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
  70. package/cellUtils/index.ts +40 -0
  71. package/cellUtils/logger.ts +2 -2
  72. package/configurationUtils/__tests__/modalBlocksParser.test.ts +134 -0
  73. package/configurationUtils/modalBlocksParser.ts +38 -0
  74. package/domUtils/logger.ts +2 -2
  75. package/entryActions/aliasPresentation.ts +1 -0
  76. package/entryActions/buildEntryActions.ts +1 -1
  77. package/focusManager/FocusManager.ts +35 -2
  78. package/focusManager/__tests__/FocusManager.test.ts +121 -0
  79. package/focusManager/focusToolbox.ts +208 -0
  80. package/focusManager/index.ts +7 -0
  81. package/focusManager/logger.ts +2 -6
  82. package/headersUtils/index.ts +2 -2
  83. package/localizationUtils/index.ts +12 -6
  84. package/logger/__tests__/subsystems.test.ts +148 -0
  85. package/logger/__tests__/xrayToolbox.test.ts +69 -0
  86. package/logger/index.ts +48 -9
  87. package/logger/subsystems.ts +112 -0
  88. package/logger/xrayToolbox.ts +69 -0
  89. package/manifestUtils/__tests__/createConfig.test.js +17 -7
  90. package/manifestUtils/_internals/getDefaultConfiguration.js +9 -11
  91. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  92. package/manifestUtils/keys.js +7 -2
  93. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
  94. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
  95. package/manifestUtils/mobileAction/groups/defaults.js +2 -1
  96. package/modalState/EditableCollectionRegistry.ts +1 -1
  97. package/modalState/ModalOrchestrator.ts +1 -0
  98. package/modalState/RemoteEditableCollection.ts +1 -1
  99. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +23 -0
  100. package/modalState/index.ts +2 -0
  101. package/modalState/types.ts +11 -0
  102. package/navigationUtils/index.ts +5 -2
  103. package/navigationUtils/xrayNavigator.ts +12 -0
  104. package/numberUtils/index.ts +2 -2
  105. package/package.json +3 -2
  106. package/playerUtils/PlayerTTS/PlayerTTS.ts +1 -1
  107. package/playerUtils/imaScriptDom.ts +1 -1
  108. package/playerUtils/useValidatePlayerConfig.tsx +1 -1
  109. package/pluginUtils/logger.ts +2 -2
  110. package/quickBrickAssets/__tests__/index.test.ts +18 -0
  111. package/quickBrickAssets/index.ts +35 -0
  112. package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
  113. package/reactHooks/actions/index.ts +29 -23
  114. package/reactHooks/cell-click/__tests__/index.test.js +67 -1
  115. package/reactHooks/cell-click/index.ts +10 -2
  116. package/reactHooks/connection/index.tsx +8 -5
  117. package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
  118. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
  119. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  120. package/reactHooks/feed/useBuildPipesUrl.ts +5 -2
  121. package/reactHooks/feed/useFeedLoader.tsx +30 -3
  122. package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
  123. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  124. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +5 -2
  125. package/reactHooks/logger.ts +5 -2
  126. package/reactHooks/navigation/usePresentScreen.ts +2 -2
  127. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +2 -2
  128. package/reactHooks/screen/useScreenData.ts +2 -2
  129. package/reactHooks/usePluginConfiguration.ts +84 -46
  130. package/reactHooks/videoModal/hooks/useChangeOrientation.ts +2 -7
  131. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +1 -1
  132. package/reactUtils/__tests__/deviceTargetGuards.test.js +73 -0
  133. package/reactUtils/createContext/helpers.ts +2 -2
  134. package/reactUtils/index.ts +28 -0
  135. package/reactUtils/logger.ts +2 -2
  136. package/riverComponetsMeasurementProvider/index.tsx +5 -5
  137. package/storage/ScreenSingleValueProvider.ts +1 -1
  138. package/storage/ScreenStateMultiSelectProvider.ts +1 -1
  139. package/storage/StorageMultiSelectProvider.ts +1 -1
  140. package/storage/StorageSingleSelectProvider.ts +1 -1
  141. package/stylesUtils/logger.ts +2 -2
  142. package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
  143. package/uiActionsRegistrator/registry.ts +17 -1
  144. package/uiActionsRegistrator/resolveActionIdentifiers.ts +1 -1
  145. package/uiActionsRegistrator/usableActionItems.ts +1 -1
  146. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +2 -1
  147. package/zappFrameworkUtils/loginPluginUtils.ts +2 -1
  148. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -1
  149. package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
  150. package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
  151. package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
  152. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
  153. package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
  154. package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
  155. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
  156. package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
@@ -19,14 +19,6 @@ export const useLoadPipesDataDispatch = () => {
19
19
  (screenData as LegacyNavigationScreenData)?.targetScreen?.id ??
20
20
  screenData?.id;
21
21
 
22
- const onLoadCB = (options) => (data, _err) => {
23
- options?.callback?.();
24
-
25
- if (data) {
26
- applyScreenRouteDefaults(data, screenStateStore, pathname);
27
- }
28
- };
29
-
30
22
  return React.useCallback(
31
23
  (
32
24
  url: string,
@@ -36,6 +28,9 @@ export const useLoadPipesDataDispatch = () => {
36
28
  clearCache?: boolean;
37
29
  silentRefresh?: boolean;
38
30
  parentFeed?: string;
31
+ method?: "get" | "post";
32
+ bodyParams?: Record<string, unknown>;
33
+ loadLocalFavorites?: boolean;
39
34
  } = {},
40
35
  {
41
36
  withResolvers = false,
@@ -46,18 +41,24 @@ export const useLoadPipesDataDispatch = () => {
46
41
  } = {}
47
42
  ) => {
48
43
  if (url) {
49
- dispatch(
44
+ return dispatch(
50
45
  ZappPipes.loadPipesData(url, {
51
46
  riverId,
52
47
  resolvers: withResolvers ? resolvers : undefined,
53
48
  ...options,
54
49
  callback: withScreenRouteMapping
55
- ? onLoadCB(options)
50
+ ? (data, error) => {
51
+ options.callback?.(data, error);
52
+
53
+ if (data) {
54
+ applyScreenRouteDefaults(data, screenStateStore, pathname);
55
+ }
56
+ }
56
57
  : options?.callback,
57
58
  })
58
59
  );
59
60
  }
60
61
  },
61
- []
62
+ [dispatch, riverId, resolvers, screenStateStore, pathname]
62
63
  );
63
64
  };
@@ -3,46 +3,91 @@ import React from "react";
3
3
  import { getDatasourceUrl } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/getDatasourceUrl";
4
4
  import { usePipesContexts } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/usePipesContexts";
5
5
  import { markPipesDataStale } from "@applicaster/zapp-react-native-redux/ZappPipes";
6
-
7
- import { useRoute } from "../navigation";
8
6
  import { useAppDispatch } from "@applicaster/zapp-react-native-redux";
7
+ import { isTrue } from "../../booleanUtils";
8
+ import { refreshCoordinator } from "../../refreshUtils/RefreshCoordinator";
9
+ import { useNavigation, useRoute } from "../navigation";
10
+ import { usePrevious } from "../utils";
11
+
12
+ const getRefreshableComponents = (components: ZappUIComponent[]) =>
13
+ components?.filter(
14
+ (c) => isTrue(c?.rules?.clear_cache_on_reload) && c?.data?.source
15
+ ) || [];
9
16
 
10
17
  /**
11
18
  * Mark a river's `clear_cache_on_reload` feeds as stale when the screen is
12
19
  * unmounted. The cached data is kept (so a screen sharing the same feed does
13
20
  * not lose it mid-mount) and revalidated on next access.
21
+ *
22
+ * Also triggers refresh for mounted components and marks feeds stale when
23
+ * returning back to this screen from a deeper route in the Transitioner
24
+ * (where the screen was kept mounted in the background).
25
+ *
14
26
  * @param {string} riverId screen id
15
27
  * @param {Array} riverComponents list of UI components
16
28
  */
17
- export const useMarkPipesDataStale = (riverId, riverComponents) => {
29
+ export const useMarkPipesDataStale = (
30
+ riverId: string,
31
+ riverComponents: ZappUIComponent[]
32
+ ) => {
18
33
  const dispatch = useAppDispatch();
19
34
  const { screenData, pathname } = useRoute();
20
35
  const pipesContexts = usePipesContexts(riverId, pathname);
36
+ const { currentRoute } = useNavigation();
37
+ const prevRoute = usePrevious(currentRoute);
21
38
 
22
- React.useEffect(() => {
23
- return () => {
24
- riverComponents.forEach((component) => {
25
- if (
26
- component?.rules?.clear_cache_on_reload &&
27
- component?.data?.source &&
28
- // We don't want to refresh cache when closing/minimising videoModal
29
- !pathname.includes("videoModal")
30
- ) {
31
- const url = getDatasourceUrl(
32
- {
33
- screenData,
34
- ...pipesContexts,
35
- },
36
- component
37
- );
38
-
39
- if (url) {
40
- dispatch(markPipesDataStale(url, { riverId }));
41
- }
39
+ const isBackToScreen = Boolean(
40
+ prevRoute && prevRoute !== currentRoute && currentRoute === pathname
41
+ );
42
+
43
+ const invalidateComponents = React.useCallback(
44
+ (components: ZappUIComponent[]) => {
45
+ components.forEach((component) => {
46
+ const url = getDatasourceUrl(
47
+ { screenData, ...pipesContexts },
48
+ component
49
+ );
50
+
51
+ if (url) {
52
+ dispatch(markPipesDataStale(url, { riverId }));
42
53
  }
43
54
  });
55
+ },
56
+ [dispatch, screenData, pipesContexts, riverId]
57
+ );
58
+
59
+ // Stale invalidation on unmount (existing behavior)
60
+ /* eslint-disable @wogns3623/better-exhaustive-deps/exhaustive-deps */
61
+ React.useEffect(() => {
62
+ return () => {
63
+ if (pathname?.includes("videoModal")) return;
64
+
65
+ invalidateComponents(getRefreshableComponents(riverComponents));
44
66
  };
45
67
  }, []);
68
+ /* eslint-enable @wogns3623/better-exhaustive-deps/exhaustive-deps */
69
+
70
+ // Reload when returning back to this screen from another screen
71
+ React.useEffect(() => {
72
+ if (!isBackToScreen || pathname?.includes("videoModal")) {
73
+ return;
74
+ }
75
+
76
+ const refreshable = getRefreshableComponents(riverComponents);
77
+
78
+ if (refreshable.length === 0) {
79
+ return;
80
+ }
81
+
82
+ invalidateComponents(refreshable);
83
+ refreshCoordinator.triggerRefresh(refreshable, riverId);
84
+ }, [
85
+ isBackToScreen,
86
+ pathname,
87
+ riverComponents,
88
+ riverId,
89
+ invalidateComponents,
90
+ ]);
46
91
  };
47
92
 
48
93
  /**
@@ -1,7 +1,10 @@
1
- import { reactHooksLogger } from "../../logger";
2
1
  import { useZappHookModalStore } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
2
+ import { subsystemLogger } from "../../../logger";
3
3
 
4
- const logger = reactHooksLogger.addSubsystem("useHookModalScreenData");
4
+ const logger = subsystemLogger(
5
+ "core/react_hooks/hook_modal",
6
+ "UseHookModalScreenData"
7
+ );
5
8
 
6
9
  type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
7
10
 
@@ -1,3 +1,6 @@
1
- import { utilsLogger } from "../logger";
1
+ import { subsystemLogger } from "../logger";
2
2
 
3
- export const reactHooksLogger = utilsLogger.addSubsystem("reactHooks");
3
+ export const reactHooksLogger = subsystemLogger(
4
+ "core/react_hooks",
5
+ "ReactHooks"
6
+ );
@@ -9,8 +9,8 @@ import { createLogger } from "../../logger";
9
9
  import { useRivers } from "../state";
10
10
 
11
11
  const { log_error, log_info } = createLogger({
12
- subsystem: "usePresentScreen",
13
- category: "General",
12
+ subsystem: "core/react_hooks/present_screen",
13
+ category: "UsePresentScreen",
14
14
  });
15
15
 
16
16
  export interface PresentScreenArgs {
@@ -13,8 +13,8 @@ import {
13
13
 
14
14
  export const { log_warning, log_debug, log_info, log_error, log_verbose } =
15
15
  createLogger({
16
- category: "General",
17
- subsystem: "TVSeekController",
16
+ category: "TVSeekController",
17
+ subsystem: "player/seek",
18
18
  });
19
19
 
20
20
  export enum SEEK_STRATEGY {
@@ -1,8 +1,8 @@
1
- import { utilsLogger } from "../../logger";
2
1
  import React from "react";
3
2
  import { useRivers } from "../state";
3
+ import { subsystemLogger } from "../../logger";
4
4
 
5
- const logger = utilsLogger.addSubsystem("useScreenData");
5
+ const logger = subsystemLogger("core/react_hooks/screen_data", "UseScreenData");
6
6
 
7
7
  export const useScreenData = (screenId: string): ZappRiver => {
8
8
  const rivers = useRivers();
@@ -1,4 +1,3 @@
1
- import * as R from "ramda";
2
1
  import { useMemo } from "react";
3
2
 
4
3
  import { usePlugins } from "@applicaster/zapp-react-native-redux/hooks";
@@ -6,7 +5,8 @@ import { usePlugins } from "@applicaster/zapp-react-native-redux/hooks";
6
5
  // importing this way prevents typescript packages importing from this
7
6
  // file to go crazy reporting errors on JS
8
7
  import { populateConfigurationValues } from "@applicaster/zapp-react-native-utils/configurationUtils";
9
- import { useLocalizedStrings } from "../localizationUtils";
8
+ import { getLocalizedStrings, useLocalizedStrings } from "../localizationUtils";
9
+ import { isNil, pathOr } from "../utils";
10
10
 
11
11
  const populateFields = (
12
12
  data,
@@ -14,16 +14,72 @@ const populateFields = (
14
14
  pathToValues: string | string[] = "configuration",
15
15
  skipDefaults = false
16
16
  ) =>
17
- R.compose(
18
- (config) =>
19
- populateConfigurationValues(manifestFields, config, skipDefaults),
20
- R.pathOr({}, R.unless(Array.isArray, Array)(pathToValues))
21
- )(data);
17
+ populateConfigurationValues(
18
+ manifestFields,
19
+ pathOr({}, pathToValues, data),
20
+ skipDefaults
21
+ );
22
22
 
23
23
  export function parsePluginConfiguration(plugin, manifest) {
24
24
  return populateFields(plugin, manifest.custom_configuration_fields);
25
25
  }
26
26
 
27
+ const getDefaultLocalizations = (manifest) =>
28
+ manifest?.localizations?.fields?.reduce(
29
+ (defaults, { key, initial_value }) => ({
30
+ en: { ...defaults.en, [key]: initial_value },
31
+ }),
32
+ { en: {} }
33
+ ) || {};
34
+
35
+ const isPlainObject = (value) =>
36
+ Object.prototype.toString.call(value) === "[object Object]";
37
+
38
+ // Deep merge where configured values win, except nil ones (defaults fill the gaps)
39
+ export const mergeLocalizations = (configured, defaults) => {
40
+ if (!isPlainObject(configured)) return { ...defaults };
41
+ if (!isPlainObject(defaults)) return { ...configured };
42
+
43
+ // Configured keys first, as R.mergeDeepWith: the first language is the fallback
44
+ return Object.keys({ ...configured, ...defaults }).reduce((merged, key) => {
45
+ const left = configured[key];
46
+ const right = defaults[key];
47
+
48
+ if (!(key in defaults)) {
49
+ merged[key] = left;
50
+ } else if (!(key in configured)) {
51
+ merged[key] = right;
52
+ } else if (isPlainObject(left) && isPlainObject(right)) {
53
+ merged[key] = mergeLocalizations(left, right);
54
+ } else {
55
+ merged[key] = isNil(left) ? right : left;
56
+ }
57
+
58
+ return merged;
59
+ }, {});
60
+ };
61
+
62
+ /**
63
+ * usePluginConfiguration outside React: the same result, read once instead of subscribed.
64
+ */
65
+ export function getPluginConfiguration<T = any, S = Record<string, any>>(
66
+ plugin,
67
+ manifest?: any
68
+ ): { configurationFields: T; localizations: S } {
69
+ return {
70
+ configurationFields: populateFields(
71
+ plugin,
72
+ manifest?.custom_configuration_fields
73
+ ),
74
+ localizations: getLocalizedStrings(
75
+ mergeLocalizations(
76
+ plugin?.configuration?.localizations,
77
+ getDefaultLocalizations(manifest)
78
+ )
79
+ ),
80
+ };
81
+ }
82
+
27
83
  export function usePluginConfiguration<T = any, S = Record<string, any>>(
28
84
  identifier: string,
29
85
  manifest?: any
@@ -31,7 +87,7 @@ export function usePluginConfiguration<T = any, S = Record<string, any>>(
31
87
  const plugins = usePlugins();
32
88
 
33
89
  const plugin = useMemo(
34
- () => R.find(R.propEq("identifier", identifier), plugins),
90
+ () => plugins?.find((item) => item?.identifier === identifier),
35
91
  [plugins, identifier]
36
92
  );
37
93
 
@@ -40,29 +96,20 @@ export function usePluginConfiguration<T = any, S = Record<string, any>>(
40
96
  [plugin, manifest]
41
97
  );
42
98
 
43
- const defaultLocalizations = useMemo(() => {
44
- return (
45
- manifest?.localizations?.fields?.reduce(
46
- (defaults, { key, initial_value }) =>
47
- R.assocPath(["en", key], initial_value, defaults),
48
- { en: {} }
49
- ) || {}
50
- );
51
- }, [manifest]);
52
-
53
- const localizationsParams = useMemo(() => {
54
- return {
55
- localizations: R.mergeDeepWith(
56
- (left, right) => {
57
- if (R.isNil(left)) return right;
99
+ const defaultLocalizations = useMemo(
100
+ () => getDefaultLocalizations(manifest),
101
+ [manifest]
102
+ );
58
103
 
59
- return left;
60
- },
104
+ const localizationsParams = useMemo(
105
+ () => ({
106
+ localizations: mergeLocalizations(
61
107
  plugin?.configuration?.localizations,
62
108
  defaultLocalizations
63
109
  ),
64
- };
65
- }, [plugin?.configuration?.localizations, defaultLocalizations]);
110
+ }),
111
+ [plugin?.configuration?.localizations, defaultLocalizations]
112
+ );
66
113
 
67
114
  const localizations: S = useLocalizedStrings(localizationsParams);
68
115
 
@@ -105,29 +152,20 @@ export function useLayoutConfiguration<
105
152
  "localizations",
106
153
  ];
107
154
 
108
- const defaultLocalizations = useMemo(() => {
109
- return (
110
- manifest?.localizations?.fields?.reduce(
111
- (defaults, { key, initial_value }) =>
112
- R.assocPath(["en", key], initial_value, defaults),
113
- { en: {} }
114
- ) || {}
115
- );
116
- }, [manifest]);
117
-
118
- const localizationsParams = useMemo(() => {
119
- return {
120
- localizations: R.mergeDeepWith(
121
- (left, right) => {
122
- if (R.isNil(left)) return right;
155
+ const defaultLocalizations = useMemo(
156
+ () => getDefaultLocalizations(manifest),
157
+ [manifest]
158
+ );
123
159
 
124
- return left;
125
- },
160
+ const localizationsParams = useMemo(
161
+ () => ({
162
+ localizations: mergeLocalizations(
126
163
  layoutData?.localizations,
127
164
  defaultLocalizations
128
165
  ),
129
- };
130
- }, [layoutData?.localizations, defaultLocalizations]);
166
+ }),
167
+ [layoutData?.localizations, defaultLocalizations]
168
+ );
131
169
 
132
170
  // Always call useLocalizedStrings regardless of whether localizations is in the keys
133
171
  const localizations: L = useLocalizedStrings(localizationsParams);
@@ -9,9 +9,7 @@ import {
9
9
 
10
10
  import { skipIf, shouldHandleOrientationChange } from "../utils";
11
11
 
12
- import { getXray } from "@applicaster/zapp-react-native-utils/logger";
13
- const { Logger } = getXray();
14
-
12
+ import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
15
13
  type Props = {
16
14
  isPortrait: boolean;
17
15
  onTransitToPortrait: () => void;
@@ -20,10 +18,7 @@ type Props = {
20
18
  docked: boolean;
21
19
  };
22
20
 
23
- export const logger = new Logger(
24
- "hooks",
25
- "zapp-react-native-utils/reactHooks/videoModal"
26
- );
21
+ export const logger = subsystemLogger("player/modal", "hooks");
27
22
 
28
23
  export const useChangeOrientation = ({
29
24
  isPortrait,
@@ -5,7 +5,7 @@ import { useRivers } from "../../state";
5
5
  import { createLogger } from "../../../logger";
6
6
 
7
7
  const { log_warning } = createLogger({
8
- subsystem: "zapp-react-native-utils/reactHooks/videoModal",
8
+ subsystem: "player/modal",
9
9
  category: "useVideoModalScreenData",
10
10
  });
11
11
 
@@ -0,0 +1,73 @@
1
+ import {
2
+ isLgPlatform,
3
+ isSamsungPlatform,
4
+ isVizioPlatform,
5
+ } from "@applicaster/zapp-react-native-utils/reactUtils";
6
+
7
+ const UA = {
8
+ lg: "Mozilla/5.0 (Web0S; Linux/SmartTV) AppleWebKit/537.36 Chrome/87.0",
9
+ samsung: "Mozilla/5.0 (SMART-TV; Linux; Tizen 6.0) AppleWebKit/537.36",
10
+ vizio: "Mozilla/5.0 (X11; Linux) Chrome/76.0 VIZIO SmartCast Conjure/MTK",
11
+ desktop: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) Chrome/120.0",
12
+ };
13
+
14
+ const originalNavigator = window.navigator;
15
+
16
+ const setUserAgent = (userAgent) => {
17
+ Object.defineProperty(window, "navigator", {
18
+ value: { userAgent },
19
+ configurable: true,
20
+ });
21
+ };
22
+
23
+ describe("web TV device checks and the build-time device target", () => {
24
+ afterEach(() => {
25
+ delete process.env.QUICK_BRICK_DEVICE_TARGET;
26
+
27
+ Object.defineProperty(window, "navigator", {
28
+ value: originalNavigator,
29
+ configurable: true,
30
+ });
31
+ });
32
+
33
+ it("detects every TV at runtime when no device target is set", () => {
34
+ setUserAgent(UA.lg);
35
+ expect(isLgPlatform()).toBe(true);
36
+
37
+ setUserAgent(UA.samsung);
38
+ expect(isSamsungPlatform()).toBe(true);
39
+
40
+ setUserAgent(UA.vizio);
41
+ expect(isVizioPlatform()).toBe(true);
42
+ });
43
+
44
+ it("rejects other TVs on a Samsung build, whatever the user agent", () => {
45
+ process.env.QUICK_BRICK_DEVICE_TARGET = "samsung_tv";
46
+
47
+ setUserAgent(UA.lg);
48
+ expect(isLgPlatform()).toBe(false);
49
+
50
+ setUserAgent(UA.vizio);
51
+ expect(isVizioPlatform()).toBe(false);
52
+ });
53
+
54
+ it("still checks its own TV at runtime, so a desktop browser is not the TV", () => {
55
+ process.env.QUICK_BRICK_DEVICE_TARGET = "samsung_tv";
56
+
57
+ setUserAgent(UA.samsung);
58
+ expect(isSamsungPlatform()).toBe(true);
59
+
60
+ setUserAgent(UA.desktop);
61
+ expect(isSamsungPlatform()).toBe(false);
62
+ });
63
+
64
+ it("keeps a Vizio build's identity separate from LG", () => {
65
+ process.env.QUICK_BRICK_DEVICE_TARGET = "vizio";
66
+
67
+ setUserAgent(UA.lg);
68
+ expect(isLgPlatform()).toBe(false);
69
+
70
+ setUserAgent(UA.vizio);
71
+ expect(isVizioPlatform()).toBe(true);
72
+ });
73
+ });
@@ -1,9 +1,9 @@
1
1
  import * as R from "ramda";
2
2
  import { capitalize } from "../../stringUtils";
3
3
 
4
- import { reactUtilsLogger } from "../logger";
4
+ import { subsystemLogger } from "../../logger";
5
5
 
6
- const logger = reactUtilsLogger.addSubsystem("CreateContext");
6
+ const logger = subsystemLogger("core/react/create_context", "CreateContext");
7
7
 
8
8
  const SETTER_PREFIX = "set";
9
9
 
@@ -129,7 +129,21 @@ export const hasWebOS = typeof window?.webOS !== "undefined";
129
129
 
130
130
  export const getUserAgent = () => window?.navigator?.userAgent;
131
131
 
132
+ /**
133
+ * Web TV device checks return false outright when the bundle was built for another
134
+ * TV: the web template inlines `process.env.QUICK_BRICK_DEVICE_TARGET` (Zapp
135
+ * `device_target`), so the guard and the code after it fold away at build time.
136
+ * A build for this TV still checks at runtime, because the same bundle also runs
137
+ * in a desktop browser.
138
+ */
132
139
  export const isLgPlatform = () => {
140
+ if (
141
+ process.env.QUICK_BRICK_DEVICE_TARGET &&
142
+ process.env.QUICK_BRICK_DEVICE_TARGET !== "lg_tv"
143
+ ) {
144
+ return false;
145
+ }
146
+
133
147
  const userAgent = getUserAgent();
134
148
 
135
149
  if (!userAgent) {
@@ -141,6 +155,13 @@ export const isLgPlatform = () => {
141
155
  };
142
156
 
143
157
  export const isSamsungPlatform = () => {
158
+ if (
159
+ process.env.QUICK_BRICK_DEVICE_TARGET &&
160
+ process.env.QUICK_BRICK_DEVICE_TARGET !== "samsung_tv"
161
+ ) {
162
+ return false;
163
+ }
164
+
144
165
  const userAgent = getUserAgent();
145
166
 
146
167
  if (!userAgent) {
@@ -161,6 +182,13 @@ export const isSamsungPlatform = () => {
161
182
  * before the VIZIO Companion Library has loaded
162
183
  */
163
184
  export const isVizioPlatform = () => {
185
+ if (
186
+ process.env.QUICK_BRICK_DEVICE_TARGET &&
187
+ process.env.QUICK_BRICK_DEVICE_TARGET !== "vizio"
188
+ ) {
189
+ return false;
190
+ }
191
+
164
192
  const userAgent = getUserAgent();
165
193
 
166
194
  if (!userAgent) {
@@ -1,3 +1,3 @@
1
- import { utilsLogger } from "../logger";
1
+ import { subsystemLogger } from "../logger";
2
2
 
3
- export const reactUtilsLogger = utilsLogger.addSubsystem("reactUtils");
3
+ export const reactUtilsLogger = subsystemLogger("core/react", "ReactUtils");
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { NativeModules, View, StyleSheet } from "react-native";
3
- import { getXray } from "@applicaster/zapp-react-native-utils/logger";
3
+ import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
4
4
 
5
5
  import { isApplePlatform, isWeb, isTV } from "../reactUtils";
6
6
  import { useRivers } from "../reactHooks";
@@ -34,15 +34,14 @@ type Props = {
34
34
  type ItemProps = {
35
35
  children: React.ReactNode;
36
36
  index: number;
37
+ testID?: string;
37
38
  };
38
39
 
39
40
  type MeasurementContext = {
40
41
  onLayout: (index: number) => (event) => void;
41
42
  };
42
43
 
43
- const { Logger } = getXray();
44
-
45
- const logger = new Logger("general", "ui");
44
+ const logger = subsystemLogger("ui/river", "general");
46
45
 
47
46
  let notified = false;
48
47
 
@@ -153,11 +152,12 @@ export const ScreenLoadingMeasurements = ({
153
152
  export const ScreenLoadingMeasurementsListItemWrapper = ({
154
153
  children,
155
154
  index,
155
+ testID,
156
156
  }: ItemProps) => {
157
157
  const { onLayout } = React.useContext(MeasurementsSettersContext);
158
158
 
159
159
  return (
160
- <View style={styles.container} onLayout={onLayout?.(index)}>
160
+ <View style={styles.container} onLayout={onLayout?.(index)} testID={testID}>
161
161
  {children}
162
162
  </View>
163
163
  );
@@ -6,7 +6,7 @@ import { useScreenStateStore } from "../reactHooks/navigation/useScreenStateStor
6
6
 
7
7
  export const { log_debug, log_error } = createLogger({
8
8
  category: "ScreenSingleValueProvider",
9
- subsystem: "zapp-react-native-bridge",
9
+ subsystem: "storage/native",
10
10
  parent: bridgeLogger,
11
11
  });
12
12
 
@@ -6,7 +6,7 @@ import { useScreenStateStore } from "../reactHooks/navigation/useScreenStateStor
6
6
 
7
7
  export const { log_debug, log_error } = createLogger({
8
8
  category: "ScreenMultiSelectProvider",
9
- subsystem: "zapp-react-native-bridge",
9
+ subsystem: "storage/native",
10
10
  parent: bridgeLogger,
11
11
  });
12
12
 
@@ -10,7 +10,7 @@ import { createLogger } from "../logger";
10
10
  export const { log_verbose, log_debug, log_warning, log_info, log_error } =
11
11
  createLogger({
12
12
  category: "StorageMultiSelectProvider",
13
- subsystem: "zapp-react-native-bridge",
13
+ subsystem: "storage/native",
14
14
  parent: bridgeLogger,
15
15
  });
16
16
 
@@ -7,7 +7,7 @@ import { createLogger } from "../logger";
7
7
  export const { log_verbose, log_debug, log_warning, log_info, log_error } =
8
8
  createLogger({
9
9
  category: "StorageSingleValueProvider",
10
- subsystem: "zapp-react-native-bridge",
10
+ subsystem: "storage/native",
11
11
  parent: bridgeLogger,
12
12
  });
13
13
 
@@ -1,3 +1,3 @@
1
- import { utilsLogger } from "../logger";
1
+ import { subsystemLogger } from "../logger";
2
2
 
3
- export const stylesUtilsLogger = utilsLogger.addSubsystem("stylesUtils");
3
+ export const stylesUtilsLogger = subsystemLogger("ui/styles", "StylesUtils");