@applicaster/zapp-react-native-utils 16.0.0-alpha.1212303401 → 16.0.0-alpha.1263110541
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actionsExecutor/ActionExecutorContext.tsx +16 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +4 -0
- package/actionsExecutor/consts.ts +2 -0
- package/appUtils/playerManager/__tests__/playerNative.test.ts +38 -0
- package/appUtils/playerManager/playerNative.ts +5 -3
- package/entryActions/__tests__/buildEntryActions.test.ts +156 -0
- package/entryActions/aliasPresentation.ts +124 -0
- package/entryActions/buildEntryActions.ts +166 -0
- package/entryActions/index.ts +17 -0
- package/entryActions/types.ts +39 -0
- package/manifestUtils/_internals/index.js +8 -3
- package/manifestUtils/defaultManifestConfigurations/player.js +22 -1
- package/package.json +2 -2
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/index.ts +17 -1
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/reactHooks/actions/index.ts +67 -2
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +107 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -203
- package/uiActionsRegistrator/registry.ts +335 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import { createLogger } from "../logger";
|
|
3
|
+
import { ActionExecutionContext } from "../actionsExecutor/types";
|
|
4
|
+
import { RegisteredAction } from "../uiActionsRegistrator";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
resolveButtonAsset,
|
|
8
|
+
resolveButtonLabel,
|
|
9
|
+
resolveExplicitLabel,
|
|
10
|
+
} from "./aliasPresentation";
|
|
11
|
+
import { EntryAction, EntryActionDeps } from "./types";
|
|
12
|
+
|
|
13
|
+
const { log_info, log_warning, log_error } = createLogger({
|
|
14
|
+
subsystem: "EntryActions",
|
|
15
|
+
category: "EntryAction",
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const ENTRY_ACTION_IDENTIFIER_PREFIX = "entry_action";
|
|
19
|
+
|
|
20
|
+
/** True for actions inflated from `entry.extensions.entry_action`. */
|
|
21
|
+
export function isEntryAction(item: RegisteredAction): boolean {
|
|
22
|
+
return item?.source === "entry";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function isValidEntryAction(value: unknown): value is EntryAction {
|
|
26
|
+
if (typeof value !== "object" || value === null) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { button, actions } = value as EntryAction;
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
(typeof button?.title === "string" ||
|
|
34
|
+
typeof button?.label === "string" ||
|
|
35
|
+
typeof button?.alias === "string") &&
|
|
36
|
+
Array.isArray(actions)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function createEntryAction(
|
|
41
|
+
entryAction: EntryAction,
|
|
42
|
+
index: number,
|
|
43
|
+
entry: ZappEntry | ZappFeed,
|
|
44
|
+
deps: EntryActionDeps
|
|
45
|
+
): RegisteredAction {
|
|
46
|
+
const { button, actions, dismiss_on_action } = entryAction;
|
|
47
|
+
|
|
48
|
+
const identifier = `${ENTRY_ACTION_IDENTIFIER_PREFIX}_${index}`;
|
|
49
|
+
const primaryAction = actions.length > 0 ? actions[0] : null;
|
|
50
|
+
|
|
51
|
+
const actionState = primaryAction
|
|
52
|
+
? deps.actionExecutor?.getActionState?.(primaryAction.type, entry)
|
|
53
|
+
: null;
|
|
54
|
+
|
|
55
|
+
// An explicit title/label outranks the executor's action state; the
|
|
56
|
+
// alias-derived defaults only fill in when neither produced anything.
|
|
57
|
+
const label: CellActionEntryState["label"] =
|
|
58
|
+
resolveExplicitLabel(button) ||
|
|
59
|
+
actionState?.label ||
|
|
60
|
+
resolveButtonLabel(button, deps.aliasPresentation);
|
|
61
|
+
|
|
62
|
+
const asset: CellActionEntryState["asset"] =
|
|
63
|
+
button?.iconURL ||
|
|
64
|
+
actionState?.asset ||
|
|
65
|
+
resolveButtonAsset(button, deps.aliasPresentation);
|
|
66
|
+
|
|
67
|
+
const initialState = { state: 0, label, asset };
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
identifier,
|
|
71
|
+
source: "entry",
|
|
72
|
+
action: {
|
|
73
|
+
initialEntryState: () => initialState,
|
|
74
|
+
invokeAction: async (
|
|
75
|
+
invokedEntry: ZappEntry,
|
|
76
|
+
options: InvokeArgsOptions = {}
|
|
77
|
+
) => {
|
|
78
|
+
if (dismiss_on_action === true) {
|
|
79
|
+
options.dismiss?.();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
log_info(
|
|
83
|
+
`invokeAction: entry action "${identifier}" triggered for entry "${invokedEntry?.id}"`,
|
|
84
|
+
{ identifier, entryId: invokedEntry?.id, actionCount: actions.length }
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
// Both of these leave the user with a button that does nothing when
|
|
88
|
+
// tapped, and neither throws, so they would otherwise be invisible.
|
|
89
|
+
if (actions.length === 0) {
|
|
90
|
+
log_warning(
|
|
91
|
+
`invokeAction: entry action "${identifier}" on entry "${invokedEntry?.id}" declares no actions - the tap does nothing`,
|
|
92
|
+
{ identifier, entryId: invokedEntry?.id }
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (typeof deps.actionExecutor?.handleActions !== "function") {
|
|
97
|
+
log_warning(
|
|
98
|
+
`invokeAction: no action executor available for entry action "${identifier}" - the tap does nothing`,
|
|
99
|
+
{ identifier, entryId: invokedEntry?.id }
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
try {
|
|
104
|
+
await deps.actionExecutor?.handleActions(actions, {
|
|
105
|
+
entry: invokedEntry,
|
|
106
|
+
entryContext: invokedEntry,
|
|
107
|
+
...deps.actionContext,
|
|
108
|
+
} as ActionExecutionContext);
|
|
109
|
+
} catch (error) {
|
|
110
|
+
log_error(
|
|
111
|
+
`invokeAction: entry action "${identifier}" failed for entry "${invokedEntry?.id}"`,
|
|
112
|
+
{
|
|
113
|
+
identifier,
|
|
114
|
+
entryId: invokedEntry?.id,
|
|
115
|
+
// Types only - the action payloads are backend supplied and may
|
|
116
|
+
// carry user data.
|
|
117
|
+
actionTypes: actions.map((action) => action?.type),
|
|
118
|
+
error,
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Builds the list of actions declared on an entry via
|
|
129
|
+
* `entry.extensions.entry_action`.
|
|
130
|
+
*/
|
|
131
|
+
export function buildEntryActions(
|
|
132
|
+
entry: ZappEntry | ZappFeed,
|
|
133
|
+
deps: EntryActionDeps
|
|
134
|
+
): RegisteredAction[] {
|
|
135
|
+
const entryId = (entry as ZappEntry)?.id;
|
|
136
|
+
const raw = (entry as any)?.extensions?.entry_action;
|
|
137
|
+
|
|
138
|
+
// Most entries simply declare no actions. This provider is resolved for
|
|
139
|
+
// every entry on every render, so saying so would drown everything else.
|
|
140
|
+
if (raw === undefined || raw === null) {
|
|
141
|
+
return [];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (!Array.isArray(raw)) {
|
|
145
|
+
log_warning(
|
|
146
|
+
`buildEntryActions: entry "${entryId}" has extensions.entry_action of type ${typeof raw} instead of an array - no entry actions will be shown`,
|
|
147
|
+
{ entryId, receivedType: typeof raw }
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
return [];
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const valid = raw.filter(isValidEntryAction);
|
|
154
|
+
const invalid = raw.length - valid.length;
|
|
155
|
+
|
|
156
|
+
if (invalid > 0) {
|
|
157
|
+
log_warning(
|
|
158
|
+
`buildEntryActions: ${invalid} invalid entry action(s) skipped for entry "${entryId}"`,
|
|
159
|
+
{ entryId, total: raw.length, invalid }
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return valid.map((entryAction, index) =>
|
|
164
|
+
createEntryAction(entryAction, index, entry, deps)
|
|
165
|
+
);
|
|
166
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { buildEntryActions, isEntryAction } from "./buildEntryActions";
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
ALIAS_ASSETS,
|
|
5
|
+
ALIAS_LABELS,
|
|
6
|
+
resolveButtonAsset,
|
|
7
|
+
resolveButtonLabel,
|
|
8
|
+
resolveExplicitLabel,
|
|
9
|
+
} from "./aliasPresentation";
|
|
10
|
+
|
|
11
|
+
export type {
|
|
12
|
+
EntryAction,
|
|
13
|
+
EntryActionDeps,
|
|
14
|
+
EntryActionExecutionContext,
|
|
15
|
+
} from "./types";
|
|
16
|
+
|
|
17
|
+
export type { AliasPresentation } from "./aliasPresentation";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import type { ActionExecutorContextType } from "../actionsExecutor/ActionExecutorContext";
|
|
3
|
+
import type { AliasPresentation } from "./aliasPresentation";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A single action declared by the backend on an entry, under
|
|
7
|
+
* `entry.extensions.entry_action`.
|
|
8
|
+
*/
|
|
9
|
+
export type EntryAction = {
|
|
10
|
+
button: {
|
|
11
|
+
title?: string;
|
|
12
|
+
label?: string;
|
|
13
|
+
alias?: string;
|
|
14
|
+
iconURL?: string;
|
|
15
|
+
};
|
|
16
|
+
actions: ZappActionType[];
|
|
17
|
+
dismiss_on_action?: boolean;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Everything `buildEntryActions` needs from the surrounding React tree in order
|
|
22
|
+
* to execute an entry action. Supplied lazily so the registered provider always
|
|
23
|
+
* reads the freshest screen context.
|
|
24
|
+
*/
|
|
25
|
+
export type EntryActionDeps = {
|
|
26
|
+
actionExecutor: ActionExecutorContextType;
|
|
27
|
+
actionContext: EntryActionExecutionContext;
|
|
28
|
+
/** App-supplied labels/icons for backend aliases; defaults are used without it. */
|
|
29
|
+
aliasPresentation?: AliasPresentation;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** The screen the action is executed against, spread into the execution context. */
|
|
33
|
+
export type EntryActionExecutionContext = {
|
|
34
|
+
screenData?: unknown;
|
|
35
|
+
screenState?: unknown;
|
|
36
|
+
screenRoute?: string;
|
|
37
|
+
screenStateStore?: unknown;
|
|
38
|
+
screenEntry?: unknown;
|
|
39
|
+
};
|
|
@@ -135,7 +135,8 @@ function generateFieldsFromDefaults(label, defaults, fields) {
|
|
|
135
135
|
function generateFieldsFromDefaultsWithoutPrefixedLabel(
|
|
136
136
|
label,
|
|
137
137
|
defaults,
|
|
138
|
-
fields
|
|
138
|
+
fields,
|
|
139
|
+
{ withStyle = false } = {}
|
|
139
140
|
) {
|
|
140
141
|
const keyPrefix = toSnakeCase(label);
|
|
141
142
|
|
|
@@ -151,7 +152,9 @@ function generateFieldsFromDefaultsWithoutPrefixedLabel(
|
|
|
151
152
|
const generatedField = {
|
|
152
153
|
...fieldProps,
|
|
153
154
|
label: capitalizeFirstLetter(field.suffix),
|
|
154
|
-
key:
|
|
155
|
+
key: withStyle
|
|
156
|
+
? `${keyPrefix}_style_${toSnakeCase(field.suffix)}`
|
|
157
|
+
: `${keyPrefix}_${toSnakeCase(field.suffix)}`,
|
|
155
158
|
initial_value: R.when(R.is(Array), R.head)(initialValue),
|
|
156
159
|
};
|
|
157
160
|
|
|
@@ -164,7 +167,9 @@ function generateFieldsFromDefaultsWithoutPrefixedLabel(
|
|
|
164
167
|
const section = condition.section ? `${condition.section}/` : "";
|
|
165
168
|
|
|
166
169
|
return {
|
|
167
|
-
key:
|
|
170
|
+
key: withStyle
|
|
171
|
+
? `${section}${keyPrefix}_style_${toSnakeCase(condition.key)}`
|
|
172
|
+
: `${section}${keyPrefix}_${toSnakeCase(condition.key)}`,
|
|
168
173
|
condition_value: condition.value,
|
|
169
174
|
};
|
|
170
175
|
});
|
|
@@ -204,6 +204,20 @@ function getPlayerConfiguration({ platform, version }) {
|
|
|
204
204
|
label_tooltip: "Label for close button accessibility",
|
|
205
205
|
type: "text_input",
|
|
206
206
|
},
|
|
207
|
+
{
|
|
208
|
+
key: "accessibility_overflow_label",
|
|
209
|
+
label: "Accessibility overflow label",
|
|
210
|
+
initial_value: "More actions",
|
|
211
|
+
label_tooltip: "Label for the overflow (…) button accessibility",
|
|
212
|
+
type: "text_input",
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
key: "accessibility_overflow_hint",
|
|
216
|
+
label: "Accessibility overflow hint",
|
|
217
|
+
initial_value: "Opens the remaining player actions",
|
|
218
|
+
label_tooltip: "Hint for the overflow (…) button accessibility",
|
|
219
|
+
type: "text_input",
|
|
220
|
+
},
|
|
207
221
|
{
|
|
208
222
|
key: "accessibility_close_hint",
|
|
209
223
|
label: "Accessibility close hint",
|
|
@@ -791,7 +805,7 @@ function getPlayerConfiguration({ platform, version }) {
|
|
|
791
805
|
label: "Player action buttons",
|
|
792
806
|
initial_value: null,
|
|
793
807
|
label_tooltip:
|
|
794
|
-
"
|
|
808
|
+
"Comma-separated action identifiers. The entry_actions token expands from the playing entry's extensions.entry_action. When more than 2 actions resolve, the video and fullscreen audio players show Overflow (…) plus one companion - the first action that did not come from the entry, otherwise the first one - and the Overflow sheet lists every resolved action. A repeated identifier is counted once. No extra plugin is required.",
|
|
795
809
|
type: "text_input",
|
|
796
810
|
},
|
|
797
811
|
{
|
|
@@ -1091,6 +1105,13 @@ function getPlayerConfiguration({ platform, version }) {
|
|
|
1091
1105
|
type: "uploader",
|
|
1092
1106
|
label_tooltip: "Override default close badge / icon",
|
|
1093
1107
|
},
|
|
1108
|
+
{
|
|
1109
|
+
key: "overflow",
|
|
1110
|
+
label: "Overflow badge",
|
|
1111
|
+
type: "uploader",
|
|
1112
|
+
label_tooltip:
|
|
1113
|
+
"Override default overflow (…) badge / icon, shown when more action buttons resolve than fit on the player overlay",
|
|
1114
|
+
},
|
|
1094
1115
|
{
|
|
1095
1116
|
key: "lock",
|
|
1096
1117
|
label: "Lock player badge",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/zapp-react-native-utils",
|
|
3
|
-
"version": "16.0.0-alpha.
|
|
3
|
+
"version": "16.0.0-alpha.1263110541",
|
|
4
4
|
"description": "Applicaster Zapp React Native utilities package",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@applicaster/applicaster-types": "16.0.0-alpha.
|
|
30
|
+
"@applicaster/applicaster-types": "16.0.0-alpha.1263110541",
|
|
31
31
|
"buffer": "^5.2.1",
|
|
32
32
|
"camelize": "^1.0.0",
|
|
33
33
|
"dayjs": "^1.11.10",
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { resolvePlayerActions } from "../resolvePlayerActions";
|
|
2
|
+
import { selectActionButtons } from "../../conf/player/selectors";
|
|
3
|
+
import { uiActionsRegistry } from "../../uiActionsRegistrator";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../conf/player/selectors", () => ({
|
|
6
|
+
selectActionButtons: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const action = (identifier: string) =>
|
|
10
|
+
({ identifier, action: { invokeAction: jest.fn() } }) as any;
|
|
11
|
+
|
|
12
|
+
describe("resolvePlayerActions", () => {
|
|
13
|
+
const entry = {
|
|
14
|
+
id: "e1",
|
|
15
|
+
extensions: {
|
|
16
|
+
entry_action: [
|
|
17
|
+
{ button: { alias: "add_to_playlist" }, actions: [{ type: "test" }] },
|
|
18
|
+
{ button: { alias: "add_to_queue" }, actions: [{ type: "test" }] },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// The entry's own actions never reach the registry; the caller expands them.
|
|
24
|
+
const expandEntryActions = jest.fn(() => [
|
|
25
|
+
action("entry_action_0"),
|
|
26
|
+
action("entry_action_1"),
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
expandEntryActions.mockClear();
|
|
31
|
+
|
|
32
|
+
jest
|
|
33
|
+
.spyOn(uiActionsRegistry, "getActions")
|
|
34
|
+
.mockImplementation((name) => [action(name)]);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
jest.restoreAllMocks();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("expands entry_actions through the caller and keeps config order", () => {
|
|
42
|
+
(selectActionButtons as jest.Mock).mockReturnValue(
|
|
43
|
+
"entry_actions,local_storage_favourites_action,offline-content-button"
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const result = resolvePlayerActions({
|
|
47
|
+
configuration: {},
|
|
48
|
+
entry,
|
|
49
|
+
expandEntryActions,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expect(expandEntryActions).toHaveBeenCalledWith(entry);
|
|
53
|
+
|
|
54
|
+
expect(uiActionsRegistry.getActions).not.toHaveBeenCalledWith(
|
|
55
|
+
"entry_actions",
|
|
56
|
+
entry
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(result.map((item) => item.identifier)).toEqual([
|
|
60
|
+
"entry_action_0",
|
|
61
|
+
"entry_action_1",
|
|
62
|
+
"local_storage_favourites_action",
|
|
63
|
+
"offline-content-button",
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it.each([undefined, null, ""])(
|
|
68
|
+
"resolves nothing when the config is %p",
|
|
69
|
+
(configured) => {
|
|
70
|
+
(selectActionButtons as jest.Mock).mockReturnValue(configured);
|
|
71
|
+
|
|
72
|
+
expect(
|
|
73
|
+
resolvePlayerActions({ configuration: {}, entry, expandEntryActions })
|
|
74
|
+
).toEqual([]);
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
it("does not cap the resolved list at two items", () => {
|
|
79
|
+
(selectActionButtons as jest.Mock).mockReturnValue("a,b,c");
|
|
80
|
+
|
|
81
|
+
expect(
|
|
82
|
+
resolvePlayerActions({
|
|
83
|
+
configuration: {},
|
|
84
|
+
entry,
|
|
85
|
+
expandEntryActions,
|
|
86
|
+
}).map((item) => item.identifier)
|
|
87
|
+
).toEqual(["a", "b", "c"]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("has no special case for any plugin identifier", () => {
|
|
91
|
+
(selectActionButtons as jest.Mock).mockReturnValue(
|
|
92
|
+
"open-modal-bottom-sheet-cell-action,local_storage_favourites_action"
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
expect(
|
|
96
|
+
resolvePlayerActions({
|
|
97
|
+
configuration: {},
|
|
98
|
+
entry,
|
|
99
|
+
expandEntryActions,
|
|
100
|
+
}).map((item) => item.identifier)
|
|
101
|
+
).toEqual([
|
|
102
|
+
"open-modal-bottom-sheet-cell-action",
|
|
103
|
+
"local_storage_favourites_action",
|
|
104
|
+
]);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("collapses a repeated identifier in the config string", () => {
|
|
108
|
+
(selectActionButtons as jest.Mock).mockReturnValue(
|
|
109
|
+
"favorites,favorites,share"
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
expect(
|
|
113
|
+
resolvePlayerActions({
|
|
114
|
+
configuration: {},
|
|
115
|
+
entry,
|
|
116
|
+
expandEntryActions,
|
|
117
|
+
}).map((item) => item.identifier)
|
|
118
|
+
).toEqual(["favorites", "share"]);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("drops resolved items that cannot be invoked", () => {
|
|
122
|
+
(selectActionButtons as jest.Mock).mockReturnValue("broken,share");
|
|
123
|
+
|
|
124
|
+
(uiActionsRegistry.getActions as jest.Mock).mockImplementation((name) =>
|
|
125
|
+
name === "broken"
|
|
126
|
+
? [{ identifier: "broken" } as any]
|
|
127
|
+
: [action(name as string)]
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(
|
|
131
|
+
resolvePlayerActions({
|
|
132
|
+
configuration: {},
|
|
133
|
+
entry,
|
|
134
|
+
expandEntryActions,
|
|
135
|
+
}).map((item) => item.identifier)
|
|
136
|
+
).toEqual(["share"]);
|
|
137
|
+
});
|
|
138
|
+
});
|
package/playerUtils/index.ts
CHANGED
|
@@ -7,7 +7,23 @@ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
|
7
7
|
import { getBoolFromConfigValue } from "../configurationUtils";
|
|
8
8
|
import { Dimensions } from "react-native";
|
|
9
9
|
|
|
10
|
-
export {
|
|
10
|
+
export { resolvePlayerActions } from "./resolvePlayerActions";
|
|
11
|
+
|
|
12
|
+
export { isEntryAction } from "../entryActions";
|
|
13
|
+
|
|
14
|
+
export {
|
|
15
|
+
parseActionIdentifiers,
|
|
16
|
+
resolveActionIdentifiers,
|
|
17
|
+
} from "../uiActionsRegistrator";
|
|
18
|
+
|
|
19
|
+
export type { ResolveActionIdentifiersParams } from "../uiActionsRegistrator";
|
|
20
|
+
|
|
21
|
+
export type {
|
|
22
|
+
ActionButtonDescriptor,
|
|
23
|
+
OverflowDescriptor,
|
|
24
|
+
PlayerControlDescriptor,
|
|
25
|
+
ResolvePlayerActionsParams,
|
|
26
|
+
} from "./resolvePlayerActions";
|
|
11
27
|
|
|
12
28
|
export {
|
|
13
29
|
resolvePlayerContentText,
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { selectActionButtons } from "../conf/player/selectors";
|
|
2
|
+
import {
|
|
3
|
+
usableActionItems,
|
|
4
|
+
RegisteredAction,
|
|
5
|
+
resolveActionIdentifiers,
|
|
6
|
+
} from "../uiActionsRegistrator";
|
|
7
|
+
|
|
8
|
+
export type ResolvePlayerActionsParams = {
|
|
9
|
+
configuration: any;
|
|
10
|
+
entry: ZappEntry | ZappFeed;
|
|
11
|
+
/** Expands the `entry_actions` token; see `resolveActionIdentifiers`. */
|
|
12
|
+
expandEntryActions?: (entry: ZappEntry | ZappFeed) => RegisteredAction[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The player's action buttons, resolved against the entry.
|
|
17
|
+
*
|
|
18
|
+
* Every `player_action_buttons` token goes through `uiActionsRegistry`, except
|
|
19
|
+
* `entry_actions`, which the caller expands from the entry itself. The list is
|
|
20
|
+
* not capped; the overlay decides how many fit and sends the rest to the sheet.
|
|
21
|
+
*/
|
|
22
|
+
export function resolvePlayerActions({
|
|
23
|
+
configuration,
|
|
24
|
+
entry,
|
|
25
|
+
expandEntryActions,
|
|
26
|
+
}: ResolvePlayerActionsParams): RegisteredAction[] {
|
|
27
|
+
const buttonsString = selectActionButtons(configuration);
|
|
28
|
+
|
|
29
|
+
if (!buttonsString) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Deduped at the source: `player_action_buttons` is a hand-typed string, so
|
|
34
|
+
// the same identifier can legitimately appear twice. Left alone, a repeat
|
|
35
|
+
// would be counted twice against the inline limit, rendered twice on the
|
|
36
|
+
// overlay, and collide as a React key. Items with no `invokeAction` are
|
|
37
|
+
// dropped here too - they can never do anything.
|
|
38
|
+
return usableActionItems(
|
|
39
|
+
resolveActionIdentifiers({
|
|
40
|
+
identifiers: buttonsString,
|
|
41
|
+
entry,
|
|
42
|
+
expandEntryActions,
|
|
43
|
+
})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** One control on the player overlay, before overflow is applied. */
|
|
48
|
+
export type ActionButtonDescriptor =
|
|
49
|
+
| { kind: "subtitle" }
|
|
50
|
+
| { kind: "close" }
|
|
51
|
+
| { kind: "airplay" }
|
|
52
|
+
| { kind: "action"; action: RegisteredAction };
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The Overflow control, produced by `splitOverflow` when more content actions
|
|
56
|
+
* resolve than fit on the overlay.
|
|
57
|
+
*/
|
|
58
|
+
export type OverflowDescriptor = {
|
|
59
|
+
kind: "overflow";
|
|
60
|
+
/**
|
|
61
|
+
* Every content action, the overlay companion included. An overlay button
|
|
62
|
+
* renders nothing when its action has no icon, so the companion needs the
|
|
63
|
+
* sheet as a second home or it could be reachable from nowhere.
|
|
64
|
+
*/
|
|
65
|
+
additionalActions: RegisteredAction[];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/** What the overlay actually renders, once overflow has been applied. */
|
|
69
|
+
export type PlayerControlDescriptor =
|
|
70
|
+
| ActionButtonDescriptor
|
|
71
|
+
| OverflowDescriptor;
|
|
@@ -6,6 +6,7 @@ import { ActionsContext } from "@applicaster/zapp-react-native-ui-components/Con
|
|
|
6
6
|
import {
|
|
7
7
|
observeEntryState,
|
|
8
8
|
RegisteredActionValue,
|
|
9
|
+
uiActionsRegistry,
|
|
9
10
|
} from "../../uiActionsRegistrator";
|
|
10
11
|
import { reactHooksLogger } from "../logger";
|
|
11
12
|
|
|
@@ -34,7 +35,13 @@ export function useActions<T = unknown>(plugId: string): any {
|
|
|
34
35
|
if (!logged) {
|
|
35
36
|
logger.warning({
|
|
36
37
|
message: `useActions: Couldn't find an action for ${plugId} plugin`,
|
|
37
|
-
|
|
38
|
+
// Identifiers only. The action map holds every plugin's module and
|
|
39
|
+
// live React context, which is far too large for a log line and can
|
|
40
|
+
// carry whatever state those plugins hold.
|
|
41
|
+
data: {
|
|
42
|
+
plugId,
|
|
43
|
+
availableActions: Object.keys(context?.actions ?? {}),
|
|
44
|
+
},
|
|
38
45
|
});
|
|
39
46
|
|
|
40
47
|
setLogged(true);
|
|
@@ -80,7 +87,31 @@ export function useEntryActionState(
|
|
|
80
87
|
useEffect(() => {
|
|
81
88
|
if (!action) return undefined;
|
|
82
89
|
|
|
83
|
-
|
|
90
|
+
// An action's stream is third-party code. Subscribing with only a `next`
|
|
91
|
+
// handler lets RxJS rethrow an error notification asynchronously, where no
|
|
92
|
+
// error boundary catches it - one plugin faulting would take the app down
|
|
93
|
+
// rather than this one button. The button keeps its last known state.
|
|
94
|
+
let subscription;
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
subscription = observeEntryState(action, entry).subscribe({
|
|
98
|
+
next: setState,
|
|
99
|
+
error: (error) =>
|
|
100
|
+
logger.warning({
|
|
101
|
+
message:
|
|
102
|
+
"useEntryActionState: the action's state stream failed - the button keeps its last state",
|
|
103
|
+
data: { entryId, error },
|
|
104
|
+
}),
|
|
105
|
+
});
|
|
106
|
+
} catch (error) {
|
|
107
|
+
logger.warning({
|
|
108
|
+
message:
|
|
109
|
+
"useEntryActionState: could not observe the action - the button keeps its initial state",
|
|
110
|
+
data: { entryId, error },
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
84
115
|
|
|
85
116
|
return () => subscription.unsubscribe();
|
|
86
117
|
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
@@ -88,6 +119,18 @@ export function useEntryActionState(
|
|
|
88
119
|
|
|
89
120
|
const invokeAction = useCallback(
|
|
90
121
|
(options: InvokeArgsOptions = {}) => {
|
|
122
|
+
if (typeof action?.invokeAction !== "function") {
|
|
123
|
+
// A button was rendered and pressed, and the press goes nowhere. Only
|
|
124
|
+
// reachable on a user interaction, so it costs nothing on render. The
|
|
125
|
+
// action value carries no identifier, so the label is what locates the
|
|
126
|
+
// button that misbehaved.
|
|
127
|
+
logger.warning({
|
|
128
|
+
message:
|
|
129
|
+
"useEntryActionState: the pressed action has no invokeAction - the press did nothing",
|
|
130
|
+
data: { entryId, label: state?.label },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
91
134
|
action?.invokeAction?.(entry, { updateState: setState, ...options });
|
|
92
135
|
},
|
|
93
136
|
// eslint-disable-next-line @wogns3623/better-exhaustive-deps/exhaustive-deps
|
|
@@ -96,3 +139,25 @@ export function useEntryActionState(
|
|
|
96
139
|
|
|
97
140
|
return { state, invokeAction };
|
|
98
141
|
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* A value that changes whenever a provider is added to or removed from
|
|
145
|
+
* `uiActionsRegistry`.
|
|
146
|
+
*
|
|
147
|
+
* Providers can register after the UI that wants them has rendered - the audio
|
|
148
|
+
* player registers playback speed only once its controller has state, and
|
|
149
|
+
* plugin-backed actions are bridged in from an effect. Put this in the
|
|
150
|
+
* dependency list of anything that resolves actions, so the list is re-read
|
|
151
|
+
* instead of being frozen at first paint.
|
|
152
|
+
*/
|
|
153
|
+
export function useRegistryRevision(): number {
|
|
154
|
+
const [revision, setRevision] = useState(0);
|
|
155
|
+
|
|
156
|
+
useEffect(
|
|
157
|
+
() =>
|
|
158
|
+
uiActionsRegistry.subscribe(() => setRevision((current) => current + 1)),
|
|
159
|
+
[]
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return revision;
|
|
163
|
+
}
|