@applicaster/zapp-react-native-ui-components 16.0.0-alpha.3683430391 → 16.0.0-alpha.4004661200
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/TvOSCellComponent.tsx +0 -1
- package/Components/MasterCell/DefaultComponents/Toggle.tsx +36 -14
- package/Components/MasterCell/DefaultComponents/__tests__/Toggle.test.tsx +167 -0
- package/Components/ModalComponent/ActionsBottomSheet/ActionButton.tsx +54 -0
- package/Components/ModalComponent/ActionsBottomSheet/boundActionButton.tsx +21 -0
- package/Components/ModalComponent/ActionsBottomSheet/index.ts +9 -0
- package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +58 -0
- package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +0 -18
- package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +17 -24
- package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +25 -73
- package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +0 -18
- package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +75 -79
- package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +89 -0
- package/Components/ModalComponent/AudioPlayer/Components/index.ts +3 -1
- package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +199 -0
- package/Components/ModalComponent/BottomSheetModalContent.tsx +379 -61
- package/Components/ModalComponent/Button/index.tsx +5 -3
- 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 +142 -0
- package/Components/ModalComponent/SortableList.web.tsx +102 -0
- package/Components/ModalComponent/TextInputContent.tsx +100 -0
- package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +238 -0
- package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +120 -0
- package/Components/ModalComponent/__tests__/showTextInput.test.ts +95 -0
- package/Components/ModalComponent/index.tsx +11 -0
- package/Components/ModalComponent/presets/__tests__/getCell.test.ts +66 -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 +76 -20
- package/Components/PlayerContainer/PlayerContainer.tsx +32 -15
- package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -4
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +189 -17
- package/Components/VideoLive/LiveImageManager.ts +1 -1
- package/Components/VideoModal/VideoModal.tsx +13 -14
- package/Components/VideoModal/__tests__/VideoModal.test.tsx +180 -0
- package/Hooks/useEntryActionsExpander.ts +63 -0
- package/package.json +6 -5
- /package/Decorators/ZappPipesDataConnector/__tests__/{Hero.js → Hero.tsx} +0 -0
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { render } from "@testing-library/react-native";
|
|
3
3
|
|
|
4
|
+
let mockContent = { title: null, summary: null };
|
|
5
|
+
|
|
6
|
+
// Read lazily inside the factory: `jest.mock` is hoisted above the `let` above,
|
|
7
|
+
// so capturing the value eagerly would freeze it at `undefined`.
|
|
8
|
+
jest.mock(
|
|
9
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent",
|
|
10
|
+
() => ({ usePlayerContent: () => mockContent })
|
|
11
|
+
);
|
|
12
|
+
|
|
4
13
|
import { AudioPlayerTV } from "..";
|
|
5
14
|
|
|
6
15
|
jest.mock("@applicaster/zapp-react-native-utils/audioPlayerUtils", () => ({
|
|
@@ -51,7 +60,17 @@ const audioPlayerProps = {
|
|
|
51
60
|
|
|
52
61
|
describe("<AudioPlayerTV />", () => {
|
|
53
62
|
it("renders correctly", () => {
|
|
63
|
+
// AudioPlayerTV no longer resolves its own title/summary from
|
|
64
|
+
// audio_item - it reads them from the player manager's content channel.
|
|
65
|
+
// Publishing the same values `audio_item.title`/`.summary` used to resolve
|
|
66
|
+
// to keeps this snapshot byte-for-byte identical to before that change.
|
|
67
|
+
mockContent = {
|
|
68
|
+
title: audioPlayerProps.audio_item.title,
|
|
69
|
+
summary: audioPlayerProps.audio_item.summary,
|
|
70
|
+
};
|
|
71
|
+
|
|
54
72
|
const { toJSON } = render(<AudioPlayerTV {...audioPlayerProps} />);
|
|
73
|
+
|
|
55
74
|
expect(toJSON()).toMatchSnapshot();
|
|
56
75
|
});
|
|
57
76
|
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
import { AudioPlayerTV } from "..";
|
|
5
|
+
|
|
6
|
+
jest.mock("@applicaster/zapp-react-native-utils/audioPlayerUtils", () => ({
|
|
7
|
+
useArtworkImage: jest.fn(() => "artwork_url"),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
let mockContent: {
|
|
11
|
+
title: Option<string | number>;
|
|
12
|
+
summary: Option<string | number>;
|
|
13
|
+
} = { title: null, summary: null };
|
|
14
|
+
|
|
15
|
+
// Read lazily inside the factory: `jest.mock` is hoisted above the `let`
|
|
16
|
+
// above, so capturing the value eagerly would freeze it at `undefined`.
|
|
17
|
+
jest.mock(
|
|
18
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent",
|
|
19
|
+
() => ({ usePlayerContent: () => mockContent })
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const baseAudioItem = {
|
|
23
|
+
title: "tittle",
|
|
24
|
+
summary: "Summary",
|
|
25
|
+
content: {
|
|
26
|
+
src: "https://example.com",
|
|
27
|
+
},
|
|
28
|
+
media_group: [
|
|
29
|
+
{
|
|
30
|
+
type: "audio",
|
|
31
|
+
media_item: [
|
|
32
|
+
{
|
|
33
|
+
type: "audio",
|
|
34
|
+
src: "https://example.com",
|
|
35
|
+
key: "base_code",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
extensions: {
|
|
41
|
+
audio_player_artwork_aspect_ratio: "1:1",
|
|
42
|
+
audio_player_background_image: "https://example.com",
|
|
43
|
+
audio_player_background_color: "black",
|
|
44
|
+
audio_player_channel_icon: "https://example.com",
|
|
45
|
+
audio_player_title_color: "white",
|
|
46
|
+
audio_player_summary_color: "white",
|
|
47
|
+
audio_player_rtl: true,
|
|
48
|
+
start_time: "10:10",
|
|
49
|
+
end_time: "11:11",
|
|
50
|
+
episode_name: "Episode Custom Title",
|
|
51
|
+
episode_summary: "Episode Custom Summary",
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const basePluginConfiguration = {
|
|
56
|
+
audio_player_background_color: "black",
|
|
57
|
+
audio_player_title_color: "white",
|
|
58
|
+
audio_player_summary_color: "white",
|
|
59
|
+
audio_player_rtl: true,
|
|
60
|
+
audio_player_background_image: "https://example.com",
|
|
61
|
+
audio_player_artwork_aspect_ratio: "1:1",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function renderAudioPlayer(
|
|
65
|
+
plugin_configuration,
|
|
66
|
+
content: {
|
|
67
|
+
title?: Option<string | number>;
|
|
68
|
+
summary?: Option<string | number>;
|
|
69
|
+
} = {}
|
|
70
|
+
) {
|
|
71
|
+
mockContent = {
|
|
72
|
+
title: content.title ?? null,
|
|
73
|
+
summary: content.summary ?? null,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return render(
|
|
77
|
+
<AudioPlayerTV
|
|
78
|
+
audio_item={baseAudioItem}
|
|
79
|
+
plugin_configuration={plugin_configuration}
|
|
80
|
+
style={{}}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
describe("<AudioPlayerTV /> player content", () => {
|
|
86
|
+
it("renders the title and summary published by the player manager", () => {
|
|
87
|
+
const { getByText } = renderAudioPlayer(basePluginConfiguration, {
|
|
88
|
+
title: "Episode Custom Title",
|
|
89
|
+
summary: "Episode Custom Summary",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(getByText("Episode Custom Title")).toBeTruthy();
|
|
93
|
+
expect(getByText("Episode Custom Summary")).toBeTruthy();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("renders nothing for title/summary when the player published neither", () => {
|
|
97
|
+
const { queryByText } = renderAudioPlayer(basePluginConfiguration);
|
|
98
|
+
|
|
99
|
+
expect(queryByText("tittle")).toBeNull();
|
|
100
|
+
expect(queryByText("Summary")).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("renders blank rather than crashing when no player is active", () => {
|
|
104
|
+
// `usePlayerContent` returns `{ title: null, summary: null }` when there is
|
|
105
|
+
// no player. A regression here means AudioPlayerTV crashes instead of
|
|
106
|
+
// rendering blank.
|
|
107
|
+
mockContent = { title: null, summary: null };
|
|
108
|
+
|
|
109
|
+
const { queryByText } = render(
|
|
110
|
+
<AudioPlayerTV
|
|
111
|
+
audio_item={baseAudioItem}
|
|
112
|
+
plugin_configuration={basePluginConfiguration}
|
|
113
|
+
style={{}}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(queryByText("tittle")).toBeNull();
|
|
118
|
+
expect(queryByText("Summary")).toBeNull();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -3,6 +3,8 @@ import React, { useCallback, useMemo } from "react";
|
|
|
3
3
|
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
4
4
|
import { useArtworkImage } from "@applicaster/zapp-react-native-utils/audioPlayerUtils";
|
|
5
5
|
|
|
6
|
+
import { usePlayerContent } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent";
|
|
7
|
+
|
|
6
8
|
import { AudioPlayerTVLayout } from "./Layout";
|
|
7
9
|
|
|
8
10
|
import { Channel } from "./Channel";
|
|
@@ -15,10 +17,12 @@ import { Props } from "../types";
|
|
|
15
17
|
|
|
16
18
|
export function AudioPlayerTV(props: Props) {
|
|
17
19
|
const { audio_item, plugin_configuration, style = {} } = props;
|
|
18
|
-
const { extensions
|
|
20
|
+
const { extensions } = audio_item;
|
|
19
21
|
|
|
20
22
|
const artwork = useArtworkImage(audio_item);
|
|
21
23
|
|
|
24
|
+
const { title, summary } = usePlayerContent();
|
|
25
|
+
|
|
22
26
|
const getProp = useCallback(
|
|
23
27
|
getPropertyFromEntryOrConfig({
|
|
24
28
|
entry: audio_item,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { useCallback, useState } from "react";
|
|
2
2
|
import { Switch } from "react-native";
|
|
3
3
|
import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
|
|
4
|
+
import { useCellClick } from "@applicaster/zapp-react-native-utils/reactHooks/cell-click";
|
|
4
5
|
|
|
5
6
|
type Props = {
|
|
6
7
|
item: ZappEntry | ZappFeed;
|
|
@@ -15,36 +16,57 @@ type Props = {
|
|
|
15
16
|
export const Toggle = (props: Props) => {
|
|
16
17
|
const { style, item, action, cellState } = props;
|
|
17
18
|
|
|
18
|
-
const {
|
|
19
|
-
trackColor,
|
|
20
|
-
trackColorActive,
|
|
21
|
-
thumbColor,
|
|
22
|
-
thumbColorActive,
|
|
23
|
-
iosBackgroundColor,
|
|
24
|
-
} = style;
|
|
19
|
+
const { trackColor, trackColorActive, thumbColor, thumbColorActive } = style;
|
|
25
20
|
|
|
21
|
+
// `focused_selected` is the selected state with a finger on the row, so the
|
|
22
|
+
// switch has to read as on for both. Leaving it out reads a pressed selected
|
|
23
|
+
// row as off, which flips the thumb for the duration of the press.
|
|
26
24
|
const isSelected = React.useMemo(
|
|
27
|
-
() => cellState === "selected",
|
|
25
|
+
() => cellState === "selected" || cellState === "focused_selected",
|
|
28
26
|
[item?.id, cellState]
|
|
29
27
|
);
|
|
30
28
|
|
|
31
29
|
const actionContext = useActions(action?.identifier);
|
|
30
|
+
const onCellClick = useCellClick({ item: item as ZappEntry });
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
// A form toggle has no action plugin behind the switch: it reflects the cell
|
|
33
|
+
// selection state and writes through the entry's tap actions, the same path a
|
|
34
|
+
// tap on the row takes.
|
|
35
|
+
//
|
|
36
|
+
// An empty identifier is the way to ask for that, which is why the cell
|
|
37
|
+
// manifest declares no initial_value for `toggle_action_identifier`:
|
|
38
|
+
// `castOrDefault` substitutes the default whenever the configured value is
|
|
39
|
+
// empty - and an empty string counts as empty - so any default there would be
|
|
40
|
+
// uncleanable and would force every toggle onto that plugin.
|
|
41
|
+
//
|
|
42
|
+
// The route is still decided on whether the identifier resolves to an
|
|
43
|
+
// installed action plugin rather than on the string being non-empty. App
|
|
44
|
+
// configurations saved while the old default was in the manifest still carry
|
|
45
|
+
// it, and a mistyped plugin id has to fall back the same way.
|
|
46
|
+
const hasActionPlugin = Boolean(
|
|
47
|
+
action?.identifier && actionContext?.invokeAction
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const [actionState, setActionState] = useState(() =>
|
|
51
|
+
hasActionPlugin ? actionContext?.initialEntryState?.(item) : undefined
|
|
35
52
|
);
|
|
36
53
|
|
|
37
54
|
const onPress = useCallback(() => {
|
|
38
|
-
|
|
55
|
+
if (!hasActionPlugin) {
|
|
56
|
+
onCellClick();
|
|
57
|
+
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
actionContext?.invokeAction?.(item, {
|
|
39
62
|
updateState: setActionState,
|
|
40
63
|
});
|
|
41
|
-
}, [actionState, actionContext?.state]);
|
|
64
|
+
}, [hasActionPlugin, onCellClick, actionState, actionContext?.state]);
|
|
42
65
|
|
|
43
66
|
return (
|
|
44
67
|
<Switch
|
|
45
68
|
trackColor={{ false: trackColor, true: trackColorActive }}
|
|
46
69
|
thumbColor={isSelected ? thumbColorActive : thumbColor}
|
|
47
|
-
ios_backgroundColor={iosBackgroundColor}
|
|
48
70
|
onValueChange={onPress}
|
|
49
71
|
value={isSelected}
|
|
50
72
|
/>
|
|
@@ -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,54 @@
|
|
|
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
|
+
};
|
|
16
|
+
|
|
17
|
+
type Props = ActionButtonProps & {
|
|
18
|
+
onPress?: (item: any) => void;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Unified action button for the modal bottom sheet.
|
|
23
|
+
*
|
|
24
|
+
* Every item is a `RegisteredAction` resolved from the registry (entry actions,
|
|
25
|
+
* registry actions and legacy context-provider actions alike), so the button
|
|
26
|
+
* simply reads `item.action` and drives it through `useEntryActionState`
|
|
27
|
+
* (backed by the action's observable / `addListener`).
|
|
28
|
+
*/
|
|
29
|
+
export function ActionButton(props: Props) {
|
|
30
|
+
const { item, entry, onPress: onItemPress } = props;
|
|
31
|
+
|
|
32
|
+
const action = item?.action;
|
|
33
|
+
|
|
34
|
+
const { state, invokeAction } = useEntryActionState(action, entry);
|
|
35
|
+
|
|
36
|
+
const onPress = React.useCallback(
|
|
37
|
+
(_item) => {
|
|
38
|
+
invokeAction({
|
|
39
|
+
context: "toast",
|
|
40
|
+
dismiss: () => onItemPress?.(item),
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
[invokeAction, item, onItemPress]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
if (!isActionAvailableFor(action, entry as ZappEntry)) return null;
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<Button {...props} item={state} onPress={onPress} label={state?.label} />
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Explicitly set display name for the component
|
|
54
|
+
ActionButton.displayName = "ActionButton";
|
|
@@ -0,0 +1,21 @@
|
|
|
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 = (entry: ZappEntry | ZappFeed) => {
|
|
12
|
+
const ActionButtonWithEntry = (props: ActionButtonProps) => (
|
|
13
|
+
<ActionButton {...props} entry={entry as ZappEntry} />
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
ActionButtonWithEntry.displayName = "ActionButtonWithEntry";
|
|
17
|
+
|
|
18
|
+
return ActionButtonWithEntry;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
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,58 @@
|
|
|
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
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Presents a list of resolved actions in the shared bottom sheet.
|
|
24
|
+
*
|
|
25
|
+
* This is the core entry point for "show these actions in a sheet": the
|
|
26
|
+
* open-modal-bottom-sheet plugin uses it for its configured list, and the
|
|
27
|
+
* player overflow uses it for the actions that did not fit on the overlay.
|
|
28
|
+
* Neither has to know about the other, and neither needs the plugin installed.
|
|
29
|
+
*/
|
|
30
|
+
export function openActionsBottomSheet({
|
|
31
|
+
entry,
|
|
32
|
+
actions,
|
|
33
|
+
title,
|
|
34
|
+
summary,
|
|
35
|
+
}: OpenActionsBottomSheetArgs): void {
|
|
36
|
+
if (!actions?.length) {
|
|
37
|
+
// Every action resolved away - unavailable for this entry, or not
|
|
38
|
+
// invokable. An empty sheet looks broken, so say why and stay put.
|
|
39
|
+
log_warning(
|
|
40
|
+
"openActionsBottomSheet: nothing to present - not opening the sheet",
|
|
41
|
+
{ entryId: (entry as ZappEntry)?.id }
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
openBottomSheetModal({
|
|
48
|
+
modalBottomSheetContentProps: {
|
|
49
|
+
// TODO: should be optional - the button handles its own tap, but
|
|
50
|
+
// BottomSheetModalContent still requires an onPress.
|
|
51
|
+
onPress: noop,
|
|
52
|
+
items: actions,
|
|
53
|
+
buttonComponent: boundActionButton(entry),
|
|
54
|
+
title,
|
|
55
|
+
summary,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -25,24 +25,6 @@ const styles = StyleSheet.create({
|
|
|
25
25
|
flexDirection: "row",
|
|
26
26
|
alignItems: "center",
|
|
27
27
|
},
|
|
28
|
-
demoScreen: {
|
|
29
|
-
flex: 1,
|
|
30
|
-
backgroundColor: "#1C1C1E",
|
|
31
|
-
paddingTop: 64,
|
|
32
|
-
paddingHorizontal: 16,
|
|
33
|
-
gap: 12,
|
|
34
|
-
},
|
|
35
|
-
demoHeading: {
|
|
36
|
-
color: "#FFFFFF",
|
|
37
|
-
fontSize: 20,
|
|
38
|
-
fontWeight: "600",
|
|
39
|
-
marginBottom: 8,
|
|
40
|
-
},
|
|
41
|
-
demoLabel: {
|
|
42
|
-
color: "#999999",
|
|
43
|
-
fontSize: 13,
|
|
44
|
-
marginTop: 8,
|
|
45
|
-
},
|
|
46
28
|
});
|
|
47
29
|
|
|
48
30
|
// ---------------------------------------------------------------------------
|
|
@@ -32,24 +32,6 @@ const styles = StyleSheet.create({
|
|
|
32
32
|
title: {
|
|
33
33
|
textAlign: "center",
|
|
34
34
|
},
|
|
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
35
|
});
|
|
54
36
|
|
|
55
37
|
// ---------------------------------------------------------------------------
|
|
@@ -310,6 +292,9 @@ function ButtonLeadingIcon({
|
|
|
310
292
|
// AudioPlayerButton — single building block driven by configuration + data
|
|
311
293
|
// ---------------------------------------------------------------------------
|
|
312
294
|
|
|
295
|
+
import { useModalBlocksStyle } from "../../ModalBlocksStyleContext";
|
|
296
|
+
import { mergeButtonConfiguration } from "../utils/mergeStyles";
|
|
297
|
+
|
|
313
298
|
export function AudioPlayerButton({
|
|
314
299
|
configuration,
|
|
315
300
|
data,
|
|
@@ -317,11 +302,19 @@ export function AudioPlayerButton({
|
|
|
317
302
|
focused = false,
|
|
318
303
|
onPress,
|
|
319
304
|
}: AudioPlayerButtonProps) {
|
|
305
|
+
const modalBlocksStyle = useModalBlocksStyle();
|
|
306
|
+
const buttonBlock = modalBlocksStyle?.button;
|
|
307
|
+
const actionBlock = modalBlocksStyle?.action;
|
|
308
|
+
|
|
309
|
+
const effectiveConfig = React.useMemo(() => {
|
|
310
|
+
return mergeButtonConfiguration(configuration, buttonBlock, actionBlock);
|
|
311
|
+
}, [configuration, buttonBlock, actionBlock]);
|
|
312
|
+
|
|
320
313
|
const {
|
|
321
|
-
background:
|
|
322
|
-
title:
|
|
314
|
+
background: effectiveBgConfig,
|
|
315
|
+
title: effectiveTitleConfig,
|
|
323
316
|
icons: iconsConfiguration,
|
|
324
|
-
} =
|
|
317
|
+
} = effectiveConfig;
|
|
325
318
|
|
|
326
319
|
const { title } = data;
|
|
327
320
|
const isDisabled = disabled ?? data.disabled ?? false;
|
|
@@ -333,7 +326,7 @@ export function AudioPlayerButton({
|
|
|
333
326
|
<ButtonContainer
|
|
334
327
|
focused={focused}
|
|
335
328
|
disabled={isDisabled}
|
|
336
|
-
configuration={
|
|
329
|
+
configuration={effectiveBgConfig}
|
|
337
330
|
onPress={onPress}
|
|
338
331
|
>
|
|
339
332
|
<View style={styles.contentRow}>
|
|
@@ -343,14 +336,14 @@ export function AudioPlayerButton({
|
|
|
343
336
|
actionType={leadingIcon.actionType}
|
|
344
337
|
configuration={iconsConfiguration}
|
|
345
338
|
/>
|
|
346
|
-
<View style={{ width:
|
|
339
|
+
<View style={{ width: effectiveBgConfig.horizontalGutter }} />
|
|
347
340
|
</>
|
|
348
341
|
) : null}
|
|
349
342
|
<ButtonTitle
|
|
350
343
|
title={title}
|
|
351
344
|
focused={focused}
|
|
352
345
|
disabled={isDisabled}
|
|
353
|
-
configuration={
|
|
346
|
+
configuration={effectiveTitleConfig}
|
|
354
347
|
/>
|
|
355
348
|
</View>
|
|
356
349
|
</ButtonContainer>
|