@applicaster/zapp-react-native-utils 16.0.0-alpha.1593888345 → 16.0.0-alpha.1701179921
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/actionsExecutor/ActionExecutor.ts +10 -1
- package/actionsExecutor/ActionExecutorContext.tsx +3 -0
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
- package/actionsExecutor/actions/index.ts +2 -0
- package/actionsExecutor/actions/openBottomSheet.ts +19 -6
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +2 -2
- package/actionsExecutor/consts.ts +1 -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/const.ts +13 -0
- package/appUtils/playerManager/player.ts +10 -0
- package/appUtils/playerManager/playerNative.ts +22 -0
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
- package/arrayUtils/index.ts +26 -43
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +78 -69
- package/configurationUtils/modalBlocksParser.ts +24 -106
- 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/modalState/ModalOrchestrator.ts +1 -0
- 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__/useModalStoreState.test.ts +142 -0
- package/modalState/store.ts +9 -2
- package/modalState/types.ts +3 -0
- package/modalState/useBottomSheetContent.ts +17 -12
- package/package.json +2 -2
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +21 -14
- package/reactHooks/navigation/__tests__/index.test.tsx +128 -1
- package/reactHooks/navigation/useRoute.ts +8 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
1
|
+
import React, { useCallback, useEffect, useState } from "react";
|
|
2
2
|
import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
3
3
|
|
|
4
4
|
import { MenuItem, modalOrchestrator } from "./ModalOrchestrator";
|
|
@@ -45,7 +45,9 @@ export const useBottomSheetContent = (props: Props): Return => {
|
|
|
45
45
|
// Subscribe to the viewModel state changes
|
|
46
46
|
useEffect(() => {
|
|
47
47
|
return viewModel?.subscribe((nextState) => {
|
|
48
|
-
setState(
|
|
48
|
+
setState((state) => {
|
|
49
|
+
return state === nextState ? state : nextState;
|
|
50
|
+
});
|
|
49
51
|
});
|
|
50
52
|
}, [viewModel]);
|
|
51
53
|
|
|
@@ -65,16 +67,19 @@ export const useBottomSheetContent = (props: Props): Return => {
|
|
|
65
67
|
* - If the item was a leaf action (not a submenu), triggers viewModel.refetch()
|
|
66
68
|
* so that checkmarks (isSelected) reflect the updated server state.
|
|
67
69
|
*/
|
|
68
|
-
const handleItemPress =
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const handleItemPress = useCallback(
|
|
71
|
+
async (item: MenuItem) => {
|
|
72
|
+
const actions = getMenuItemActions(item);
|
|
73
|
+
const isSubMenu = actions.some(isPresentSubMenuAction);
|
|
71
74
|
|
|
72
|
-
|
|
75
|
+
await onPress(item);
|
|
73
76
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
77
|
+
if (!isSubMenu) {
|
|
78
|
+
await viewModel?.refetch();
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
[onPress, viewModel]
|
|
82
|
+
);
|
|
78
83
|
|
|
79
84
|
const goBackOrClose = React.useCallback(() => {
|
|
80
85
|
if (modalOrchestrator.canGoBack) {
|
|
@@ -82,7 +87,7 @@ export const useBottomSheetContent = (props: Props): Return => {
|
|
|
82
87
|
} else {
|
|
83
88
|
modalOrchestrator.close();
|
|
84
89
|
}
|
|
85
|
-
}, [
|
|
90
|
+
}, []);
|
|
86
91
|
|
|
87
92
|
return {
|
|
88
93
|
items: viewModel?.editableCollection ? editableItems : state?.items,
|
|
@@ -94,7 +99,7 @@ export const useBottomSheetContent = (props: Props): Return => {
|
|
|
94
99
|
canGoBack: modalOrchestrator.canGoBack,
|
|
95
100
|
handleItemPress,
|
|
96
101
|
goBackOrClose,
|
|
97
|
-
close: () => modalOrchestrator.close(),
|
|
102
|
+
close: useCallback(() => modalOrchestrator.close(), []),
|
|
98
103
|
role: state?.role,
|
|
99
104
|
behavior: state?.behavior,
|
|
100
105
|
dynamicCollection: state?.dynamicCollection,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "16.0.0-alpha.
|
|
3
|
+
"version": "16.0.0-alpha.1701179921",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@applicaster/applicaster-types": "16.0.0-alpha.
|
|
30
|
+
"@applicaster/applicaster-types": "16.0.0-alpha.1701179921",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
const mockAppStoreGet = jest.fn();
|
|
2
|
+
|
|
3
|
+
jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
|
|
4
|
+
appStore: { get: (key) => mockAppStoreGet(key) },
|
|
5
|
+
}));
|
|
6
|
+
|
|
1
7
|
import * as R from "ramda";
|
|
2
8
|
import * as pluginUtils from "../index";
|
|
3
9
|
|
|
@@ -148,6 +154,32 @@ describe("findPluginByIdentifier", () => {
|
|
|
148
154
|
});
|
|
149
155
|
});
|
|
150
156
|
|
|
157
|
+
describe("getPluginByIdentifier", () => {
|
|
158
|
+
const { getPluginByIdentifier } = pluginUtils;
|
|
159
|
+
|
|
160
|
+
const plugins = {
|
|
161
|
+
foo: pluginMock("foo", "foo", "some_plugin_type"),
|
|
162
|
+
bar: pluginMock("foo", "bar", "some_plugin_type"),
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
beforeEach(() => {
|
|
166
|
+
mockAppStoreGet.mockReset();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("reads plugins from appStore and returns the matching plugin", () => {
|
|
170
|
+
mockAppStoreGet.mockReturnValue(plugins);
|
|
171
|
+
|
|
172
|
+
expect(getPluginByIdentifier("foo")).toEqual(plugins.foo);
|
|
173
|
+
expect(mockAppStoreGet).toHaveBeenCalledWith("plugins");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("returns undefined when the plugin is not found", () => {
|
|
177
|
+
mockAppStoreGet.mockReturnValue(plugins);
|
|
178
|
+
|
|
179
|
+
expect(getPluginByIdentifier("do_not_exist")).toBeUndefined();
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
151
183
|
describe("findPluginByType", () => {
|
|
152
184
|
const { findPluginByType } = pluginUtils;
|
|
153
185
|
|
package/pluginUtils/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
|
+
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
2
3
|
import { toCamelCase, toPascalCase } from "../stringUtils";
|
|
3
4
|
|
|
4
5
|
import { getNavigationType } from "../navigationUtils";
|
|
@@ -97,6 +98,34 @@ export function findPluginByIdentifier(
|
|
|
97
98
|
return plugin;
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
/**
|
|
102
|
+
* Like findPluginByIdentifier, but reads the current plugins list from appStore.
|
|
103
|
+
* Convenience for non-render / hook code that doesn't already have `plugins` in hand.
|
|
104
|
+
* @param identifier of the plugin to look for
|
|
105
|
+
* @param doNotWarn if set to true, will not log a warning if plugin is not found
|
|
106
|
+
* @return whole plugin if found, undefined otherwise
|
|
107
|
+
*/
|
|
108
|
+
export function getPluginByIdentifier(
|
|
109
|
+
identifier: string,
|
|
110
|
+
doNotWarn: boolean = false
|
|
111
|
+
): (QuickBrickPlugin | ZappPlugin | Plugin) | undefined {
|
|
112
|
+
try {
|
|
113
|
+
const plugins = appStore.get("plugins") ?? {};
|
|
114
|
+
|
|
115
|
+
return findPluginByIdentifier(identifier, plugins, doNotWarn);
|
|
116
|
+
} catch (error) {
|
|
117
|
+
if (!doNotWarn) {
|
|
118
|
+
pluginUtilsLogger.warning({
|
|
119
|
+
message:
|
|
120
|
+
"Could not read plugins from appStore while resolving plugin by identifier",
|
|
121
|
+
data: { identifier, error },
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return undefined;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
100
129
|
const pluginTypeForItemTypeMap = {
|
|
101
130
|
playable: "player",
|
|
102
131
|
};
|
|
@@ -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
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
|
|
3
|
-
import { renderHook } from "@testing-library/react-native";
|
|
3
|
+
import { act, render, renderHook } from "@testing-library/react-native";
|
|
4
4
|
import { isNavBarVisible, useRoute } from "../";
|
|
5
5
|
import { Provider } from "react-redux";
|
|
6
6
|
import configureMockStore from "redux-mock-store";
|
|
@@ -181,6 +181,45 @@ const hookModalWrapper = ({ children }) => (
|
|
|
181
181
|
</Provider>
|
|
182
182
|
);
|
|
183
183
|
|
|
184
|
+
// Reports every render of useRoute so the tests below can assert on route
|
|
185
|
+
// transitions and on subscription behaviour, not just on a one-shot result.
|
|
186
|
+
function RouteProbe({ onRender }: { onRender: (route: any) => void }) {
|
|
187
|
+
onRender(useRoute());
|
|
188
|
+
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const openRiverModal = () =>
|
|
193
|
+
act(() => {
|
|
194
|
+
modalStore.getState().openModal({
|
|
195
|
+
item: rivers["river-general"] as any,
|
|
196
|
+
props: { entry: modalEntry },
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const renderRouteProbe = (pathname: string, onRender: (route: any) => void) => {
|
|
201
|
+
const tree = (currentPathname: string) => (
|
|
202
|
+
<Provider store={store}>
|
|
203
|
+
<ScreenDataContext.Provider value={homeStack.state}>
|
|
204
|
+
<NavigationContext.Provider value={videoModalNavigator}>
|
|
205
|
+
<PathnameContext.Provider value={currentPathname}>
|
|
206
|
+
<RouteProbe onRender={onRender} />
|
|
207
|
+
</PathnameContext.Provider>
|
|
208
|
+
</NavigationContext.Provider>
|
|
209
|
+
</ScreenDataContext.Provider>
|
|
210
|
+
</Provider>
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
const { rerender } = render(tree(pathname));
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
navigateTo: (nextPathname: string) =>
|
|
217
|
+
act(() => {
|
|
218
|
+
rerender(tree(nextPathname));
|
|
219
|
+
}),
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
|
|
184
223
|
describe("navigation", () => {
|
|
185
224
|
describe("useRoute", () => {
|
|
186
225
|
describe("Main stack components", () => {
|
|
@@ -279,6 +318,94 @@ describe("navigation", () => {
|
|
|
279
318
|
);
|
|
280
319
|
});
|
|
281
320
|
});
|
|
321
|
+
|
|
322
|
+
describe("store subscriptions", () => {
|
|
323
|
+
afterEach(() => {
|
|
324
|
+
act(() => {
|
|
325
|
+
modalStore.getState().dismissModal();
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// Every hook in useRoute must run on every render. When the modal and
|
|
330
|
+
// hook-modal subscriptions lived inside the route branches, walking a
|
|
331
|
+
// single mounted component through the route types changed the hook
|
|
332
|
+
// count and React threw "Rendered more hooks than during the previous
|
|
333
|
+
// render".
|
|
334
|
+
it("keeps a stable hook order when the route type changes", () => {
|
|
335
|
+
let route: any;
|
|
336
|
+
|
|
337
|
+
const { navigateTo } = renderRouteProbe(homeStack.route, (current) => {
|
|
338
|
+
route = current;
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
expect(route.screenData.id).toEqual(entry.id);
|
|
342
|
+
expect(route.screenData.targetScreen.id).toEqual(screen.id);
|
|
343
|
+
|
|
344
|
+
openRiverModal();
|
|
345
|
+
navigateTo(modalPathname);
|
|
346
|
+
|
|
347
|
+
expect(route.pathname).toEqual(modalPathname);
|
|
348
|
+
expect(route.screenData.id).toEqual(modalEntry.id);
|
|
349
|
+
|
|
350
|
+
expect(route.screenData.targetScreen.id).toEqual(
|
|
351
|
+
rivers["river-general"].id
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
navigateTo(hooksModalPathname);
|
|
355
|
+
|
|
356
|
+
expect(route.pathname).toEqual(hooksModalPathname);
|
|
357
|
+
|
|
358
|
+
expect(route.screenData.id).toEqual(
|
|
359
|
+
hookModalContextState.state.screenData.payload.id
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
navigateTo(videoModalPathname);
|
|
363
|
+
|
|
364
|
+
expect(route.pathname).toEqual(videoModalPathname);
|
|
365
|
+
expect(route.screenData.id).toEqual(videoItem.id);
|
|
366
|
+
|
|
367
|
+
expect(route.screenData.targetScreen.id).toEqual(
|
|
368
|
+
rivers["river-player"].id
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
navigateTo(homeStack.route);
|
|
372
|
+
|
|
373
|
+
expect(route.pathname).toEqual(homeStack.route);
|
|
374
|
+
expect(route.screenData.id).toEqual(entry.id);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("does not re-render a non-modal route when modal state changes", () => {
|
|
378
|
+
let renders = 0;
|
|
379
|
+
|
|
380
|
+
renderRouteProbe(homeStack.route, () => {
|
|
381
|
+
renders += 1;
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
const rendersBeforeOpen = renders;
|
|
385
|
+
|
|
386
|
+
openRiverModal();
|
|
387
|
+
|
|
388
|
+
expect(renders).toBe(rendersBeforeOpen);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("re-renders a modal route when modal state changes", () => {
|
|
392
|
+
let route: any;
|
|
393
|
+
|
|
394
|
+
renderRouteProbe(modalPathname, (current) => {
|
|
395
|
+
route = current;
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
expect(route.screenData).toEqual({});
|
|
399
|
+
|
|
400
|
+
openRiverModal();
|
|
401
|
+
|
|
402
|
+
expect(route.screenData.id).toEqual(modalEntry.id);
|
|
403
|
+
|
|
404
|
+
expect(route.screenData.targetScreen.id).toEqual(
|
|
405
|
+
rivers["river-general"].id
|
|
406
|
+
);
|
|
407
|
+
});
|
|
408
|
+
});
|
|
282
409
|
});
|
|
283
410
|
|
|
284
411
|
describe("isNavBarVisible", () => {
|
|
@@ -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(
|