@applicaster/zapp-react-native-ui-components 15.1.6-alpha.3988508055 → 15.1.6

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 (34) hide show
  1. package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +69 -33
  2. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +47 -25
  3. package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +39 -122
  4. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +131 -299
  5. package/Components/ModalComponent/AudioPlayer/Components/index.ts +4 -8
  6. package/Components/ModalComponent/BottomSheetModalContent.tsx +55 -290
  7. package/Components/ModalComponent/Button/index.tsx +3 -5
  8. package/Components/ModalComponent/Header/utils.ts +1 -1
  9. package/Components/ModalComponent/index.tsx +0 -11
  10. package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +13 -82
  11. package/Components/OfflineHandler/__tests__/index.test.tsx +100 -35
  12. package/Components/OfflineHandler/hooks.ts +123 -0
  13. package/Components/OfflineHandler/index.tsx +51 -73
  14. package/Components/OfflineHandler/utils/index.ts +1 -13
  15. package/package.json +5 -6
  16. package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +0 -671
  17. package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +0 -86
  18. package/Components/ModalComponent/SortableList.tsx +0 -142
  19. package/Components/ModalComponent/TextInputContent.tsx +0 -100
  20. package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +0 -183
  21. package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +0 -128
  22. package/Components/ModalComponent/__tests__/showTextInput.test.ts +0 -95
  23. package/Components/ModalComponent/presets/__tests__/getCell.test.ts +0 -66
  24. package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +0 -74
  25. package/Components/ModalComponent/presets/index.ts +0 -27
  26. package/Components/ModalComponent/presets/selectableCell.tsx +0 -27
  27. package/Components/ModalComponent/presets/standardCell.tsx +0 -41
  28. package/Components/ModalComponent/presets/types.ts +0 -35
  29. package/Components/ModalComponent/showTextInput.ts +0 -43
  30. package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +0 -112
  31. package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +0 -107
  32. package/Components/OfflineHandler/NotificationView/NotificationView.tsx +0 -153
  33. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +0 -67
  34. package/Components/OfflineHandler/NotificationView/utils.ts +0 -34
@@ -1,86 +0,0 @@
1
- import React from "react";
2
- import { StyleSheet, View } from "react-native";
3
- import {
4
- AudioPlayerTrackItem,
5
- VARIANT_NOW_PLAYING,
6
- mapMenuItemToNowPlayingData,
7
- } from "./Item";
8
- import { AudioPlayerHeader, VARIANT_SECTION_HEADER } from "./Header";
9
- import type { MenuItem } from "@applicaster/zapp-react-native-utils/modalState/types";
10
- import { usePlayer } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer";
11
- import { usePlayerState } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerState";
12
-
13
- const styles = StyleSheet.create({
14
- divider: {
15
- height: StyleSheet.hairlineWidth,
16
- backgroundColor: "rgba(255, 255, 255, 0.1)",
17
- marginHorizontal: 20,
18
- marginVertical: 8,
19
- },
20
- });
21
-
22
- type NowPlayingHeaderSectionProps = {
23
- onClear?: () => void;
24
- };
25
-
26
- export function NowPlayingHeaderSection({
27
- onClear,
28
- }: NowPlayingHeaderSectionProps) {
29
- const player = usePlayer();
30
- const playerState = usePlayerState("queue-now-playing-section");
31
-
32
- const renderNowPlayingTrack = () => {
33
- if (!player?.entry) {
34
- return null;
35
- }
36
-
37
- const mediaGroup = player.entry.media_group;
38
-
39
- const imageGroup = Array.isArray(mediaGroup)
40
- ? mediaGroup.find((g: any) => g.type === "image")
41
- : null;
42
-
43
- const firstImage = Array.isArray(imageGroup?.media_item)
44
- ? imageGroup.media_item[0]?.src
45
- : imageGroup?.media_item?.src;
46
-
47
- const nowPlayingItem: MenuItem = {
48
- title: (player.entry.title as string) || String(player.entry.id),
49
- summary: (player.entry.summary as string) ?? "",
50
- icon: firstImage,
51
- };
52
-
53
- const data = mapMenuItemToNowPlayingData(nowPlayingItem);
54
- data.isSelected = !playerState?.isPaused;
55
-
56
- const handlePlayPause = () => {
57
- if (playerState?.isPaused) {
58
- player?.play();
59
- } else {
60
- player?.pause();
61
- }
62
- };
63
-
64
- return (
65
- <View>
66
- <AudioPlayerTrackItem
67
- configuration={VARIANT_NOW_PLAYING}
68
- data={data}
69
- onTrailingButtonPress={handlePlayPause}
70
- />
71
- <View style={styles.divider} />
72
- </View>
73
- );
74
- };
75
-
76
- return (
77
- <View>
78
- {renderNowPlayingTrack()}
79
- <AudioPlayerHeader
80
- configuration={VARIANT_SECTION_HEADER}
81
- data={{ title: "Next Up" }}
82
- onClear={onClear}
83
- />
84
- </View>
85
- );
86
- }
@@ -1,142 +0,0 @@
1
- import React, { useCallback, useEffect, useState } from "react";
2
- import Sortable from "react-native-sortables";
3
- import { Text, View, ViewStyle } from "react-native";
4
- import Animated, { useAnimatedRef } from "react-native-reanimated";
5
-
6
- const DEFAULT_HEADERS: any[] = [];
7
- const DEFAULT_SORTABLE_DATA: any[] = [];
8
-
9
- const renderHeaderComponent = (component: any) => {
10
- if (!component) return null;
11
- if (React.isValidElement(component)) return component;
12
-
13
- if (typeof component === "function") {
14
- const HeaderComponent = component;
15
-
16
- return <HeaderComponent />;
17
- }
18
-
19
- return null;
20
- };
21
-
22
- const SortableListHeader = ({
23
- title,
24
- style,
25
- }: {
26
- title?: string;
27
- style?: ViewStyle;
28
- }) => {
29
- const displayTitle = typeof title === "string" ? title : String(title ?? "");
30
-
31
- return (
32
- <View style={style}>
33
- {displayTitle ? <Text>{displayTitle}</Text> : null}
34
- </View>
35
- );
36
- };
37
-
38
- export type SortableListProps = {
39
- scrollViewStyle?: ViewStyle;
40
- contentContainerStyle?: ViewStyle;
41
- itemStyle?: ViewStyle;
42
- headerStyle?: ViewStyle;
43
- columns?: number;
44
- rowGap?: number;
45
- columnGap?: number;
46
- spacing?: number;
47
- keyExtractor?: (item: any, index?: number) => string;
48
- renderItem: ({
49
- item,
50
- index,
51
- renderHandle,
52
- }: {
53
- item: any;
54
- index: number;
55
- renderHandle: (children: React.ReactElement) => React.ReactElement;
56
- }) => React.ReactNode;
57
- sortableData?: any[];
58
- headers?: { index: number; title?: string; component: any }[];
59
- onDragEnd?: (params: {
60
- fromIndex?: number;
61
- toIndex?: number;
62
- from?: number;
63
- to?: number;
64
- data: any[];
65
- }) => void;
66
- };
67
-
68
- export const SortableList = ({
69
- scrollViewStyle,
70
- contentContainerStyle,
71
- itemStyle,
72
- headerStyle,
73
- columns = 1,
74
- rowGap = 0,
75
- columnGap = 0,
76
- keyExtractor = (item, index) =>
77
- `sortable-item-${item?.id ?? item?.title ?? index}`,
78
- renderItem,
79
- sortableData = DEFAULT_SORTABLE_DATA,
80
- headers = DEFAULT_HEADERS,
81
- onDragEnd,
82
- }: SortableListProps) => {
83
- const scrollableRef = useAnimatedRef<Animated.ScrollView>();
84
-
85
- const [localData, setLocalData] = useState(sortableData);
86
-
87
- useEffect(() => {
88
- setLocalData(sortableData);
89
- }, [sortableData]);
90
-
91
- const handleDragEnd = useCallback(
92
- (params: any) => {
93
- if (params?.data) {
94
- setLocalData(params.data);
95
- }
96
-
97
- if (onDragEnd) {
98
- onDragEnd(params);
99
- }
100
- },
101
- [onDragEnd]
102
- );
103
-
104
- return (
105
- <Animated.ScrollView
106
- ref={scrollableRef}
107
- style={scrollViewStyle}
108
- contentContainerStyle={contentContainerStyle}
109
- >
110
- {(headers || []).map((header, idx) => (
111
- <View key={`static-header-${idx}`} style={headerStyle}>
112
- {header.title ? (
113
- <SortableListHeader title={header.title} />
114
- ) : (
115
- renderHeaderComponent(header.component)
116
- )}
117
- </View>
118
- ))}
119
- <Sortable.Grid
120
- scrollableRef={scrollableRef}
121
- customHandle
122
- columns={columns}
123
- rowGap={rowGap}
124
- columnGap={columnGap}
125
- data={localData}
126
- keyExtractor={keyExtractor}
127
- onDragEnd={handleDragEnd}
128
- renderItem={({ item, index }) => (
129
- <View key={"sortable-item-" + index} style={itemStyle}>
130
- {renderItem({
131
- item,
132
- index,
133
- renderHandle: (children) => (
134
- <Sortable.Handle>{children}</Sortable.Handle>
135
- ),
136
- })}
137
- </View>
138
- )}
139
- />
140
- </Animated.ScrollView>
141
- );
142
- };
@@ -1,100 +0,0 @@
1
- import React, { useCallback, useState } from "react";
2
- import { StyleSheet, View } from "react-native";
3
- import { actionExecutor } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor";
4
- import {
5
- AudioPlayerInput,
6
- VARIANT_NAME_PLAYLIST_INPUT,
7
- } from "./AudioPlayer/Components/Input";
8
- import {
9
- AudioPlayerButton,
10
- VARIANT_TEXT_ONLY,
11
- } from "./AudioPlayer/Components/Button";
12
-
13
- export type TextInputContentProps = {
14
- /** Injected by the sheet host; unused for layout (header is owned by ModalComponent). */
15
- dismiss?: () => void;
16
- width?: number;
17
- maxHeight?: number;
18
- currentRoute?: boolean;
19
- inputLabel?: string;
20
- defaultValue?: string;
21
- buttonLabel: string;
22
- actions: ActionType[];
23
- };
24
-
25
- const styles = StyleSheet.create({
26
- container: {
27
- paddingHorizontal: 20,
28
- paddingBottom: 8,
29
- },
30
- inputWrap: {
31
- marginTop: 8,
32
- marginBottom: 24,
33
- },
34
- });
35
-
36
- /**
37
- * Modal body only — input + submit.
38
- * Standard dismiss header comes from BottomSheetModalContent / ModalHeader.
39
- */
40
- export function TextInputContent(props: TextInputContentProps) {
41
- const { inputLabel, defaultValue = "", buttonLabel, actions } = props;
42
-
43
- const [textValue, setTextValue] = useState(defaultValue);
44
- const [submitting, setSubmitting] = useState(false);
45
-
46
- const onSubmit = useCallback(async () => {
47
- if (submitting) {
48
- return;
49
- }
50
-
51
- setSubmitting(true);
52
-
53
- try {
54
- const updatedActions = (actions || []).map((item) => {
55
- if (item.type === "sendCloudEvent" || item.options?.data) {
56
- return {
57
- ...item,
58
- options: {
59
- ...item.options,
60
- data: {
61
- ...(item.options?.data || {}),
62
- name: textValue,
63
- },
64
- },
65
- };
66
- }
67
-
68
- return item;
69
- });
70
-
71
- await actionExecutor.handleActions(updatedActions);
72
- await actionExecutor.handleAction({ type: "dismissBottomSheet" });
73
- } finally {
74
- setSubmitting(false);
75
- }
76
- }, [submitting, actions, textValue]);
77
-
78
- return (
79
- <View style={styles.container}>
80
- <View style={styles.inputWrap}>
81
- <AudioPlayerInput
82
- configuration={VARIANT_NAME_PLAYLIST_INPUT}
83
- data={{
84
- placeholder: inputLabel || "",
85
- label: inputLabel,
86
- }}
87
- value={textValue}
88
- onChangeText={setTextValue}
89
- onClearPress={() => setTextValue("")}
90
- />
91
- </View>
92
- <AudioPlayerButton
93
- configuration={VARIANT_TEXT_ONLY}
94
- data={{ title: buttonLabel }}
95
- onPress={onSubmit}
96
- disabled={submitting}
97
- />
98
- </View>
99
- );
100
- }
@@ -1,183 +0,0 @@
1
- import React from "react";
2
- import { render, screen } from "@testing-library/react-native";
3
- import { BottomSheetModalContent } from "../BottomSheetModalContent";
4
- import { ContentViewModel } from "@applicaster/zapp-react-native-utils/modalState";
5
-
6
- jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
7
- useTheme: () => ({
8
- modal_bottom_sheet_padding_top: 0,
9
- modal_bottom_sheet_padding_bottom: 0,
10
- modal_bottom_sheet_background_color: "#000",
11
- modal_bottom_sheet_item_selected_icon: null,
12
- }),
13
- }));
14
-
15
- jest.mock("react-native-safe-area-context", () => ({
16
- useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }),
17
- }));
18
-
19
- jest.mock("../Header", () => ({
20
- ModalHeader: ({ title }: any) => {
21
- const { Text } = require("react-native");
22
-
23
- return <Text testID="default-header">{title}</Text>;
24
- },
25
- }));
26
-
27
- jest.mock("../Button", () => ({
28
- Button: ({ label }: any) => {
29
- const { Text } = require("react-native");
30
-
31
- return <Text testID="generic-button">{label}</Text>;
32
- },
33
- }));
34
-
35
- jest.mock("../AudioPlayer/Components/Item", () => ({
36
- AudioPlayerTrackItem: ({ data }: any) => {
37
- const { Text } = require("react-native");
38
-
39
- return <Text testID="selectable-row">{data.textLabel1}</Text>;
40
- },
41
- mapMenuItemToPlaylistData: (item: any) => ({ textLabel1: item.title }),
42
- VARIANT_PLAYLIST_ITEM: {},
43
- }));
44
-
45
- jest.mock("../AudioPlayer/Components", () => ({
46
- NowPlayingHeaderSection: () => null,
47
- AudioPlayerButton: ({ data, onPress }: any) => {
48
- const { Text } = require("react-native");
49
-
50
- return (
51
- <Text testID="create-playlist-button" onPress={onPress}>
52
- {data.title}
53
- </Text>
54
- );
55
- },
56
- VARIANT_WITH_ICON: {},
57
- }));
58
-
59
- jest.mock(
60
- "react-native-sortables",
61
- () => {
62
- const { View } = require("react-native");
63
-
64
- return {
65
- __esModule: true,
66
- default: {
67
- Grid: ({ data, renderItem }: any) => (
68
- <View testID="sortable-grid">
69
- {(data || []).map((item: any, index: number) =>
70
- renderItem({
71
- item,
72
- index,
73
- renderHandle: (children: any) => (
74
- <View testID={`sortable-handle-${index}`}>{children}</View>
75
- ),
76
- })
77
- )}
78
- </View>
79
- ),
80
- Handle: ({ children }: any) => (
81
- <View testID="sortable-handle-wrapper">{children}</View>
82
- ),
83
- },
84
- };
85
- },
86
- { virtual: true }
87
- );
88
-
89
- const baseProps = {
90
- items: [{ title: "Track A", label: "Track A" }],
91
- onPress: jest.fn(),
92
- width: 320,
93
- currentRoute: true,
94
- dismiss: jest.fn(),
95
- title: "Sheet Title",
96
- maxHeight: 400,
97
- };
98
-
99
- describe("BottomSheetModalContent role/behavior cells", () => {
100
- it("renders standard Button rows and default header when no viewModel/role", () => {
101
- render(<BottomSheetModalContent {...baseProps} />);
102
-
103
- expect(screen.getByTestId("default-header")).toBeTruthy();
104
- expect(screen.getByTestId("generic-button")).toBeTruthy();
105
- expect(screen.queryByTestId("selectable-row")).toBeNull();
106
- });
107
-
108
- it("renders selectable rows when viewModel has collection_selector role", () => {
109
- const viewModel = new ContentViewModel({
110
- title: "Playlists",
111
- items: [{ title: "Favorites" }],
112
- role: "collection_selector",
113
- behavior: { selectMode: "multi", currentSelection: [] },
114
- });
115
-
116
- render(<BottomSheetModalContent {...baseProps} viewModel={viewModel} />);
117
-
118
- expect(screen.getByTestId("default-header")).toBeTruthy();
119
- expect(screen.getByTestId("selectable-row")).toBeTruthy();
120
- expect(screen.queryByTestId("generic-button")).toBeNull();
121
- });
122
-
123
- it("does not accept styleVariant as a rendering input", () => {
124
- render(
125
- <BottomSheetModalContent
126
- {...baseProps}
127
- {...({ styleVariant: "audio_player" } as any)}
128
- />
129
- );
130
-
131
- expect(screen.getByTestId("generic-button")).toBeTruthy();
132
- expect(screen.queryByTestId("selectable-row")).toBeNull();
133
- });
134
-
135
- it("renders SortableList when viewModel has dynamic_collection role with reorder operation", () => {
136
- const moveMock = jest.fn();
137
- const { BehaviorSubject } = require("rxjs");
138
-
139
- const viewModel = new ContentViewModel({
140
- title: "Queue",
141
- items: [{ title: "Track 1" }, { title: "Track 2" }],
142
- role: "dynamic_collection",
143
- dynamicCollection: { operations: ["remove", "reorder"] },
144
- });
145
-
146
- viewModel.editableCollection = {
147
- items$: new BehaviorSubject([{ title: "Track 1" }, { title: "Track 2" }]),
148
- operations: ["remove", "reorder"],
149
- move: moveMock,
150
- };
151
-
152
- render(<BottomSheetModalContent {...baseProps} viewModel={viewModel} />);
153
-
154
- expect(screen.getByTestId("sortable-grid")).toBeTruthy();
155
- });
156
-
157
- it("renders create playlist button when operations include add and calls editableCollection.add on press", () => {
158
- const addMock = jest.fn();
159
- const { BehaviorSubject } = require("rxjs");
160
-
161
- const viewModel = new ContentViewModel({
162
- title: "Playlists",
163
- items: [{ title: "Playlist 1" }],
164
- role: "collection_selector",
165
- dynamicCollection: { operations: ["add"] },
166
- });
167
-
168
- viewModel.editableCollection = {
169
- items$: new BehaviorSubject([{ title: "Playlist 1" }]),
170
- operations: ["add"],
171
- add: addMock,
172
- };
173
-
174
- render(<BottomSheetModalContent {...baseProps} viewModel={viewModel} />);
175
-
176
- const createBtn = screen.getByTestId("create-playlist-button");
177
- expect(createBtn).toBeTruthy();
178
-
179
- const { fireEvent } = require("@testing-library/react-native");
180
- fireEvent.press(createBtn);
181
- expect(addMock).toHaveBeenCalledWith({ title: "Create New Playlist" });
182
- });
183
- });
@@ -1,128 +0,0 @@
1
- import React from "react";
2
- import {
3
- fireEvent,
4
- render,
5
- screen,
6
- waitFor,
7
- } from "@testing-library/react-native";
8
- import { actionExecutor } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor";
9
-
10
- jest.mock(
11
- "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor",
12
- () => ({
13
- actionExecutor: {
14
- handleAction: jest.fn().mockResolvedValue(undefined),
15
- handleActions: jest.fn().mockResolvedValue(undefined),
16
- },
17
- ActionResult: { Success: "success", Error: "error" },
18
- })
19
- );
20
-
21
- jest.mock(
22
- "../AudioPlayer/Components/Input",
23
- () => ({
24
- AudioPlayerInput: ({ value, onChangeText, data }: any) => {
25
- const { TextInput, Text } = require("react-native");
26
-
27
- return (
28
- <>
29
- <Text testID="input-label">{data?.label}</Text>
30
- <TextInput
31
- testID="playlist-input"
32
- value={value}
33
- onChangeText={onChangeText}
34
- placeholder={data?.placeholder}
35
- />
36
- </>
37
- );
38
- },
39
- VARIANT_NAME_PLAYLIST_INPUT: {},
40
- }),
41
- { virtual: true }
42
- );
43
-
44
- jest.mock(
45
- "../AudioPlayer/Components/Button",
46
- () => ({
47
- AudioPlayerButton: ({ data, onPress }: any) => {
48
- const { Pressable, Text } = require("react-native");
49
-
50
- return (
51
- <Pressable testID="submit-button" onPress={onPress}>
52
- <Text>{data?.title}</Text>
53
- </Pressable>
54
- );
55
- },
56
- VARIANT_TEXT_ONLY: {},
57
- }),
58
- { virtual: true }
59
- );
60
-
61
- import { TextInputContent } from "../TextInputContent";
62
-
63
- const submitAction = {
64
- type: "sendCloudEvent",
65
- options: {
66
- url: "https://server.com/cloud-events",
67
- type: "com.applicaster.collection.create.v1",
68
- subject: "edit_collection",
69
- data: { collectionId: "playlist-123" },
70
- },
71
- };
72
-
73
- const baseProps = {
74
- inputLabel: "Name your playlist",
75
- defaultValue: "Summer Hits",
76
- buttonLabel: "Update",
77
- actions: [submitAction],
78
- };
79
-
80
- describe("TextInputContent", () => {
81
- beforeEach(() => {
82
- jest.clearAllMocks();
83
- });
84
-
85
- it("renders default value and button label without a modal header", () => {
86
- render(<TextInputContent {...baseProps} />);
87
-
88
- expect(screen.queryByTestId("sheet-header")).toBeNull();
89
-
90
- expect(screen.getByTestId("playlist-input").props.value).toBe(
91
- "Summer Hits"
92
- );
93
-
94
- expect(screen.getByTestId("submit-button")).toBeTruthy();
95
- expect(screen.getByText("Update")).toBeTruthy();
96
- });
97
-
98
- it("on submit merges name into sendCloudEvent data then dismisses", async () => {
99
- render(<TextInputContent {...baseProps} />);
100
-
101
- fireEvent.changeText(screen.getByTestId("playlist-input"), "New Name");
102
- fireEvent.press(screen.getByTestId("submit-button"));
103
-
104
- await waitFor(() => {
105
- expect(actionExecutor.handleActions).toHaveBeenCalledTimes(1);
106
- expect(actionExecutor.handleAction).toHaveBeenCalledTimes(1);
107
- });
108
-
109
- expect(actionExecutor.handleActions).toHaveBeenCalledWith([
110
- {
111
- type: "sendCloudEvent",
112
- options: {
113
- url: "https://server.com/cloud-events",
114
- type: "com.applicaster.collection.create.v1",
115
- subject: "edit_collection",
116
- data: {
117
- collectionId: "playlist-123",
118
- name: "New Name",
119
- },
120
- },
121
- },
122
- ]);
123
-
124
- expect(actionExecutor.handleAction).toHaveBeenCalledWith({
125
- type: "dismissBottomSheet",
126
- });
127
- });
128
- });