@applicaster/zapp-react-native-utils 16.0.0-alpha.2663208063 → 16.0.0-alpha.2710214351
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.
- package/actionUtils/index.ts +3 -1
- package/actionsExecutor/ActionExecutor.ts +10 -1
- package/actionsExecutor/ActionExecutorContext.tsx +29 -1
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +91 -0
- package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +267 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +273 -1
- package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
- package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
- package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +8 -0
- package/actionsExecutor/actions/navigateToScreen.ts +43 -45
- package/actionsExecutor/actions/openBottomSheet.ts +36 -16
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +1 -3
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +2 -2
- package/actionsExecutor/consts.ts +4 -0
- package/actionsExecutor/feedDecorator.ts +12 -6
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -22
- package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
- package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +0 -25
- package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
- package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
- package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
- package/appUtils/contextKeysManager/index.ts +28 -129
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +4 -11
- package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +9 -2
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -1
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -1
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +21 -2
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -1
- package/appUtils/playerManager/OverlayObserver/utils.ts +9 -7
- package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
- package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
- package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
- package/appUtils/playerManager/const.ts +13 -0
- package/appUtils/playerManager/index.ts +7 -0
- package/appUtils/playerManager/player.ts +25 -0
- package/appUtils/playerManager/playerNative.ts +27 -3
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/appUtils/playerManager/playerToolbox.ts +196 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
- package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
- package/arrayUtils/index.ts +26 -43
- package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
- package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
- package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
- package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
- package/cellUtils/index.ts +70 -3
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +297 -1
- package/configurationUtils/manifestKeyParser.ts +12 -1
- package/configurationUtils/modalBlocksParser.ts +78 -4
- package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
- package/entryActions/aliasPresentation.ts +108 -0
- package/entryActions/buildEntryActions.ts +167 -0
- package/entryActions/index.ts +15 -0
- package/entryActions/types.ts +39 -0
- package/focusManager/FocusManager.ts +26 -0
- package/focusManager/__tests__/FocusManager.test.ts +9 -0
- package/localizationUtils/index.ts +12 -6
- package/logger/__tests__/xrayToolbox.test.ts +69 -0
- package/logger/xrayToolbox.ts +67 -0
- package/manifestUtils/_internals/index.js +8 -3
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +30 -1
- package/manifestUtils/keys.js +7 -2
- package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
- package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
- package/manifestUtils/mobileAction/groups/defaults.js +2 -1
- package/modalState/ModalOrchestrator.ts +23 -9
- package/modalState/RemoteEditableCollection.ts +9 -1
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +39 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
- package/modalState/__tests__/index.test.ts +30 -1
- package/modalState/__tests__/useModalStoreState.test.ts +142 -0
- package/modalState/index.ts +8 -1
- package/modalState/store.ts +9 -2
- package/modalState/types.ts +42 -2
- package/modalState/useBottomSheetContent.ts +24 -17
- package/navigationUtils/xrayNavigator.ts +12 -0
- package/package.json +3 -2
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/index.ts +17 -1
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/quickBrickAssets/__tests__/index.test.ts +18 -0
- package/quickBrickAssets/index.ts +35 -0
- package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
- package/reactHooks/actions/index.ts +74 -3
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +21 -14
- package/reactHooks/connection/index.tsx +8 -5
- package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
- package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
- package/reactHooks/feed/useFeedLoader.tsx +28 -1
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
- package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
- package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
- package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
- package/reactHooks/navigation/index.ts +2 -0
- package/reactHooks/navigation/usePresentScreen.ts +157 -0
- package/reactHooks/navigation/useRoute.ts +22 -5
- package/reactHooks/usePluginConfiguration.ts +84 -46
- package/riverComponetsMeasurementProvider/index.tsx +3 -1
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -203
- package/uiActionsRegistrator/registry.ts +351 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
- package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The Jest stand-in for @applicaster/quick-brick-assets maps each existing key to itself
|
|
2
|
+
import { getQuickBrickAsset } from "..";
|
|
3
|
+
|
|
4
|
+
describe("getQuickBrickAsset", () => {
|
|
5
|
+
it("returns the asset for a plugin identifier and path", () => {
|
|
6
|
+
expect(
|
|
7
|
+
getQuickBrickAsset("mute_unmute_action", "action/flavour_1/mute.png")
|
|
8
|
+
).toBe("mute_unmute_action/action/flavour_1/mute.png");
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("rejects unknown paths and plugin identifiers at compile time", () => {
|
|
12
|
+
// @ts-expect-error - no such file in mute_unmute_action
|
|
13
|
+
getQuickBrickAsset("mute_unmute_action", "action/flavour_9/mute.png");
|
|
14
|
+
|
|
15
|
+
// @ts-expect-error - no assets folder for this plugin
|
|
16
|
+
getQuickBrickAsset("unknown_plugin", "action/flavour_1/mute.png");
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import assets from "@applicaster/quick-brick-assets";
|
|
2
|
+
import type {
|
|
3
|
+
QuickBrickAssetKey,
|
|
4
|
+
QuickBrickAssetSource,
|
|
5
|
+
} from "@applicaster/quick-brick-assets";
|
|
6
|
+
|
|
7
|
+
export type { QuickBrickAssetKey, QuickBrickAssetSource };
|
|
8
|
+
|
|
9
|
+
type PluginOf<K> = K extends `${infer Plugin}/${string}` ? Plugin : never;
|
|
10
|
+
|
|
11
|
+
type PathOf<K, Plugin extends string> = K extends `${Plugin}/${infer Path}`
|
|
12
|
+
? Path
|
|
13
|
+
: never;
|
|
14
|
+
|
|
15
|
+
/** Plugin identifiers that have a folder in `@applicaster/quick-brick-assets`. */
|
|
16
|
+
export type QuickBrickAssetPlugin = PluginOf<QuickBrickAssetKey>;
|
|
17
|
+
|
|
18
|
+
/** Asset paths inside the given plugin's folder. */
|
|
19
|
+
export type QuickBrickAssetPath<Plugin extends QuickBrickAssetPlugin> = PathOf<
|
|
20
|
+
QuickBrickAssetKey,
|
|
21
|
+
Plugin
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Looks up an asset of `@applicaster/quick-brick-assets` by plugin identifier
|
|
26
|
+
* and path relative to the plugin folder, e.g.
|
|
27
|
+
* `getQuickBrickAsset("mute_unmute_action", "action/flavour_1/mute.png")`.
|
|
28
|
+
* Both arguments are checked against the package's files at compile time.
|
|
29
|
+
* Density variants (`@2x` / `@3x`) are not supported.
|
|
30
|
+
*/
|
|
31
|
+
export const getQuickBrickAsset = <Plugin extends QuickBrickAssetPlugin>(
|
|
32
|
+
pluginIdentifier: Plugin,
|
|
33
|
+
assetPath: QuickBrickAssetPath<Plugin>
|
|
34
|
+
): QuickBrickAssetSource =>
|
|
35
|
+
assets[`${pluginIdentifier}/${assetPath}` as QuickBrickAssetKey];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-native";
|
|
2
|
+
|
|
3
|
+
const plugin = {
|
|
4
|
+
identifier: "cast",
|
|
5
|
+
configuration: {
|
|
6
|
+
title: "Configured",
|
|
7
|
+
localizations: { fr: { close: "Fermer" } },
|
|
8
|
+
},
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
jest.mock("@applicaster/zapp-react-native-redux/hooks", () => ({
|
|
12
|
+
usePlugins: () => [plugin],
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock(
|
|
16
|
+
"@applicaster/zapp-react-native-utils/appUtils/localizationsHelper",
|
|
17
|
+
() => ({ getUILanguage: () => "fr" })
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
getPluginConfiguration,
|
|
22
|
+
mergeLocalizations,
|
|
23
|
+
usePluginConfiguration,
|
|
24
|
+
} from "../usePluginConfiguration";
|
|
25
|
+
|
|
26
|
+
const manifest = {
|
|
27
|
+
custom_configuration_fields: [
|
|
28
|
+
{ key: "title", initial_value: "Default" },
|
|
29
|
+
{ key: "color", initial_value: "red" },
|
|
30
|
+
],
|
|
31
|
+
localizations: {
|
|
32
|
+
fields: [
|
|
33
|
+
{ key: "close", initial_value: "Close" },
|
|
34
|
+
{ key: "cancel", initial_value: "Cancel" },
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
it("matches usePluginConfiguration outside React", () => {
|
|
40
|
+
const { result } = renderHook(() => usePluginConfiguration("cast", manifest));
|
|
41
|
+
|
|
42
|
+
expect(getPluginConfiguration(plugin, manifest)).toEqual(result.current);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Expected values are what R.mergeDeepWith((l, r) => (isNil(l) ? r : l)) returned before ramda was removed
|
|
46
|
+
describe("mergeLocalizations", () => {
|
|
47
|
+
const defaults = { en: { close: "Close", cancel: "Cancel" } };
|
|
48
|
+
|
|
49
|
+
it("returns the defaults when nothing is configured", () => {
|
|
50
|
+
expect(mergeLocalizations(undefined, defaults)).toEqual(defaults);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("keeps configured values, fills nil ones and missing keys from defaults", () => {
|
|
54
|
+
expect(
|
|
55
|
+
mergeLocalizations(
|
|
56
|
+
{ en: { close: null, extra: "X" }, fr: { close: "Fermer" } },
|
|
57
|
+
defaults
|
|
58
|
+
)
|
|
59
|
+
).toEqual({
|
|
60
|
+
en: { close: "Close", extra: "X", cancel: "Cancel" },
|
|
61
|
+
fr: { close: "Fermer" },
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("does not merge arrays", () => {
|
|
66
|
+
expect(
|
|
67
|
+
mergeLocalizations(
|
|
68
|
+
{ en: { close: ["a"] } },
|
|
69
|
+
{ en: { close: ["b"], cancel: "C" } }
|
|
70
|
+
)
|
|
71
|
+
).toEqual({ en: { close: ["a"], cancel: "C" } });
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("keeps configured languages first, so the fallback language stays the configured one", () => {
|
|
76
|
+
const merged = mergeLocalizations(
|
|
77
|
+
{ he: { close: "סגור" }, en: { close: "Close it" } },
|
|
78
|
+
{ en: { close: "Close" } }
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
expect(Object.keys(merged)).toEqual(["he", "en"]);
|
|
82
|
+
});
|
|
@@ -6,6 +6,7 @@ import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Con
|
|
|
6
6
|
import {
|
|
7
7
|
observeEntryState,
|
|
8
8
|
RegisteredActionValue,
|
|
9
|
+
uiActionsRegistry,
|
|
9
10
|
} from "../../uiActionsRegistrator";
|
|
10
11
|
import { reactHooksLogger } from "../logger";
|
|
11
12
|
|
|
@@ -20,21 +21,55 @@ type ActionContexts<T = unknown> = {
|
|
|
20
21
|
};
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
|
-
*
|
|
24
|
+
* A value that changes whenever a provider is added to or removed from
|
|
25
|
+
* `uiActionsRegistry`.
|
|
26
|
+
*
|
|
27
|
+
* Providers can register after the UI that wants them has rendered - the audio
|
|
28
|
+
* player registers playback speed only once its controller has state, and
|
|
29
|
+
* plugin-backed actions are bridged in from an effect. Put this in the
|
|
30
|
+
* dependency list of anything that resolves actions, so the list is re-read
|
|
31
|
+
* instead of being frozen at first paint.
|
|
32
|
+
*/
|
|
33
|
+
export function useRegistryRevision(): number {
|
|
34
|
+
const [revision, setRevision] = useState(0);
|
|
35
|
+
|
|
36
|
+
useEffect(
|
|
37
|
+
() =>
|
|
38
|
+
uiActionsRegistry.subscribe(() => setRevision((current) => current + 1)),
|
|
39
|
+
[]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return revision;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Resolves a legacy action context or falls back to the UI action registry.
|
|
24
47
|
* @param {*} plugId - subscribes to the context of that action plugin
|
|
25
48
|
* @return {*} - global action provider context or context for specific action plugin
|
|
26
49
|
*/
|
|
27
50
|
export function useActions<T = unknown>(plugId: string): any {
|
|
28
51
|
const [logged, setLogged] = useState(false);
|
|
29
52
|
const context = useContext<ActionContexts<T>>(ActionsContext);
|
|
53
|
+
useRegistryRevision();
|
|
54
|
+
|
|
30
55
|
const actionContext = context?.actions?.[plugId]?.module?.context;
|
|
31
56
|
|
|
32
57
|
if (plugId) {
|
|
33
58
|
if (!actionContext) {
|
|
59
|
+
const registeredAction = uiActionsRegistry.getAction(plugId);
|
|
60
|
+
|
|
61
|
+
if (registeredAction) return registeredAction;
|
|
62
|
+
|
|
34
63
|
if (!logged) {
|
|
35
64
|
logger.warning({
|
|
36
65
|
message: `useActions: Couldn't find an action for ${plugId} plugin`,
|
|
37
|
-
|
|
66
|
+
// Identifiers only. The action map holds every plugin's module and
|
|
67
|
+
// live React context, which is far too large for a log line and can
|
|
68
|
+
// carry whatever state those plugins hold.
|
|
69
|
+
data: {
|
|
70
|
+
plugId,
|
|
71
|
+
availableActions: Object.keys(context?.actions ?? {}),
|
|
72
|
+
},
|
|
38
73
|
});
|
|
39
74
|
|
|
40
75
|
setLogged(true);
|
|
@@ -80,7 +115,31 @@ export function useEntryActionState(
|
|
|
80
115
|
useEffect(() => {
|
|
81
116
|
if (!action) return undefined;
|
|
82
117
|
|
|
83
|
-
|
|
118
|
+
// An action's stream is third-party code. Subscribing with only a `next`
|
|
119
|
+
// handler lets RxJS rethrow an error notification asynchronously, where no
|
|
120
|
+
// error boundary catches it - one plugin faulting would take the app down
|
|
121
|
+
// rather than this one button. The button keeps its last known state.
|
|
122
|
+
let subscription;
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
subscription = observeEntryState(action, entry).subscribe({
|
|
126
|
+
next: setState,
|
|
127
|
+
error: (error) =>
|
|
128
|
+
logger.warning({
|
|
129
|
+
message:
|
|
130
|
+
"useEntryActionState: the action's state stream failed - the button keeps its last state",
|
|
131
|
+
data: { entryId, error },
|
|
132
|
+
}),
|
|
133
|
+
});
|
|
134
|
+
} catch (error) {
|
|
135
|
+
logger.warning({
|
|
136
|
+
message:
|
|
137
|
+
"useEntryActionState: could not observe the action - the button keeps its initial state",
|
|
138
|
+
data: { entryId, error },
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
84
143
|
|
|
85
144
|
return () => subscription.unsubscribe();
|
|
86
145
|
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
@@ -88,6 +147,18 @@ export function useEntryActionState(
|
|
|
88
147
|
|
|
89
148
|
const invokeAction = useCallback(
|
|
90
149
|
(options: InvokeArgsOptions = {}) => {
|
|
150
|
+
if (typeof action?.invokeAction !== "function") {
|
|
151
|
+
// A button was rendered and pressed, and the press goes nowhere. Only
|
|
152
|
+
// reachable on a user interaction, so it costs nothing on render. The
|
|
153
|
+
// action value carries no identifier, so the label is what locates the
|
|
154
|
+
// button that misbehaved.
|
|
155
|
+
logger.warning({
|
|
156
|
+
message:
|
|
157
|
+
"useEntryActionState: the pressed action has no invokeAction - the press did nothing",
|
|
158
|
+
data: { entryId, label: state?.label },
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
91
162
|
action?.invokeAction?.(entry, { updateState: setState, ...options });
|
|
92
163
|
},
|
|
93
164
|
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
@@ -5,6 +5,7 @@ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/acti
|
|
|
5
5
|
|
|
6
6
|
const mockNavigator = {
|
|
7
7
|
getPathname: () => "pathnameMock",
|
|
8
|
+
currentRoute: "pathnameMock",
|
|
8
9
|
push: jest.fn(),
|
|
9
10
|
data: {},
|
|
10
11
|
};
|
|
@@ -29,6 +30,7 @@ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
|
|
|
29
30
|
),
|
|
30
31
|
useTargetScreenData: jest.fn(() => ({})),
|
|
31
32
|
useCurrentScreenData: jest.fn(() => ({})),
|
|
33
|
+
useScreenContext: jest.fn(() => ({})),
|
|
32
34
|
}));
|
|
33
35
|
|
|
34
36
|
jest.mock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
@@ -66,6 +68,12 @@ const wrapper = ({ children }) => (
|
|
|
66
68
|
</CellTapContext.Provider>
|
|
67
69
|
);
|
|
68
70
|
|
|
71
|
+
const actionExecutorWrapper = ({ children }) => (
|
|
72
|
+
<ActionExecutorContext.Provider value={actionExecutor}>
|
|
73
|
+
{children}
|
|
74
|
+
</ActionExecutorContext.Provider>
|
|
75
|
+
);
|
|
76
|
+
|
|
69
77
|
describe("useCellClick", () => {
|
|
70
78
|
it("returns a function", () => {
|
|
71
79
|
const { result } = renderHook(() => useCellClick(mockProps));
|
|
@@ -95,4 +103,60 @@ describe("useCellClick", () => {
|
|
|
95
103
|
|
|
96
104
|
cleanup();
|
|
97
105
|
});
|
|
106
|
+
|
|
107
|
+
it("does not push when the cell finishes a hook", async () => {
|
|
108
|
+
mockNavigator.push.mockClear();
|
|
109
|
+
|
|
110
|
+
const item = {
|
|
111
|
+
id: "profile-1",
|
|
112
|
+
type: { value: "feed" },
|
|
113
|
+
extensions: {
|
|
114
|
+
tap_actions: {
|
|
115
|
+
actions: [
|
|
116
|
+
{ type: "sessionStorageSet" },
|
|
117
|
+
{ type: "finishHook", options: { success: true } },
|
|
118
|
+
],
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const { result } = renderHook(() => useCellClick({ item }), {
|
|
124
|
+
wrapper: actionExecutorWrapper,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await result.current();
|
|
128
|
+
|
|
129
|
+
await waitFor(() => {
|
|
130
|
+
expect(actionExecutor.handleEntryActions).toHaveBeenCalled();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
expect(mockNavigator.push).not.toHaveBeenCalled();
|
|
134
|
+
cleanup();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("pushes after tap actions that do not finish a hook", async () => {
|
|
138
|
+
mockNavigator.push.mockClear();
|
|
139
|
+
|
|
140
|
+
const item = {
|
|
141
|
+
id: "episode-1",
|
|
142
|
+
type: { value: "feed" },
|
|
143
|
+
extensions: {
|
|
144
|
+
tap_actions: {
|
|
145
|
+
actions: [{ type: "sessionStorageSet" }],
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const { result } = renderHook(() => useCellClick({ item }), {
|
|
151
|
+
wrapper: actionExecutorWrapper,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
await result.current();
|
|
155
|
+
|
|
156
|
+
await waitFor(() => {
|
|
157
|
+
expect(mockNavigator.push).toHaveBeenCalled();
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
cleanup();
|
|
161
|
+
});
|
|
98
162
|
});
|
|
@@ -83,6 +83,12 @@ export const useCellClick = ({
|
|
|
83
83
|
|
|
84
84
|
logOnPress(selectedItem, pathname, component, onCellTap);
|
|
85
85
|
|
|
86
|
+
const tapActions = selectedItem?.extensions?.tap_actions?.actions;
|
|
87
|
+
|
|
88
|
+
const finishesHook =
|
|
89
|
+
Array.isArray(tapActions) &&
|
|
90
|
+
tapActions.some((action) => action?.type === "finishHook");
|
|
91
|
+
|
|
86
92
|
if (selectedItem) {
|
|
87
93
|
await actionExecutor?.handleEntryActions(selectedItem, {
|
|
88
94
|
component,
|
|
@@ -101,20 +107,21 @@ export const useCellClick = ({
|
|
|
101
107
|
url: selectedItem.link.href,
|
|
102
108
|
});
|
|
103
109
|
}
|
|
104
|
-
} else {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
110
|
+
} else if (isFunction(onCellTap)) {
|
|
111
|
+
onCellTap?.(selectedItem, _index);
|
|
112
|
+
} else if (!finishesHook) {
|
|
113
|
+
// finishHook already completes the hook and navigates to the original
|
|
114
|
+
// target. Pushing the cell as well stacks a second copy of that screen
|
|
115
|
+
// (e.g. home/home after a profile selector hook).
|
|
116
|
+
if (currentRoute === pathname || pathname.includes("video-modal")) {
|
|
117
|
+
const targetScreen = component?.data?.target;
|
|
118
|
+
|
|
119
|
+
push(
|
|
120
|
+
R.when(
|
|
121
|
+
() => targetScreen,
|
|
122
|
+
R.mergeLeft({ screen_type: targetScreen })
|
|
123
|
+
)(selectedItem)
|
|
124
|
+
);
|
|
118
125
|
}
|
|
119
126
|
}
|
|
120
127
|
},
|
|
@@ -4,6 +4,11 @@ import { NetInfoState } from "@react-native-community/netinfo";
|
|
|
4
4
|
import { NetworkStatusContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NetworkStatusContext";
|
|
5
5
|
import { isOnline } from "@applicaster/quick-brick-core/App/NetworkStatusProvider/utils";
|
|
6
6
|
|
|
7
|
+
type ConnectionInfo = NetInfoState & {
|
|
8
|
+
deviceStatus: NetStatus;
|
|
9
|
+
stillOfflineAfterResumeCount?: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* This hook returns connection type from RN NetInfo component or boolean for iConnected if justOnlineStatus flag is set
|
|
9
14
|
* @param {boolean} justOnlineStatus - flag if to return boolean for isConnected
|
|
@@ -12,16 +17,14 @@ import { isOnline } from "@applicaster/quick-brick-core/App/NetworkStatusProvide
|
|
|
12
17
|
|
|
13
18
|
export function useConnectionInfo(justOnlineStatus: true): boolean;
|
|
14
19
|
|
|
15
|
-
export function useConnectionInfo(
|
|
16
|
-
justOnlineStatus: false
|
|
17
|
-
): NetInfoState & { deviceStatus: NetStatus };
|
|
20
|
+
export function useConnectionInfo(justOnlineStatus: false): ConnectionInfo;
|
|
18
21
|
|
|
19
22
|
export function useConnectionInfo(
|
|
20
23
|
justOnlineStatus: boolean
|
|
21
|
-
): boolean |
|
|
24
|
+
): boolean | ConnectionInfo {
|
|
22
25
|
const connectionInfo = React.useContext(
|
|
23
26
|
NetworkStatusContext
|
|
24
|
-
) as
|
|
27
|
+
) as ConnectionInfo;
|
|
25
28
|
|
|
26
29
|
return justOnlineStatus ? isOnline(connectionInfo) === true : connectionInfo;
|
|
27
30
|
}
|