@applicaster/zapp-react-native-utils 16.0.0-alpha.2434153375 → 16.0.0-alpha.2500443242
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/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 +139 -5
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +201 -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 +29 -45
- package/actionsExecutor/actions/openBottomSheet.ts +35 -16
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +2 -2
- package/actionsExecutor/consts.ts +4 -0
- 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.ts +15 -2
- package/appUtils/playerManager/OverlayObserver/utils.ts +2 -5
- package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
- package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -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 +10 -0
- package/appUtils/playerManager/playerNative.ts +22 -0
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/appUtils/playerManager/playerToolbox.ts +157 -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 +74 -19
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +286 -1
- package/configurationUtils/index.ts +77 -73
- package/configurationUtils/manifestKeyParser.ts +12 -1
- package/configurationUtils/modalBlocksParser.ts +78 -4
- package/entryActions/__tests__/buildEntryActions.test.ts +97 -18
- package/entryActions/aliasPresentation.ts +26 -42
- package/entryActions/buildEntryActions.ts +1 -0
- package/entryActions/index.ts +0 -2
- 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 +8 -0
- package/manifestUtils/keys.js +6 -1
- 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 +22 -9
- package/modalState/RemoteEditableCollection.ts +9 -1
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +16 -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 +6 -1
- package/modalState/store.ts +9 -2
- package/modalState/types.ts +31 -2
- package/modalState/useBottomSheetContent.ts +24 -17
- package/navigationUtils/xrayNavigator.ts +12 -0
- package/package.json +2 -2
- package/perfTracker.ts +206 -0
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
- 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__/useMarkPipesDataStale.test.tsx +243 -0
- 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 +8 -1
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
- package/uiActionsRegistrator/registry.ts +16 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { modalStore } from "../../../modalState";
|
|
2
|
+
import { isWeb } from "../../../reactUtils";
|
|
3
|
+
import { presentScreen } from "../usePresentScreen";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../../reactUtils", () => ({
|
|
6
|
+
...jest.requireActual("../../../reactUtils"),
|
|
7
|
+
isWeb: jest.fn(() => false),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
const river = { id: "river-parent-lock", type: "parent_lock" } as any;
|
|
11
|
+
|
|
12
|
+
const rivers = { "river-parent-lock": river };
|
|
13
|
+
|
|
14
|
+
const contentTypes = { parent_lock: { screen_id: "river-parent-lock" } };
|
|
15
|
+
|
|
16
|
+
const present = (args = {}) =>
|
|
17
|
+
presentScreen({ typeMapping: "parent_lock", rivers, contentTypes, ...args });
|
|
18
|
+
|
|
19
|
+
const modalState = () => modalStore.getState().modalState;
|
|
20
|
+
|
|
21
|
+
const screenCallback = () => modalState().props?.resultCallback as hookCallback;
|
|
22
|
+
|
|
23
|
+
describe("presentScreen", () => {
|
|
24
|
+
beforeEach(() => {
|
|
25
|
+
jest.clearAllMocks();
|
|
26
|
+
(isWeb as jest.Mock).mockReturnValue(false);
|
|
27
|
+
modalStore.getState().dismissModal();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("opens a modal with the river resolved from typeMapping", () => {
|
|
31
|
+
void present();
|
|
32
|
+
|
|
33
|
+
expect(modalState().visible).toBe(true);
|
|
34
|
+
expect(modalState().screen).toBe(river);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("resolves with success when the presented screen reports success", async () => {
|
|
38
|
+
const result = present();
|
|
39
|
+
|
|
40
|
+
screenCallback()({ success: true, payload: { verified: true } });
|
|
41
|
+
|
|
42
|
+
await expect(result).resolves.toMatchObject({
|
|
43
|
+
success: true,
|
|
44
|
+
cancelled: false,
|
|
45
|
+
payload: { verified: true },
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("dismisses the modal once the presented screen reports a result", async () => {
|
|
50
|
+
const result = present();
|
|
51
|
+
|
|
52
|
+
screenCallback()({ success: true, payload: {} });
|
|
53
|
+
await result;
|
|
54
|
+
|
|
55
|
+
expect(modalState().visible).toBe(false);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("resolves as cancelled when the modal is dismissed without a result", async () => {
|
|
59
|
+
const result = present();
|
|
60
|
+
|
|
61
|
+
// What the hardware back button does: RN Modal's onRequestClose resets modal state.
|
|
62
|
+
modalStore.getState().dismissModal();
|
|
63
|
+
|
|
64
|
+
await expect(result).resolves.toMatchObject({
|
|
65
|
+
success: false,
|
|
66
|
+
cancelled: true,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("resolves as cancelled when the presented screen reports cancellation", async () => {
|
|
71
|
+
const result = present();
|
|
72
|
+
|
|
73
|
+
screenCallback()({ success: false, payload: {}, cancelled: true });
|
|
74
|
+
|
|
75
|
+
await expect(result).resolves.toMatchObject({
|
|
76
|
+
success: false,
|
|
77
|
+
cancelled: true,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("resolves as cancelled when another modal replaces the presented screen", async () => {
|
|
82
|
+
const result = present();
|
|
83
|
+
|
|
84
|
+
modalStore.getState().openModal({ item: { id: "other-modal" } as any });
|
|
85
|
+
|
|
86
|
+
await expect(result).resolves.toMatchObject({ cancelled: true });
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("leaves the modal that replaced the presented screen open", async () => {
|
|
90
|
+
const result = present();
|
|
91
|
+
const other = { id: "other-modal" } as any;
|
|
92
|
+
|
|
93
|
+
modalStore.getState().openModal({ item: other });
|
|
94
|
+
await result;
|
|
95
|
+
|
|
96
|
+
expect(modalState().screen).toBe(other);
|
|
97
|
+
expect(modalState().visible).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("ignores a result reported after the modal was already cancelled", async () => {
|
|
101
|
+
const result = present();
|
|
102
|
+
const callback = screenCallback();
|
|
103
|
+
|
|
104
|
+
modalStore.getState().dismissModal();
|
|
105
|
+
callback({ success: true, payload: {} });
|
|
106
|
+
|
|
107
|
+
await expect(result).resolves.toMatchObject({
|
|
108
|
+
success: false,
|
|
109
|
+
cancelled: true,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("hands the entry to the ModalProvider so it reaches ScreenDataContext", () => {
|
|
114
|
+
const entry = { id: "entry-1", type: { value: "video" } } as any;
|
|
115
|
+
|
|
116
|
+
void present({ entry });
|
|
117
|
+
|
|
118
|
+
expect(modalState().props?.entry).toBe(entry);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("omits the entry when the screen is presented without one", () => {
|
|
122
|
+
void present();
|
|
123
|
+
|
|
124
|
+
expect(modalState().props).not.toHaveProperty("entry");
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("fails without opening a modal when typeMapping has no content type", async () => {
|
|
128
|
+
const result = await present({ typeMapping: "unmapped" });
|
|
129
|
+
|
|
130
|
+
expect(result).toMatchObject({ success: false, cancelled: false });
|
|
131
|
+
expect(result.error).toEqual(expect.any(String));
|
|
132
|
+
expect(modalState().visible).toBe(false);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("fails without opening a modal when the content type resolves to a missing river", async () => {
|
|
136
|
+
const result = await present({
|
|
137
|
+
contentTypes: { parent_lock: { screen_id: "gone" } },
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
expect(result).toMatchObject({ success: false, cancelled: false });
|
|
141
|
+
expect(result.error).toEqual(expect.any(String));
|
|
142
|
+
expect(modalState().visible).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("fails without opening a modal on web, where no modal host exists", async () => {
|
|
146
|
+
(isWeb as jest.Mock).mockReturnValue(true);
|
|
147
|
+
|
|
148
|
+
const result = await present();
|
|
149
|
+
|
|
150
|
+
expect(result).toMatchObject({ success: false, cancelled: false });
|
|
151
|
+
expect(result.error).toEqual(expect.any(String));
|
|
152
|
+
expect(modalState().visible).toBe(false);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -22,6 +22,8 @@ import { useLayoutVersion } from "../layout";
|
|
|
22
22
|
|
|
23
23
|
export { useNavigation } from "./useNavigation";
|
|
24
24
|
|
|
25
|
+
export { usePresentScreen, presentScreen } from "./usePresentScreen";
|
|
26
|
+
|
|
25
27
|
export { useRoute } from "./useRoute";
|
|
26
28
|
|
|
27
29
|
export { usePathname } from "./usePathname";
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
|
|
4
|
+
import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
|
|
5
|
+
|
|
6
|
+
import { modalStore } from "../../modalState";
|
|
7
|
+
import { isWeb } from "../../reactUtils";
|
|
8
|
+
import { createLogger } from "../../logger";
|
|
9
|
+
import { useRivers } from "../state";
|
|
10
|
+
|
|
11
|
+
const { log_error, log_info } = createLogger({
|
|
12
|
+
subsystem: "usePresentScreen",
|
|
13
|
+
category: "General",
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export interface PresentScreenArgs {
|
|
17
|
+
/** The screen type to present (from content types mapping) */
|
|
18
|
+
typeMapping: string;
|
|
19
|
+
|
|
20
|
+
/** Entry to present the screen with. Omit to present the screen on its own. */
|
|
21
|
+
entry?: ZappEntry;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface PresentScreenResult {
|
|
25
|
+
/** The presented screen completed successfully */
|
|
26
|
+
success: boolean;
|
|
27
|
+
|
|
28
|
+
/** The presented screen was dismissed without completing (e.g. the back button) */
|
|
29
|
+
cancelled: boolean;
|
|
30
|
+
|
|
31
|
+
/** Set when the screen could not be presented at all */
|
|
32
|
+
error?: string;
|
|
33
|
+
|
|
34
|
+
/** Whatever the presented screen reported back */
|
|
35
|
+
payload?: unknown;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type PresentScreenFn = (
|
|
39
|
+
args: PresentScreenArgs
|
|
40
|
+
) => Promise<PresentScreenResult>;
|
|
41
|
+
|
|
42
|
+
interface Dependencies {
|
|
43
|
+
rivers: Record<string, ZappRiver>;
|
|
44
|
+
contentTypes: ZappContentTypes;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const failure = (error: string): Promise<PresentScreenResult> => {
|
|
48
|
+
log_error(`presentScreen: ${error}`);
|
|
49
|
+
|
|
50
|
+
return Promise.resolve({ success: false, cancelled: false, error });
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Presents a screen as a modal and resolves once that screen reports a result
|
|
55
|
+
* or is dismissed.
|
|
56
|
+
*
|
|
57
|
+
* The screen is rendered by the ModalProvider through the regular ScreenResolver,
|
|
58
|
+
* so it receives the `resultCallback` we pass here as its `callback` prop — the
|
|
59
|
+
* same channel hook screens already use to report success and cancellation.
|
|
60
|
+
*/
|
|
61
|
+
export const presentScreen = ({
|
|
62
|
+
typeMapping,
|
|
63
|
+
entry,
|
|
64
|
+
rivers,
|
|
65
|
+
contentTypes,
|
|
66
|
+
}: PresentScreenArgs & Dependencies): Promise<PresentScreenResult> => {
|
|
67
|
+
if (!typeMapping) {
|
|
68
|
+
return failure("typeMapping option is missing");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The web ModalProvider renders nothing, so no result could ever arrive and
|
|
72
|
+
// awaiting one would stall the caller indefinitely.
|
|
73
|
+
if (isWeb()) {
|
|
74
|
+
return failure("screens can not be presented as modals on web");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const screenId = contentTypes?.[typeMapping]?.screen_id;
|
|
78
|
+
|
|
79
|
+
if (!screenId) {
|
|
80
|
+
return failure(`can not resolve screen type mapping: ${typeMapping}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const river = rivers?.[screenId];
|
|
84
|
+
|
|
85
|
+
if (!river) {
|
|
86
|
+
return failure(`can not resolve river for screen id: ${screenId}`);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return new Promise<PresentScreenResult>((resolve) => {
|
|
90
|
+
let settled = false;
|
|
91
|
+
let unsubscribe: () => void = () => {};
|
|
92
|
+
|
|
93
|
+
const settle = (result: PresentScreenResult) => {
|
|
94
|
+
if (settled) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
settled = true;
|
|
99
|
+
unsubscribe();
|
|
100
|
+
resolve(result);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const resultCallback = ({
|
|
104
|
+
success,
|
|
105
|
+
cancelled,
|
|
106
|
+
payload,
|
|
107
|
+
}: hookCallbackArgs) =>
|
|
108
|
+
settle({ success: !!success, cancelled: !!cancelled, payload });
|
|
109
|
+
|
|
110
|
+
const props: Record<string, unknown> = { resultCallback };
|
|
111
|
+
|
|
112
|
+
if (entry) {
|
|
113
|
+
// The ModalProvider turns this into the screen's ScreenDataContext and
|
|
114
|
+
// screenData, so the presented screen reads the entry exactly as it
|
|
115
|
+
// would when navigated to.
|
|
116
|
+
props.entry = entry;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
log_info(
|
|
120
|
+
`presentScreen: presenting screen type: ${typeMapping}${
|
|
121
|
+
entry ? ` with entry id: ${entry.id}` : ""
|
|
122
|
+
}`
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
modalStore.getState().openModal({ item: river, props });
|
|
126
|
+
|
|
127
|
+
// Covers every dismissal we do not initiate ourselves: the hardware back
|
|
128
|
+
// button (via the Modal's onRequestClose), a swipe dismiss, another modal
|
|
129
|
+
// taking our slot, or dismissModal() called from anywhere else.
|
|
130
|
+
unsubscribe = modalStore.subscribe(({ modalState }) => {
|
|
131
|
+
if (!modalState.visible || modalState.screen !== river) {
|
|
132
|
+
settle({ success: false, cancelled: true });
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}).then((result) => {
|
|
136
|
+
// Only take down our own modal — by now something else may already own the slot.
|
|
137
|
+
if (modalStore.getState().modalState.screen === river) {
|
|
138
|
+
modalStore.getState().dismissModal();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return result;
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @returns a function presenting a screen as a modal, resolving with its result.
|
|
147
|
+
*/
|
|
148
|
+
export const usePresentScreen = (): PresentScreenFn => {
|
|
149
|
+
const rivers = useRivers();
|
|
150
|
+
const contentTypes = useContentTypes();
|
|
151
|
+
|
|
152
|
+
return useCallback(
|
|
153
|
+
(args: PresentScreenArgs) =>
|
|
154
|
+
presentScreen({ ...args, rivers, contentTypes }),
|
|
155
|
+
[rivers, contentTypes]
|
|
156
|
+
);
|
|
157
|
+
};
|
|
@@ -50,14 +50,18 @@ export const useRoute = (
|
|
|
50
50
|
const rivers = useRivers();
|
|
51
51
|
const contentTypes = useContentTypes();
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
// useRoute runs in every cell, so both modal stores are subscribed to only on
|
|
54
|
+
// the routes that actually read them. Off those routes the selectors return a
|
|
55
|
+
// stable reference, which keeps an unrelated modal opening or closing from
|
|
56
|
+
// re-rendering the whole tree.
|
|
57
57
|
const hookModalScreenData = useHookModalScreenData(
|
|
58
58
|
!isHookModalPathname(pathname)
|
|
59
59
|
);
|
|
60
60
|
|
|
61
|
+
const modalState = useModalStoreState(!isModalPathname(pathname));
|
|
62
|
+
|
|
63
|
+
const modalScreenData = modalState.screen;
|
|
64
|
+
|
|
61
65
|
const videoModalScreenData =
|
|
62
66
|
navigator?.videoModalState?.item &&
|
|
63
67
|
legacyScreenData(
|
|
@@ -80,7 +84,20 @@ export const useRoute = (
|
|
|
80
84
|
// if path is hook grab screenData from screenData
|
|
81
85
|
|
|
82
86
|
if (isModalPathname(pathname)) {
|
|
83
|
-
|
|
87
|
+
if (!modalScreenData) {
|
|
88
|
+
return { screenData: {} as ZappEntry, pathname };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Mirror the pushed-screen shape ({ ...entry, targetScreen }) so a screen
|
|
92
|
+
// presented as a modal reads its entry the same way it would when
|
|
93
|
+
// navigated to, instead of only seeing the bare river.
|
|
94
|
+
const screenData = legacyScreenData(
|
|
95
|
+
{
|
|
96
|
+
screen: modalScreenData,
|
|
97
|
+
entry: modalState.props?.entry as NavigatorEntry,
|
|
98
|
+
},
|
|
99
|
+
plugins
|
|
100
|
+
);
|
|
84
101
|
|
|
85
102
|
return { screenData, pathname };
|
|
86
103
|
}
|
|
@@ -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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
)
|
|
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
|
-
() =>
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
60
|
-
|
|
104
|
+
const localizationsParams = useMemo(
|
|
105
|
+
() => ({
|
|
106
|
+
localizations: mergeLocalizations(
|
|
61
107
|
plugin?.configuration?.localizations,
|
|
62
108
|
defaultLocalizations
|
|
63
109
|
),
|
|
64
|
-
}
|
|
65
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
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
|
-
|
|
125
|
-
|
|
160
|
+
const localizationsParams = useMemo(
|
|
161
|
+
() => ({
|
|
162
|
+
localizations: mergeLocalizations(
|
|
126
163
|
layoutData?.localizations,
|
|
127
164
|
defaultLocalizations
|
|
128
165
|
),
|
|
129
|
-
}
|
|
130
|
-
|
|
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);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { NativeModules, View, StyleSheet } from "react-native";
|
|
3
3
|
import { getXray } from "@applicaster/zapp-react-native-utils/logger";
|
|
4
|
+
import { countRender, dumpSummary } from "../perfTracker";
|
|
4
5
|
|
|
5
6
|
import { isApplePlatform, isWeb, isTV } from "../reactUtils";
|
|
6
7
|
import { useRivers } from "../reactHooks";
|
|
@@ -34,6 +35,7 @@ type Props = {
|
|
|
34
35
|
type ItemProps = {
|
|
35
36
|
children: React.ReactNode;
|
|
36
37
|
index: number;
|
|
38
|
+
testID?: string;
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
type MeasurementContext = {
|
|
@@ -76,6 +78,8 @@ export const ScreenLoadingMeasurements = ({
|
|
|
76
78
|
(index) => (event) => {
|
|
77
79
|
const { height } = event.nativeEvent.layout;
|
|
78
80
|
|
|
81
|
+
countRender("ScreenLoading_onItemLayout", { index, height });
|
|
82
|
+
|
|
79
83
|
if (!notified) {
|
|
80
84
|
// Don't need to set state when event was already sent (optimization)
|
|
81
85
|
dispatchItemLayout({ payload: { index, height } });
|
|
@@ -104,6 +108,8 @@ export const ScreenLoadingMeasurements = ({
|
|
|
104
108
|
|
|
105
109
|
if (finishLoadingVisible) {
|
|
106
110
|
if (screenData?.home) {
|
|
111
|
+
dumpSummary("app_home_loaded");
|
|
112
|
+
|
|
107
113
|
if (isWeb()) {
|
|
108
114
|
logger.sendAudienceEvent("app_home_loaded", {
|
|
109
115
|
loading_duration: Date.now() - moduleInitTime,
|
|
@@ -153,11 +159,12 @@ export const ScreenLoadingMeasurements = ({
|
|
|
153
159
|
export const ScreenLoadingMeasurementsListItemWrapper = ({
|
|
154
160
|
children,
|
|
155
161
|
index,
|
|
162
|
+
testID,
|
|
156
163
|
}: ItemProps) => {
|
|
157
164
|
const { onLayout } = React.useContext(MeasurementsSettersContext);
|
|
158
165
|
|
|
159
166
|
return (
|
|
160
|
-
<View style={styles.container} onLayout={onLayout?.(index)}>
|
|
167
|
+
<View style={styles.container} onLayout={onLayout?.(index)} testID={testID}>
|
|
161
168
|
{children}
|
|
162
169
|
</View>
|
|
163
170
|
);
|
|
@@ -105,3 +105,29 @@ describe("isActionAvailableFor", () => {
|
|
|
105
105
|
expect(isActionAvailableFor(undefined, entry)).toBe(true);
|
|
106
106
|
});
|
|
107
107
|
});
|
|
108
|
+
|
|
109
|
+
describe("uiActionsRegistry.notifyProviderChanged", () => {
|
|
110
|
+
it("notifies subscribers for a registered provider", () => {
|
|
111
|
+
const unregister = uiActionsRegistry.registerAction("live-action", value);
|
|
112
|
+
const listener = jest.fn();
|
|
113
|
+
const unsubscribe = uiActionsRegistry.subscribe(listener);
|
|
114
|
+
|
|
115
|
+
uiActionsRegistry.notifyProviderChanged("live-action");
|
|
116
|
+
|
|
117
|
+
expect(listener).toHaveBeenCalledTimes(1);
|
|
118
|
+
|
|
119
|
+
unsubscribe();
|
|
120
|
+
unregister();
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("ignores names that are not registered", () => {
|
|
124
|
+
const listener = jest.fn();
|
|
125
|
+
const unsubscribe = uiActionsRegistry.subscribe(listener);
|
|
126
|
+
|
|
127
|
+
uiActionsRegistry.notifyProviderChanged("unknown-action");
|
|
128
|
+
|
|
129
|
+
expect(listener).not.toHaveBeenCalled();
|
|
130
|
+
|
|
131
|
+
unsubscribe();
|
|
132
|
+
});
|
|
133
|
+
});
|
|
@@ -246,6 +246,22 @@ class UIActionsRegistry {
|
|
|
246
246
|
this.changeListeners.slice().forEach((listener) => listener());
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
+
/**
|
|
250
|
+
* Tells consumers that a registered provider now returns different actions.
|
|
251
|
+
*
|
|
252
|
+
* Resolved actions are snapshots: an action whose availability depends on
|
|
253
|
+
* live state (cast devices found, downloads allowed) hands out a new value
|
|
254
|
+
* when that state changes, and consumers that resolved the old one keep
|
|
255
|
+
* asking it until they re-resolve. Registration alone never tells them.
|
|
256
|
+
*/
|
|
257
|
+
notifyProviderChanged(name: string): void {
|
|
258
|
+
if (!this.registeredActions[name]) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
this.notifyChanged();
|
|
263
|
+
}
|
|
264
|
+
|
|
249
265
|
/**
|
|
250
266
|
* Register a dynamic action provider under a unique `name`.
|
|
251
267
|
* The provider can return one or more actions and may use the passed `entry`.
|