@applicaster/zapp-react-native-ui-components 15.0.0-alpha.1690332913 → 15.0.0-alpha.1693300296
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/Cell/Cell.tsx +6 -0
- package/Components/GeneralContentScreen/GeneralContentScreen.tsx +39 -28
- package/Components/GeneralContentScreen/__tests__/GeneralContentScreen.test.tsx +104 -0
- package/Components/GeneralContentScreen/utils/__tests__/getScreenDataSource.test.ts +19 -0
- package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +1 -1
- package/Components/GeneralContentScreen/utils/getScreenDataSource.ts +9 -0
- package/Components/GeneralContentScreen/utils/useCurationAPI.ts +7 -7
- package/Components/HandlePlayable/HandlePlayable.tsx +16 -29
- package/Components/HandlePlayable/utils.ts +31 -0
- package/Components/HookRenderer/HookRenderer.tsx +40 -10
- package/Components/HookRenderer/__tests__/HookRenderer.test.tsx +60 -0
- package/Components/Layout/TV/NavBarContainer.tsx +1 -10
- package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +7 -12
- package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +7 -12
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/model.test.ts +80 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +187 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/selectors.test.ts +45 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/style.test.ts +49 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/model.ts +47 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +170 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/selectors.ts +26 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/style.ts +29 -0
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/types.ts +37 -0
- package/Components/MasterCell/DefaultComponents/Button.tsx +0 -15
- package/Components/MasterCell/DefaultComponents/LiveImage/__tests__/prepareEntry.test.ts +352 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/executePreloadHooks.ts +136 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +33 -16
- package/Components/MasterCell/DefaultComponents/PressableView.tsx +196 -0
- package/Components/MasterCell/DefaultComponents/SecondaryImage/Image.tsx +40 -39
- package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/Image.test.tsx +95 -0
- package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/__snapshots__/Image.test.tsx.snap +86 -0
- package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/index.test.ts +141 -0
- package/Components/MasterCell/DefaultComponents/SecondaryImage/hooks/__tests__/useGetImageDimensions.test.ts +7 -6
- package/Components/MasterCell/DefaultComponents/SecondaryImage/index.ts +1 -1
- package/Components/MasterCell/DefaultComponents/Text/index.tsx +2 -6
- package/Components/MasterCell/DefaultComponents/index.ts +2 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Asset.ts +46 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +126 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ButtonContainerView.ts +23 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +16 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabel.ts +67 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +32 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +191 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/builders.test.ts +140 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +222 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/helpers.ts +105 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +104 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +118 -0
- package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +73 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/index.test.ts +86 -0
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +35 -48
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/getPluginIdentifier.test.ts +115 -29
- package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +39 -144
- package/Components/MasterCell/elementMapper.tsx +1 -0
- package/Components/MasterCell/hoc/__tests__/withAsyncRender.test.tsx +219 -0
- package/Components/MasterCell/hoc/withAsyncRender.tsx +9 -7
- package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +17 -9
- package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +16 -8
- package/Components/OfflineHandler/NotificationView/utils.ts +34 -0
- package/Components/PlayerContainer/PlayerContainer.tsx +1 -18
- package/Components/PreloaderWrapper/__tests__/index.test.tsx +26 -0
- package/Components/PreloaderWrapper/index.tsx +15 -0
- package/Components/River/ComponentsMap/ComponentsMap.tsx +16 -0
- package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +1 -1
- package/Components/River/RefreshControl.tsx +36 -13
- package/Components/River/RiverItem.tsx +26 -20
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -0
- package/Components/River/__tests__/componentsMap.test.js +38 -0
- package/Components/Screen/__tests__/Screen.test.tsx +1 -0
- package/Components/Screen/hooks.ts +73 -3
- package/Components/Screen/index.tsx +7 -1
- package/Components/Screen/orientationHandler.ts +7 -10
- package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +46 -0
- package/Components/ScreenFeedLoader/__tests__/ScreenFeedLoader.test.tsx +94 -0
- package/Components/ScreenFeedLoader/index.ts +1 -0
- package/Components/ScreenResolver/__tests__/screenResolver.test.js +24 -0
- package/Components/ScreenResolver/hooks/index.ts +3 -0
- package/Components/ScreenResolver/hooks/useGetComponent.ts +15 -0
- package/Components/ScreenResolver/hooks/useScreenComponentResolver.tsx +90 -0
- package/Components/ScreenResolver/index.tsx +15 -117
- package/Components/ScreenResolver/utils/__tests__/getScreenTypeProps.test.ts +45 -0
- package/Components/ScreenResolver/utils/getScreenTypeProps.ts +43 -0
- package/Components/ScreenResolver/utils/index.ts +1 -0
- package/Components/ScreenResolver/withDefaultScreenContext.tsx +16 -0
- package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +25 -0
- package/Components/ScreenResolverFeedProvider/__tests__/ScreenResolverFeedProvider.test.tsx +44 -0
- package/Components/ScreenResolverFeedProvider/index.ts +1 -0
- package/Components/Tabs/TabContent.tsx +7 -4
- package/Components/Transitioner/Scene.tsx +9 -15
- package/Components/VideoLive/LiveImageManager.ts +199 -54
- package/Components/VideoLive/PlayerLiveImageComponent.tsx +31 -33
- package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +2 -17
- package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +15 -7
- package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +0 -2
- package/Components/Viewport/ViewportAware/index.tsx +16 -7
- package/Components/Viewport/ViewportEvents/__tests__/viewportEvents.test.js +1 -1
- package/Components/ZappUIComponent/index.tsx +12 -6
- package/Components/default-cell-renderer/viewTrees/mobile/index.ts +0 -3
- package/Components/index.js +1 -1
- package/Contexts/ScreenContext/__tests__/index.test.tsx +57 -0
- package/Contexts/ScreenContext/index.tsx +71 -19
- package/Contexts/ScreenTrackedViewPositionsContext/__tests__/index.test.tsx +1 -1
- package/Contexts/ZappHookModalContext/index.tsx +37 -61
- package/Contexts/ZappPipesContext/ZappPipesContextFactory.tsx +18 -7
- package/Contexts/index.ts +0 -2
- package/Decorators/ZappPipesDataConnector/ResolverSelector.tsx +25 -7
- package/Decorators/ZappPipesDataConnector/__tests__/ResolverSelector.test.tsx +212 -5
- package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +39 -21
- package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +18 -7
- package/events/index.ts +3 -0
- package/events/scrollEndReached.ts +15 -0
- package/package.json +5 -5
- package/Components/MasterCell/DefaultComponents/Text/utils/__tests__/withAdjustedLineHeight.test.ts +0 -46
- package/Components/MasterCell/DefaultComponents/Text/utils/index.ts +0 -21
- package/Components/PlayerContainer/ErrorDisplay/ErrorDisplay.tsx +0 -57
- package/Components/PlayerContainer/ErrorDisplay/index.ts +0 -9
- package/Components/PlayerContainer/useRestrictMobilePlayback.tsx +0 -101
- /package/Components/HookRenderer/{index.tsx → index.ts} +0 -0
package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { MobileActionButtons } from "..";
|
|
2
|
+
|
|
3
|
+
describe("MobileActionButtons", () => {
|
|
4
|
+
const configuration = {
|
|
5
|
+
mobile_buttons_container_buttons_enabled: true,
|
|
6
|
+
mobile_buttons_container_position: "over_image",
|
|
7
|
+
mobile_buttons_container_align: "left",
|
|
8
|
+
mobile_buttons_container_margin_top: 0,
|
|
9
|
+
mobile_buttons_container_margin_right: 0,
|
|
10
|
+
mobile_buttons_container_margin_bottom: 0,
|
|
11
|
+
mobile_buttons_container_margin_left: 0,
|
|
12
|
+
mobile_buttons_container_stacking: "horizontal",
|
|
13
|
+
mobile_buttons_container_horizontal_gutter: 8,
|
|
14
|
+
mobile_buttons_container_vertical_gutter: 8,
|
|
15
|
+
mobile_buttons_container_independent_styles: true,
|
|
16
|
+
mobile_buttons_container_over_image_position: "top_right",
|
|
17
|
+
mobile_button_1_button_enabled: true,
|
|
18
|
+
mobile_button_1_assign_action: "navigation_action",
|
|
19
|
+
mobile_button_1_display_mode: "dynamic",
|
|
20
|
+
mobile_button_1_contents_alignment: "center",
|
|
21
|
+
mobile_button_1_background_color: "rgba(1,1,1,1)",
|
|
22
|
+
mobile_button_1_border_color: "rgba(0,0,0,0)",
|
|
23
|
+
mobile_button_1_border_size: 0,
|
|
24
|
+
mobile_button_1_corner_radius: 8,
|
|
25
|
+
mobile_button_1_padding_top: 10,
|
|
26
|
+
mobile_button_1_padding_right: 10,
|
|
27
|
+
mobile_button_1_padding_bottom: 10,
|
|
28
|
+
mobile_button_1_padding_left: 10,
|
|
29
|
+
mobile_button_1_asset_width: 24,
|
|
30
|
+
mobile_button_1_asset_height: 24,
|
|
31
|
+
mobile_button_1_asset_margin_top: 0,
|
|
32
|
+
mobile_button_1_asset_margin_right: 0,
|
|
33
|
+
mobile_button_1_asset_margin_bottom: 0,
|
|
34
|
+
mobile_button_1_asset_margin_left: 0,
|
|
35
|
+
mobile_button_1_asset_enabled: true,
|
|
36
|
+
mobile_button_1_label_enabled: true,
|
|
37
|
+
mobile_button_1_font_color: "rgba(255,255,255,1)",
|
|
38
|
+
mobile_button_1_focused_font_color: "rgba(255,0,0,1)",
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const value = (key) => configuration[key];
|
|
42
|
+
|
|
43
|
+
it("renders over-image buttons only for over_image placement", () => {
|
|
44
|
+
const result = MobileActionButtons({
|
|
45
|
+
value,
|
|
46
|
+
configuration,
|
|
47
|
+
placement: "over_image",
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(result).toBeTruthy();
|
|
51
|
+
expect(result.type).toBe("View");
|
|
52
|
+
expect(result.style.position).toBe("absolute");
|
|
53
|
+
expect(result.style.top).toBe(0);
|
|
54
|
+
expect(result.style.right).toBe(0);
|
|
55
|
+
expect(result.elements).toHaveLength(1);
|
|
56
|
+
expect(result.elements[0].type).toBe("View");
|
|
57
|
+
expect(result.elements[0].style.flexDirection).toBe("row");
|
|
58
|
+
expect(result.elements[0].elements[0].type).toBe("PressableView");
|
|
59
|
+
|
|
60
|
+
expect(result.elements[0].elements[0].elements).toEqual(
|
|
61
|
+
expect.arrayContaining([
|
|
62
|
+
expect.objectContaining({ type: "Image" }),
|
|
63
|
+
expect.objectContaining({ type: "View" }),
|
|
64
|
+
])
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("does not render label placement when position is over_image", () => {
|
|
69
|
+
const result = MobileActionButtons({
|
|
70
|
+
value,
|
|
71
|
+
configuration,
|
|
72
|
+
placement: "labels",
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
expect(result).toBeNull();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it("renders button 1 when only button 1 is enabled", () => {
|
|
79
|
+
const configurationWithSingleButton = {
|
|
80
|
+
...configuration,
|
|
81
|
+
mobile_button_1_button_enabled: true,
|
|
82
|
+
mobile_button_2_button_enabled: false,
|
|
83
|
+
mobile_button_3_button_enabled: false,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const singleButtonValue = (key) => configurationWithSingleButton[key];
|
|
87
|
+
|
|
88
|
+
const result = MobileActionButtons({
|
|
89
|
+
value: singleButtonValue,
|
|
90
|
+
configuration: configurationWithSingleButton,
|
|
91
|
+
placement: "over_image",
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
expect(result?.elements?.[0]?.elements).toHaveLength(1);
|
|
95
|
+
expect(result?.elements?.[0]?.elements?.[0]?.type).toBe("PressableView");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("renders button 2 when only button 2 is enabled", () => {
|
|
99
|
+
const configurationWithSingleButton = {
|
|
100
|
+
...configuration,
|
|
101
|
+
mobile_button_1_button_enabled: false,
|
|
102
|
+
mobile_button_2_button_enabled: true,
|
|
103
|
+
mobile_button_3_button_enabled: false,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const singleButtonValue = (key) => configurationWithSingleButton[key];
|
|
107
|
+
|
|
108
|
+
const result = MobileActionButtons({
|
|
109
|
+
value: singleButtonValue,
|
|
110
|
+
configuration: configurationWithSingleButton,
|
|
111
|
+
placement: "over_image",
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(result?.elements?.[0]?.elements).toHaveLength(1);
|
|
115
|
+
expect(result?.elements?.[0]?.elements?.[0]?.type).toBe("PressableView");
|
|
116
|
+
|
|
117
|
+
expect(
|
|
118
|
+
result?.elements?.[0]?.elements?.[0]?.additionalProps?.action?.identifier
|
|
119
|
+
).toBe(configurationWithSingleButton.mobile_button_2_assign_action);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("renders button 3 when only button 3 is enabled", () => {
|
|
123
|
+
const configurationWithSingleButton = {
|
|
124
|
+
...configuration,
|
|
125
|
+
mobile_button_1_button_enabled: false,
|
|
126
|
+
mobile_button_2_button_enabled: false,
|
|
127
|
+
mobile_button_3_button_enabled: true,
|
|
128
|
+
mobile_button_3_assign_action: "local_storage_favourites_action",
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const singleButtonValue = (key) => configurationWithSingleButton[key];
|
|
132
|
+
|
|
133
|
+
const result = MobileActionButtons({
|
|
134
|
+
value: singleButtonValue,
|
|
135
|
+
configuration: configurationWithSingleButton,
|
|
136
|
+
placement: "over_image",
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
expect(result?.elements?.[0]?.elements).toHaveLength(1);
|
|
140
|
+
expect(result?.elements?.[0]?.elements?.[0]?.type).toBe("PressableView");
|
|
141
|
+
|
|
142
|
+
expect(
|
|
143
|
+
result?.elements?.[0]?.elements?.[0]?.additionalProps?.action?.identifier
|
|
144
|
+
).toBe(configurationWithSingleButton.mobile_button_3_assign_action);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("renders sparse slots contiguously while preserving slot-specific actions", () => {
|
|
148
|
+
const configurationWithSparseButtons = {
|
|
149
|
+
...configuration,
|
|
150
|
+
mobile_button_1_button_enabled: true,
|
|
151
|
+
mobile_button_1_assign_action: "action_1",
|
|
152
|
+
mobile_button_2_button_enabled: false,
|
|
153
|
+
mobile_button_3_button_enabled: true,
|
|
154
|
+
mobile_button_3_assign_action: "action_3",
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const sparseValue = (key) => configurationWithSparseButtons[key];
|
|
158
|
+
|
|
159
|
+
const result = MobileActionButtons({
|
|
160
|
+
value: sparseValue,
|
|
161
|
+
configuration: configurationWithSparseButtons,
|
|
162
|
+
placement: "over_image",
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
expect(result?.elements?.[0]?.elements).toHaveLength(2);
|
|
166
|
+
|
|
167
|
+
expect(
|
|
168
|
+
result?.elements?.[0]?.elements?.[0]?.additionalProps?.action?.identifier
|
|
169
|
+
).toBe("action_1");
|
|
170
|
+
|
|
171
|
+
expect(
|
|
172
|
+
result?.elements?.[0]?.elements?.[1]?.additionalProps?.action?.identifier
|
|
173
|
+
).toBe("action_3");
|
|
174
|
+
|
|
175
|
+
expect(result?.elements?.[0]?.elements?.[0]?.additionalProps?.testID).toBe(
|
|
176
|
+
"mobile_action_button_1"
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
expect(result?.elements?.[0]?.elements?.[1]?.additionalProps?.testID).toBe(
|
|
180
|
+
"mobile_action_button_2"
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("maps shared semantic layout data into content styles", () => {
|
|
185
|
+
const configurationWithLayout = {
|
|
186
|
+
...configuration,
|
|
187
|
+
mobile_buttons_container_align: "middle",
|
|
188
|
+
mobile_buttons_container_margin_top: 5,
|
|
189
|
+
mobile_buttons_container_margin_right: 6,
|
|
190
|
+
mobile_buttons_container_margin_bottom: 7,
|
|
191
|
+
mobile_buttons_container_margin_left: 8,
|
|
192
|
+
mobile_buttons_container_stacking: "vertical",
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const layoutValue = (key) => configurationWithLayout[key];
|
|
196
|
+
|
|
197
|
+
const result = MobileActionButtons({
|
|
198
|
+
value: layoutValue,
|
|
199
|
+
configuration: configurationWithLayout,
|
|
200
|
+
placement: "labels",
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
expect(result).toBeNull();
|
|
204
|
+
|
|
205
|
+
const overImageResult = MobileActionButtons({
|
|
206
|
+
value: layoutValue,
|
|
207
|
+
configuration: configurationWithLayout,
|
|
208
|
+
placement: "over_image",
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
expect(overImageResult?.elements?.[0]?.style).toMatchObject({
|
|
212
|
+
flexDirection: "column",
|
|
213
|
+
alignItems: "center",
|
|
214
|
+
marginTop: 5,
|
|
215
|
+
marginRight: 6,
|
|
216
|
+
marginBottom: 7,
|
|
217
|
+
marginLeft: 8,
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
expect(overImageResult?.elements?.[0]?.style.alignSelf).toBeUndefined();
|
|
221
|
+
});
|
|
222
|
+
});
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Platform } from "react-native";
|
|
2
|
+
|
|
3
|
+
export function isStringAsset(asset) {
|
|
4
|
+
return typeof asset === "string" || Array.isArray(asset);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function getAssetValue(asset, flavour, fallbackAsset = null) {
|
|
8
|
+
if (!asset) {
|
|
9
|
+
return fallbackAsset;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (typeof asset === "string") {
|
|
13
|
+
return asset;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (Array.isArray(asset)) {
|
|
17
|
+
const flavourIndex = Number(String(flavour || "").replace("flavour_", ""));
|
|
18
|
+
|
|
19
|
+
if (!Number.isNaN(flavourIndex) && flavourIndex > 0) {
|
|
20
|
+
return asset[flavourIndex - 1];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return asset[0];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return asset.src || fallbackAsset;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getContentDirection(alignment = "left") {
|
|
30
|
+
switch (alignment) {
|
|
31
|
+
case "right":
|
|
32
|
+
return "row-reverse";
|
|
33
|
+
case "above":
|
|
34
|
+
return "column";
|
|
35
|
+
case "below":
|
|
36
|
+
return "column-reverse";
|
|
37
|
+
case "left":
|
|
38
|
+
default:
|
|
39
|
+
return "row";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getContentsAlignment(alignment = "center") {
|
|
44
|
+
switch (alignment) {
|
|
45
|
+
case "left":
|
|
46
|
+
return "flex-start";
|
|
47
|
+
case "right":
|
|
48
|
+
return "flex-end";
|
|
49
|
+
case "center":
|
|
50
|
+
default:
|
|
51
|
+
return "center";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function resolveLabelText(label) {
|
|
56
|
+
if (typeof label === "string") {
|
|
57
|
+
return label;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return label?.label_1 || "";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function resolveIsActive(actionState, fallbackSelected = false) {
|
|
64
|
+
if (actionState == null) {
|
|
65
|
+
return fallbackSelected;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return Boolean(
|
|
69
|
+
actionState?.active ??
|
|
70
|
+
actionState?.isActive ??
|
|
71
|
+
actionState?.selected ??
|
|
72
|
+
actionState?.isSelected ??
|
|
73
|
+
fallbackSelected
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function buildLegacySelection(item, actionContext) {
|
|
78
|
+
const defaultIsSelected = (actionContext?.state || []).includes(item);
|
|
79
|
+
|
|
80
|
+
return actionContext?.masterCell?.isSelected
|
|
81
|
+
? actionContext?.masterCell?.isSelected(item)
|
|
82
|
+
: defaultIsSelected;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function buildLabelStyle(label) {
|
|
86
|
+
if (!label?.enabled) {
|
|
87
|
+
return {};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const platformFontFamily =
|
|
91
|
+
Platform.OS === "ios"
|
|
92
|
+
? label?.iosFontFamily || label?.normalStyle?.fontFamily
|
|
93
|
+
: label?.androidFontFamily || label?.normalStyle?.fontFamily;
|
|
94
|
+
|
|
95
|
+
const platformLetterSpacing =
|
|
96
|
+
Platform.OS === "ios"
|
|
97
|
+
? label?.iosLetterSpacing
|
|
98
|
+
: label?.androidLetterSpacing;
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
...label?.normalStyle,
|
|
102
|
+
fontFamily: platformFontFamily,
|
|
103
|
+
letterSpacing: platformLetterSpacing,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { compact } from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
2
|
+
import {
|
|
3
|
+
insertButtonsBetweenLabels,
|
|
4
|
+
insertButtonsBetweenLabelContainers,
|
|
5
|
+
mobileOverImagePositionStyles,
|
|
6
|
+
} from "./utils";
|
|
7
|
+
import { Button } from "./Button";
|
|
8
|
+
import { ButtonContainerView } from "./ButtonContainerView";
|
|
9
|
+
import { buildActionButtonsModel } from "../../ActionButtonsCore/model";
|
|
10
|
+
|
|
11
|
+
const CONTAINER_PREFIX = "mobile_buttons_container";
|
|
12
|
+
const BUTTON_PREFIX = "mobile_button";
|
|
13
|
+
|
|
14
|
+
type MobileActionButtonsProps = {
|
|
15
|
+
value: (key: string) => unknown;
|
|
16
|
+
configuration: Record<string, unknown>;
|
|
17
|
+
placement: "labels" | "over_image"; // Indicates where the component was placed, to apply specific display rules
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const MobileActionButtons = ({
|
|
21
|
+
value,
|
|
22
|
+
configuration,
|
|
23
|
+
placement,
|
|
24
|
+
}: MobileActionButtonsProps) => {
|
|
25
|
+
const position = value(`${CONTAINER_PREFIX}_position`);
|
|
26
|
+
|
|
27
|
+
if (placement === "labels" && position === "over_image") {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (placement === "over_image" && position !== "over_image") {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const model = buildActionButtonsModel({
|
|
36
|
+
configuration,
|
|
37
|
+
value,
|
|
38
|
+
containerPrefix: CONTAINER_PREFIX,
|
|
39
|
+
buttonPrefix: BUTTON_PREFIX,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (!model) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const elements = compact(
|
|
47
|
+
model.buttons.map(({ renderIndex, specificPrefix, stylePrefix }) => {
|
|
48
|
+
const isNotLast = renderIndex < model.buttons.length - 1;
|
|
49
|
+
|
|
50
|
+
const {
|
|
51
|
+
container: { stacking, verticalGutter, horizontalGutter },
|
|
52
|
+
} = model;
|
|
53
|
+
|
|
54
|
+
const isVertical = stacking === "vertical";
|
|
55
|
+
const gutter = isVertical ? verticalGutter : horizontalGutter;
|
|
56
|
+
|
|
57
|
+
const spacingStyle = {
|
|
58
|
+
[isVertical ? "marginBottom" : "marginRight"]: isNotLast ? gutter : 0,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
return Button({
|
|
62
|
+
index: renderIndex,
|
|
63
|
+
value,
|
|
64
|
+
stylePrefix,
|
|
65
|
+
specificPrefix,
|
|
66
|
+
spacingStyle,
|
|
67
|
+
});
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return ButtonContainerView({
|
|
72
|
+
style: {
|
|
73
|
+
alignItems: "center",
|
|
74
|
+
...(placement === "over_image"
|
|
75
|
+
? {
|
|
76
|
+
position: "absolute",
|
|
77
|
+
zIndex: 10,
|
|
78
|
+
top: 0,
|
|
79
|
+
left: 0,
|
|
80
|
+
right: 0,
|
|
81
|
+
bottom: 0,
|
|
82
|
+
...mobileOverImagePositionStyles(
|
|
83
|
+
value(`${CONTAINER_PREFIX}_over_image_position`) as string
|
|
84
|
+
),
|
|
85
|
+
}
|
|
86
|
+
: {}),
|
|
87
|
+
},
|
|
88
|
+
contentStyle: {
|
|
89
|
+
flexDirection: model.container.stacking === "vertical" ? "column" : "row",
|
|
90
|
+
alignSelf:
|
|
91
|
+
placement !== "over_image"
|
|
92
|
+
? model.container.horizontalAlign
|
|
93
|
+
: undefined,
|
|
94
|
+
alignItems: model.container.horizontalAlign,
|
|
95
|
+
marginTop: model.container.margins.top,
|
|
96
|
+
marginRight: model.container.margins.right,
|
|
97
|
+
marginBottom: model.container.margins.bottom,
|
|
98
|
+
marginLeft: model.container.margins.left,
|
|
99
|
+
},
|
|
100
|
+
elements,
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export { insertButtonsBetweenLabels, insertButtonsBetweenLabelContainers };
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import {
|
|
2
|
+
insertButtonsBetweenLabelContainers,
|
|
3
|
+
insertButtonsBetweenLabels,
|
|
4
|
+
mobileOverImagePositionStyles,
|
|
5
|
+
} from "..";
|
|
6
|
+
|
|
7
|
+
describe("mobile action insertion helpers", () => {
|
|
8
|
+
const labels = [{ name: "text_label_1" }, { name: "text_label_2" }];
|
|
9
|
+
const buttons = { type: "View", name: "buttons" };
|
|
10
|
+
|
|
11
|
+
it("inserts label buttons below target label", () => {
|
|
12
|
+
const result = insertButtonsBetweenLabels(
|
|
13
|
+
{ mobile_buttons_container_position: "below_text_label_1" },
|
|
14
|
+
buttons,
|
|
15
|
+
labels
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
expect(result).toEqual([labels[0], buttons, labels[1]]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("returns labels unchanged when the flat-label target is unknown", () => {
|
|
22
|
+
const result = insertButtonsBetweenLabels(
|
|
23
|
+
{ mobile_buttons_container_position: "unknown" },
|
|
24
|
+
buttons,
|
|
25
|
+
labels
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect(result).toEqual([labels[0], labels[1]]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("inserts label-container buttons below nested target", () => {
|
|
32
|
+
const labelContainers = [
|
|
33
|
+
{
|
|
34
|
+
elements: [{ elements: [{ name: "top_text_label_1" }] }],
|
|
35
|
+
},
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
const result = insertButtonsBetweenLabelContainers(
|
|
39
|
+
{ mobile_buttons_container_position: "top_text_label_1" },
|
|
40
|
+
buttons,
|
|
41
|
+
labelContainers
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
expect(result).toEqual([
|
|
45
|
+
{
|
|
46
|
+
elements: [{ elements: [{ name: "top_text_label_1" }, buttons] }],
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("inserts label-container buttons below direct target in two-level structure", () => {
|
|
52
|
+
const labelContainers = [
|
|
53
|
+
{
|
|
54
|
+
elements: [{ name: "top_text_label_1" }],
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
|
|
58
|
+
const result = insertButtonsBetweenLabelContainers(
|
|
59
|
+
{ mobile_buttons_container_position: "top_text_label_1" },
|
|
60
|
+
buttons,
|
|
61
|
+
labelContainers
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
expect(result).toEqual([
|
|
65
|
+
{
|
|
66
|
+
elements: [{ name: "top_text_label_1" }, buttons],
|
|
67
|
+
},
|
|
68
|
+
]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("appends container buttons into the last container when target is unknown", () => {
|
|
72
|
+
const labelContainers = [
|
|
73
|
+
{
|
|
74
|
+
elements: [{ elements: [{ name: "top_text_label_1" }] }],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
elements: [{ elements: [{ name: "bottom_text_label_1" }] }],
|
|
78
|
+
},
|
|
79
|
+
];
|
|
80
|
+
|
|
81
|
+
const result = insertButtonsBetweenLabelContainers(
|
|
82
|
+
{ mobile_buttons_container_position: "unknown" },
|
|
83
|
+
buttons,
|
|
84
|
+
labelContainers
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
expect(result).toEqual([
|
|
88
|
+
labelContainers[0],
|
|
89
|
+
{
|
|
90
|
+
elements: [...labelContainers[1].elements, buttons],
|
|
91
|
+
},
|
|
92
|
+
]);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
describe("mobileOverImagePositionStyles", () => {
|
|
97
|
+
it("maps bottom left anchor to absolute positioning", () => {
|
|
98
|
+
const result = mobileOverImagePositionStyles("bottom_left");
|
|
99
|
+
|
|
100
|
+
expect(result).toEqual({
|
|
101
|
+
justifyContent: "flex-end",
|
|
102
|
+
alignItems: "flex-start",
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("maps center anchor to absolute center positioning", () => {
|
|
107
|
+
const result = mobileOverImagePositionStyles("center");
|
|
108
|
+
|
|
109
|
+
expect(result).toEqual({
|
|
110
|
+
justifyContent: "center",
|
|
111
|
+
alignItems: "center",
|
|
112
|
+
top: 0,
|
|
113
|
+
left: 0,
|
|
114
|
+
right: 0,
|
|
115
|
+
bottom: 0,
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
insertBetweenLabelContainers,
|
|
3
|
+
insertBetweenLabels,
|
|
4
|
+
} from "../../../ActionButtonsCore/placement";
|
|
5
|
+
|
|
6
|
+
export const insertButtonsBetweenLabels = (
|
|
7
|
+
configuration: Record<string, unknown>,
|
|
8
|
+
buttons,
|
|
9
|
+
labels = []
|
|
10
|
+
) =>
|
|
11
|
+
insertBetweenLabels(
|
|
12
|
+
{
|
|
13
|
+
position: configuration?.mobile_buttons_container_position as
|
|
14
|
+
| string
|
|
15
|
+
| undefined,
|
|
16
|
+
allowOnTop: false,
|
|
17
|
+
appendWhenMissing: false,
|
|
18
|
+
},
|
|
19
|
+
buttons,
|
|
20
|
+
labels // "text_label_1", "text_label_2", "text_label_3", "text_label_4"
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const insertButtonsBetweenLabelContainers = (
|
|
24
|
+
configuration: Record<string, unknown>,
|
|
25
|
+
buttons,
|
|
26
|
+
labelContainers = []
|
|
27
|
+
) =>
|
|
28
|
+
insertBetweenLabelContainers(
|
|
29
|
+
{
|
|
30
|
+
position: configuration?.mobile_buttons_container_position as
|
|
31
|
+
| string
|
|
32
|
+
| undefined,
|
|
33
|
+
allowOnTop: false,
|
|
34
|
+
appendWhenMissing: true,
|
|
35
|
+
},
|
|
36
|
+
buttons,
|
|
37
|
+
labelContainers // top_label_1, top_label_2, bottom_label_1, bottom_label_2, etc.
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export const mobileOverImagePositionStyles = (position: string) => {
|
|
41
|
+
switch (position) {
|
|
42
|
+
case "top_left":
|
|
43
|
+
return {
|
|
44
|
+
justifyContent: "flex-start",
|
|
45
|
+
alignItems: "flex-start",
|
|
46
|
+
};
|
|
47
|
+
case "top_right":
|
|
48
|
+
return {
|
|
49
|
+
justifyContent: "flex-start",
|
|
50
|
+
alignItems: "flex-end",
|
|
51
|
+
};
|
|
52
|
+
case "bottom_left":
|
|
53
|
+
return {
|
|
54
|
+
justifyContent: "flex-end",
|
|
55
|
+
alignItems: "flex-start",
|
|
56
|
+
};
|
|
57
|
+
case "bottom_right":
|
|
58
|
+
return {
|
|
59
|
+
justifyContent: "flex-end",
|
|
60
|
+
alignItems: "flex-end",
|
|
61
|
+
};
|
|
62
|
+
case "center":
|
|
63
|
+
default:
|
|
64
|
+
return {
|
|
65
|
+
justifyContent: "center",
|
|
66
|
+
alignItems: "center",
|
|
67
|
+
top: 0,
|
|
68
|
+
left: 0,
|
|
69
|
+
right: 0,
|
|
70
|
+
bottom: 0,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { TvActionButtons } from "..";
|
|
2
|
+
|
|
3
|
+
describe("TvActionButtons", () => {
|
|
4
|
+
const baseConfiguration = {
|
|
5
|
+
tv_buttons_container_buttons_enabled: true,
|
|
6
|
+
tv_buttons_container_align: "middle",
|
|
7
|
+
tv_buttons_container_margin_top: 1,
|
|
8
|
+
tv_buttons_container_margin_right: 2,
|
|
9
|
+
tv_buttons_container_margin_bottom: 3,
|
|
10
|
+
tv_buttons_container_margin_left: 4,
|
|
11
|
+
tv_buttons_container_horizontal_gutter: 10,
|
|
12
|
+
tv_buttons_container_independent_styles: false,
|
|
13
|
+
tv_buttons_button_1_button_enabled: true,
|
|
14
|
+
tv_buttons_button_1_assign_action: "action_1",
|
|
15
|
+
tv_buttons_button_1_background_padding_top: 11,
|
|
16
|
+
tv_buttons_button_1_background_padding_right: 12,
|
|
17
|
+
tv_buttons_button_1_background_padding_bottom: 13,
|
|
18
|
+
tv_buttons_button_1_background_padding_left: 14,
|
|
19
|
+
tv_buttons_button_3_button_enabled: true,
|
|
20
|
+
tv_buttons_button_3_assign_action: "action_3",
|
|
21
|
+
tv_buttons_button_3_background_padding_top: 31,
|
|
22
|
+
tv_buttons_button_3_background_padding_right: 32,
|
|
23
|
+
tv_buttons_button_3_background_padding_bottom: 33,
|
|
24
|
+
tv_buttons_button_3_background_padding_left: 34,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const platformValue = jest.fn();
|
|
28
|
+
|
|
29
|
+
it("renders sparse enabled slots with slot-based action lookup and ids", () => {
|
|
30
|
+
const value = (key) => baseConfiguration[key];
|
|
31
|
+
|
|
32
|
+
const result = TvActionButtons({
|
|
33
|
+
value,
|
|
34
|
+
platformValue,
|
|
35
|
+
configuration: baseConfiguration,
|
|
36
|
+
state: "focused",
|
|
37
|
+
skipButtons: false,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
expect(result.style.justifyContent).toBe("center");
|
|
41
|
+
expect(result.additionalProps.buttonsCount).toBe(2);
|
|
42
|
+
expect(result.elements).toHaveLength(2);
|
|
43
|
+
|
|
44
|
+
expect(result.elements[0].additionalProps.pluginIdentifier).toBe(
|
|
45
|
+
"action_1"
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
expect(result.elements[0].additionalProps.suffixId).toBe(
|
|
49
|
+
"tv_buttons_button_1"
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
expect(result.elements[0].additionalProps.preferredFocus).toBe(true);
|
|
53
|
+
|
|
54
|
+
expect(result.elements[1].additionalProps.pluginIdentifier).toBe(
|
|
55
|
+
"action_3"
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect(result.elements[1].additionalProps.suffixId).toBe(
|
|
59
|
+
"tv_buttons_button_3"
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect(result.elements[1].additionalProps.preferredFocus).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("keeps shared button styles from slot 1 while preserving slot 3 identity", () => {
|
|
66
|
+
const value = (key) => baseConfiguration[key];
|
|
67
|
+
|
|
68
|
+
const result = TvActionButtons({
|
|
69
|
+
value,
|
|
70
|
+
platformValue,
|
|
71
|
+
configuration: baseConfiguration,
|
|
72
|
+
state: "focused",
|
|
73
|
+
skipButtons: false,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(result.elements[1].style.paddingTop).toBe(11);
|
|
77
|
+
|
|
78
|
+
expect(result.elements[1].additionalProps.pluginIdentifier).toBe(
|
|
79
|
+
"action_3"
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
expect(result.elements[1].additionalProps.suffixId).toBe(
|
|
83
|
+
"tv_buttons_button_3"
|
|
84
|
+
);
|
|
85
|
+
});
|
|
86
|
+
});
|