@applicaster/zapp-react-native-utils 16.0.0-alpha.9530606740 → 16.0.0-alpha.9572544619
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/ActionExecutorContext.tsx +2 -2
- package/actionsExecutor/actions/index.ts +1 -1
- package/actionsExecutor/actions/showToast.ts +31 -0
- package/actionsExecutor/types.ts +1 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +12 -6
- package/appUtils/playerManager/conts.ts +6 -0
- package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
- package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
- package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
- package/arrayUtils/__tests__/isFirst.test.ts +17 -0
- package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
- package/arrayUtils/__tests__/isLast.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
- package/arrayUtils/__tests__/sample.test.ts +61 -0
- package/arrayUtils/index.ts +57 -20
- package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
- package/bottomSheet/index.ts +17 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +19 -19
- package/modalState/index.ts +74 -25
- package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
- package/numberUtils/__tests__/isZero.test.ts +27 -0
- package/numberUtils/__tests__/requireNumber.test.ts +50 -0
- package/numberUtils/__tests__/toNumber.test.ts +27 -0
- package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
- package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
- package/numberUtils/index.ts +27 -8
- package/package.json +2 -2
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/navigation/__mocks__/index.ts +4 -0
- package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
- package/reactHooks/navigation/index.ts +1 -1
- package/reactHooks/navigation/useIsScreenActive.ts +29 -8
- package/reactHooks/state/useComponentScreenState.ts +1 -1
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +2 -2
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +9 -13
- package/actionsExecutor/actions/openBottomSheet.ts +0 -177
- package/modalState/ContentViewModel.ts +0 -59
- package/modalState/ModalOrchestrator.ts +0 -204
- package/modalState/__tests__/ContentViewModel.test.ts +0 -107
- package/modalState/components/ActionItem.tsx +0 -155
- package/modalState/components/BottomSheetHeader.tsx +0 -245
- package/modalState/components/PrimaryButton.tsx +0 -54
- package/modalState/components/TrackItem.tsx +0 -241
- package/modalState/store.ts +0 -102
- package/modalState/types.ts +0 -55
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
-
import {
|
|
3
|
-
PipesClientResponseHelper,
|
|
4
|
-
RequestBuilder,
|
|
5
|
-
} from "@applicaster/zapp-pipes-v2-client";
|
|
6
|
-
import { modalOrchestrator } from "../../modalState/ModalOrchestrator";
|
|
7
|
-
import { isPresentSubMenuAction, Menu, MenuItem } from "../../modalState/types";
|
|
8
|
-
import { actionExecutor, ActionResult } from "../ActionExecutor";
|
|
9
|
-
import { createLogger } from "../../logger";
|
|
10
|
-
|
|
11
|
-
const { log_info, log_error } = createLogger({
|
|
12
|
-
subsystem: "ActionExecutorContext",
|
|
13
|
-
category: "General",
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Converts a ZappEntry from a pipes feed into a MenuItem.
|
|
18
|
-
* - Icon: first src found in the image media_group.
|
|
19
|
-
* - Primary action: taken from tap_actions.actions[0].
|
|
20
|
-
* - isSelected: true when entry.id is in currentSelection.
|
|
21
|
-
*/
|
|
22
|
-
export function entryToMenuItem(
|
|
23
|
-
entry: ZappEntry,
|
|
24
|
-
currentSelection: string[] = []
|
|
25
|
-
): MenuItem {
|
|
26
|
-
const imageGroup = entry.media_group?.find((g) => g.type === "image");
|
|
27
|
-
|
|
28
|
-
const firstImage = Array.isArray(imageGroup?.media_item)
|
|
29
|
-
? imageGroup.media_item[0]
|
|
30
|
-
: imageGroup?.media_item;
|
|
31
|
-
|
|
32
|
-
// Primary action — first tap_action on the entry
|
|
33
|
-
const tapActions = entry.extensions?.tap_actions?.actions || [];
|
|
34
|
-
const primaryAction = tapActions.length > 0 ? tapActions[0] : undefined;
|
|
35
|
-
|
|
36
|
-
let summary = entry.summary as string;
|
|
37
|
-
|
|
38
|
-
// TODO: remove just a small logic for debugging
|
|
39
|
-
|
|
40
|
-
if (
|
|
41
|
-
!summary &&
|
|
42
|
-
entry.extensions &&
|
|
43
|
-
typeof entry.extensions.item_count === "number"
|
|
44
|
-
) {
|
|
45
|
-
const count = entry.extensions.item_count;
|
|
46
|
-
summary = `${count} ${count === 1 ? "Item" : "Items"}`;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
title: entry.title as string,
|
|
51
|
-
summary,
|
|
52
|
-
icon: firstImage?.src,
|
|
53
|
-
isSelected: currentSelection.includes(String(entry.id)),
|
|
54
|
-
action: primaryAction,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Exported so MultiLevelBottomSheetContent can lazy-load sub-levels
|
|
59
|
-
export async function loadItemsFromSource(
|
|
60
|
-
source: string,
|
|
61
|
-
context?: Record<string, any>
|
|
62
|
-
): Promise<MenuItem[]> {
|
|
63
|
-
const requestBuilder = new RequestBuilder()
|
|
64
|
-
.setEntryContext(context?.entry || {})
|
|
65
|
-
.setScreenContext(context?.screenData || {})
|
|
66
|
-
.setUrl(source);
|
|
67
|
-
|
|
68
|
-
await requestBuilder.buildAxiosRequest();
|
|
69
|
-
|
|
70
|
-
const responseData = await requestBuilder.call<ZappFeed>();
|
|
71
|
-
|
|
72
|
-
const responseHelper = new PipesClientResponseHelper(responseData);
|
|
73
|
-
|
|
74
|
-
if (responseHelper.error) {
|
|
75
|
-
throw responseHelper.error;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const feed = responseData?.response as ZappFeed;
|
|
79
|
-
|
|
80
|
-
const rawSelection = feed?.extensions?.behavior?.current_selection;
|
|
81
|
-
|
|
82
|
-
const currentSelection: string[] = Array.isArray(rawSelection)
|
|
83
|
-
? (rawSelection as any).map(String)
|
|
84
|
-
: rawSelection !== undefined && rawSelection !== null
|
|
85
|
-
? [String(rawSelection)]
|
|
86
|
-
: [];
|
|
87
|
-
|
|
88
|
-
return (feed?.entry || []).map((entry) =>
|
|
89
|
-
entryToMenuItem(entry, currentSelection)
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export async function openBottomSheetAction(
|
|
94
|
-
action: ActionType,
|
|
95
|
-
context?: Record<string, any>
|
|
96
|
-
): Promise<ActionResult> {
|
|
97
|
-
try {
|
|
98
|
-
const { content, header } = action.options || {};
|
|
99
|
-
|
|
100
|
-
const inlineItems: ZappEntry[] = content?.items;
|
|
101
|
-
const itemsUrl: string = content?.itemsUrl;
|
|
102
|
-
|
|
103
|
-
let items: MenuItem[];
|
|
104
|
-
|
|
105
|
-
if (Array.isArray(inlineItems) && inlineItems.length > 0) {
|
|
106
|
-
log_info("openBottomSheet: using inline items from action options", {
|
|
107
|
-
count: inlineItems.length,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
items = inlineItems.map((entry) => entryToMenuItem(entry));
|
|
111
|
-
} else if (itemsUrl) {
|
|
112
|
-
log_info(`openBottomSheet: loading items from source: ${itemsUrl}`);
|
|
113
|
-
|
|
114
|
-
items = await loadItemsFromSource(itemsUrl, context);
|
|
115
|
-
|
|
116
|
-
log_info(
|
|
117
|
-
`openBottomSheet: loaded ${items.length} items from source: ${itemsUrl}`
|
|
118
|
-
);
|
|
119
|
-
} else {
|
|
120
|
-
log_error(
|
|
121
|
-
"openBottomSheet: no itemsUrl or items provided in action options"
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
return ActionResult.Error;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const menu: Menu = {
|
|
128
|
-
header: header
|
|
129
|
-
? {
|
|
130
|
-
title: header.title,
|
|
131
|
-
subtitle: header.subtitle,
|
|
132
|
-
icon: header.icon,
|
|
133
|
-
}
|
|
134
|
-
: undefined,
|
|
135
|
-
content: {
|
|
136
|
-
title: content?.title ?? "",
|
|
137
|
-
items,
|
|
138
|
-
itemsUrl, // stored so the component can reload after an action
|
|
139
|
-
},
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Called when the user taps a menu item.
|
|
144
|
-
*
|
|
145
|
-
* - PresentSubMenuAction → handled by the orchestrator (pushes sub-menu)
|
|
146
|
-
* - Any other Action type → forwarded to the action executor, keeping the
|
|
147
|
-
* original execution context so screen/entry data is available to handlers.
|
|
148
|
-
* The pressed item is also added as `entry` so downstream actions can
|
|
149
|
-
* reference it.
|
|
150
|
-
*/
|
|
151
|
-
const onItemPress = async (item: MenuItem): Promise<void> => {
|
|
152
|
-
if (!item.action || isPresentSubMenuAction(item.action)) {
|
|
153
|
-
// Submenu navigation is handled internally by the orchestrator
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
await actionExecutor.handleAction(
|
|
158
|
-
item.action as ActionType,
|
|
159
|
-
{
|
|
160
|
-
...context,
|
|
161
|
-
entry: item as any,
|
|
162
|
-
} as any
|
|
163
|
-
);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
modalOrchestrator.open(menu, onItemPress);
|
|
167
|
-
|
|
168
|
-
return ActionResult.Success;
|
|
169
|
-
} catch (error) {
|
|
170
|
-
log_error("openBottomSheet: failed to open bottom sheet", {
|
|
171
|
-
error,
|
|
172
|
-
action,
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
return ActionResult.Error;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { BehaviorSubject, Observable } from "rxjs";
|
|
2
|
-
import { Content, MenuItem } from "./types";
|
|
3
|
-
import { loadItemsFromSource } from "../actionsExecutor/actions/openBottomSheet";
|
|
4
|
-
|
|
5
|
-
export interface ContentState {
|
|
6
|
-
items: MenuItem[];
|
|
7
|
-
isLoading: boolean;
|
|
8
|
-
error?: Error | string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export class ContentViewModel {
|
|
12
|
-
private state$: BehaviorSubject<ContentState>;
|
|
13
|
-
readonly itemsUrl?: string;
|
|
14
|
-
|
|
15
|
-
constructor(content: Content) {
|
|
16
|
-
this.itemsUrl = content.itemsUrl;
|
|
17
|
-
|
|
18
|
-
this.state$ = new BehaviorSubject<ContentState>({
|
|
19
|
-
items: content.items || [],
|
|
20
|
-
isLoading: false,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
if (this.itemsUrl && this.state$.value.items.length === 0) {
|
|
24
|
-
this.refetch();
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getState = (): ContentState => this.state$.value;
|
|
29
|
-
|
|
30
|
-
get stateObservable(): Observable<ContentState> {
|
|
31
|
-
return this.state$.asObservable();
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
subscribe = (listener: (state: ContentState) => void) => {
|
|
35
|
-
const subscription = this.state$.subscribe(listener);
|
|
36
|
-
|
|
37
|
-
return () => subscription.unsubscribe();
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
private updateState(partialState: Partial<ContentState>) {
|
|
41
|
-
this.state$.next({ ...this.state$.value, ...partialState });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
refetch = async () => {
|
|
45
|
-
if (!this.itemsUrl) return;
|
|
46
|
-
|
|
47
|
-
this.updateState({ isLoading: true, error: undefined });
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
const items = await loadItemsFromSource(this.itemsUrl);
|
|
51
|
-
this.updateState({ items, isLoading: false });
|
|
52
|
-
} catch (err) {
|
|
53
|
-
this.updateState({
|
|
54
|
-
error: err?.message || "Failed to load",
|
|
55
|
-
isLoading: false,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { dismissModal, modalStore, openBottomSheetModal } from "./store";
|
|
2
|
-
import { isPresentSubMenuAction, Menu, MenuItem } from "./types";
|
|
3
|
-
import { ContentViewModel } from "./ContentViewModel";
|
|
4
|
-
|
|
5
|
-
export type { Menu, MenuItem };
|
|
6
|
-
|
|
7
|
-
export { isPresentSubMenuAction };
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Converts a Menu model into the props expected by BottomSheetModalContent.
|
|
11
|
-
* - Maps MenuItem.title → label (required by BottomSheetModalContent)
|
|
12
|
-
* - Maps MenuItem.icon → image src
|
|
13
|
-
* - Flattens header.title / header.subtitle into top-level title / summary
|
|
14
|
-
*/
|
|
15
|
-
interface StackEntry {
|
|
16
|
-
menu: Menu;
|
|
17
|
-
onItemPress?: (item: MenuItem) => void | Promise<void>;
|
|
18
|
-
viewModel: ContentViewModel;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function menuToModalArgs(
|
|
22
|
-
menu: Menu,
|
|
23
|
-
viewModel: ContentViewModel,
|
|
24
|
-
onItemPress: (item: MenuItem) => void | Promise<void>,
|
|
25
|
-
key: string
|
|
26
|
-
): OpenModalBottomSheetArgs {
|
|
27
|
-
const items = menu.content.items.map((item) => ({
|
|
28
|
-
...item,
|
|
29
|
-
// BottomSheetModalContent renders `theme[item.label] ?? item.label`
|
|
30
|
-
label: item.title,
|
|
31
|
-
}));
|
|
32
|
-
|
|
33
|
-
return {
|
|
34
|
-
modalBottomSheetContentProps: {
|
|
35
|
-
key,
|
|
36
|
-
items,
|
|
37
|
-
itemsUrl: menu.content.itemsUrl,
|
|
38
|
-
title: menu.header?.title ?? menu.content.title,
|
|
39
|
-
summary: menu.header?.subtitle,
|
|
40
|
-
onPress: onItemPress,
|
|
41
|
-
viewModel,
|
|
42
|
-
},
|
|
43
|
-
options: {},
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* ModalOrchestrator manages a stack of Menu modals, enabling push/pop
|
|
49
|
-
* navigation between bottom sheet screens.
|
|
50
|
-
*
|
|
51
|
-
* Usage:
|
|
52
|
-
* modalOrchestrator.open(menu);
|
|
53
|
-
* modalOrchestrator.back(); // go to previous modal in the stack
|
|
54
|
-
* modalOrchestrator.close(); // dismiss all and clear the stack
|
|
55
|
-
*/
|
|
56
|
-
class ModalOrchestrator {
|
|
57
|
-
private _stack: StackEntry[] = [];
|
|
58
|
-
private _sheetContentComponent: any = null;
|
|
59
|
-
|
|
60
|
-
public registerSheetContentComponent(component: any) {
|
|
61
|
-
this._sheetContentComponent = component;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** Number of entries currently in the stack. */
|
|
65
|
-
get stackSize(): number {
|
|
66
|
-
return this._stack.length;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/** Whether there is a previous modal to go back to. */
|
|
70
|
-
get canGoBack(): boolean {
|
|
71
|
-
return this._stack.length > 1;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** The Menu currently shown, or null if the stack is empty. */
|
|
75
|
-
get current(): Menu | null {
|
|
76
|
-
return this._stack[this._stack.length - 1]?.menu ?? null;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Push a new Menu onto the stack and display it.
|
|
81
|
-
* If a menu item carries a PresentSubMenuAction it will automatically
|
|
82
|
-
* push the sub-menu when pressed; all other items delegate to
|
|
83
|
-
* the optional `onItemPress` callback.
|
|
84
|
-
*/
|
|
85
|
-
open(
|
|
86
|
-
menu: Menu,
|
|
87
|
-
onItemPress?: (item: MenuItem) => void | Promise<void>
|
|
88
|
-
): void {
|
|
89
|
-
const viewModel = new ContentViewModel(menu.content);
|
|
90
|
-
this._stack.push({ menu, onItemPress, viewModel });
|
|
91
|
-
this._present(menu, viewModel, onItemPress);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Pop the current modal and return to the previous one.
|
|
96
|
-
* If the stack has only one entry, closes entirely.
|
|
97
|
-
*/
|
|
98
|
-
back(): void {
|
|
99
|
-
if (this._stack.length === 0) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
this._stack.pop();
|
|
104
|
-
|
|
105
|
-
const previous = this._stack[this._stack.length - 1];
|
|
106
|
-
|
|
107
|
-
if (previous) {
|
|
108
|
-
this._present(previous.menu, previous.viewModel, previous.onItemPress);
|
|
109
|
-
} else {
|
|
110
|
-
dismissModal();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Close all modals and clear the entire stack.
|
|
116
|
-
*/
|
|
117
|
-
close(): void {
|
|
118
|
-
this._stack = [];
|
|
119
|
-
dismissModal();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Replace the current top of the stack without adding a new history entry.
|
|
124
|
-
*/
|
|
125
|
-
replace(
|
|
126
|
-
menu: Menu,
|
|
127
|
-
onItemPress?: (item: MenuItem) => void | Promise<void>
|
|
128
|
-
): void {
|
|
129
|
-
if (this._stack.length === 0) {
|
|
130
|
-
this.open(menu, onItemPress);
|
|
131
|
-
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const viewModel = new ContentViewModel(menu.content);
|
|
136
|
-
this._stack[this._stack.length - 1] = { menu, onItemPress, viewModel };
|
|
137
|
-
this._present(menu, viewModel, onItemPress);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
private _buildOnPress(
|
|
141
|
-
onItemPress?: (item: MenuItem) => void | Promise<void>
|
|
142
|
-
): (item: MenuItem) => void | Promise<void> {
|
|
143
|
-
return (item: MenuItem) => {
|
|
144
|
-
if (isPresentSubMenuAction(item.action)) {
|
|
145
|
-
// Navigate deeper into the sub-menu
|
|
146
|
-
this.open(item.action.menu, onItemPress);
|
|
147
|
-
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return onItemPress?.(item);
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Called when the UI dismisses the modal (swipe / overlay tap).
|
|
157
|
-
* Clears the stack without calling dismissModal() again to avoid
|
|
158
|
-
* a feedback loop with the store reset.
|
|
159
|
-
*/
|
|
160
|
-
private _onUIDismiss(): void {
|
|
161
|
-
this._stack = [];
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* True when the Zustand modal store already has a visible bottom sheet.
|
|
166
|
-
* Used to skip the slide-in animation when navigating to a deeper level.
|
|
167
|
-
*/
|
|
168
|
-
private get _isOpen(): boolean {
|
|
169
|
-
return modalStore.getState().modalState.visible;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
private _present(
|
|
173
|
-
menu: Menu,
|
|
174
|
-
viewModel: ContentViewModel,
|
|
175
|
-
onItemPress?: (item: MenuItem) => void | Promise<void>
|
|
176
|
-
): void {
|
|
177
|
-
const key = `menu-level-${this._stack.length}`;
|
|
178
|
-
|
|
179
|
-
const args = menuToModalArgs(
|
|
180
|
-
menu,
|
|
181
|
-
viewModel,
|
|
182
|
-
this._buildOnPress(onItemPress),
|
|
183
|
-
key
|
|
184
|
-
);
|
|
185
|
-
|
|
186
|
-
const alreadyOpen = this._isOpen;
|
|
187
|
-
|
|
188
|
-
openBottomSheetModal({
|
|
189
|
-
...args,
|
|
190
|
-
ModalBottomSheetContent: this._sheetContentComponent,
|
|
191
|
-
options: {
|
|
192
|
-
...args.options,
|
|
193
|
-
// Skip the slide-in when updating an already-visible sheet (sub-level nav)
|
|
194
|
-
animated: !alreadyOpen,
|
|
195
|
-
animationType: alreadyOpen ? "none" : "slide",
|
|
196
|
-
// Keep the stack in sync when the user dismisses via swipe or overlay
|
|
197
|
-
onDismiss: () => this._onUIDismiss(),
|
|
198
|
-
onRequestClose: () => this._onUIDismiss(),
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export const modalOrchestrator = new ModalOrchestrator();
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { ContentViewModel } from "../ContentViewModel";
|
|
2
|
-
import { loadItemsFromSource } from "../../actionsExecutor/actions/openBottomSheet";
|
|
3
|
-
|
|
4
|
-
jest.mock("../../actionsExecutor/actions/openBottomSheet", () => ({
|
|
5
|
-
loadItemsFromSource: jest.fn(),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
describe("ContentViewModel", () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
jest.clearAllMocks();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("should initialize with items and not fetch if itemsUrl is not provided", () => {
|
|
14
|
-
const content = {
|
|
15
|
-
title: "Test Menu",
|
|
16
|
-
items: [{ title: "Item 1" }, { title: "Item 2" }],
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const viewModel = new ContentViewModel(content);
|
|
20
|
-
|
|
21
|
-
expect(viewModel.getState()).toEqual({
|
|
22
|
-
items: content.items,
|
|
23
|
-
isLoading: false,
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
expect(loadItemsFromSource).not.toHaveBeenCalled();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should trigger fetch on init if items is empty and itemsUrl is present", async () => {
|
|
30
|
-
const mockItems = [{ title: "Fetched Item" }];
|
|
31
|
-
(loadItemsFromSource as jest.Mock).mockResolvedValueOnce(mockItems);
|
|
32
|
-
|
|
33
|
-
const content = {
|
|
34
|
-
title: "Test Menu",
|
|
35
|
-
items: [],
|
|
36
|
-
itemsUrl: "http://example.com/items",
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const viewModel = new ContentViewModel(content);
|
|
40
|
-
|
|
41
|
-
// Initial state should be loading
|
|
42
|
-
expect(viewModel.getState().isLoading).toBe(true);
|
|
43
|
-
|
|
44
|
-
// Wait for the asynchronous refetch to complete
|
|
45
|
-
await new Promise(process.nextTick);
|
|
46
|
-
|
|
47
|
-
expect(loadItemsFromSource).toHaveBeenCalledWith(
|
|
48
|
-
"http://example.com/items"
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
expect(viewModel.getState()).toEqual({
|
|
52
|
-
items: mockItems,
|
|
53
|
-
isLoading: false,
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it("should notify subscribers of state changes", async () => {
|
|
58
|
-
const mockItems = [{ title: "Fetched Item" }];
|
|
59
|
-
(loadItemsFromSource as jest.Mock).mockResolvedValue(mockItems);
|
|
60
|
-
|
|
61
|
-
const content = {
|
|
62
|
-
title: "Test Menu",
|
|
63
|
-
items: [],
|
|
64
|
-
itemsUrl: "http://example.com/items",
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
const viewModel = new ContentViewModel(content);
|
|
68
|
-
|
|
69
|
-
// Wait for constructor's refetch to finish
|
|
70
|
-
await new Promise(process.nextTick);
|
|
71
|
-
|
|
72
|
-
const listener = jest.fn();
|
|
73
|
-
const unsubscribe = viewModel.subscribe(listener);
|
|
74
|
-
|
|
75
|
-
await viewModel.refetch();
|
|
76
|
-
|
|
77
|
-
expect(listener).toHaveBeenCalled();
|
|
78
|
-
expect(viewModel.getState().items).toEqual(mockItems);
|
|
79
|
-
|
|
80
|
-
unsubscribe();
|
|
81
|
-
listener.mockClear();
|
|
82
|
-
|
|
83
|
-
await viewModel.refetch();
|
|
84
|
-
expect(listener).not.toHaveBeenCalled();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("should handle error states during fetching", async () => {
|
|
88
|
-
const error = new Error("Network Error");
|
|
89
|
-
(loadItemsFromSource as jest.Mock).mockRejectedValueOnce(error);
|
|
90
|
-
|
|
91
|
-
const content = {
|
|
92
|
-
title: "Test Menu",
|
|
93
|
-
items: [],
|
|
94
|
-
itemsUrl: "http://example.com/items",
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
const viewModel = new ContentViewModel(content);
|
|
98
|
-
|
|
99
|
-
await new Promise(process.nextTick);
|
|
100
|
-
|
|
101
|
-
expect(viewModel.getState()).toEqual({
|
|
102
|
-
items: [],
|
|
103
|
-
isLoading: false,
|
|
104
|
-
error: "Network Error",
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
2
|
-
import { View, Text, StyleSheet, Pressable, Image } from "react-native";
|
|
3
|
-
import { MenuItem, isPresentSubMenuAction } from "../types";
|
|
4
|
-
|
|
5
|
-
const styles = StyleSheet.create({
|
|
6
|
-
itemRowContainer: {
|
|
7
|
-
flexDirection: "row",
|
|
8
|
-
alignItems: "stretch",
|
|
9
|
-
justifyContent: "space-between",
|
|
10
|
-
borderBottomWidth: 1,
|
|
11
|
-
borderBottomColor: "#2a2a2a",
|
|
12
|
-
backgroundColor: "#1e1e1e",
|
|
13
|
-
},
|
|
14
|
-
itemMainPart: {
|
|
15
|
-
flex: 1,
|
|
16
|
-
flexDirection: "row",
|
|
17
|
-
alignItems: "center",
|
|
18
|
-
paddingVertical: 14,
|
|
19
|
-
paddingHorizontal: 16,
|
|
20
|
-
},
|
|
21
|
-
itemMainPartPressed: {
|
|
22
|
-
backgroundColor: "#2d2d2d",
|
|
23
|
-
},
|
|
24
|
-
itemIconImage: {
|
|
25
|
-
width: 24,
|
|
26
|
-
height: 24,
|
|
27
|
-
borderRadius: 4,
|
|
28
|
-
marginRight: 12,
|
|
29
|
-
backgroundColor: "#2a2a2a",
|
|
30
|
-
},
|
|
31
|
-
itemIconText: {
|
|
32
|
-
color: "#FFFFFF",
|
|
33
|
-
fontSize: 20,
|
|
34
|
-
marginRight: 12,
|
|
35
|
-
width: 24,
|
|
36
|
-
textAlign: "center",
|
|
37
|
-
},
|
|
38
|
-
itemText: {
|
|
39
|
-
color: "#ffffff",
|
|
40
|
-
fontSize: 15,
|
|
41
|
-
fontWeight: "500",
|
|
42
|
-
flex: 1,
|
|
43
|
-
},
|
|
44
|
-
itemTextSelected: {
|
|
45
|
-
fontWeight: "bold",
|
|
46
|
-
},
|
|
47
|
-
checkmark: {
|
|
48
|
-
color: "#30d158",
|
|
49
|
-
marginLeft: 8,
|
|
50
|
-
fontSize: 16,
|
|
51
|
-
fontWeight: "bold",
|
|
52
|
-
},
|
|
53
|
-
chevronWrapper: {
|
|
54
|
-
justifyContent: "center",
|
|
55
|
-
alignItems: "center",
|
|
56
|
-
paddingHorizontal: 16,
|
|
57
|
-
},
|
|
58
|
-
chevron: {
|
|
59
|
-
color: "#8e8e93",
|
|
60
|
-
fontSize: 20,
|
|
61
|
-
fontWeight: "300",
|
|
62
|
-
},
|
|
63
|
-
secondaryActionButton: {
|
|
64
|
-
justifyContent: "center",
|
|
65
|
-
alignItems: "center",
|
|
66
|
-
paddingHorizontal: 16,
|
|
67
|
-
borderLeftWidth: 1,
|
|
68
|
-
borderLeftColor: "#2a2a2a",
|
|
69
|
-
},
|
|
70
|
-
secondaryActionButtonPressed: {
|
|
71
|
-
backgroundColor: "#333333",
|
|
72
|
-
},
|
|
73
|
-
secondaryActionText: {
|
|
74
|
-
color: "#aeaeb2",
|
|
75
|
-
fontSize: 14,
|
|
76
|
-
fontWeight: "bold",
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
export interface ActionItemProps {
|
|
81
|
-
item: MenuItem;
|
|
82
|
-
onPress?: () => void;
|
|
83
|
-
onSecondaryPress?: () => void;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export const ActionItem: React.FC<ActionItemProps> = ({
|
|
87
|
-
item,
|
|
88
|
-
onPress,
|
|
89
|
-
onSecondaryPress,
|
|
90
|
-
}) => {
|
|
91
|
-
const [isFocused, setIsFocused] = useState(false);
|
|
92
|
-
|
|
93
|
-
const hasSub =
|
|
94
|
-
(item.submenu && item.submenu.length > 0) ||
|
|
95
|
-
(item.action && isPresentSubMenuAction(item.action));
|
|
96
|
-
|
|
97
|
-
const hasSecondary = !!item.secondaryAction;
|
|
98
|
-
const isSelected = !!item.isSelected;
|
|
99
|
-
|
|
100
|
-
// Determine if icon is a remote image URI or text/emoji
|
|
101
|
-
const isIconUri =
|
|
102
|
-
item.icon &&
|
|
103
|
-
(item.icon.startsWith("http") ||
|
|
104
|
-
item.icon.startsWith("file") ||
|
|
105
|
-
item.icon.includes("/") ||
|
|
106
|
-
item.icon.includes("."));
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
<View style={styles.itemRowContainer}>
|
|
110
|
-
<Pressable
|
|
111
|
-
style={({ pressed }) => [
|
|
112
|
-
styles.itemMainPart,
|
|
113
|
-
(pressed || isFocused) && styles.itemMainPartPressed,
|
|
114
|
-
]}
|
|
115
|
-
onPress={onPress}
|
|
116
|
-
onPressIn={() => setIsFocused(true)}
|
|
117
|
-
onPressOut={() => setIsFocused(false)}
|
|
118
|
-
>
|
|
119
|
-
{item.icon ? (
|
|
120
|
-
isIconUri ? (
|
|
121
|
-
<Image source={{ uri: item.icon }} style={styles.itemIconImage} />
|
|
122
|
-
) : (
|
|
123
|
-
<Text style={styles.itemIconText}>{item.icon}</Text>
|
|
124
|
-
)
|
|
125
|
-
) : null}
|
|
126
|
-
|
|
127
|
-
<Text style={[styles.itemText, isSelected && styles.itemTextSelected]}>
|
|
128
|
-
{item.title}
|
|
129
|
-
</Text>
|
|
130
|
-
|
|
131
|
-
{isSelected && !hasSecondary ? (
|
|
132
|
-
<Text style={styles.checkmark}>✓</Text>
|
|
133
|
-
) : null}
|
|
134
|
-
</Pressable>
|
|
135
|
-
|
|
136
|
-
{hasSecondary ? (
|
|
137
|
-
<Pressable
|
|
138
|
-
onPress={onSecondaryPress}
|
|
139
|
-
style={({ pressed }) => [
|
|
140
|
-
styles.secondaryActionButton,
|
|
141
|
-
pressed && styles.secondaryActionButtonPressed,
|
|
142
|
-
]}
|
|
143
|
-
>
|
|
144
|
-
<Text style={styles.secondaryActionText}>
|
|
145
|
-
{item.secondaryAction?.icon || "•••"}
|
|
146
|
-
</Text>
|
|
147
|
-
</Pressable>
|
|
148
|
-
) : hasSub ? (
|
|
149
|
-
<View style={styles.chevronWrapper}>
|
|
150
|
-
<Text style={styles.chevron}>›</Text>
|
|
151
|
-
</View>
|
|
152
|
-
) : null}
|
|
153
|
-
</View>
|
|
154
|
-
);
|
|
155
|
-
};
|