@applicaster/zapp-react-native-utils 16.0.0-alpha.8901714553 → 16.0.0-alpha.9530606740
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 +8 -10
- package/actionsExecutor/ActionExecutorContext.tsx +41 -325
- package/actionsExecutor/actions/appRestart.ts +24 -0
- package/actionsExecutor/actions/confirmDialog.ts +53 -0
- package/actionsExecutor/actions/index.ts +30 -0
- package/actionsExecutor/actions/localStorageRemove.ts +27 -0
- package/actionsExecutor/actions/localStorageSet.ts +28 -0
- package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
- package/actionsExecutor/actions/navigateToScreen.ts +123 -0
- package/actionsExecutor/actions/openBottomSheet.ts +177 -0
- package/actionsExecutor/actions/refreshComponent.ts +79 -0
- package/actionsExecutor/actions/screenSetVariable.ts +35 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +88 -0
- package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
- package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
- package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
- package/actionsExecutor/actions/switchLayout.ts +40 -0
- package/actionsExecutor/types.ts +59 -0
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
- package/appUtils/contextKeysManager/index.ts +1 -1
- package/cellUtils/index.ts +3 -5
- package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
- package/colorUtils/__tests__/isValidColor.test.ts +70 -0
- package/colorUtils/index.ts +50 -0
- package/manifestUtils/_internals/index.js +6 -0
- package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
- package/manifestUtils/fieldUtils/index.js +125 -0
- package/manifestUtils/keys.js +9 -0
- package/manifestUtils/mobileAction/button/index.js +16 -0
- package/manifestUtils/mobileAction/container/index.js +3 -1
- package/manifestUtils/mobileAction/groups/defaults.js +3 -1
- package/manifestUtils/platformIsTV.js +1 -0
- package/modalState/ContentViewModel.ts +59 -0
- package/modalState/ModalOrchestrator.ts +204 -0
- package/modalState/__tests__/ContentViewModel.test.ts +107 -0
- package/modalState/components/ActionItem.tsx +155 -0
- package/modalState/components/BottomSheetHeader.tsx +245 -0
- package/modalState/components/PrimaryButton.tsx +54 -0
- package/modalState/components/TrackItem.tsx +241 -0
- package/modalState/index.ts +25 -74
- package/modalState/store.ts +102 -0
- package/modalState/types.ts +55 -0
- package/package.json +2 -2
- package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
- package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
- package/pipesUtils/index.ts +1 -0
- package/pipesUtils/withPipesEndpoint.tsx +54 -0
- package/reactHooks/actions/index.ts +51 -1
- package/reactHooks/cell-click/index.ts +3 -3
- package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
- package/reactHooks/feed/index.ts +5 -1
- package/reactHooks/feed/useBatchLoading.ts +9 -1
- package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
- package/reactHooks/utils/index.ts +3 -2
- package/riverComponetsMeasurementProvider/index.tsx +12 -8
- package/uiActionsRegistrator/index.ts +203 -0
- package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createStore, useStore } from "zustand";
|
|
2
|
+
|
|
3
|
+
export interface ModalState {
|
|
4
|
+
visible: boolean;
|
|
5
|
+
screen: any;
|
|
6
|
+
options: Record<string, unknown>;
|
|
7
|
+
props: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ModalStore {
|
|
11
|
+
modalState: ModalState;
|
|
12
|
+
setModalState: (newState: Partial<ModalState>) => void;
|
|
13
|
+
openModal: (
|
|
14
|
+
item: any,
|
|
15
|
+
options?: Record<string, unknown>,
|
|
16
|
+
props?: Record<string, unknown>
|
|
17
|
+
) => void;
|
|
18
|
+
dismissModal: () => void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const initialModalState: ModalState = {
|
|
22
|
+
visible: false,
|
|
23
|
+
screen: null,
|
|
24
|
+
options: {},
|
|
25
|
+
props: {},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const modalStore = createStore<ModalStore>((set, get) => ({
|
|
29
|
+
modalState: initialModalState,
|
|
30
|
+
setModalState: (newState) =>
|
|
31
|
+
set((state) => ({
|
|
32
|
+
modalState: { ...state.modalState, ...newState },
|
|
33
|
+
})),
|
|
34
|
+
openModal: ({ item, options = {}, props }: OpenModalArg) => {
|
|
35
|
+
const resetStore = () => set({ modalState: initialModalState });
|
|
36
|
+
const { onDismiss, onRequestClose, ...restOptions } = options as any;
|
|
37
|
+
|
|
38
|
+
set({
|
|
39
|
+
modalState: {
|
|
40
|
+
visible: true,
|
|
41
|
+
screen: item,
|
|
42
|
+
options: {
|
|
43
|
+
animated: true,
|
|
44
|
+
animationType: "slide",
|
|
45
|
+
onShow: () => {},
|
|
46
|
+
presentationStyle: "overFullScreen",
|
|
47
|
+
transparent: true,
|
|
48
|
+
...restOptions,
|
|
49
|
+
// Compose caller-provided callbacks with the store reset so both run
|
|
50
|
+
onDismiss: () => {
|
|
51
|
+
resetStore();
|
|
52
|
+
onDismiss?.();
|
|
53
|
+
},
|
|
54
|
+
onRequestClose: () => {
|
|
55
|
+
resetStore();
|
|
56
|
+
onRequestClose?.();
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
props,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
},
|
|
63
|
+
dismissModal: () => {
|
|
64
|
+
const onDismiss = (get().modalState?.options as any)?.onDismiss;
|
|
65
|
+
|
|
66
|
+
if (typeof onDismiss === "function") {
|
|
67
|
+
onDismiss();
|
|
68
|
+
} else {
|
|
69
|
+
set({ modalState: initialModalState });
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
}));
|
|
73
|
+
|
|
74
|
+
export const useModalStore = <T>(selector: (state: ModalStore) => T) =>
|
|
75
|
+
useStore(modalStore, selector);
|
|
76
|
+
|
|
77
|
+
export const openModal = modalStore.getInitialState().openModal;
|
|
78
|
+
|
|
79
|
+
export const dismissModal = modalStore.getInitialState().dismissModal;
|
|
80
|
+
|
|
81
|
+
export const openBottomSheetModal = ({
|
|
82
|
+
ModalBottomSheetContent,
|
|
83
|
+
modalBottomSheetContentProps,
|
|
84
|
+
props = {},
|
|
85
|
+
options = {},
|
|
86
|
+
}: OpenModalBottomSheetArgs) => {
|
|
87
|
+
openModal({
|
|
88
|
+
item: {
|
|
89
|
+
ModalBottomSheetContent,
|
|
90
|
+
modalBottomSheetContentProps,
|
|
91
|
+
},
|
|
92
|
+
props,
|
|
93
|
+
options: {
|
|
94
|
+
animationType: "none",
|
|
95
|
+
animated: false,
|
|
96
|
+
...options,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export const useModalStoreState = (): ModalState =>
|
|
102
|
+
useModalStore<ModalState>((state) => state.modalState);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export interface Header {
|
|
2
|
+
title: string;
|
|
3
|
+
subtitle?: string;
|
|
4
|
+
icon?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface Action {
|
|
8
|
+
type: string;
|
|
9
|
+
payload?: any;
|
|
10
|
+
options?: any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// Represented as 3 dots icon on top menu (opens new second level menu on desktop
|
|
14
|
+
// or a new bottom sheet on mobile)
|
|
15
|
+
export interface PresentSubMenuAction extends Action {
|
|
16
|
+
menu: Menu;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface SecondaryAction {
|
|
20
|
+
action: Action | PresentSubMenuAction;
|
|
21
|
+
icon?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface MenuItem {
|
|
25
|
+
title: string;
|
|
26
|
+
summary?: string;
|
|
27
|
+
icon?: string;
|
|
28
|
+
isSelected?: boolean;
|
|
29
|
+
// When item represents an audio item, clicking on it will start playback
|
|
30
|
+
// and secondary action will allow to add it to queue or playlist
|
|
31
|
+
action?: Action | PresentSubMenuAction;
|
|
32
|
+
secondaryAction?: SecondaryAction;
|
|
33
|
+
submenu?: MenuItem[]; // todo: not needed. Must be replaced with PresentSubMenuAction
|
|
34
|
+
trailingButton?: any;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Content {
|
|
38
|
+
title: string;
|
|
39
|
+
stickyTitle?: boolean;
|
|
40
|
+
items: MenuItem[];
|
|
41
|
+
itemsUrl?: string;
|
|
42
|
+
action?: Action;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface Menu {
|
|
46
|
+
header?: Header;
|
|
47
|
+
content: Content;
|
|
48
|
+
closeButton?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function isPresentSubMenuAction(
|
|
52
|
+
action: any
|
|
53
|
+
): action is PresentSubMenuAction {
|
|
54
|
+
return !!action && typeof action === "object" && "menu" in action;
|
|
55
|
+
}
|
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.9530606740",
|
|
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.9530606740",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { buildUrlWithQuery } from "../withPipesEndpoint";
|
|
2
|
+
|
|
3
|
+
describe("buildUrlWithQuery", () => {
|
|
4
|
+
it("returns the url unchanged when requestParams is null", () => {
|
|
5
|
+
expect(buildUrlWithQuery("https://foo.com/path", null)).toBe(
|
|
6
|
+
"https://foo.com/path"
|
|
7
|
+
);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
it("returns the url unchanged when requestParams has no params", () => {
|
|
11
|
+
expect(buildUrlWithQuery("https://foo.com/path", { headers: {} })).toBe(
|
|
12
|
+
"https://foo.com/path"
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("returns the url unchanged when url is empty", () => {
|
|
17
|
+
expect(buildUrlWithQuery("", { params: { a: "1" } })).toBe("");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("appends params to a url with no existing query", () => {
|
|
21
|
+
expect(
|
|
22
|
+
buildUrlWithQuery("https://foo.com/path", { params: { token: "abc" } })
|
|
23
|
+
).toBe("https://foo.com/path?token=abc");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it("merges params with an existing query string", () => {
|
|
27
|
+
expect(
|
|
28
|
+
buildUrlWithQuery("https://foo.com/path?existing=1", {
|
|
29
|
+
params: { token: "abc" },
|
|
30
|
+
})
|
|
31
|
+
).toBe("https://foo.com/path?existing=1&token=abc");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
import { Text } from "react-native";
|
|
4
|
+
|
|
5
|
+
const mockedUseBuildPipesUrl = jest.fn();
|
|
6
|
+
|
|
7
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/feed", () => ({
|
|
8
|
+
useBuildPipesUrl: (args) => mockedUseBuildPipesUrl(args),
|
|
9
|
+
}));
|
|
10
|
+
|
|
11
|
+
const { withPipesEndpoint } = require("../withPipesEndpoint");
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line react/display-name
|
|
14
|
+
const Wrapped = React.forwardRef((props: any, _ref) => (
|
|
15
|
+
<Text testID="wrapped">{`${props.uri}|${JSON.stringify(props.headers)}`}</Text>
|
|
16
|
+
));
|
|
17
|
+
|
|
18
|
+
describe("withPipesEndpoint", () => {
|
|
19
|
+
afterEach(() => jest.clearAllMocks());
|
|
20
|
+
|
|
21
|
+
it("renders nothing while the endpoint context is resolving", () => {
|
|
22
|
+
mockedUseBuildPipesUrl.mockReturnValue({ requestParams: null });
|
|
23
|
+
|
|
24
|
+
const Decorated = withPipesEndpoint(Wrapped);
|
|
25
|
+
const { queryByTestId } = render(<Decorated uri="https://foo.com" />);
|
|
26
|
+
|
|
27
|
+
expect(queryByTestId("wrapped")).toBeNull();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("passes the uri through unchanged when there are no params", () => {
|
|
31
|
+
mockedUseBuildPipesUrl.mockReturnValue({ requestParams: {} });
|
|
32
|
+
|
|
33
|
+
const Decorated = withPipesEndpoint(Wrapped);
|
|
34
|
+
const { getByTestId } = render(<Decorated uri="https://foo.com/path" />);
|
|
35
|
+
|
|
36
|
+
expect(getByTestId("wrapped").props.children).toBe(
|
|
37
|
+
"https://foo.com/path|{}"
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("merges resolved params into the uri and forwards headers", () => {
|
|
42
|
+
mockedUseBuildPipesUrl.mockReturnValue({
|
|
43
|
+
requestParams: {
|
|
44
|
+
params: { token: "abc" },
|
|
45
|
+
headers: { Authorization: "Bearer xyz" },
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const Decorated = withPipesEndpoint(Wrapped);
|
|
50
|
+
const { getByTestId } = render(<Decorated uri="https://foo.com/path" />);
|
|
51
|
+
|
|
52
|
+
expect(getByTestId("wrapped").props.children).toBe(
|
|
53
|
+
'https://foo.com/path?token=abc|{"Authorization":"Bearer xyz"}'
|
|
54
|
+
);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { withPipesEndpoint, buildUrlWithQuery } from "./withPipesEndpoint";
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React, { forwardRef, RefObject } from "react";
|
|
2
|
+
import URL from "url";
|
|
3
|
+
|
|
4
|
+
import { useBuildPipesUrl } from "@applicaster/zapp-react-native-utils/reactHooks/feed";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Merges the query params resolved from a pipes endpoint context into the url.
|
|
8
|
+
* Returns the url unchanged when there is nothing to merge.
|
|
9
|
+
*/
|
|
10
|
+
export function buildUrlWithQuery(url: string, requestParams): string {
|
|
11
|
+
if (!url || !requestParams?.params) {
|
|
12
|
+
return url;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const parsedURL = URL.parse(url, true);
|
|
16
|
+
|
|
17
|
+
parsedURL.query = { ...parsedURL.query, ...requestParams.params };
|
|
18
|
+
parsedURL.search = null;
|
|
19
|
+
|
|
20
|
+
return URL.format(parsedURL);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Props = {
|
|
24
|
+
uri: string;
|
|
25
|
+
} & Record<string, unknown>;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* HOC that resolves the wrapped component's `uri` against its matching Zapp
|
|
29
|
+
* Pipes endpoint. Endpoint context keys are added as query params (merged into
|
|
30
|
+
* the uri) and as request `headers`. Rendering is deferred until the context
|
|
31
|
+
* has been resolved so the component never loads without its required headers.
|
|
32
|
+
*/
|
|
33
|
+
export function withPipesEndpoint(Component) {
|
|
34
|
+
function WithPipesEndpoint(props: Props, ref: RefObject<unknown>) {
|
|
35
|
+
const { requestParams } = useBuildPipesUrl({ url: props.uri });
|
|
36
|
+
|
|
37
|
+
if (requestParams !== null) {
|
|
38
|
+
const urlWithQuery = buildUrlWithQuery(props.uri, requestParams);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Component
|
|
42
|
+
ref={ref}
|
|
43
|
+
{...props}
|
|
44
|
+
uri={urlWithQuery}
|
|
45
|
+
headers={requestParams.headers || {}}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return forwardRef(WithPipesEndpoint);
|
|
54
|
+
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
/// <reference types="@applicaster/applicaster-types" />
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
|
-
import { Context, useContext, useState } from "react";
|
|
3
|
+
import { Context, useCallback, useContext, useEffect, useState } from "react";
|
|
4
4
|
import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ActionsContext";
|
|
5
5
|
|
|
6
|
+
import {
|
|
7
|
+
observeEntryState,
|
|
8
|
+
RegisteredActionValue,
|
|
9
|
+
} from "../../uiActionsRegistrator";
|
|
6
10
|
import { reactHooksLogger } from "../logger";
|
|
7
11
|
|
|
8
12
|
const logger = reactHooksLogger.addSubsystem("actions");
|
|
@@ -46,3 +50,49 @@ export function useActions<T = unknown>(plugId: string): any {
|
|
|
46
50
|
|
|
47
51
|
return context;
|
|
48
52
|
}
|
|
53
|
+
|
|
54
|
+
export type UseEntryActionState = {
|
|
55
|
+
state: CellActionEntryState | undefined;
|
|
56
|
+
invokeAction: (options?: InvokeArgsOptions) => void;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Subscribes a component to a single action's state for a given `entry`.
|
|
61
|
+
*
|
|
62
|
+
* It observes state changes reactively via `observeEntryState` (which is backed
|
|
63
|
+
* by the action's `addListener`), seeds the initial value synchronously from
|
|
64
|
+
* `initialEntryState`, and returns a memoized `invokeAction` that forwards
|
|
65
|
+
* optimistic `updateState` updates back into local state.
|
|
66
|
+
*
|
|
67
|
+
* This is the single, unified way to drive an action button - it works the same
|
|
68
|
+
* for registry actions, legacy context-provider actions and entry actions.
|
|
69
|
+
*/
|
|
70
|
+
export function useEntryActionState(
|
|
71
|
+
action: RegisteredActionValue | undefined,
|
|
72
|
+
entry: ZappEntry | ZappFeed
|
|
73
|
+
): UseEntryActionState {
|
|
74
|
+
const [state, setState] = useState<CellActionEntryState | undefined>(() =>
|
|
75
|
+
action?.initialEntryState?.(entry)
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const entryId = (entry as ZappEntry)?.id;
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!action) return undefined;
|
|
82
|
+
|
|
83
|
+
const subscription = observeEntryState(action, entry).subscribe(setState);
|
|
84
|
+
|
|
85
|
+
return () => subscription.unsubscribe();
|
|
86
|
+
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
87
|
+
}, [action, entryId]);
|
|
88
|
+
|
|
89
|
+
const invokeAction = useCallback(
|
|
90
|
+
(options: InvokeArgsOptions = {}) => {
|
|
91
|
+
action?.invokeAction?.(entry, { updateState: setState, ...options });
|
|
92
|
+
},
|
|
93
|
+
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
94
|
+
[action, entryId]
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
return { state, invokeAction };
|
|
98
|
+
}
|
|
@@ -4,6 +4,7 @@ import * as React from "react";
|
|
|
4
4
|
import * as R from "ramda";
|
|
5
5
|
import { handleActionSchemeUrl } from "@applicaster/quick-brick-core/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useUrlSchemeHandler";
|
|
6
6
|
import { CellTapContext } from "@applicaster/zapp-react-native-ui-components/Contexts/CellTapContext";
|
|
7
|
+
import { useUIComponentContext } from "@applicaster/zapp-react-native-ui-components/Contexts/UIComponentContext";
|
|
7
8
|
import {
|
|
8
9
|
useNavigation,
|
|
9
10
|
useProfilerLogging,
|
|
@@ -28,7 +29,6 @@ import { useScreenStateStore } from "../navigation/useScreenStateStore";
|
|
|
28
29
|
type Props = {
|
|
29
30
|
item?: ZappEntry;
|
|
30
31
|
index?: number;
|
|
31
|
-
component?: ZappUIComponent;
|
|
32
32
|
zappPipesData?: ZappPipesData;
|
|
33
33
|
};
|
|
34
34
|
|
|
@@ -37,16 +37,16 @@ type onPressReturnFn =
|
|
|
37
37
|
| (() => void);
|
|
38
38
|
|
|
39
39
|
export const useCellClick = ({
|
|
40
|
-
component,
|
|
41
40
|
zappPipesData,
|
|
42
41
|
item,
|
|
43
|
-
}: Props): onPressReturnFn => {
|
|
42
|
+
}: Props = {}): onPressReturnFn => {
|
|
44
43
|
const { push, currentRoute } = useNavigation();
|
|
45
44
|
const { pathname } = useRoute();
|
|
46
45
|
const screenStateStore = useScreenStateStore();
|
|
47
46
|
|
|
48
47
|
const onCellTap: Option<Function> = React.useContext(CellTapContext);
|
|
49
48
|
const actionExecutor = React.useContext(ActionExecutorContext);
|
|
49
|
+
const component = useUIComponentContext();
|
|
50
50
|
const screenData = useCurrentScreenData();
|
|
51
51
|
const screenState = useScreenContext()?.options;
|
|
52
52
|
const entry = useScreenContext()?.entry;
|
package/reactHooks/feed/index.ts
CHANGED
|
@@ -6,7 +6,11 @@ export { useEntryScreenId } from "./useEntryScreenId";
|
|
|
6
6
|
|
|
7
7
|
export { useBuildPipesUrl } from "./useBuildPipesUrl";
|
|
8
8
|
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
useMarkPipesDataStale,
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
12
|
+
usePipesCacheReset,
|
|
13
|
+
} from "./useMarkPipesDataStale";
|
|
10
14
|
|
|
11
15
|
export { useBatchLoading } from "./useBatchLoading";
|
|
12
16
|
|
|
@@ -159,9 +159,17 @@ export const useBatchLoading = (
|
|
|
159
159
|
options.riverId,
|
|
160
160
|
]);
|
|
161
161
|
|
|
162
|
+
// Initial preload only. Batch loading warms the first batch of component
|
|
163
|
+
// feeds and signals readiness; the feed set is frozen at mount on purpose.
|
|
164
|
+
// Per-component loads and reloads (including stale revalidation) are owned by
|
|
165
|
+
// useFeedLoader in ZappPipesDataConnector. Re-running on `feeds`/input changes
|
|
166
|
+
// would re-fire on every store update and cause redundant dispatch storms, so
|
|
167
|
+
// this intentionally runs once on mount.
|
|
168
|
+
/* eslint-disable @wogns3623/better-exhaustive-deps/exhaustive-deps */
|
|
162
169
|
React.useEffect(() => {
|
|
163
170
|
runBatchLoading();
|
|
164
|
-
}, [
|
|
171
|
+
}, []);
|
|
172
|
+
/* eslint-enable @wogns3623/better-exhaustive-deps/exhaustive-deps */
|
|
165
173
|
|
|
166
174
|
React.useEffect(() => {
|
|
167
175
|
// check if all feeds are ready and set hasEverBeenReady to true
|
|
@@ -2,17 +2,19 @@ import React from "react";
|
|
|
2
2
|
|
|
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
|
-
import {
|
|
5
|
+
import { markPipesDataStale } from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
6
6
|
|
|
7
7
|
import { useRoute } from "../navigation";
|
|
8
8
|
import { useAppDispatch } from "@applicaster/zapp-react-native-redux";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* Mark a river's `clear_cache_on_reload` feeds as stale when the screen is
|
|
12
|
+
* unmounted. The cached data is kept (so a screen sharing the same feed does
|
|
13
|
+
* not lose it mid-mount) and revalidated on next access.
|
|
12
14
|
* @param {string} riverId screen id
|
|
13
15
|
* @param {Array} riverComponents list of UI components
|
|
14
16
|
*/
|
|
15
|
-
export const
|
|
17
|
+
export const useMarkPipesDataStale = (riverId, riverComponents) => {
|
|
16
18
|
const dispatch = useAppDispatch();
|
|
17
19
|
const { screenData, pathname } = useRoute();
|
|
18
20
|
const pipesContexts = usePipesContexts(riverId, pathname);
|
|
@@ -35,10 +37,16 @@ export const usePipesCacheReset = (riverId, riverComponents) => {
|
|
|
35
37
|
);
|
|
36
38
|
|
|
37
39
|
if (url) {
|
|
38
|
-
dispatch(
|
|
40
|
+
dispatch(markPipesDataStale(url, { riverId }));
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
});
|
|
42
44
|
};
|
|
43
45
|
}, []);
|
|
44
46
|
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Renamed to `useMarkPipesDataStale`. Kept as an alias for backward
|
|
50
|
+
* compatibility with external consumers.
|
|
51
|
+
*/
|
|
52
|
+
export const usePipesCacheReset = useMarkPipesDataStale;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This hook returns a previous value that was passed to it.
|
|
@@ -40,6 +40,7 @@ export const shouldDispatchData = (
|
|
|
40
40
|
) => {
|
|
41
41
|
const currentFeedHasData = feed?.data;
|
|
42
42
|
const isLocalFeed = checkIsLocalFeed(url);
|
|
43
|
+
const isFeedStale = feed?.stale;
|
|
43
44
|
|
|
44
|
-
return !currentFeedHasData || clearCache || isLocalFeed;
|
|
45
|
+
return !currentFeedHasData || clearCache || isFeedStale || isLocalFeed;
|
|
45
46
|
};
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { NativeModules,
|
|
2
|
+
import { NativeModules, View, StyleSheet } from "react-native";
|
|
3
3
|
import { getXray } from "@applicaster/zapp-react-native-utils/logger";
|
|
4
4
|
|
|
5
|
-
import { isApplePlatform, isWeb } from "../reactUtils";
|
|
5
|
+
import { isApplePlatform, isWeb, isTV } from "../reactUtils";
|
|
6
6
|
import { useRivers } from "../reactHooks";
|
|
7
7
|
|
|
8
|
+
const isTVPlatform = isTV();
|
|
9
|
+
|
|
10
|
+
const styles = StyleSheet.create({
|
|
11
|
+
container: isTVPlatform
|
|
12
|
+
? {
|
|
13
|
+
flex: 1,
|
|
14
|
+
}
|
|
15
|
+
: {},
|
|
16
|
+
});
|
|
17
|
+
|
|
8
18
|
const layoutReducer = (state, { payload }) => {
|
|
9
19
|
return state.map((item, index, _state) => ({
|
|
10
20
|
height: index === payload.index ? payload.height : item.height,
|
|
@@ -30,12 +40,6 @@ type MeasurementContext = {
|
|
|
30
40
|
onLayout: (index: number) => (event) => void;
|
|
31
41
|
};
|
|
32
42
|
|
|
33
|
-
const styles = StyleSheet.create({
|
|
34
|
-
container: {
|
|
35
|
-
flex: 1,
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
43
|
const { Logger } = getXray();
|
|
40
44
|
|
|
41
45
|
const logger = new Logger("general", "ui");
|