@applicaster/zapp-react-native-ui-components 16.0.0-alpha.7845362739 → 16.0.0-alpha.8101951023
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/Components/AudioPlayer/tv/__tests__/audioPlayer.test.js +19 -0
- package/Components/AudioPlayer/tv/__tests__/index.test.tsx +120 -0
- package/Components/AudioPlayer/tv/index.tsx +5 -1
- package/Components/Cell/Cell.tsx +3 -6
- package/Components/Cell/TvOSCellComponent.tsx +0 -1
- package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +15 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/skipExpression.test.ts +294 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +64 -0
- package/Components/GeneralContentScreen/hookAdapter/skipExpression.ts +252 -0
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +18 -0
- package/Components/LinkHandler/LinkHandler.tsx +2 -7
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +5 -1
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +19 -4
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +43 -1
- package/Components/MasterCell/DefaultComponents/Button.tsx +1 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/executePreloadHooks.ts +2 -4
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +2 -3
- package/Components/MasterCell/DefaultComponents/Toggle.tsx +36 -14
- package/Components/MasterCell/DefaultComponents/__tests__/Toggle.test.tsx +167 -0
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/factory.test.ts +32 -0
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +1 -2
- package/Components/ModalComponent/ActionsBottomSheet/ActionButton.tsx +56 -0
- package/Components/ModalComponent/ActionsBottomSheet/__tests__/openActionsBottomSheet.test.ts +38 -0
- package/Components/ModalComponent/ActionsBottomSheet/boundActionButton.tsx +24 -0
- package/Components/ModalComponent/ActionsBottomSheet/index.ts +9 -0
- package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +61 -0
- package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +87 -97
- package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +87 -126
- package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +1 -44
- package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +252 -123
- package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +84 -0
- package/Components/ModalComponent/AudioPlayer/Components/__tests__/Item.test.tsx +113 -0
- package/Components/ModalComponent/AudioPlayer/Components/index.ts +3 -3
- package/Components/ModalComponent/AudioPlayer/utils/__tests__/mergeStyles.test.ts +356 -0
- package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +521 -0
- package/Components/ModalComponent/BottomSheetModalContent.tsx +488 -66
- package/Components/ModalComponent/Button/index.tsx +5 -3
- package/Components/ModalComponent/Header/CloseButton.tsx +12 -0
- package/Components/ModalComponent/Header/__tests__/CloseButton.test.tsx +72 -0
- package/Components/ModalComponent/Header/index.tsx +20 -7
- package/Components/ModalComponent/Header/utils.ts +1 -1
- package/Components/ModalComponent/ModalBlocksStyleContext.tsx +10 -0
- package/Components/ModalComponent/SortableList.tsx +157 -0
- package/Components/ModalComponent/SortableList.web.tsx +34 -0
- package/Components/ModalComponent/TextInputContent.tsx +112 -0
- package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +270 -0
- package/Components/ModalComponent/__tests__/SortableList.web.test.tsx +16 -0
- package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +156 -0
- package/Components/ModalComponent/__tests__/showTextInput.test.ts +95 -0
- package/Components/ModalComponent/index.tsx +18 -9
- package/Components/ModalComponent/presets/__tests__/getCell.test.ts +90 -0
- package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +78 -0
- package/Components/ModalComponent/presets/index.ts +27 -0
- package/Components/ModalComponent/presets/selectableCell.tsx +28 -0
- package/Components/ModalComponent/presets/standardCell.tsx +41 -0
- package/Components/ModalComponent/presets/types.ts +35 -0
- package/Components/ModalComponent/showTextInput.ts +43 -0
- package/Components/ModalComponent/utils.ts +82 -21
- package/Components/OfflineHandler/hooks.ts +0 -12
- package/Components/PlayerContainer/PlayerContainer.tsx +11 -7
- package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -4
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +66 -13
- package/Components/River/ComponentsMap/ComponentsMap.tsx +85 -59
- package/Components/River/River.tsx +4 -0
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +138 -75
- package/Components/River/__tests__/componentsMap.test.js +8 -3
- package/Components/River/__tests__/resultCallback.test.tsx +47 -0
- package/Components/Screen/__tests__/Screen.test.tsx +24 -0
- package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +2 -0
- package/Components/Screen/index.tsx +5 -0
- package/Components/Screen/navigationHandler.ts +8 -8
- package/Components/ScreenRevealManager/ScreenRevealManager.ts +18 -2
- package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +36 -0
- package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +56 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +21 -4
- package/Components/VideoLive/LiveImageManager.ts +1 -1
- package/Contexts/ModalNavigationContext/__tests__/index.test.tsx +15 -0
- package/Contexts/ModalNavigationContext/index.tsx +2 -2
- package/Hooks/useEntryActionsExpander.ts +63 -0
- package/package.json +6 -5
- package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +0 -332
- /package/Decorators/ZappPipesDataConnector/__tests__/{Hero.js → Hero.tsx} +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { fireEvent, render } from "@testing-library/react-native";
|
|
3
|
+
import { Switch } from "react-native";
|
|
4
|
+
import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
|
|
5
|
+
|
|
6
|
+
import { Toggle } from "../Toggle";
|
|
7
|
+
|
|
8
|
+
const mockOnCellClick = jest.fn();
|
|
9
|
+
const mockInvokeAction = jest.fn();
|
|
10
|
+
const mockInitialEntryState = jest.fn().mockReturnValue({ state: 0 });
|
|
11
|
+
|
|
12
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/cell-click", () => ({
|
|
13
|
+
useCellClick: jest.fn(() => mockOnCellClick),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
|
|
17
|
+
useActions: jest.fn(() => ({
|
|
18
|
+
invokeAction: mockInvokeAction,
|
|
19
|
+
initialEntryState: mockInitialEntryState,
|
|
20
|
+
})),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
const style = {
|
|
24
|
+
trackColor: "rgba(0,0,0,1)",
|
|
25
|
+
trackColorActive: "rgba(4,207,153,1)",
|
|
26
|
+
thumbColor: "rgba(255,255,255,1)",
|
|
27
|
+
thumbColorActive: "rgba(255,255,255,1)",
|
|
28
|
+
} as any;
|
|
29
|
+
|
|
30
|
+
const item = { id: "true", title: "I agree" } as any;
|
|
31
|
+
|
|
32
|
+
const renderToggle = (identifier: string, cellState) =>
|
|
33
|
+
render(
|
|
34
|
+
<Toggle
|
|
35
|
+
item={item}
|
|
36
|
+
action={{ identifier }}
|
|
37
|
+
style={style}
|
|
38
|
+
cellState={cellState}
|
|
39
|
+
/>
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
describe("Toggle with an empty action identifier", () => {
|
|
43
|
+
beforeEach(() => {
|
|
44
|
+
jest.clearAllMocks();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("is on when the cell is selected", () => {
|
|
48
|
+
const { getByRole } = renderToggle("", "selected");
|
|
49
|
+
|
|
50
|
+
expect(getByRole("switch").props.value).toBe(true);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("is off when the cell is not selected", () => {
|
|
54
|
+
const { getByRole } = renderToggle("", "default");
|
|
55
|
+
|
|
56
|
+
expect(getByRole("switch").props.value).toBe(false);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// A finger on a selected row resolves the cell to focused_selected. Reading
|
|
60
|
+
// that as unselected flipped the thumb for the duration of the press and let
|
|
61
|
+
// it jump back on release, which reads as a second tap.
|
|
62
|
+
it("stays on while a selected cell is pressed", () => {
|
|
63
|
+
const { getByRole } = renderToggle("", "focused_selected");
|
|
64
|
+
|
|
65
|
+
expect(getByRole("switch").props.value).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("is off while an unselected cell is pressed", () => {
|
|
69
|
+
const { getByRole } = renderToggle("", "focused");
|
|
70
|
+
|
|
71
|
+
expect(getByRole("switch").props.value).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("routes a change through the cell click path", () => {
|
|
75
|
+
const { getByRole } = renderToggle("", "default");
|
|
76
|
+
|
|
77
|
+
fireEvent(getByRole("switch"), "valueChange", true);
|
|
78
|
+
|
|
79
|
+
expect(mockOnCellClick).toHaveBeenCalledTimes(1);
|
|
80
|
+
expect(mockInvokeAction).not.toHaveBeenCalled();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("does not read the action plugin state", () => {
|
|
84
|
+
renderToggle("", "default");
|
|
85
|
+
|
|
86
|
+
expect(mockInitialEntryState).not.toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// Asserted on the Switch element rather than the rendered host component:
|
|
90
|
+
// what Toggle owns is the props it hands to Switch, and React Native rewrites
|
|
91
|
+
// them into platform-specific ones (tintColor, a style entry) underneath.
|
|
92
|
+
it("forwards every configured color to the switch", () => {
|
|
93
|
+
const { UNSAFE_getByType } = renderToggle("", "default");
|
|
94
|
+
|
|
95
|
+
expect(UNSAFE_getByType(Switch).props).toMatchObject({
|
|
96
|
+
trackColor: { false: style.trackColor, true: style.trackColorActive },
|
|
97
|
+
thumbColor: style.thumbColor,
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// ios_backgroundColor paints an opaque layer behind the track that the track
|
|
102
|
+
// color cannot cover, which on iOS reads as a halo around the switch. The
|
|
103
|
+
// switch is left on its platform default instead, so the prop must stay
|
|
104
|
+
// unset even if a style happens to carry a color for it.
|
|
105
|
+
it("does not set an iOS background color on the switch", () => {
|
|
106
|
+
const { UNSAFE_getByType } = renderToggle("", "default");
|
|
107
|
+
|
|
108
|
+
expect(UNSAFE_getByType(Switch).props.ios_backgroundColor).toBeUndefined();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe("Toggle with an action plugin identifier", () => {
|
|
113
|
+
beforeEach(() => {
|
|
114
|
+
jest.clearAllMocks();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("routes a change through the action plugin", () => {
|
|
118
|
+
const { getByRole } = renderToggle("firebase-push-topic-action", "default");
|
|
119
|
+
|
|
120
|
+
fireEvent(getByRole("switch"), "valueChange", true);
|
|
121
|
+
|
|
122
|
+
expect(mockInvokeAction).toHaveBeenCalledWith(
|
|
123
|
+
item,
|
|
124
|
+
expect.objectContaining({ updateState: expect.any(Function) })
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
expect(mockOnCellClick).not.toHaveBeenCalled();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("Toggle with an identifier whose action plugin is not installed", () => {
|
|
132
|
+
// The cell manifest no longer defaults toggle_action_identifier, but app
|
|
133
|
+
// configurations saved while it did still carry "firebase-push-topic-action",
|
|
134
|
+
// and a mistyped id is always possible. A toggle can therefore still arrive
|
|
135
|
+
// with a non-empty identifier it never asked for - the presence of a real
|
|
136
|
+
// action context, not the identifier string, is what decides the route.
|
|
137
|
+
beforeEach(() => {
|
|
138
|
+
jest.clearAllMocks();
|
|
139
|
+
|
|
140
|
+
(useActions as jest.Mock).mockReturnValue(undefined);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
afterEach(() => {
|
|
144
|
+
(useActions as jest.Mock).mockReturnValue({
|
|
145
|
+
invokeAction: mockInvokeAction,
|
|
146
|
+
initialEntryState: mockInitialEntryState,
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("routes a change through the cell click path", () => {
|
|
151
|
+
const { getByRole } = renderToggle("firebase-push-topic-action", "default");
|
|
152
|
+
|
|
153
|
+
fireEvent(getByRole("switch"), "valueChange", true);
|
|
154
|
+
|
|
155
|
+
expect(mockOnCellClick).toHaveBeenCalledTimes(1);
|
|
156
|
+
expect(mockInvokeAction).not.toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("still reflects the cell selection state", () => {
|
|
160
|
+
const { getByRole } = renderToggle(
|
|
161
|
+
"firebase-push-topic-action",
|
|
162
|
+
"selected"
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
expect(getByRole("switch").props.value).toBe(true);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CollapsibleTextContainer } from "../index";
|
|
2
|
+
|
|
3
|
+
const getValue = (key: string) => {
|
|
4
|
+
const values: Record<string, unknown> = {
|
|
5
|
+
text_alignment: "left",
|
|
6
|
+
margin_top: 0,
|
|
7
|
+
margin_right: 0,
|
|
8
|
+
margin_bottom: 0,
|
|
9
|
+
margin_left: 0,
|
|
10
|
+
padding_top: 0,
|
|
11
|
+
padding_right: 0,
|
|
12
|
+
padding_bottom: 0,
|
|
13
|
+
padding_left: 0,
|
|
14
|
+
corner_radius: 0,
|
|
15
|
+
data_key: "title",
|
|
16
|
+
custom_data_key: undefined,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
return values[key];
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
describe("CollapsibleTextContainer view tree", () => {
|
|
23
|
+
it("stretches to the parent width so labels wrap using the cell width", () => {
|
|
24
|
+
const result = CollapsibleTextContainer({
|
|
25
|
+
getValue,
|
|
26
|
+
elements: [],
|
|
27
|
+
additionalStyles: { backgroundColor: "transparent" },
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
expect(result.style.alignSelf).toBe("stretch");
|
|
31
|
+
});
|
|
32
|
+
});
|
|
@@ -3,7 +3,6 @@ import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/he
|
|
|
3
3
|
import {
|
|
4
4
|
getColorFromData,
|
|
5
5
|
getKeyForLabel,
|
|
6
|
-
mapSelfAlignment,
|
|
7
6
|
} from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
8
7
|
import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/numberUtils";
|
|
9
8
|
|
|
@@ -23,7 +22,7 @@ export const CollapsibleTextContainer = ({
|
|
|
23
22
|
return {
|
|
24
23
|
type: "CollapsibleTextContainer", // Collapsible Text Container,
|
|
25
24
|
style: {
|
|
26
|
-
alignSelf:
|
|
25
|
+
alignSelf: "stretch",
|
|
27
26
|
marginTop: toNumberWithDefaultZero(getValue("margin_top")),
|
|
28
27
|
marginRight: toNumberWithDefaultZero(getValue("margin_right")),
|
|
29
28
|
marginBottom: toNumberWithDefaultZero(getValue("margin_bottom")),
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useEntryActionState } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
|
|
3
|
+
import {
|
|
4
|
+
isActionAvailableFor,
|
|
5
|
+
RegisteredAction,
|
|
6
|
+
} from "@applicaster/zapp-react-native-utils/uiActionsRegistrator";
|
|
7
|
+
|
|
8
|
+
import { Button } from "../Button";
|
|
9
|
+
|
|
10
|
+
export type ActionButtonProps = {
|
|
11
|
+
entry: ZappEntry;
|
|
12
|
+
item: RegisteredAction;
|
|
13
|
+
configuration: any;
|
|
14
|
+
width: number;
|
|
15
|
+
component?: ZappUIComponent & { parent?: ZappUIComponent };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type Props = ActionButtonProps & {
|
|
19
|
+
onPress?: (item: any) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Unified action button for the modal bottom sheet.
|
|
24
|
+
*
|
|
25
|
+
* Every item is a `RegisteredAction` resolved from the registry (entry actions,
|
|
26
|
+
* registry actions and legacy context-provider actions alike), so the button
|
|
27
|
+
* simply reads `item.action` and drives it through `useEntryActionState`
|
|
28
|
+
* (backed by the action's observable / `addListener`).
|
|
29
|
+
*/
|
|
30
|
+
export function ActionButton(props: Props) {
|
|
31
|
+
const { item, entry, onPress: onItemPress, component } = props;
|
|
32
|
+
|
|
33
|
+
const action = item?.action;
|
|
34
|
+
|
|
35
|
+
const { state, invokeAction } = useEntryActionState(action, entry);
|
|
36
|
+
|
|
37
|
+
const onPress = React.useCallback(
|
|
38
|
+
(_item) => {
|
|
39
|
+
invokeAction({
|
|
40
|
+
context: "toast",
|
|
41
|
+
dismiss: () => onItemPress?.(item),
|
|
42
|
+
...(component ? { component } : {}),
|
|
43
|
+
});
|
|
44
|
+
},
|
|
45
|
+
[invokeAction, item, onItemPress, component]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
if (!isActionAvailableFor(action, entry as ZappEntry)) return null;
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Button {...props} item={state} onPress={onPress} label={state?.label} />
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Explicitly set display name for the component
|
|
56
|
+
ActionButton.displayName = "ActionButton";
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { openBottomSheetModal } from "@applicaster/zapp-react-native-utils/modalState";
|
|
2
|
+
import { boundActionButton } from "../boundActionButton";
|
|
3
|
+
import { openActionsBottomSheet } from "../openActionsBottomSheet";
|
|
4
|
+
|
|
5
|
+
jest.mock("@applicaster/zapp-react-native-utils/modalState", () => ({
|
|
6
|
+
openBottomSheetModal: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
jest.mock("../boundActionButton", () => ({
|
|
10
|
+
boundActionButton: jest.fn(() => jest.fn()),
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
describe("openActionsBottomSheet", () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.clearAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("binds the List component into the sheet row button", () => {
|
|
19
|
+
const entry = { id: "entry-1" } as ZappEntry;
|
|
20
|
+
|
|
21
|
+
const component = {
|
|
22
|
+
data: { source: "https://example.com/user/collections/abc" },
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const actions = [
|
|
26
|
+
{ identifier: "entry_action_0", action: { invokeAction: jest.fn() } },
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
openActionsBottomSheet({
|
|
30
|
+
entry,
|
|
31
|
+
actions: actions as any,
|
|
32
|
+
component: component as any,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
expect(boundActionButton).toHaveBeenCalledWith(entry, component);
|
|
36
|
+
expect(openBottomSheetModal).toHaveBeenCalledTimes(1);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
import { ActionButton, ActionButtonProps } from "./ActionButton";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Binds an entry to the sheet's row button.
|
|
7
|
+
*
|
|
8
|
+
* `BottomSheetModalContent` renders `buttonComponent` per item and does not
|
|
9
|
+
* know about entries, so the entry is closed over here instead.
|
|
10
|
+
*/
|
|
11
|
+
export const boundActionButton = (
|
|
12
|
+
entry: ZappEntry | ZappFeed,
|
|
13
|
+
component?: ZappUIComponent & { parent?: ZappUIComponent }
|
|
14
|
+
) => {
|
|
15
|
+
const ActionButtonWithEntry = (props: ActionButtonProps) => (
|
|
16
|
+
<ActionButton {...props} entry={entry as ZappEntry} component={component} />
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
ActionButtonWithEntry.displayName = "ActionButtonWithEntry";
|
|
20
|
+
|
|
21
|
+
return ActionButtonWithEntry;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
boundActionButton.displayName = "boundActionButton";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { ActionButton } from "./ActionButton";
|
|
2
|
+
|
|
3
|
+
export type { ActionButtonProps } from "./ActionButton";
|
|
4
|
+
|
|
5
|
+
export { boundActionButton } from "./boundActionButton";
|
|
6
|
+
|
|
7
|
+
export { openActionsBottomSheet } from "./openActionsBottomSheet";
|
|
8
|
+
|
|
9
|
+
export type { OpenActionsBottomSheetArgs } from "./openActionsBottomSheet";
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
2
|
+
import { openBottomSheetModal } from "@applicaster/zapp-react-native-utils/modalState";
|
|
3
|
+
import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
4
|
+
import { RegisteredAction } from "@applicaster/zapp-react-native-utils/uiActionsRegistrator";
|
|
5
|
+
|
|
6
|
+
import { boundActionButton } from "./boundActionButton";
|
|
7
|
+
|
|
8
|
+
const { log_warning } = createLogger({
|
|
9
|
+
subsystem: "ActionsBottomSheet",
|
|
10
|
+
category: "Presentation",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
export type OpenActionsBottomSheetArgs = {
|
|
14
|
+
/** Entry the actions act on; bound into every row button. */
|
|
15
|
+
entry: ZappEntry | ZappFeed;
|
|
16
|
+
/** Already resolved and merged actions, in the order they should appear. */
|
|
17
|
+
actions: RegisteredAction[];
|
|
18
|
+
title?: string;
|
|
19
|
+
summary?: string;
|
|
20
|
+
/** List that opened the sheet; forwarded into row invokeAction context. */
|
|
21
|
+
component?: ZappUIComponent & { parent?: ZappUIComponent };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Presents a list of resolved actions in the shared bottom sheet.
|
|
26
|
+
*
|
|
27
|
+
* This is the core entry point for "show these actions in a sheet": the
|
|
28
|
+
* open-modal-bottom-sheet plugin uses it for its configured list, and the
|
|
29
|
+
* player overflow uses it for the actions that did not fit on the overlay.
|
|
30
|
+
* Neither has to know about the other, and neither needs the plugin installed.
|
|
31
|
+
*/
|
|
32
|
+
export function openActionsBottomSheet({
|
|
33
|
+
entry,
|
|
34
|
+
actions,
|
|
35
|
+
title,
|
|
36
|
+
summary,
|
|
37
|
+
component,
|
|
38
|
+
}: OpenActionsBottomSheetArgs): void {
|
|
39
|
+
if (!actions?.length) {
|
|
40
|
+
// Every action resolved away - unavailable for this entry, or not
|
|
41
|
+
// invokable. An empty sheet looks broken, so say why and stay put.
|
|
42
|
+
log_warning(
|
|
43
|
+
"openActionsBottomSheet: nothing to present - not opening the sheet",
|
|
44
|
+
{ entryId: (entry as ZappEntry)?.id }
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
openBottomSheetModal({
|
|
51
|
+
modalBottomSheetContentProps: {
|
|
52
|
+
// TODO: should be optional - the button handles its own tap, but
|
|
53
|
+
// BottomSheetModalContent still requires an onPress.
|
|
54
|
+
onPress: noop,
|
|
55
|
+
items: actions,
|
|
56
|
+
buttonComponent: boundActionButton(entry, component),
|
|
57
|
+
title,
|
|
58
|
+
summary,
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
@@ -17,6 +17,9 @@ import {
|
|
|
17
17
|
Text,
|
|
18
18
|
View,
|
|
19
19
|
} from "react-native";
|
|
20
|
+
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
21
|
+
|
|
22
|
+
const logger = createLogger({ category: "ModalComponent:AudioPlayerButton" });
|
|
20
23
|
|
|
21
24
|
const styles = StyleSheet.create({
|
|
22
25
|
container: {
|
|
@@ -32,24 +35,6 @@ const styles = StyleSheet.create({
|
|
|
32
35
|
title: {
|
|
33
36
|
textAlign: "center",
|
|
34
37
|
},
|
|
35
|
-
demoScreen: {
|
|
36
|
-
flex: 1,
|
|
37
|
-
backgroundColor: "#1C1C1E",
|
|
38
|
-
paddingTop: 64,
|
|
39
|
-
paddingHorizontal: 24,
|
|
40
|
-
gap: 12,
|
|
41
|
-
},
|
|
42
|
-
demoHeading: {
|
|
43
|
-
color: "#FFFFFF",
|
|
44
|
-
fontSize: 20,
|
|
45
|
-
fontWeight: "600",
|
|
46
|
-
marginBottom: 8,
|
|
47
|
-
},
|
|
48
|
-
demoLabel: {
|
|
49
|
-
color: "#999999",
|
|
50
|
-
fontSize: 13,
|
|
51
|
-
marginTop: 8,
|
|
52
|
-
},
|
|
53
38
|
});
|
|
54
39
|
|
|
55
40
|
// ---------------------------------------------------------------------------
|
|
@@ -99,6 +84,8 @@ export type LeadingIconConfiguration = {
|
|
|
99
84
|
enabled: boolean;
|
|
100
85
|
/** Decides which icon will be displayed when enabled */
|
|
101
86
|
actionType?: ButtonActionType;
|
|
87
|
+
/** Optional Studio / modal-blocks asset URI (overrides actionType mapping) */
|
|
88
|
+
asset?: string;
|
|
102
89
|
};
|
|
103
90
|
|
|
104
91
|
export type IconsConfiguration = {
|
|
@@ -146,6 +133,28 @@ export const DEFAULT_ICONS_CONFIGURATION: IconsConfiguration = {
|
|
|
146
133
|
},
|
|
147
134
|
};
|
|
148
135
|
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// Variant configurations
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
|
|
140
|
+
export const VARIANT_TEXT_ONLY: ButtonConfiguration = {
|
|
141
|
+
background: DEFAULT_BACKGROUND_CONFIGURATION,
|
|
142
|
+
title: DEFAULT_TITLE_CONFIGURATION,
|
|
143
|
+
icons: DEFAULT_ICONS_CONFIGURATION,
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const VARIANT_WITH_ICON: ButtonConfiguration = {
|
|
147
|
+
background: DEFAULT_BACKGROUND_CONFIGURATION,
|
|
148
|
+
title: DEFAULT_TITLE_CONFIGURATION,
|
|
149
|
+
icons: {
|
|
150
|
+
...DEFAULT_ICONS_CONFIGURATION,
|
|
151
|
+
leadingIcon: {
|
|
152
|
+
enabled: true,
|
|
153
|
+
actionType: "addToPlaylist",
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
|
|
149
158
|
// ---------------------------------------------------------------------------
|
|
150
159
|
// Data (runtime / localization — not styling config)
|
|
151
160
|
// ---------------------------------------------------------------------------
|
|
@@ -156,30 +165,15 @@ export type ButtonData = {
|
|
|
156
165
|
};
|
|
157
166
|
|
|
158
167
|
export type AudioPlayerButtonProps = {
|
|
159
|
-
configuration
|
|
160
|
-
data
|
|
168
|
+
configuration?: ButtonConfiguration;
|
|
169
|
+
data?: ButtonData;
|
|
161
170
|
disabled?: boolean;
|
|
162
171
|
focused?: boolean;
|
|
163
172
|
onPress?: () => void;
|
|
164
173
|
};
|
|
165
174
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
// ---------------------------------------------------------------------------
|
|
169
|
-
|
|
170
|
-
// Hardcoded: action type → icon asset mapping (base64 PNG)
|
|
171
|
-
const ACTION_ICON_ASSETS: Record<ButtonActionType, string> = {
|
|
172
|
-
addToQueue:
|
|
173
|
-
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAKUlEQVR42mNgGAVDCfxHw6MWjFpAvEGk4lELKLdgNJmOWkA7C0YBbQAAwiZvkR9eFgQAAAAASUVORK5CYII=",
|
|
174
|
-
addToPlaylist:
|
|
175
|
-
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAJklEQVR42mNgGAUjFvzHgmluATF4cFswGsmjkTwayaORPAqGLwAA6Jpxj9Ms9QMAAAAASUVORK5CYII=",
|
|
176
|
-
goToPlaylist:
|
|
177
|
-
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAALklEQVR42mNgGAWjYNiD/7Q2/D8tLflPiSX/ycQ0t+D/yLGAEkeMWjAKRgG9AQB4zlSshwSzWwAAAABJRU5ErkJggg==",
|
|
178
|
-
confirm:
|
|
179
|
-
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAJElEQVR42mNgGAWjYBSQCv4TwKMWDHELho/hNE/3o2AUDDcAAPv0QMAyy1CtAAAAAElFTkSuQmCC",
|
|
180
|
-
cancel:
|
|
181
|
-
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAASElEQVR42mNgGAWjGvynkVoUTf+pqA6nxv8UqiHbEooNx2cQ1QzHZiDVDcdlCcOQsoCmQUTTSKZpMqV5RqNLUUHTwm4UDBMAALBLQ73LTvoyAAAAAElFTkSuQmCC",
|
|
182
|
-
};
|
|
175
|
+
const PLACEHOLDER_RED_BOX =
|
|
176
|
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAJ0lEQVR4nO3NMQEAAAjDsIF/z2ACvlRAU5NMHuvPOQAAAAAAAMBdC/07Ai5sNw+CAAAAAElFTkSuQmCC";
|
|
183
177
|
|
|
184
178
|
function getTextTransformStyle(
|
|
185
179
|
textTransform: TextTransform
|
|
@@ -188,7 +182,9 @@ function getTextTransformStyle(
|
|
|
188
182
|
}
|
|
189
183
|
|
|
190
184
|
function shouldShowLeadingIcon(leadingIcon: LeadingIconConfiguration) {
|
|
191
|
-
return
|
|
185
|
+
return (
|
|
186
|
+
leadingIcon.enabled && (!!leadingIcon.actionType || !!leadingIcon.asset)
|
|
187
|
+
);
|
|
192
188
|
}
|
|
193
189
|
|
|
194
190
|
// ---------------------------------------------------------------------------
|
|
@@ -286,17 +282,31 @@ function ButtonTitle({
|
|
|
286
282
|
}
|
|
287
283
|
|
|
288
284
|
type ButtonLeadingIconProps = {
|
|
289
|
-
actionType
|
|
285
|
+
actionType?: ButtonActionType;
|
|
290
286
|
configuration: IconsConfiguration;
|
|
291
287
|
};
|
|
292
288
|
|
|
293
|
-
function ButtonLeadingIcon({
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
289
|
+
function ButtonLeadingIcon({ configuration }: ButtonLeadingIconProps) {
|
|
290
|
+
const asset = configuration.leadingIcon.asset || PLACEHOLDER_RED_BOX;
|
|
291
|
+
|
|
292
|
+
React.useEffect(() => {
|
|
293
|
+
if (!configuration.leadingIcon.asset) {
|
|
294
|
+
logger.log_warning(
|
|
295
|
+
"AudioPlayerButton has leadingIcon enabled but no asset was provided. Falling back to placeholder red box. Ensure the relevant plugin (e.g. playlist-experience) provides leadingIcon.asset in styleOverrides.",
|
|
296
|
+
{
|
|
297
|
+
leadingIcon: configuration.leadingIcon,
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
}, [configuration.leadingIcon.asset]);
|
|
302
|
+
|
|
303
|
+
if (!asset) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
|
|
297
307
|
return (
|
|
298
308
|
<Image
|
|
299
|
-
source={{ uri:
|
|
309
|
+
source={{ uri: asset }}
|
|
300
310
|
style={{
|
|
301
311
|
width: configuration.width,
|
|
302
312
|
height: configuration.height,
|
|
@@ -310,22 +320,46 @@ function ButtonLeadingIcon({
|
|
|
310
320
|
// AudioPlayerButton — single building block driven by configuration + data
|
|
311
321
|
// ---------------------------------------------------------------------------
|
|
312
322
|
|
|
323
|
+
import { useModalBlocksStyle } from "../../ModalBlocksStyleContext";
|
|
324
|
+
import { mergeButtonConfiguration } from "../utils/mergeStyles";
|
|
325
|
+
|
|
313
326
|
export function AudioPlayerButton({
|
|
314
|
-
configuration,
|
|
315
|
-
data,
|
|
327
|
+
configuration = VARIANT_WITH_ICON,
|
|
328
|
+
data = { title: undefined },
|
|
316
329
|
disabled,
|
|
317
330
|
focused = false,
|
|
318
331
|
onPress,
|
|
319
332
|
}: AudioPlayerButtonProps) {
|
|
333
|
+
const modalBlocksStyle = useModalBlocksStyle();
|
|
334
|
+
|
|
335
|
+
const buttonBlock = modalBlocksStyle?.button;
|
|
336
|
+
const actionBlock = modalBlocksStyle?.action;
|
|
337
|
+
|
|
338
|
+
const effectiveConfig = React.useMemo(() => {
|
|
339
|
+
return mergeButtonConfiguration(configuration, buttonBlock, actionBlock);
|
|
340
|
+
}, [configuration, buttonBlock, actionBlock]);
|
|
341
|
+
|
|
320
342
|
const {
|
|
321
|
-
background:
|
|
322
|
-
title:
|
|
343
|
+
background: effectiveBgConfig,
|
|
344
|
+
title: effectiveTitleConfig,
|
|
323
345
|
icons: iconsConfiguration,
|
|
324
|
-
} =
|
|
346
|
+
} = effectiveConfig;
|
|
325
347
|
|
|
326
|
-
const
|
|
348
|
+
const title = data?.title || buttonBlock?.title.default;
|
|
327
349
|
const isDisabled = disabled ?? data.disabled ?? false;
|
|
328
350
|
|
|
351
|
+
React.useEffect(() => {
|
|
352
|
+
if (!title) {
|
|
353
|
+
logger.log_warning(
|
|
354
|
+
"Create New Playlist button rendering with empty title. Ensure data.title is set for AudioPlayerButton or styleOverrides providing button title.",
|
|
355
|
+
{
|
|
356
|
+
leadingIcon: iconsConfiguration.leadingIcon,
|
|
357
|
+
modalBlocksStyle: modalBlocksStyle,
|
|
358
|
+
}
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
}, [title]);
|
|
362
|
+
|
|
329
363
|
const { leadingIcon } = iconsConfiguration;
|
|
330
364
|
const showIcon = shouldShowLeadingIcon(leadingIcon);
|
|
331
365
|
|
|
@@ -333,7 +367,7 @@ export function AudioPlayerButton({
|
|
|
333
367
|
<ButtonContainer
|
|
334
368
|
focused={focused}
|
|
335
369
|
disabled={isDisabled}
|
|
336
|
-
configuration={
|
|
370
|
+
configuration={effectiveBgConfig}
|
|
337
371
|
onPress={onPress}
|
|
338
372
|
>
|
|
339
373
|
<View style={styles.contentRow}>
|
|
@@ -343,60 +377,16 @@ export function AudioPlayerButton({
|
|
|
343
377
|
actionType={leadingIcon.actionType}
|
|
344
378
|
configuration={iconsConfiguration}
|
|
345
379
|
/>
|
|
346
|
-
<View style={{ width:
|
|
380
|
+
<View style={{ width: effectiveBgConfig.horizontalGutter }} />
|
|
347
381
|
</>
|
|
348
382
|
) : null}
|
|
349
383
|
<ButtonTitle
|
|
350
384
|
title={title}
|
|
351
385
|
focused={focused}
|
|
352
386
|
disabled={isDisabled}
|
|
353
|
-
configuration={
|
|
387
|
+
configuration={effectiveTitleConfig}
|
|
354
388
|
/>
|
|
355
389
|
</View>
|
|
356
390
|
</ButtonContainer>
|
|
357
391
|
);
|
|
358
392
|
}
|
|
359
|
-
|
|
360
|
-
// ---------------------------------------------------------------------------
|
|
361
|
-
// Snack demo — two Button variants from configuration only
|
|
362
|
-
// ---------------------------------------------------------------------------
|
|
363
|
-
|
|
364
|
-
export const VARIANT_TEXT_ONLY: ButtonConfiguration = {
|
|
365
|
-
background: DEFAULT_BACKGROUND_CONFIGURATION,
|
|
366
|
-
title: DEFAULT_TITLE_CONFIGURATION,
|
|
367
|
-
icons: DEFAULT_ICONS_CONFIGURATION,
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
export const VARIANT_WITH_ICON: ButtonConfiguration = {
|
|
371
|
-
background: DEFAULT_BACKGROUND_CONFIGURATION,
|
|
372
|
-
title: DEFAULT_TITLE_CONFIGURATION,
|
|
373
|
-
icons: {
|
|
374
|
-
...DEFAULT_ICONS_CONFIGURATION,
|
|
375
|
-
leadingIcon: {
|
|
376
|
-
enabled: true,
|
|
377
|
-
actionType: "addToPlaylist",
|
|
378
|
-
},
|
|
379
|
-
},
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
export const VARIANT_UPPERCASE_TITLE: ButtonConfiguration = {
|
|
383
|
-
background: DEFAULT_BACKGROUND_CONFIGURATION,
|
|
384
|
-
title: {
|
|
385
|
-
...DEFAULT_TITLE_CONFIGURATION,
|
|
386
|
-
textTransform: "uppercase",
|
|
387
|
-
},
|
|
388
|
-
icons: DEFAULT_ICONS_CONFIGURATION,
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
export const VARIANT_LARGE_ICON: ButtonConfiguration = {
|
|
392
|
-
background: DEFAULT_BACKGROUND_CONFIGURATION,
|
|
393
|
-
title: DEFAULT_TITLE_CONFIGURATION,
|
|
394
|
-
icons: {
|
|
395
|
-
width: 32,
|
|
396
|
-
height: 32,
|
|
397
|
-
leadingIcon: {
|
|
398
|
-
enabled: true,
|
|
399
|
-
actionType: "addToQueue",
|
|
400
|
-
},
|
|
401
|
-
},
|
|
402
|
-
};
|