@applicaster/zapp-react-native-ui-components 16.0.0-rc.99 → 17.0.0-alpha.1102403272
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/index.web.tsx +10 -0
- package/Components/Cell/PlatformCellComponent.ts +9 -0
- package/Components/Cell/PlatformCellComponent.web.ts +3 -0
- package/Components/Cell/index.js +2 -9
- package/Components/CellRendererResolver/index.ts +22 -3
- package/Components/ComponentResolver/ComponentResolver.ts +6 -2
- package/Components/ComponentResolver/__tests__/componentResolver.test.js +13 -5
- package/Components/ContentScreen/index.js +2 -2
- package/Components/Focusable/index.web.tsx +3 -0
- package/Components/FocusableList/hooks/useCheckItemIdsForUnique.ts +2 -7
- package/Components/GeneralContentScreen/GeneralContentScreen.tsx +1 -1
- package/Components/GeneralContentScreen/hookAdapter/logger.ts +1 -1
- package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +158 -1
- package/Components/GeneralContentScreen/utils/index.ts +2 -2
- package/Components/GeneralContentScreen/utils/logger.ts +3 -4
- package/Components/GeneralContentScreen/utils/useCurationAPI.ts +32 -10
- package/Components/HandlePlayable/utils.ts +2 -7
- package/Components/HookRenderer/HookRenderer.tsx +2 -2
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +42 -4
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.android.tv.tsx +7 -4
- package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +1 -0
- package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +10 -4
- package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts +1 -1
- package/Components/MasterCell/DefaultComponents/Image/hoc/utils/index.ts +2 -4
- package/Components/MasterCell/DefaultComponents/Image/hooks/checkTooBigImageSize.ts +2 -7
- package/Components/MasterCell/DefaultComponents/Image/index.web.ts +7 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/__tests__/prepareEntry.test.ts +30 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +34 -7
- package/Components/MasterCell/DefaultComponents/PressableView.tsx +3 -0
- package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +2 -7
- package/Components/MasterCell/DefaultComponents/__tests__/ActionButton.missingPlugin.test.tsx +66 -0
- package/Components/MasterCell/DefaultComponents/__tests__/ActionButton.test.tsx +288 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +2 -1
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +4 -2
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/factory.test.ts +2 -2
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +2 -1
- package/Components/MasterCell/__tests__/masterCell.test.js +116 -0
- package/Components/MasterCell/index.tsx +45 -6
- package/Components/MasterCell/logger.ts +2 -2
- package/Components/MasterCell/utils/__tests__/getFocusableElementId.test.ts +38 -0
- package/Components/MasterCell/utils/__tests__/useIsCellSelected.test.ts +91 -0
- package/Components/MasterCell/utils/__tests__/withoutFocusedState.test.js +20 -0
- package/Components/MasterCell/utils/behaviorProvider.ts +57 -38
- package/Components/MasterCell/utils/index.ts +60 -19
- package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +1 -1
- package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +7 -3
- package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +22 -1
- package/Components/ModalComponent/AudioPlayer/Components/__tests__/Item.test.tsx +52 -1
- package/Components/ModalComponent/AudioPlayer/utils/__tests__/mergeStyles.test.ts +77 -0
- package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +58 -16
- package/Components/ModalComponent/BottomSheetDragArea.web.tsx +15 -0
- package/Components/ModalComponent/BottomSheetModalContent.tsx +51 -82
- package/Components/ModalComponent/Button/index.tsx +3 -1
- package/Components/ModalComponent/SortableList.tsx +2 -3
- package/Components/ModalComponent/__tests__/BottomSheetDragArea.test.tsx +30 -0
- package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +237 -17
- package/Components/ModalComponent/__tests__/showTextInput.test.ts +25 -0
- package/Components/ModalComponent/presets/__tests__/getCell.test.ts +29 -2
- package/Components/ModalComponent/presets/index.ts +2 -3
- package/Components/ModalComponent/showTextInput.ts +2 -0
- package/Components/OfflineHandler/__tests__/index.test.tsx +136 -0
- package/Components/OfflineHandler/index.tsx +45 -6
- package/Components/PlayerContainer/PlayerContainer.tsx +30 -6
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +51 -0
- package/Components/PlayerContainer/logger.ts +9 -5
- package/Components/River/ComponentsMap/ComponentsMap.tsx +4 -1
- package/Components/River/ComponentsMap/index.web.tsx +3 -0
- package/Components/River/RiverItem.tsx +4 -0
- package/Components/River/TV/River.tsx +7 -1
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -0
- package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +2 -2
- package/Components/ScreenResolver/index.tsx +6 -4
- package/Components/Tabs/TV/index.web.tsx +5 -0
- package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +56 -10
- package/Components/TopCutoffOverlay/index.tsx +41 -10
- package/Components/Transitioner/AnimationManager.js +1 -1
- package/Components/Transitioner/Scene.tsx +4 -3
- package/Components/Transitioner/Transitioner.tsx +71 -33
- package/Components/Transitioner/__tests__/transitioner.test.js +372 -3
- package/Components/VideoLive/LiveImageManager.ts +126 -12
- package/Components/VideoLive/MuteUnmuteController.ts +135 -0
- package/Components/VideoLive/PlayerLiveImageComponent.tsx +15 -19
- package/Components/VideoLive/__tests__/LiveImageManager.test.ts +30 -0
- package/Components/VideoLive/__tests__/LiveImageMuteState.test.ts +311 -0
- package/Components/VideoLive/__tests__/MuteUnmuteController.test.ts +135 -0
- package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +63 -1
- package/Components/VideoLive/loggerHelper.ts +2 -2
- package/Components/VideoModal/PlayerDetails.tsx +27 -2
- package/Components/VideoModal/PlayerWrapper.tsx +9 -2
- package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +84 -0
- package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -0
- package/Components/VideoModal/__tests__/playerWrapperStyle.test.ts +263 -0
- package/Components/VideoModal/__tests__/playerWrapperUtils.test.ts +125 -0
- package/Components/VideoModal/hooks/useModalSize.ts +2 -7
- package/Components/VideoModal/playerWrapperStyle.ts +62 -23
- package/Components/VideoModal/playerWrapperUtils.ts +141 -1
- package/Components/__tests__/webVariants.test.js +73 -0
- package/Components/default-cell-renderer/containerStyles/index.web.ts +6 -0
- package/Components/default-cell-renderer/viewTrees/index.web.ts +10 -0
- package/Contexts/ZappPipesContext/ZappPipesContextFactory.tsx +3 -5
- package/Decorators/RiverResolver/__tests__/riverResolver.missingRiver.test.tsx +52 -0
- package/Decorators/RiverResolver/index.tsx +25 -0
- package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +4 -3
- package/Decorators/ZappPipesDataConnector/__tests__/screenToolbox.test.ts +347 -0
- package/Decorators/ZappPipesDataConnector/__tests__/screenToolboxUnavailable.test.ts +53 -0
- package/Decorators/ZappPipesDataConnector/index.tsx +19 -4
- package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +2 -21
- package/Decorators/ZappPipesDataConnector/screenToolbox.ts +384 -0
- package/Decorators/ZappPipesDataConnector/utils/mongoFilter.ts +1 -1
- package/Decorators/ZappPipesDataConnector/utils/useFilter.tsx +1 -1
- package/Helpers/logger.js +2 -2
- package/package.json +5 -5
|
@@ -76,6 +76,122 @@ describe("masterCellBuilder", () => {
|
|
|
76
76
|
});
|
|
77
77
|
});
|
|
78
78
|
|
|
79
|
+
describe("cellOptions.interactive", () => {
|
|
80
|
+
// renders a single View tagged with the state the cell was built with
|
|
81
|
+
const dataAdapter =
|
|
82
|
+
() =>
|
|
83
|
+
({ state }) => [
|
|
84
|
+
{ type: "View", style: {}, props: { testID: `state-${state}` } },
|
|
85
|
+
];
|
|
86
|
+
|
|
87
|
+
// Only the root View gets this testID: cell elements pass their own testID, which overrides it
|
|
88
|
+
const ROOT_TEST_ID = "master-cell-root";
|
|
89
|
+
|
|
90
|
+
// forwardRef: MasterCell attaches a ref to its root View
|
|
91
|
+
const TestView = React.forwardRef((props, ref) => (
|
|
92
|
+
<View testID={ROOT_TEST_ID} {...props} ref={ref} />
|
|
93
|
+
));
|
|
94
|
+
|
|
95
|
+
const renderCell = (cellOptions, state) => {
|
|
96
|
+
const MasterCell = masterCellBuilder({
|
|
97
|
+
cellConfiguration: singleView,
|
|
98
|
+
dataAdapter,
|
|
99
|
+
components: { View: TestView },
|
|
100
|
+
cellOptions,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
return renderWithProviders(<MasterCell item={entry} state={state} />);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const getRoot = (wrapper) => wrapper.getByTestId(ROOT_TEST_ID);
|
|
107
|
+
|
|
108
|
+
it("keeps focused state and default root props when omitted", () => {
|
|
109
|
+
const wrapper = renderCell(undefined, "focused");
|
|
110
|
+
const root = getRoot(wrapper);
|
|
111
|
+
|
|
112
|
+
expect(wrapper.getByTestId("state-focused")).toBeDefined();
|
|
113
|
+
expect(root.props.onStartShouldSetResponder).toBeUndefined();
|
|
114
|
+
expect(root.props.collapsable).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("claims body touches on a non-collapsable root when false", () => {
|
|
118
|
+
const wrapper = renderCell({ interactive: false }, "default");
|
|
119
|
+
const root = getRoot(wrapper);
|
|
120
|
+
|
|
121
|
+
expect(root.props.onStartShouldSetResponder()).toBe(true);
|
|
122
|
+
expect(root.props.collapsable).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("renders focused as default when false", () => {
|
|
126
|
+
const wrapper = renderCell({ interactive: false }, "focused");
|
|
127
|
+
|
|
128
|
+
expect(wrapper.getByTestId("state-default")).toBeDefined();
|
|
129
|
+
expect(wrapper.queryByTestId("state-focused")).toBeNull();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("renders focused_selected as selected when false", () => {
|
|
133
|
+
const wrapper = renderCell({ interactive: false }, "focused_selected");
|
|
134
|
+
|
|
135
|
+
expect(wrapper.getByTestId("state-selected")).toBeDefined();
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe("live-image cell ids", () => {
|
|
140
|
+
const component = {
|
|
141
|
+
id: "rail",
|
|
142
|
+
component_type: "horizontal_list_qb",
|
|
143
|
+
styles: { cell_plugin_configuration_id: "cell-style" },
|
|
144
|
+
rules: {
|
|
145
|
+
enable_video_preview: true,
|
|
146
|
+
player_screen_id: "player-screen",
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
const dataAdapter = () => () => [
|
|
151
|
+
{
|
|
152
|
+
type: "LiveImage",
|
|
153
|
+
style: {},
|
|
154
|
+
props: { testID: "live-image" },
|
|
155
|
+
},
|
|
156
|
+
];
|
|
157
|
+
|
|
158
|
+
const LiveImage = (props) => <View {...props} />;
|
|
159
|
+
|
|
160
|
+
const MasterCell = masterCellBuilder({
|
|
161
|
+
cellConfiguration: singleView,
|
|
162
|
+
dataAdapter,
|
|
163
|
+
components: { LiveImage },
|
|
164
|
+
cellOptions: { component },
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const firstEntry = { ...entry, id: "entry-1" };
|
|
168
|
+
const secondEntry = { ...entry, id: "entry-2" };
|
|
169
|
+
|
|
170
|
+
const renderEntries = (firstState, secondState) => (
|
|
171
|
+
<>
|
|
172
|
+
<MasterCell item={firstEntry} state={firstState} />
|
|
173
|
+
<MasterCell item={secondEntry} state={secondState} />
|
|
174
|
+
</>
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
it("gives each entry its own id and keeps it when focus changes", () => {
|
|
178
|
+
const wrapper = renderWithProviders(renderEntries(null, null));
|
|
179
|
+
|
|
180
|
+
const [firstCell, secondCell] = wrapper.getAllByTestId("live-image");
|
|
181
|
+
|
|
182
|
+
expect(firstCell.props.cellUUID).toBe("rail-cell-style-entry-1");
|
|
183
|
+
expect(secondCell.props.cellUUID).toBe("rail-cell-style-entry-2");
|
|
184
|
+
|
|
185
|
+
wrapper.rerender(renderEntries("focused", "focused"));
|
|
186
|
+
|
|
187
|
+
const [focusedFirst, focusedSecond] =
|
|
188
|
+
wrapper.getAllByTestId("live-image");
|
|
189
|
+
|
|
190
|
+
expect(focusedFirst.props.cellUUID).toBe(firstCell.props.cellUUID);
|
|
191
|
+
expect(focusedSecond.props.cellUUID).toBe(secondCell.props.cellUUID);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
79
195
|
describe.skip("when using custom default components", () => {
|
|
80
196
|
// the collapsable prop is added here to easily check from the snapshot that the mock
|
|
81
197
|
// component is being used instead of the default one
|
|
@@ -10,7 +10,12 @@ import { useScreenState } from "@applicaster/zapp-react-native-utils/screenState
|
|
|
10
10
|
import { defaultComponents } from "./DefaultComponents";
|
|
11
11
|
import { defaultDataAdapter } from "./dataAdapter";
|
|
12
12
|
import { elementMapper, mapElementWithKey } from "./elementMapper";
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
getCellInstanceId,
|
|
15
|
+
getEntryState,
|
|
16
|
+
hasFocusableInsideBuilder,
|
|
17
|
+
withoutFocusedState,
|
|
18
|
+
} from "./utils";
|
|
14
19
|
|
|
15
20
|
type Props = {
|
|
16
21
|
item: ZappEntry;
|
|
@@ -19,6 +24,16 @@ type Props = {
|
|
|
19
24
|
|
|
20
25
|
const defaultContainerStyle = { flex: 1 };
|
|
21
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Root props of a non-interactive cell: the root view claims touches on the cell body,
|
|
29
|
+
* so the host list's touchable never fires (buttons, being deeper, still receive theirs).
|
|
30
|
+
* `collapsable: false` keeps Android / Fabric from flattening the view away.
|
|
31
|
+
*/
|
|
32
|
+
const nonInteractiveRootProps = {
|
|
33
|
+
onStartShouldSetResponder: () => true,
|
|
34
|
+
collapsable: false,
|
|
35
|
+
};
|
|
36
|
+
|
|
22
37
|
/**
|
|
23
38
|
* Constructs a MasterCell with the provided options
|
|
24
39
|
* @param {Object} options
|
|
@@ -27,6 +42,8 @@ const defaultContainerStyle = { flex: 1 };
|
|
|
27
42
|
* @param {Function} options.dataAdapter optional dataAdapter to use instead of the default one.
|
|
28
43
|
* See dataAdapter.js for more info
|
|
29
44
|
* @param {containerStyles} options.containerStyle style to apply at the top level of the master cell
|
|
45
|
+
* @param {Object} options.cellOptions optional cell options. `interactive: false` makes the cell body
|
|
46
|
+
* ignore taps and render without focused / pressed states (inner buttons keep working). Defaults to `true`.
|
|
30
47
|
* @returns {Function} Functional React Component to render the masterCell with the provided options
|
|
31
48
|
*/
|
|
32
49
|
|
|
@@ -39,6 +56,7 @@ type MasterCellBuilderOptions = {
|
|
|
39
56
|
isRTL?: boolean;
|
|
40
57
|
skipButtons?: boolean;
|
|
41
58
|
component?: ZappComponent;
|
|
59
|
+
interactive?: boolean;
|
|
42
60
|
};
|
|
43
61
|
};
|
|
44
62
|
|
|
@@ -49,7 +67,7 @@ export function masterCellBuilder({
|
|
|
49
67
|
containerStyle = defaultContainerStyle,
|
|
50
68
|
cellOptions = {},
|
|
51
69
|
}: MasterCellBuilderOptions) {
|
|
52
|
-
const { skipButtons = false, component } = cellOptions;
|
|
70
|
+
const { skipButtons = false, component, interactive = true } = cellOptions;
|
|
53
71
|
|
|
54
72
|
const componentsMap = R.merge(defaultComponents, components);
|
|
55
73
|
const { View } = componentsMap;
|
|
@@ -88,7 +106,10 @@ export function masterCellBuilder({
|
|
|
88
106
|
() =>
|
|
89
107
|
elementsBuilder({
|
|
90
108
|
entry: item,
|
|
91
|
-
state: getEntryState(
|
|
109
|
+
state: getEntryState(
|
|
110
|
+
interactive ? state : withoutFocusedState(state),
|
|
111
|
+
entryIsSelected
|
|
112
|
+
),
|
|
92
113
|
allowDynamicColorsOutsideExtensions:
|
|
93
114
|
theme?.allow_dynamic_colors_outside_extensions,
|
|
94
115
|
}),
|
|
@@ -110,8 +131,11 @@ export function masterCellBuilder({
|
|
|
110
131
|
|
|
111
132
|
const isHL = isHorizontalList(component);
|
|
112
133
|
|
|
113
|
-
|
|
114
|
-
|
|
134
|
+
const entryId = item?.id;
|
|
135
|
+
|
|
136
|
+
// Player ids are unique. The entry id keeps each cell on its own player.
|
|
137
|
+
return isHL && isLiveImage && entryId
|
|
138
|
+
? `${component?.id}-${component?.styles?.cell_plugin_configuration_id}-${entryId}`
|
|
115
139
|
: uuid();
|
|
116
140
|
}, [
|
|
117
141
|
component?.id,
|
|
@@ -122,11 +146,22 @@ export function masterCellBuilder({
|
|
|
122
146
|
item?.id,
|
|
123
147
|
]);
|
|
124
148
|
|
|
149
|
+
// cellUUID is the player id shared by every copy of this entry.
|
|
150
|
+
// cellInstanceId distinguishes each rendered copy for focus only.
|
|
151
|
+
const focusIndex = (item as { focusIndex?: number } | undefined)
|
|
152
|
+
?.focusIndex;
|
|
153
|
+
|
|
154
|
+
const cellInstanceId = React.useMemo(
|
|
155
|
+
() => getCellInstanceId(item?.id, focusIndex),
|
|
156
|
+
[item?.id, focusIndex]
|
|
157
|
+
);
|
|
158
|
+
|
|
125
159
|
const remapElements = mapElementWithKey(
|
|
126
160
|
elementMapper(componentsMap, {
|
|
127
161
|
...otherProps,
|
|
128
162
|
wrapperRef,
|
|
129
163
|
cellUUID,
|
|
164
|
+
cellInstanceId,
|
|
130
165
|
skipButtons,
|
|
131
166
|
hasFocusableInside,
|
|
132
167
|
entry: item,
|
|
@@ -134,7 +169,11 @@ export function masterCellBuilder({
|
|
|
134
169
|
);
|
|
135
170
|
|
|
136
171
|
return (
|
|
137
|
-
<View
|
|
172
|
+
<View
|
|
173
|
+
style={containerStyle}
|
|
174
|
+
ref={wrapperRef}
|
|
175
|
+
{...(interactive ? undefined : nonInteractiveRootProps)}
|
|
176
|
+
>
|
|
138
177
|
{elements.map(remapElements)}
|
|
139
178
|
</View>
|
|
140
179
|
);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { subsystemLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
2
2
|
|
|
3
|
-
export const masterCellLogger =
|
|
3
|
+
export const masterCellLogger = subsystemLogger("ui/cells", "MasterCell");
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { getCellInstanceId, getFocusableElementId } from "..";
|
|
2
|
+
|
|
3
|
+
describe("getFocusableElementId", () => {
|
|
4
|
+
it("uses the player id and the focusable suffix when there is no entry", () => {
|
|
5
|
+
expect(
|
|
6
|
+
getFocusableElementId({
|
|
7
|
+
playerId: "player-1",
|
|
8
|
+
suffix: "tv_buttons_button_1",
|
|
9
|
+
})
|
|
10
|
+
).toBe("player-1--tv_buttons_button_1");
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("adds the cell instance id for one rendered entry", () => {
|
|
14
|
+
const cellInstanceId = getCellInstanceId("entry-a");
|
|
15
|
+
|
|
16
|
+
expect(
|
|
17
|
+
getFocusableElementId({
|
|
18
|
+
playerId: "player-1",
|
|
19
|
+
cellInstanceId,
|
|
20
|
+
suffix: "tv_buttons_button_1",
|
|
21
|
+
})
|
|
22
|
+
).toBe("player-1--entry-a--tv_buttons_button_1");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("keeps a zero clone index on the cell instance id", () => {
|
|
26
|
+
const cellInstanceId = getCellInstanceId("entry-a", 0);
|
|
27
|
+
|
|
28
|
+
expect(cellInstanceId).toBe("entry-a--0");
|
|
29
|
+
|
|
30
|
+
expect(
|
|
31
|
+
getFocusableElementId({
|
|
32
|
+
playerId: "player-1",
|
|
33
|
+
cellInstanceId,
|
|
34
|
+
suffix: "tv_buttons_button_1",
|
|
35
|
+
})
|
|
36
|
+
).toBe("player-1--entry-a--0--tv_buttons_button_1");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { renderHook, act } from "@testing-library/react-native";
|
|
2
|
+
import { BehaviorSubject } from "rxjs";
|
|
3
|
+
|
|
4
|
+
const mockSubject = new BehaviorSubject<string[]>([]);
|
|
5
|
+
|
|
6
|
+
jest.mock(
|
|
7
|
+
"@applicaster/zapp-react-native-utils/storage/StorageMultiSelectProvider",
|
|
8
|
+
() => ({
|
|
9
|
+
StorageMultiSelectProvider: {
|
|
10
|
+
getProvider: () => ({
|
|
11
|
+
getObservable: () => mockSubject,
|
|
12
|
+
getSelectedItems: () => mockSubject.getValue(),
|
|
13
|
+
}),
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
|
|
19
|
+
useRoute: () => ({ pathname: "/selector" }),
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
jest.mock(
|
|
23
|
+
"@applicaster/zapp-react-native-utils/reactHooks/navigation/useScreenStateStore",
|
|
24
|
+
() => ({ useScreenStateStore: () => ({}) })
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
jest.mock(
|
|
28
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer",
|
|
29
|
+
() => ({ usePlayer: () => null })
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
jest.mock("@applicaster/zapp-react-native-utils/appUtils", () => ({
|
|
33
|
+
playerManager: {},
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
jest.mock(
|
|
37
|
+
"@applicaster/zapp-react-native-bridge/PushNotifications/PushTopicManager",
|
|
38
|
+
() => ({ PushTopicManager: {} })
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
import { useIsCellSelected } from "../behaviorProvider";
|
|
42
|
+
|
|
43
|
+
const behavior = {
|
|
44
|
+
select_mode: "multi",
|
|
45
|
+
current_selection: "@{ctx/user_preferences.teams}",
|
|
46
|
+
} as Behavior;
|
|
47
|
+
|
|
48
|
+
const renderCell = (id: string) => {
|
|
49
|
+
let renders = 0;
|
|
50
|
+
|
|
51
|
+
const hook = renderHook(() => {
|
|
52
|
+
renders++;
|
|
53
|
+
|
|
54
|
+
return useIsCellSelected(behavior, { id } as ZappEntry);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return { hook, getRenders: () => renders };
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
describe("useIsCellSelected", () => {
|
|
61
|
+
beforeEach(() => mockSubject.next([]));
|
|
62
|
+
|
|
63
|
+
it("re-renders only the cell whose selection changed", () => {
|
|
64
|
+
const a = renderCell("a");
|
|
65
|
+
const b = renderCell("b");
|
|
66
|
+
|
|
67
|
+
const rendersBefore = [a.getRenders(), b.getRenders()];
|
|
68
|
+
|
|
69
|
+
act(() => mockSubject.next(["a"]));
|
|
70
|
+
|
|
71
|
+
expect(a.hook.result.current).toBe(true);
|
|
72
|
+
expect(b.hook.result.current).toBe(false);
|
|
73
|
+
expect(a.getRenders()).toBe(rendersBefore[0] + 1);
|
|
74
|
+
expect(b.getRenders()).toBe(rendersBefore[1]);
|
|
75
|
+
|
|
76
|
+
act(() => mockSubject.next([]));
|
|
77
|
+
|
|
78
|
+
expect(a.hook.result.current).toBe(false);
|
|
79
|
+
expect(a.getRenders()).toBe(rendersBefore[0] + 2);
|
|
80
|
+
expect(b.getRenders()).toBe(rendersBefore[1]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("does not re-render on mount because of the initial emission", () => {
|
|
84
|
+
mockSubject.next(["a"]);
|
|
85
|
+
|
|
86
|
+
const a = renderCell("a");
|
|
87
|
+
|
|
88
|
+
expect(a.hook.result.current).toBe(true);
|
|
89
|
+
expect(a.getRenders()).toBe(1);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { withoutFocusedState } from "..";
|
|
2
|
+
|
|
3
|
+
describe("withoutFocusedState", () => {
|
|
4
|
+
it("maps focused to default", () => {
|
|
5
|
+
expect(withoutFocusedState("focused")).toBe("default");
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("maps focused_selected to selected", () => {
|
|
9
|
+
expect(withoutFocusedState("focused_selected")).toBe("selected");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("keeps default and selected states", () => {
|
|
13
|
+
expect(withoutFocusedState("default")).toBe("default");
|
|
14
|
+
expect(withoutFocusedState("selected")).toBe("selected");
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it("keeps a missing state", () => {
|
|
18
|
+
expect(withoutFocusedState(undefined)).toBeUndefined();
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -69,45 +69,8 @@ const getDataSourceProvider = (
|
|
|
69
69
|
return null;
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
export const useBehaviorUpdate = (behavior: Behavior) => {
|
|
73
|
-
const [lastUpdate, setLastUpdate] = React.useState<number | null>(null);
|
|
74
|
-
const screenRoute = useRoute()?.pathname || "";
|
|
75
|
-
const screenStateStore = useScreenStateStore();
|
|
76
|
-
const player = usePlayer();
|
|
77
|
-
|
|
78
|
-
const triggerUpdate = () => setLastUpdate(Date.now());
|
|
79
|
-
|
|
80
|
-
useEffect(() => {
|
|
81
|
-
if (!behavior) return;
|
|
82
|
-
|
|
83
|
-
const dataSource = getDataSourceProvider(
|
|
84
|
-
behavior,
|
|
85
|
-
screenRoute,
|
|
86
|
-
screenStateStore
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
if (dataSource) {
|
|
90
|
-
const subscription = dataSource.subscribe(triggerUpdate);
|
|
91
|
-
|
|
92
|
-
return () => subscription.unsubscribe();
|
|
93
|
-
}
|
|
94
|
-
}, [behavior]);
|
|
95
|
-
|
|
96
|
-
useEffect(() => {
|
|
97
|
-
if (!behavior || !player || behavior.selection_source !== "now_playing") {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const subscription = player.getEntryObservable().subscribe(triggerUpdate);
|
|
102
|
-
|
|
103
|
-
return () => subscription.unsubscribe();
|
|
104
|
-
}, [behavior, player]);
|
|
105
|
-
|
|
106
|
-
return lastUpdate;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
72
|
// We cant use async in this function (its inside render),
|
|
110
|
-
// so we rely on
|
|
73
|
+
// so we rely on useIsCellSelected to trigger re-render when the value changes
|
|
111
74
|
export const isCellSelected = ({
|
|
112
75
|
item,
|
|
113
76
|
screenRoute,
|
|
@@ -202,3 +165,59 @@ export const isCellSelected = ({
|
|
|
202
165
|
|
|
203
166
|
return false;
|
|
204
167
|
};
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Every cell observes the same provider, so a plain "something changed" trigger
|
|
171
|
+
* re-renders the whole list on each tap. Re-render only the cell whose own
|
|
172
|
+
* selected state changed.
|
|
173
|
+
*/
|
|
174
|
+
export const useIsCellSelected = (
|
|
175
|
+
behavior: Behavior,
|
|
176
|
+
item: ZappEntry
|
|
177
|
+
): boolean => {
|
|
178
|
+
const [, forceUpdate] = React.useState(0);
|
|
179
|
+
const screenRoute = useRoute()?.pathname || "";
|
|
180
|
+
const screenStateStore = useScreenStateStore();
|
|
181
|
+
const player = usePlayer();
|
|
182
|
+
|
|
183
|
+
const isSelected = () =>
|
|
184
|
+
isCellSelected({ item, screenRoute, screenStateStore, behavior });
|
|
185
|
+
|
|
186
|
+
const selected = isSelected();
|
|
187
|
+
const latest = React.useRef({ isSelected, selected });
|
|
188
|
+
latest.current = { isSelected, selected };
|
|
189
|
+
|
|
190
|
+
const triggerUpdate = () => {
|
|
191
|
+
if (latest.current.isSelected() !== latest.current.selected) {
|
|
192
|
+
forceUpdate((n) => n + 1);
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
if (!behavior) return;
|
|
198
|
+
|
|
199
|
+
const dataSource = getDataSourceProvider(
|
|
200
|
+
behavior,
|
|
201
|
+
screenRoute,
|
|
202
|
+
screenStateStore
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
if (dataSource) {
|
|
206
|
+
const subscription = dataSource.subscribe(triggerUpdate);
|
|
207
|
+
|
|
208
|
+
return () => subscription.unsubscribe();
|
|
209
|
+
}
|
|
210
|
+
}, [behavior]);
|
|
211
|
+
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
if (!behavior || !player || behavior.selection_source !== "now_playing") {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const subscription = player.getEntryObservable().subscribe(triggerUpdate);
|
|
218
|
+
|
|
219
|
+
return () => subscription.unsubscribe();
|
|
220
|
+
}, [behavior, player]);
|
|
221
|
+
|
|
222
|
+
return selected;
|
|
223
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
import memoizee from "memoizee";
|
|
4
4
|
|
|
@@ -8,12 +8,10 @@ import { isValidColor } from "@applicaster/zapp-react-native-utils/colorUtils";
|
|
|
8
8
|
import { getColorFromData } from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
9
9
|
import { pathOr, get, isNil } from "@applicaster/zapp-react-native-utils/utils";
|
|
10
10
|
import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
|
|
11
|
-
import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
12
|
-
import { useScreenStateStore } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useScreenStateStore";
|
|
13
11
|
import { isNotEmptyString } from "@applicaster/zapp-react-native-utils/stringUtils";
|
|
14
12
|
import { masterCellLogger } from "../logger";
|
|
15
13
|
import { getCellState } from "../../Cell/utils";
|
|
16
|
-
import {
|
|
14
|
+
import { useIsCellSelected } from "./behaviorProvider";
|
|
17
15
|
import { DataProvider } from "../DefaultComponents/DataProvider";
|
|
18
16
|
|
|
19
17
|
const hasElementSpecificViewType = (viewType) => (element) => {
|
|
@@ -239,7 +237,12 @@ export const useFilterChildren = <
|
|
|
239
237
|
|
|
240
238
|
masterCellLogger.error({
|
|
241
239
|
message: `Action plugin for ${actionIdentifier} could not be found, check the configuration of your action button`,
|
|
242
|
-
data: {
|
|
240
|
+
data: {
|
|
241
|
+
diagnostic: { code: "action-plugin-missing" },
|
|
242
|
+
identifier: actionIdentifier,
|
|
243
|
+
item,
|
|
244
|
+
action: actionIdentifier,
|
|
245
|
+
},
|
|
243
246
|
});
|
|
244
247
|
|
|
245
248
|
return false;
|
|
@@ -332,6 +335,39 @@ export const getFocusedButtonId = (focusable) => {
|
|
|
332
335
|
});
|
|
333
336
|
};
|
|
334
337
|
|
|
338
|
+
// One rendered copy of an entry. focusIndex separates auto-loop clones.
|
|
339
|
+
// Omitted when the entry has no id; the player id is already unique per mount.
|
|
340
|
+
export const getCellInstanceId = (
|
|
341
|
+
entryId?: string | number,
|
|
342
|
+
focusIndex?: number
|
|
343
|
+
): string | undefined => {
|
|
344
|
+
if (entryId == null || entryId === "") {
|
|
345
|
+
return undefined;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const indexSuffix = typeof focusIndex === "number" ? `--${focusIndex}` : "";
|
|
349
|
+
|
|
350
|
+
return `${entryId}${indexSuffix}`;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// Final FocusManager id. playerId is the shared playback identity (cellUUID).
|
|
354
|
+
// Registration and initial-focus lookup both call this.
|
|
355
|
+
export const getFocusableElementId = ({
|
|
356
|
+
playerId,
|
|
357
|
+
cellInstanceId,
|
|
358
|
+
suffix,
|
|
359
|
+
}: {
|
|
360
|
+
playerId: string;
|
|
361
|
+
cellInstanceId?: string;
|
|
362
|
+
suffix: string;
|
|
363
|
+
}): string => {
|
|
364
|
+
const instanceId = cellInstanceId
|
|
365
|
+
? `${playerId}--${cellInstanceId}`
|
|
366
|
+
: playerId;
|
|
367
|
+
|
|
368
|
+
return `${instanceId}--${suffix}`;
|
|
369
|
+
};
|
|
370
|
+
|
|
335
371
|
export const useCellState = ({
|
|
336
372
|
item,
|
|
337
373
|
behavior,
|
|
@@ -341,20 +377,7 @@ export const useCellState = ({
|
|
|
341
377
|
behavior: Behavior;
|
|
342
378
|
focused: boolean;
|
|
343
379
|
}): CellState => {
|
|
344
|
-
const
|
|
345
|
-
const router = useRoute();
|
|
346
|
-
const screenStateStore = useScreenStateStore();
|
|
347
|
-
|
|
348
|
-
const _isSelected = useMemo(
|
|
349
|
-
() =>
|
|
350
|
-
isCellSelected({
|
|
351
|
-
item,
|
|
352
|
-
screenRoute: router?.pathname,
|
|
353
|
-
screenStateStore,
|
|
354
|
-
behavior,
|
|
355
|
-
}),
|
|
356
|
-
[behavior, item, lastUpdate]
|
|
357
|
-
);
|
|
380
|
+
const _isSelected = useIsCellSelected(behavior, item);
|
|
358
381
|
|
|
359
382
|
return getCellState({ focused, selected: _isSelected });
|
|
360
383
|
};
|
|
@@ -386,3 +409,21 @@ export function getEntryState(state, selected) {
|
|
|
386
409
|
|
|
387
410
|
return selected ? "selected" : "default";
|
|
388
411
|
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Drops focused (pressed) variants of a cell state, so a non-interactive cell
|
|
415
|
+
* always renders its idle look. `selected` is kept – it is not touch feedback.
|
|
416
|
+
*/
|
|
417
|
+
export function withoutFocusedState(
|
|
418
|
+
state?: CellState | null
|
|
419
|
+
): CellState | null | undefined {
|
|
420
|
+
if (state === "focused_selected") {
|
|
421
|
+
return "selected";
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
if (state === "focused") {
|
|
425
|
+
return "default";
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return state;
|
|
429
|
+
}
|
|
@@ -6,7 +6,7 @@ import { RegisteredAction } from "@applicaster/zapp-react-native-utils/uiActions
|
|
|
6
6
|
import { boundActionButton } from "./boundActionButton";
|
|
7
7
|
|
|
8
8
|
const { log_warning } = createLogger({
|
|
9
|
-
subsystem: "
|
|
9
|
+
subsystem: "ui/bottom_sheet",
|
|
10
10
|
category: "Presentation",
|
|
11
11
|
});
|
|
12
12
|
|
|
@@ -19,7 +19,10 @@ import {
|
|
|
19
19
|
} from "react-native";
|
|
20
20
|
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
21
21
|
|
|
22
|
-
const logger = createLogger({
|
|
22
|
+
const logger = createLogger({
|
|
23
|
+
category: "ModalComponent:AudioPlayerButton",
|
|
24
|
+
subsystem: "player/audio",
|
|
25
|
+
});
|
|
23
26
|
|
|
24
27
|
const styles = StyleSheet.create({
|
|
25
28
|
container: {
|
|
@@ -345,13 +348,14 @@ export function AudioPlayerButton({
|
|
|
345
348
|
icons: iconsConfiguration,
|
|
346
349
|
} = effectiveConfig;
|
|
347
350
|
|
|
348
|
-
const title = data
|
|
351
|
+
const title = data.title;
|
|
352
|
+
|
|
349
353
|
const isDisabled = disabled ?? data.disabled ?? false;
|
|
350
354
|
|
|
351
355
|
React.useEffect(() => {
|
|
352
356
|
if (!title) {
|
|
353
357
|
logger.log_warning(
|
|
354
|
-
"
|
|
358
|
+
"AudioPlayerButton rendering with empty title. Ensure data.title is set.",
|
|
355
359
|
{
|
|
356
360
|
leadingIcon: iconsConfiguration.leadingIcon,
|
|
357
361
|
modalBlocksStyle: modalBlocksStyle,
|