@applicaster/zapp-react-native-ui-components 15.0.0-alpha.4225160176 → 15.0.0-alpha.4232833803

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.
Files changed (84) hide show
  1. package/Components/Cell/TvOSCellComponent.tsx +1 -3
  2. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +5 -0
  3. package/Components/MasterCell/CONFIG_BUILDER_TO_REACT_COMPONENT.md +144 -0
  4. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/model.test.ts +80 -0
  5. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +187 -0
  6. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/selectors.test.ts +45 -0
  7. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/style.test.ts +49 -0
  8. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +165 -0
  9. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +405 -0
  10. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/index.ts +1 -0
  11. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/model.ts +47 -0
  12. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +170 -0
  13. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/selectors.ts +26 -0
  14. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/style.ts +29 -0
  15. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/types.ts +37 -0
  16. package/Components/MasterCell/DefaultComponents/Button.tsx +0 -15
  17. package/Components/MasterCell/DefaultComponents/ButtonContainerView/components/HorizontalSeparator.tsx +8 -0
  18. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +15 -0
  19. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tv.android.tsx +58 -0
  20. package/Components/MasterCell/DefaultComponents/{tv/ButtonContainerView/index.tsx → ButtonContainerView/index.tv.tsx} +3 -11
  21. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.web.ts +1 -0
  22. package/Components/MasterCell/DefaultComponents/ButtonContainerView/types.ts +40 -0
  23. package/Components/MasterCell/DefaultComponents/DataProvider/index.tsx +163 -0
  24. package/Components/MasterCell/DefaultComponents/FocusableView/index.android.tsx +2 -23
  25. package/Components/MasterCell/DefaultComponents/FocusableView/index.tsx +4 -22
  26. package/Components/MasterCell/DefaultComponents/Image/Image.android.tsx +3 -1
  27. package/Components/MasterCell/DefaultComponents/PressableView.tsx +34 -0
  28. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +11 -0
  29. package/Components/MasterCell/DefaultComponents/Text/index.tsx +2 -2
  30. package/Components/MasterCell/DefaultComponents/__tests__/DataProvider.test.tsx +141 -0
  31. package/Components/MasterCell/DefaultComponents/index.ts +9 -3
  32. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +135 -0
  33. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Asset.ts +33 -0
  34. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +22 -0
  35. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +125 -0
  36. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +16 -0
  37. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabel.ts +67 -0
  38. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +37 -0
  39. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +393 -0
  40. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/builders.test.ts +141 -0
  41. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +343 -0
  42. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/helpers.ts +105 -0
  43. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +122 -0
  44. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +118 -0
  45. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +238 -0
  46. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Asset.ts +4 -18
  47. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/Button.ts +24 -73
  48. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TextLabelsContainer.ts +37 -18
  49. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/TvActionButton.tsx +27 -0
  50. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/index.test.ts +89 -0
  51. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/renderedTree.test.tsx +231 -0
  52. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +47 -52
  53. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/getPluginIdentifier.test.ts +35 -171
  54. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +98 -145
  55. package/Components/MasterCell/MappingFunctions/index.js +3 -2
  56. package/Components/MasterCell/README.md +4 -0
  57. package/Components/MasterCell/__tests__/__snapshots__/dataAdapter.test.js.snap +24 -0
  58. package/Components/MasterCell/__tests__/configInflater.test.js +1 -0
  59. package/Components/MasterCell/__tests__/elementMapper.test.js +46 -0
  60. package/Components/MasterCell/dataAdapter.ts +4 -1
  61. package/Components/MasterCell/elementMapper.tsx +52 -7
  62. package/Components/MasterCell/utils/__tests__/cloneChildrenWithIds.test.tsx +43 -0
  63. package/Components/MasterCell/utils/__tests__/useFilterChildren.test.tsx +80 -0
  64. package/Components/MasterCell/utils/index.ts +85 -15
  65. package/Components/Navigator/StackNavigator.tsx +6 -0
  66. package/Components/PlayerContainer/PlayerContainer.tsx +1 -1
  67. package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -16
  68. package/Components/River/RefreshControl.tsx +19 -88
  69. package/Components/River/River.tsx +9 -82
  70. package/Components/River/hooks/__tests__/usePullToRefresh.test.ts +132 -0
  71. package/Components/River/hooks/index.ts +1 -0
  72. package/Components/River/hooks/usePullToRefresh.ts +51 -0
  73. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +4 -1
  74. package/Components/TopCutoffOverlay/__tests__/TopCutoffOverlay.test.tsx +201 -0
  75. package/Components/{TopMarginApplicator/TopMarginApplicator.android.tsx → TopCutoffOverlay/index.tsx} +8 -5
  76. package/Components/TopMarginApplicator/TopMarginApplicator.tsx +60 -4
  77. package/Components/default-cell-renderer/viewTrees/mobile/index.ts +0 -3
  78. package/package.json +5 -5
  79. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/index.android.tsx +0 -135
  80. package/Components/MasterCell/DefaultComponents/tv/ButtonContainerView/types.ts +0 -25
  81. package/Components/TopMarginApplicator/index.tsx +0 -11
  82. /package/Components/{TopMarginApplicator → TopCutoffOverlay}/hooks/__tests__/useMarginTop.test.ts +0 -0
  83. /package/Components/{TopMarginApplicator → TopCutoffOverlay}/hooks/index.ts +0 -0
  84. /package/Components/{TopMarginApplicator → TopCutoffOverlay}/hooks/useMarginTop.ts +0 -0
@@ -195,7 +195,6 @@ class TvOSCell extends React.Component<Props, State> {
195
195
  groupId,
196
196
  component,
197
197
  index,
198
- componentsMapOffset,
199
198
  } = this.props;
200
199
 
201
200
  this.setScreenLayout(componentAnchorPointY, screenLayout);
@@ -222,8 +221,7 @@ class TvOSCell extends React.Component<Props, State> {
222
221
  const totalOffset =
223
222
  headerOffset +
224
223
  toNumberWithDefaultZero(componentAnchorPointY) +
225
- extraAnchorPointYOffset -
226
- toNumberWithDefaultZero(componentsMapOffset) +
224
+ extraAnchorPointYOffset +
227
225
  componentMarginTop +
228
226
  componentPaddingTop;
229
227
 
@@ -9,6 +9,11 @@ exports[`Layout TV renders 1`] = `
9
9
  excludeFromFocusSearching={true}
10
10
  id="/river/A1234"
11
11
  preferredFocus={true}
12
+ style={
13
+ {
14
+ "flex": 1,
15
+ }
16
+ }
12
17
  >
13
18
  <View
14
19
  Components={
@@ -0,0 +1,144 @@
1
+ # Config Builder -> React Component Migration Guide
2
+
3
+ This guide explains how to migrate MasterCell config-builders to React components incrementally, without breaking existing config-node rendering.
4
+
5
+ ## Why This Exists
6
+
7
+ MasterCell currently supports config-node builders such as:
8
+
9
+ ```ts
10
+ {
11
+ type: "View",
12
+ style: {},
13
+ additionalProps: {},
14
+ data: [],
15
+ elements: []
16
+ }
17
+ ```
18
+
19
+ This is still valid and should continue to work.
20
+
21
+ For incremental migration, MasterCell also supports inline React nodes:
22
+
23
+ ```ts
24
+ {
25
+ type: "ReactComponent",
26
+ style: {},
27
+ additionalProps: {
28
+ component: MyComponent
29
+ }
30
+ }
31
+ ```
32
+
33
+ This lets you migrate one builder at a time.
34
+
35
+ ## Rendering Pipeline
36
+
37
+ 1. Builder returns node config (`type`, `style`, `additionalProps`, `data`, `elements`).
38
+ 2. `configInflater` converts `additionalProps` into runtime `props` and resolves `data`.
39
+ 3. `elementMapper` renders:
40
+ 4. String `type` nodes via component registry (`components[type]`).
41
+ 5. `type: "ReactComponent"` nodes via `props.component`.
42
+
43
+ ## Migration Pattern
44
+
45
+ 1. Keep existing builder API unchanged.
46
+ 2. Add a dedicated React component for the node being migrated.
47
+ 3. Change builder output from string `type` to `type: "ReactComponent"`.
48
+ 4. Pass component reference through `additionalProps.component`.
49
+ 5. Keep behavioral props unchanged (`testID`, roles, accessibility props).
50
+ 6. Set `renderChildren` explicitly:
51
+ 7. `false` when React component renders everything itself.
52
+ 8. `true` (or omit) when builder still provides `elements` children.
53
+ 9. Set `requiresCellUUID: true` only if the component needs `cellUUID`.
54
+ 10. Update builder-shape tests and rendering tests together.
55
+
56
+ ## Example Using `TextLabelsContainer.ts`
57
+
58
+ Current builder (config-node only):
59
+
60
+ ```ts
61
+ export const TextLabelsContainer = ({ actionIdentifier, testID, style, extraProps }) => ({
62
+ type: "View",
63
+ additionalProps: {
64
+ mobileActionRole: "label_container",
65
+ },
66
+ elements: [
67
+ {
68
+ type: "Text",
69
+ style,
70
+ additionalProps: {
71
+ label: { context: actionIdentifier, name: "label_1" },
72
+ state: "default",
73
+ mobileActionRole: "label",
74
+ testID: testID ? `${testID}-label` : undefined,
75
+ ...extraProps,
76
+ },
77
+ },
78
+ ],
79
+ });
80
+ ```
81
+
82
+ Incremental migration target:
83
+
84
+ ```ts
85
+ import { TextLabelsContainerView } from "./TextLabelsContainerView";
86
+
87
+ export const TextLabelsContainer = ({ actionIdentifier, testID, style, extraProps }) => ({
88
+ type: "ReactComponent",
89
+ additionalProps: {
90
+ component: TextLabelsContainerView,
91
+ renderChildren: false,
92
+ mobileActionRole: "label_container",
93
+ actionIdentifier,
94
+ testID,
95
+ textStyle: style,
96
+ textProps: extraProps,
97
+ },
98
+ });
99
+ ```
100
+
101
+ And React component:
102
+
103
+ ```tsx
104
+ export const TextLabelsContainerView = ({
105
+ actionIdentifier,
106
+ testID,
107
+ textStyle,
108
+ textProps,
109
+ mobileActionRole,
110
+ }) => (
111
+ <View mobileActionRole={mobileActionRole}>
112
+ <Text
113
+ style={textStyle}
114
+ label={{ context: actionIdentifier, name: "label_1" }}
115
+ state="default"
116
+ mobileActionRole="label"
117
+ testID={testID ? `${testID}-label` : undefined}
118
+ {...textProps}
119
+ />
120
+ </View>
121
+ );
122
+ ```
123
+
124
+ This keeps external behavior and props contract intact while moving implementation to React.
125
+
126
+ ## Rules for Safe Incremental Migration
127
+
128
+ 1. Do not change role markers used by parent logic (for example `mobileActionRole`).
129
+ 2. Do not rename `testID` contracts during migration.
130
+ 3. Keep output shape stable for parent builders (`null` handling, `elements` presence).
131
+ 4. Keep data-mapping semantics identical (`label`, `state`, `entry`, etc.).
132
+ 5. Migrate one node per PR where possible.
133
+
134
+ ## Testing Checklist
135
+
136
+ 1. Builder test: node type and required props (`component`, role, `testID`) are correct.
137
+ 2. Rendering test: `configInflater + elementMapper` still renders expected UI.
138
+ 3. Behavior test: parent container logic that clones/filters children still works.
139
+ 4. Regression test: hidden/empty states still return `null` as before.
140
+
141
+ ## Important Limitation
142
+
143
+ `additionalProps.component` is a function reference and is suitable for local JS-built trees.
144
+ If a tree must be fully serialized JSON, use a string `componentKey` and resolve it in a registry instead of storing a function directly.
@@ -0,0 +1,80 @@
1
+ import { buildActionButtonsModel } from "../model";
2
+
3
+ describe("buildActionButtonsModel", () => {
4
+ it("returns null when the container is disabled", () => {
5
+ const configuration = {
6
+ mobile_buttons_container_buttons_enabled: false,
7
+ mobile_button_1_button_enabled: true,
8
+ };
9
+
10
+ const value = (key) => configuration[key];
11
+
12
+ expect(
13
+ buildActionButtonsModel({
14
+ configuration,
15
+ value,
16
+ containerPrefix: "mobile_buttons_container",
17
+ buttonPrefix: "mobile_button",
18
+ })
19
+ ).toBeNull();
20
+ });
21
+
22
+ it("returns explicit enabled slots and semantic container data", () => {
23
+ const configuration = {
24
+ mobile_buttons_container_buttons_enabled: true,
25
+ mobile_buttons_container_align: "right",
26
+ mobile_buttons_container_margin_top: 1,
27
+ mobile_buttons_container_margin_right: 2,
28
+ mobile_buttons_container_margin_bottom: 3,
29
+ mobile_buttons_container_margin_left: 4,
30
+ mobile_buttons_container_stacking: "vertical",
31
+ mobile_buttons_container_horizontal_gutter: 8,
32
+ mobile_buttons_container_vertical_gutter: 12,
33
+ mobile_buttons_container_independent_styles: false,
34
+ mobile_button_1_button_enabled: true,
35
+ mobile_button_2_button_enabled: false,
36
+ mobile_button_3_button_enabled: true,
37
+ };
38
+
39
+ const value = (key) => configuration[key];
40
+
41
+ expect(
42
+ buildActionButtonsModel({
43
+ configuration,
44
+ value,
45
+ containerPrefix: "mobile_buttons_container",
46
+ buttonPrefix: "mobile_button",
47
+ })
48
+ ).toEqual({
49
+ enabledSlots: [1, 3],
50
+ buttonsCount: 2,
51
+ container: {
52
+ horizontalAlign: "flex-end",
53
+ margins: {
54
+ top: 1,
55
+ right: 2,
56
+ bottom: 3,
57
+ left: 4,
58
+ },
59
+ stacking: "vertical",
60
+ horizontalGutter: 8,
61
+ verticalGutter: 12,
62
+ independentStyles: false,
63
+ },
64
+ buttons: [
65
+ {
66
+ slot: 1,
67
+ renderIndex: 0,
68
+ specificPrefix: "mobile_button_1",
69
+ stylePrefix: "mobile_button_1",
70
+ },
71
+ {
72
+ slot: 3,
73
+ renderIndex: 1,
74
+ specificPrefix: "mobile_button_3",
75
+ stylePrefix: "mobile_button_1",
76
+ },
77
+ ],
78
+ });
79
+ });
80
+ });
@@ -0,0 +1,187 @@
1
+ import {
2
+ insertBetweenLabelContainers,
3
+ insertBetweenLabels,
4
+ } from "../placement";
5
+
6
+ describe("ActionButtonsCore placement", () => {
7
+ const buttons = { type: "View", name: "buttons" };
8
+
9
+ const above_labels = [
10
+ { name: "above_label_1" },
11
+ { name: "above_label_2" },
12
+ { name: "above_label_3" },
13
+ ];
14
+
15
+ const below_labels = [
16
+ { name: "below_label_1" },
17
+ { name: "below_label_2" },
18
+ { name: "below_label_3" },
19
+ ];
20
+
21
+ it("inserts buttons after the matching label", () => {
22
+ expect(
23
+ insertBetweenLabels({ position: "below_label_2" }, buttons, below_labels)
24
+ ).toEqual([below_labels[0], below_labels[1], buttons, below_labels[2]]);
25
+ });
26
+
27
+ it("inserts buttons before the matching label", () => {
28
+ expect(
29
+ insertBetweenLabels({ position: "above_label_2" }, buttons, above_labels)
30
+ ).toEqual([above_labels[0], buttons, above_labels[1], above_labels[2]]);
31
+ });
32
+
33
+ it("prepends buttons only when on_top is allowed", () => {
34
+ expect(
35
+ insertBetweenLabels(
36
+ { position: "on_top", allowOnTop: true },
37
+ buttons,
38
+ below_labels
39
+ )
40
+ ).toEqual([buttons, ...below_labels]);
41
+
42
+ expect(
43
+ insertBetweenLabels(
44
+ { position: "on_top", allowOnTop: false },
45
+ buttons,
46
+ below_labels
47
+ )
48
+ ).toEqual(below_labels);
49
+ });
50
+
51
+ it("appends buttons when appendWhenMissing is enabled", () => {
52
+ expect(
53
+ insertBetweenLabels(
54
+ { position: "unknown", appendWhenMissing: true },
55
+ buttons,
56
+ below_labels
57
+ )
58
+ ).toEqual([...below_labels, buttons]);
59
+ });
60
+
61
+ it("returns labels unchanged when appendWhenMissing is disabled", () => {
62
+ expect(
63
+ insertBetweenLabels(
64
+ { position: "unknown", appendWhenMissing: false },
65
+ buttons,
66
+ below_labels
67
+ )
68
+ ).toEqual(below_labels);
69
+ });
70
+
71
+ const labelContainers = [
72
+ {
73
+ elements: [
74
+ {
75
+ elements: [{ name: "top_label_1" }, { name: "top_label_2" }],
76
+ },
77
+ ],
78
+ },
79
+ {
80
+ elements: [
81
+ {
82
+ elements: [{ name: "bottom_label_1" }],
83
+ },
84
+ ],
85
+ },
86
+ ];
87
+
88
+ it("inserts buttons after the matching label in a nested container", () => {
89
+ expect(
90
+ insertBetweenLabelContainers(
91
+ { position: "below_top_label_2" },
92
+ buttons,
93
+ labelContainers
94
+ )
95
+ ).toEqual([
96
+ {
97
+ elements: [
98
+ {
99
+ elements: [
100
+ { name: "top_label_1" },
101
+ { name: "top_label_2" },
102
+ buttons,
103
+ ],
104
+ },
105
+ ],
106
+ },
107
+ labelContainers[1],
108
+ ]);
109
+ });
110
+
111
+ it("inserts buttons before the matching label in a nested container", () => {
112
+ expect(
113
+ insertBetweenLabelContainers(
114
+ { position: "above_top_label_2" },
115
+ buttons,
116
+ labelContainers
117
+ )
118
+ ).toEqual([
119
+ {
120
+ elements: [
121
+ {
122
+ elements: [
123
+ { name: "top_label_1" },
124
+ buttons,
125
+ { name: "top_label_2" },
126
+ ],
127
+ },
128
+ ],
129
+ },
130
+ labelContainers[1],
131
+ ]);
132
+ });
133
+
134
+ it("prepends buttons into the first container only when on_top is allowed", () => {
135
+ expect(
136
+ insertBetweenLabelContainers(
137
+ { position: "on_top", allowOnTop: true },
138
+ buttons,
139
+ labelContainers
140
+ )
141
+ ).toEqual([
142
+ {
143
+ elements: [buttons, ...labelContainers[0].elements],
144
+ },
145
+ labelContainers[1],
146
+ ]);
147
+ });
148
+
149
+ it("appends buttons into the last container when configured", () => {
150
+ expect(
151
+ insertBetweenLabelContainers(
152
+ { position: "unknown", appendWhenMissing: true },
153
+ buttons,
154
+ labelContainers
155
+ )
156
+ ).toEqual([
157
+ labelContainers[0],
158
+ {
159
+ elements: [...labelContainers[1].elements, buttons],
160
+ },
161
+ ]);
162
+ });
163
+
164
+ it("inserts buttons after a matching label in a direct two-level container", () => {
165
+ const directLabelContainers = [
166
+ {
167
+ elements: [{ name: "top_label_1" }, { name: "top_label_2" }],
168
+ },
169
+ {
170
+ elements: [{ name: "bottom_label_1" }],
171
+ },
172
+ ];
173
+
174
+ expect(
175
+ insertBetweenLabelContainers(
176
+ { position: "below_top_label_2" },
177
+ buttons,
178
+ directLabelContainers
179
+ )
180
+ ).toEqual([
181
+ {
182
+ elements: [{ name: "top_label_1" }, { name: "top_label_2" }, buttons],
183
+ },
184
+ directLabelContainers[1],
185
+ ]);
186
+ });
187
+ });
@@ -0,0 +1,45 @@
1
+ import {
2
+ getButtonSlotPrefix,
3
+ getEnabledButtonSlots,
4
+ getStylePrefix,
5
+ } from "../selectors";
6
+
7
+ describe("ActionButtonsCore selectors", () => {
8
+ it("returns explicit enabled button slots without collapsing sparse slots", () => {
9
+ const configuration = {
10
+ mobile_button_1_button_enabled: true,
11
+ mobile_button_2_button_enabled: false,
12
+ mobile_button_3_button_enabled: true,
13
+ };
14
+
15
+ expect(getEnabledButtonSlots(configuration, "mobile_button")).toEqual([
16
+ 1, 3,
17
+ ]);
18
+ });
19
+
20
+ it("returns slot-based prefixes", () => {
21
+ expect(getButtonSlotPrefix("tv_buttons_button", 3)).toBe(
22
+ "tv_buttons_button_3"
23
+ );
24
+ });
25
+
26
+ it("reuses button 1 styles when independent styles are disabled", () => {
27
+ expect(
28
+ getStylePrefix({
29
+ slot: 3,
30
+ independentStyles: false,
31
+ buttonPrefix: "mobile_button",
32
+ })
33
+ ).toBe("mobile_button_1");
34
+ });
35
+
36
+ it("uses the explicit slot prefix when independent styles are enabled", () => {
37
+ expect(
38
+ getStylePrefix({
39
+ slot: 3,
40
+ independentStyles: true,
41
+ buttonPrefix: "mobile_button",
42
+ })
43
+ ).toBe("mobile_button_3");
44
+ });
45
+ });
@@ -0,0 +1,49 @@
1
+ import { buildContainerLayout, getContainerMargins } from "../style";
2
+
3
+ describe("ActionButtonsCore style helpers", () => {
4
+ it("returns numeric margins with zero defaults", () => {
5
+ const configuration = {
6
+ mobile_buttons_container_margin_top: "4",
7
+ mobile_buttons_container_margin_left: 6,
8
+ };
9
+
10
+ const value = (key) => configuration[key];
11
+
12
+ expect(getContainerMargins(value, "mobile_buttons_container")).toEqual({
13
+ top: 4,
14
+ right: 0,
15
+ bottom: 0,
16
+ left: 6,
17
+ });
18
+ });
19
+
20
+ it("returns semantic layout data using shared alignment mapping", () => {
21
+ const configuration = {
22
+ tv_buttons_container_align: "middle",
23
+ tv_buttons_container_margin_top: 1,
24
+ tv_buttons_container_margin_right: 2,
25
+ tv_buttons_container_margin_bottom: 3,
26
+ tv_buttons_container_margin_left: 4,
27
+ tv_buttons_container_stacking: "vertical",
28
+ tv_buttons_container_horizontal_gutter: 8,
29
+ tv_buttons_container_vertical_gutter: 12,
30
+ tv_buttons_container_independent_styles: true,
31
+ };
32
+
33
+ const value = (key) => configuration[key];
34
+
35
+ expect(buildContainerLayout(value, "tv_buttons_container")).toEqual({
36
+ horizontalAlign: "center",
37
+ margins: {
38
+ top: 1,
39
+ right: 2,
40
+ bottom: 3,
41
+ left: 4,
42
+ },
43
+ stacking: "vertical",
44
+ horizontalGutter: 8,
45
+ verticalGutter: 12,
46
+ independentStyles: true,
47
+ });
48
+ });
49
+ });
@@ -0,0 +1,165 @@
1
+ import React, {
2
+ useCallback,
3
+ useEffect,
4
+ useMemo,
5
+ useRef,
6
+ useState,
7
+ } from "react";
8
+ import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
9
+
10
+ type ActionDefinition = {
11
+ identifier?: string;
12
+ };
13
+
14
+ type ControllerRenderProps = {
15
+ actionContext: any;
16
+ actionState: any;
17
+ entry: any;
18
+ isActive: boolean;
19
+ onPress: () => Promise<unknown> | unknown;
20
+ };
21
+
22
+ type Props = {
23
+ action?: ActionDefinition;
24
+ pluginIdentifier?: string;
25
+ entry?: any;
26
+ onMissingActionContext?: (identifier?: string) => void;
27
+ children: (props: ControllerRenderProps) => React.ReactNode;
28
+ };
29
+
30
+ const resolveIsActive = (actionState: any, fallbackSelected = false) => {
31
+ if (actionState == null) {
32
+ return fallbackSelected;
33
+ }
34
+
35
+ return Boolean(
36
+ actionState?.active ??
37
+ actionState?.isActive ??
38
+ actionState?.selected ??
39
+ actionState?.isSelected ??
40
+ fallbackSelected
41
+ );
42
+ };
43
+
44
+ const buildLegacySelection = (entry: any, actionContext: any) => {
45
+ const defaultIsSelected = Array.isArray(actionContext?.state)
46
+ ? (actionContext?.state || []).includes(entry)
47
+ : false;
48
+
49
+ return actionContext?.masterCell?.isSelected
50
+ ? actionContext.masterCell.isSelected(entry)
51
+ : defaultIsSelected;
52
+ };
53
+
54
+ export function ActionButtonController({
55
+ action,
56
+ pluginIdentifier,
57
+ entry,
58
+ onMissingActionContext,
59
+ children,
60
+ }: Props) {
61
+ const resolvedEntry = entry;
62
+ const resolvedIdentifier = action?.identifier || pluginIdentifier || "";
63
+ const actionContext = useActions(resolvedIdentifier);
64
+
65
+ const actionDisabled =
66
+ typeof actionContext?.isActionAvailable === "function" &&
67
+ !actionContext.isActionAvailable(resolvedEntry);
68
+
69
+ const supportsEntryState =
70
+ typeof actionContext?.initialEntryState === "function" && !actionDisabled;
71
+
72
+ const hydrationKey = `${resolvedIdentifier}::${String(resolvedEntry?.id ?? "")}`;
73
+ const lastHydratedKeyRef = useRef<string | null>(null);
74
+
75
+ const [actionState, setActionState] = useState(() =>
76
+ supportsEntryState ? actionContext.initialEntryState(resolvedEntry) : null
77
+ );
78
+
79
+ useEffect(() => {
80
+ if (supportsEntryState) {
81
+ if (lastHydratedKeyRef.current === hydrationKey) {
82
+ return;
83
+ }
84
+
85
+ lastHydratedKeyRef.current = hydrationKey;
86
+ setActionState(actionContext.initialEntryState(resolvedEntry));
87
+ }
88
+ }, [supportsEntryState, actionContext, resolvedEntry, hydrationKey]);
89
+
90
+ useEffect(() => {
91
+ if (typeof actionContext?.addListener === "function") {
92
+ return actionContext.addListener(String(resolvedEntry?.id), (nextState) =>
93
+ setActionState(nextState)
94
+ );
95
+ }
96
+
97
+ if (typeof actionContext?.addListeners === "function") {
98
+ return actionContext.addListeners(
99
+ ({ entryState, entry: updatedEntry }) => {
100
+ if (updatedEntry?.id === resolvedEntry?.id) {
101
+ setActionState(entryState);
102
+ }
103
+ }
104
+ );
105
+ }
106
+
107
+ return undefined;
108
+ }, [
109
+ actionContext,
110
+ resolvedEntry?.id,
111
+ resolvedIdentifier,
112
+ actionContext?.addListener,
113
+ actionContext?.addListeners,
114
+ ]);
115
+
116
+ const legacySelected = useMemo(() => {
117
+ if (!actionContext || supportsEntryState) {
118
+ return false;
119
+ }
120
+
121
+ return buildLegacySelection(resolvedEntry, actionContext);
122
+ }, [actionContext, supportsEntryState, resolvedEntry]);
123
+
124
+ const isActive = resolveIsActive(actionState, legacySelected);
125
+
126
+ const onPress = useCallback(async () => {
127
+ if (!actionContext) {
128
+ return;
129
+ }
130
+
131
+ if (supportsEntryState) {
132
+ return actionContext.invokeAction?.(resolvedEntry, {
133
+ updateState: setActionState,
134
+ });
135
+ }
136
+
137
+ const favouritesAction = legacySelected
138
+ ? actionContext.removeFavourite
139
+ : actionContext.addFavourite;
140
+
141
+ const toggleAction = actionContext?.invokeAction ?? favouritesAction;
142
+
143
+ return toggleAction?.(resolvedEntry);
144
+ }, [actionContext, supportsEntryState, resolvedEntry, legacySelected]);
145
+
146
+ if (!actionContext || actionDisabled) {
147
+ if (!actionContext) {
148
+ onMissingActionContext?.(resolvedIdentifier);
149
+ }
150
+
151
+ return null;
152
+ }
153
+
154
+ return (
155
+ <>
156
+ {children({
157
+ actionContext,
158
+ actionState,
159
+ entry: resolvedEntry,
160
+ isActive,
161
+ onPress,
162
+ })}
163
+ </>
164
+ );
165
+ }