@applicaster/zapp-react-native-utils 16.0.0-alpha.9183418480 → 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.
Files changed (84) hide show
  1. package/actionsExecutor/ActionExecutor.ts +8 -10
  2. package/actionsExecutor/ActionExecutorContext.tsx +43 -326
  3. package/actionsExecutor/actions/appRestart.ts +24 -0
  4. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  5. package/actionsExecutor/actions/index.ts +30 -0
  6. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  7. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  8. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  9. package/actionsExecutor/actions/navigateToScreen.ts +123 -0
  10. package/actionsExecutor/actions/openBottomSheet.ts +177 -0
  11. package/actionsExecutor/actions/refreshComponent.ts +79 -0
  12. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  13. package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
  14. package/actionsExecutor/actions/sendCloudEvent.ts +88 -0
  15. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  16. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  17. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  18. package/actionsExecutor/actions/switchLayout.ts +40 -0
  19. package/actionsExecutor/types.ts +59 -0
  20. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
  21. package/analyticsUtils/PlayerAnalyticsManager.ts +11 -1
  22. package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
  23. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
  24. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
  25. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
  26. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
  27. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
  28. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
  29. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
  30. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
  31. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
  32. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
  33. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
  34. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
  35. package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
  36. package/analyticsUtils/__tests__/fixtures/index.js +20 -0
  37. package/analyticsUtils/analyticsMapper.ts +4 -1
  38. package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
  39. package/appUtils/HooksManager/index.ts +3 -8
  40. package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
  41. package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
  42. package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
  43. package/appUtils/contextKeysManager/index.ts +1 -1
  44. package/appUtils/contextKeysManager/utils/index.ts +38 -25
  45. package/cellUtils/index.ts +3 -5
  46. package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
  47. package/colorUtils/__tests__/isValidColor.test.ts +70 -0
  48. package/colorUtils/index.ts +50 -0
  49. package/manifestUtils/_internals/index.js +6 -0
  50. package/manifestUtils/defaultManifestConfigurations/generalContent.js +35 -0
  51. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
  52. package/manifestUtils/fieldUtils/index.js +125 -0
  53. package/manifestUtils/keys.js +9 -0
  54. package/manifestUtils/mobileAction/button/index.js +16 -0
  55. package/manifestUtils/mobileAction/container/index.js +3 -1
  56. package/manifestUtils/mobileAction/groups/defaults.js +3 -1
  57. package/manifestUtils/platformIsTV.js +1 -0
  58. package/modalState/ContentViewModel.ts +59 -0
  59. package/modalState/ModalOrchestrator.ts +204 -0
  60. package/modalState/__tests__/ContentViewModel.test.ts +107 -0
  61. package/modalState/components/ActionItem.tsx +155 -0
  62. package/modalState/components/BottomSheetHeader.tsx +245 -0
  63. package/modalState/components/PrimaryButton.tsx +54 -0
  64. package/modalState/components/TrackItem.tsx +241 -0
  65. package/modalState/index.ts +25 -74
  66. package/modalState/store.ts +102 -0
  67. package/modalState/types.ts +55 -0
  68. package/package.json +2 -2
  69. package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
  70. package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
  71. package/pipesUtils/index.ts +1 -0
  72. package/pipesUtils/withPipesEndpoint.tsx +54 -0
  73. package/playerUtils/index.ts +4 -2
  74. package/reactHooks/actions/index.ts +51 -1
  75. package/reactHooks/cell-click/index.ts +18 -10
  76. package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
  77. package/reactHooks/feed/index.ts +5 -1
  78. package/reactHooks/feed/useBatchLoading.ts +9 -1
  79. package/reactHooks/feed/{usePipesCacheReset.ts → useMarkPipesDataStale.ts} +12 -4
  80. package/reactHooks/utils/index.ts +3 -2
  81. package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +22 -4
  82. package/riverComponetsMeasurementProvider/index.tsx +12 -8
  83. package/uiActionsRegistrator/index.ts +203 -0
  84. package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
@@ -0,0 +1,204 @@
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();
@@ -0,0 +1,107 @@
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
+ });
@@ -0,0 +1,155 @@
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
+ };
@@ -0,0 +1,245 @@
1
+ import React from "react";
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ Pressable,
7
+ ActivityIndicator,
8
+ } from "react-native";
9
+
10
+ const styles = StyleSheet.create({
11
+ headerContainer: {
12
+ flexDirection: "row",
13
+ alignItems: "center",
14
+ justifyContent: "space-between",
15
+ backgroundColor: "#262626",
16
+ paddingVertical: 12,
17
+ },
18
+ navBarBorder: {
19
+ borderBottomWidth: 1,
20
+ borderBottomColor: "#333333",
21
+ },
22
+ headerGutter16: {
23
+ paddingHorizontal: 16,
24
+ },
25
+ headerGutter12: {
26
+ paddingHorizontal: 12,
27
+ },
28
+ headerTitle: {
29
+ color: "#FFFFFF",
30
+ fontWeight: "bold",
31
+ fontSize: 16,
32
+ textAlign: "center",
33
+ },
34
+ headerTitleCenter: {
35
+ fontSize: 17,
36
+ flex: 1,
37
+ textAlign: "center",
38
+ },
39
+ headerTitleSection: {
40
+ color: "#aaaaaa",
41
+ fontSize: 13,
42
+ fontWeight: "600",
43
+ textTransform: "uppercase",
44
+ },
45
+ titleWrapper: {
46
+ flex: 1,
47
+ alignItems: "center",
48
+ justifyContent: "center",
49
+ },
50
+ subtitle: {
51
+ color: "#aaaaaa",
52
+ fontSize: 11,
53
+ marginTop: 2,
54
+ textAlign: "center",
55
+ },
56
+ backButton: {
57
+ paddingVertical: 6,
58
+ paddingHorizontal: 12,
59
+ borderRadius: 6,
60
+ backgroundColor: "#333333",
61
+ width: 70,
62
+ alignItems: "center",
63
+ justifyContent: "center",
64
+ },
65
+ backButtonText: {
66
+ color: "#ffffff",
67
+ fontSize: 14,
68
+ fontWeight: "600",
69
+ },
70
+ closeButton: {
71
+ width: 44,
72
+ height: 44,
73
+ alignItems: "center",
74
+ justifyContent: "center",
75
+ },
76
+ closeButtonText: {
77
+ color: "#FFFFFF",
78
+ fontSize: 18,
79
+ },
80
+ headerActionButton: {
81
+ backgroundColor: "#3e3e3e",
82
+ paddingVertical: 6,
83
+ paddingHorizontal: 10,
84
+ borderRadius: 16,
85
+ minWidth: 70,
86
+ alignItems: "center",
87
+ justifyContent: "center",
88
+ },
89
+ headerActionText: {
90
+ color: "#FFFFFF",
91
+ fontWeight: "600",
92
+ fontSize: 14,
93
+ },
94
+ navSpacer: {
95
+ width: 70,
96
+ alignItems: "center",
97
+ justifyContent: "center",
98
+ },
99
+ pressedState: {
100
+ opacity: 0.7,
101
+ },
102
+ });
103
+
104
+ export interface BottomSheetHeaderProps {
105
+ variant?: "single" | "actions" | "section";
106
+ title: string;
107
+ subtitle?: string;
108
+ onClose?: () => void;
109
+ onBack?: () => void;
110
+ onCancel?: () => void;
111
+ onDone?: () => void;
112
+ onClear?: () => void;
113
+ isLoading?: boolean;
114
+ }
115
+
116
+ export const BottomSheetHeader: React.FC<BottomSheetHeaderProps> = ({
117
+ variant = "single",
118
+ title,
119
+ subtitle,
120
+ onClose,
121
+ onBack,
122
+ onCancel,
123
+ onDone,
124
+ onClear,
125
+ isLoading = false,
126
+ }) => {
127
+ if (variant === "actions") {
128
+ return (
129
+ <View
130
+ style={[
131
+ styles.headerContainer,
132
+ styles.headerGutter12,
133
+ styles.navBarBorder,
134
+ ]}
135
+ >
136
+ <Pressable
137
+ style={({ pressed }) => [
138
+ styles.headerActionButton,
139
+ pressed && styles.pressedState,
140
+ ]}
141
+ onPress={onCancel}
142
+ >
143
+ <Text style={styles.headerActionText}>Cancel</Text>
144
+ </Pressable>
145
+ <View style={styles.titleWrapper}>
146
+ <Text
147
+ numberOfLines={1}
148
+ style={[styles.headerTitle, styles.headerTitleCenter]}
149
+ >
150
+ {title}
151
+ </Text>
152
+ {subtitle ? (
153
+ <Text numberOfLines={1} style={styles.subtitle}>
154
+ {subtitle}
155
+ </Text>
156
+ ) : null}
157
+ </View>
158
+ <Pressable
159
+ style={({ pressed }) => [
160
+ styles.headerActionButton,
161
+ pressed && styles.pressedState,
162
+ ]}
163
+ onPress={onDone}
164
+ >
165
+ <Text style={styles.headerActionText}>Done</Text>
166
+ </Pressable>
167
+ </View>
168
+ );
169
+ }
170
+
171
+ if (variant === "section") {
172
+ return (
173
+ <View style={[styles.headerContainer, styles.headerGutter12]}>
174
+ <Text style={[styles.headerTitle, styles.headerTitleSection]}>
175
+ {title}
176
+ </Text>
177
+ {onClear ? (
178
+ <Pressable
179
+ style={({ pressed }) => [
180
+ styles.headerActionButton,
181
+ pressed && styles.pressedState,
182
+ ]}
183
+ onPress={onClear}
184
+ >
185
+ <Text style={styles.headerActionText}>Clear</Text>
186
+ </Pressable>
187
+ ) : null}
188
+ </View>
189
+ );
190
+ }
191
+
192
+ // Default: Single Line with Back and Close button options
193
+ return (
194
+ <View
195
+ style={[
196
+ styles.headerContainer,
197
+ styles.headerGutter16,
198
+ styles.navBarBorder,
199
+ ]}
200
+ >
201
+ {onBack ? (
202
+ <Pressable
203
+ onPress={onBack}
204
+ style={({ pressed }) => [
205
+ styles.backButton,
206
+ pressed && styles.pressedState,
207
+ ]}
208
+ >
209
+ <Text style={styles.backButtonText}>‹ Back</Text>
210
+ </Pressable>
211
+ ) : (
212
+ <View style={styles.navSpacer} />
213
+ )}
214
+
215
+ <View style={styles.titleWrapper}>
216
+ <Text numberOfLines={1} style={styles.headerTitle}>
217
+ {title}
218
+ </Text>
219
+ {subtitle ? (
220
+ <Text numberOfLines={1} style={styles.subtitle}>
221
+ {subtitle}
222
+ </Text>
223
+ ) : null}
224
+ </View>
225
+
226
+ {isLoading ? (
227
+ <View style={styles.navSpacer}>
228
+ <ActivityIndicator size="small" color="#aaaaaa" />
229
+ </View>
230
+ ) : onClose ? (
231
+ <Pressable
232
+ style={({ pressed }) => [
233
+ styles.closeButton,
234
+ pressed && styles.pressedState,
235
+ ]}
236
+ onPress={onClose}
237
+ >
238
+ <Text style={styles.closeButtonText}>✕</Text>
239
+ </Pressable>
240
+ ) : (
241
+ <View style={styles.navSpacer} />
242
+ )}
243
+ </View>
244
+ );
245
+ };