@applicaster/zapp-react-native-utils 16.0.0-rc.56 → 16.0.0-rc.58
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 +40 -2
- package/actionsExecutor/ActionExecutorContext.tsx +70 -16
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +22 -0
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +130 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +22 -0
- package/actionsExecutor/actions/index.ts +4 -0
- package/actionsExecutor/actions/openBottomSheet.ts +322 -0
- package/actionsExecutor/actions/refreshComponent.ts +6 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
- package/actionsExecutor/consts.ts +23 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +5 -2
- package/appUtils/playerManager/OverlayObserver/utils.ts +46 -20
- package/arrayUtils/__tests__/reorderByIds.test.ts +50 -0
- package/arrayUtils/index.ts +79 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +107 -0
- package/configurationUtils/manifestKeyParser.ts +38 -9
- package/configurationUtils/modalBlocksParser.ts +178 -0
- package/manifestUtils/index.js +3 -0
- package/manifestUtils/modalBlocks.js +304 -0
- package/modalState/ContentViewModel.ts +113 -0
- package/modalState/EditableCollection.ts +17 -0
- package/modalState/EditableCollectionRegistry.ts +51 -0
- package/modalState/ModalOrchestrator.ts +201 -0
- package/modalState/RemoteEditableCollection.ts +227 -0
- package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
- package/modalState/__tests__/ContentViewModel.test.ts +165 -0
- package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +55 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +326 -0
- package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
- package/modalState/index.ts +30 -83
- package/modalState/store.ts +102 -0
- package/modalState/types.ts +137 -0
- package/modalState/useBottomSheetContent.ts +102 -0
- package/package.json +2 -2
- package/reactHooks/index.ts +2 -0
- package/reactHooks/usePluginConfiguration.ts +4 -1
- package/reactHooks/utils/__tests__/index.test.js +22 -2
- package/reactHooks/utils/index.ts +11 -1
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
isPresentSubMenuAction,
|
|
6
|
+
MenuItem,
|
|
7
|
+
modalOrchestrator,
|
|
8
|
+
} from "./ModalOrchestrator";
|
|
9
|
+
|
|
10
|
+
import { ContentViewModel } from "./ContentViewModel";
|
|
11
|
+
import type { DynamicCollectionOptions, SelectionBehavior } from "./types";
|
|
12
|
+
import type { EditableCollection } from "./EditableCollection";
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
viewModel?: ContentViewModel | null;
|
|
16
|
+
onPress: (item: MenuItem) => void | Promise<void>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type Return = {
|
|
20
|
+
items: MenuItem[];
|
|
21
|
+
isLoading: boolean;
|
|
22
|
+
error?: Error | string;
|
|
23
|
+
showCentralLoading: boolean;
|
|
24
|
+
canGoBack: boolean;
|
|
25
|
+
handleItemPress: (item: MenuItem) => Promise<void>;
|
|
26
|
+
goBackOrClose: () => void;
|
|
27
|
+
close: () => void;
|
|
28
|
+
role?: string;
|
|
29
|
+
behavior?: SelectionBehavior;
|
|
30
|
+
dynamicCollection?: DynamicCollectionOptions;
|
|
31
|
+
editableCollection: EditableCollection | null;
|
|
32
|
+
themePluginId?: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const useBottomSheetContent = (props: Props): Return => {
|
|
36
|
+
const { onPress, viewModel } = props;
|
|
37
|
+
|
|
38
|
+
const [state, setState] = useState(viewModel?.getState());
|
|
39
|
+
|
|
40
|
+
const [editableItems, setEditableItems] = useState<MenuItem[]>(
|
|
41
|
+
() => viewModel?.getState().items || []
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
// Subscribe to the viewModel state changes
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
return viewModel?.subscribe((nextState) => {
|
|
47
|
+
setState(nextState);
|
|
48
|
+
});
|
|
49
|
+
}, [viewModel]);
|
|
50
|
+
|
|
51
|
+
// Subscribe to editable collection items
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (viewModel?.editableCollection) {
|
|
54
|
+
const subscription =
|
|
55
|
+
viewModel.editableCollection.items$.subscribe(setEditableItems);
|
|
56
|
+
|
|
57
|
+
return () => subscription.unsubscribe();
|
|
58
|
+
}
|
|
59
|
+
}, [viewModel?.editableCollection]);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Handles an item press:
|
|
63
|
+
* - Delegates to the parent onPress (which runs the action and awaits it).
|
|
64
|
+
* - If the item was a leaf action (not a submenu), triggers viewModel.refetch()
|
|
65
|
+
* so that checkmarks (isSelected) reflect the updated server state.
|
|
66
|
+
*/
|
|
67
|
+
const handleItemPress = async (item: MenuItem) => {
|
|
68
|
+
const isSubMenu = item.action && isPresentSubMenuAction(item.action);
|
|
69
|
+
|
|
70
|
+
await onPress(item);
|
|
71
|
+
|
|
72
|
+
if (!isSubMenu) {
|
|
73
|
+
await viewModel?.refetch();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const goBackOrClose = React.useCallback(() => {
|
|
78
|
+
if (modalOrchestrator.canGoBack) {
|
|
79
|
+
modalOrchestrator.back();
|
|
80
|
+
} else {
|
|
81
|
+
modalOrchestrator.close();
|
|
82
|
+
}
|
|
83
|
+
}, [modalOrchestrator.canGoBack]);
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
items: viewModel?.editableCollection ? editableItems : state?.items,
|
|
87
|
+
isLoading: toBooleanWithDefaultFalse(state?.isLoading),
|
|
88
|
+
error: state?.error,
|
|
89
|
+
showCentralLoading: toBooleanWithDefaultFalse(
|
|
90
|
+
state?.isLoading && state?.items.length === 0
|
|
91
|
+
),
|
|
92
|
+
canGoBack: modalOrchestrator.canGoBack,
|
|
93
|
+
handleItemPress,
|
|
94
|
+
goBackOrClose,
|
|
95
|
+
close: () => modalOrchestrator.close(),
|
|
96
|
+
role: state?.role,
|
|
97
|
+
behavior: state?.behavior,
|
|
98
|
+
dynamicCollection: state?.dynamicCollection,
|
|
99
|
+
editableCollection: viewModel?.editableCollection || null,
|
|
100
|
+
themePluginId: state?.themePluginId,
|
|
101
|
+
};
|
|
102
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "16.0.0-rc.
|
|
3
|
+
"version": "16.0.0-rc.58",
|
|
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-rc.
|
|
30
|
+
"@applicaster/applicaster-types": "16.0.0-rc.58",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
package/reactHooks/index.ts
CHANGED
|
@@ -24,7 +24,10 @@ export function parsePluginConfiguration(plugin, manifest) {
|
|
|
24
24
|
return populateFields(plugin, manifest.custom_configuration_fields);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function usePluginConfiguration<T, S
|
|
27
|
+
export function usePluginConfiguration<T = any, S = Record<string, any>>(
|
|
28
|
+
identifier: string,
|
|
29
|
+
manifest?: any
|
|
30
|
+
) {
|
|
28
31
|
const plugins = usePlugins();
|
|
29
32
|
|
|
30
33
|
const plugin = useMemo(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { usePrevious, useIsInitialRender } from "../";
|
|
2
|
-
import { renderHook, cleanup } from "@testing-library/react-native";
|
|
1
|
+
import { usePrevious, useIsInitialRender, useForceUpdate } from "../";
|
|
2
|
+
import { renderHook, cleanup, act } from "@testing-library/react-native";
|
|
3
3
|
|
|
4
4
|
describe("usePrevious", () => {
|
|
5
5
|
it("renders", () => {
|
|
@@ -49,3 +49,23 @@ describe("useIsInitialRender", () => {
|
|
|
49
49
|
expect(result.current).toBe(false);
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
|
+
|
|
53
|
+
describe("useForceUpdate", () => {
|
|
54
|
+
it("forces component to re-render when called", () => {
|
|
55
|
+
let renderCount = 0;
|
|
56
|
+
|
|
57
|
+
const { result } = renderHook(() => {
|
|
58
|
+
renderCount++;
|
|
59
|
+
|
|
60
|
+
return useForceUpdate();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(renderCount).toBe(1);
|
|
64
|
+
|
|
65
|
+
act(() => {
|
|
66
|
+
result.current();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(renderCount).toBe(2);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
1
|
+
import { useEffect, useReducer, useRef } from "react";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* This hook returns a previous value that was passed to it.
|
|
@@ -31,6 +31,16 @@ export const useIsInitialRender = (): boolean => {
|
|
|
31
31
|
return isInitialRenderRef.current;
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Returns a function that forces a re-render of the component when invoked.
|
|
36
|
+
* @return {() => void}
|
|
37
|
+
*/
|
|
38
|
+
export const useForceUpdate = (): (() => void) => {
|
|
39
|
+
const [, forceUpdate] = useReducer((n: number) => n + 1, 0);
|
|
40
|
+
|
|
41
|
+
return forceUpdate;
|
|
42
|
+
};
|
|
43
|
+
|
|
34
44
|
export const checkIsLocalFeed = (feedUrl) => feedUrl?.startsWith("pipesv2://");
|
|
35
45
|
|
|
36
46
|
export const shouldDispatchData = (
|
|
File without changes
|