@applicaster/zapp-react-native-ui-components 16.0.0-rc.33 → 16.0.0-rc.35

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 (26) hide show
  1. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +47 -21
  2. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +34 -6
  3. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -3
  4. package/Components/MasterCell/DefaultComponents/PressableView.tsx +29 -9
  5. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +4 -0
  6. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +154 -100
  7. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +15 -4
  8. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +56 -22
  9. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
  10. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +3 -1
  11. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +32 -21
  12. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +15 -4
  13. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +23 -16
  14. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +8 -3
  15. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +2 -2
  16. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/insertButtonsBetweenLabels.test.ts +45 -13
  17. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +2 -2
  18. package/Components/MasterCell/contexts/PressedStateContext.ts +3 -0
  19. package/Components/MasterCell/hooks/index.ts +2 -0
  20. package/Components/MasterCell/hooks/usePressedState.ts +4 -0
  21. package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +332 -0
  22. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +402 -0
  23. package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +811 -0
  24. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +878 -0
  25. package/Components/ModalComponent/AudioPlayer/Components/index.ts +7 -0
  26. package/package.json +5 -5
@@ -6,28 +6,54 @@ import {
6
6
  describe("ActionButtonsCore placement", () => {
7
7
  const buttons = { type: "View", name: "buttons" };
8
8
 
9
- const above_labels = [
10
- { name: "above_label_1" },
11
- { name: "above_label_2" },
12
- { name: "above_label_3" },
9
+ const slots = [
10
+ { name: "text_label_1", element: { type: "View", id: "label_1" } },
11
+ { name: "text_label_2", element: { type: "View", id: "label_2" } },
12
+ { name: "text_label_3", element: { type: "View", id: "label_3" } },
13
13
  ];
14
14
 
15
- const below_labels = [
16
- { name: "below_label_1" },
17
- { name: "below_label_2" },
18
- { name: "below_label_3" },
19
- ];
15
+ const labels = slots.map((slot) => slot.element);
20
16
 
21
17
  it("inserts buttons after the matching label", () => {
22
18
  expect(
23
- insertBetweenLabels({ position: "below_label_2" }, buttons, below_labels)
24
- ).toEqual([below_labels[0], below_labels[1], buttons, below_labels[2]]);
19
+ insertBetweenLabels({ position: "below_text_label_2" }, buttons, slots)
20
+ ).toEqual([labels[0], labels[1], buttons, labels[2]]);
25
21
  });
26
22
 
27
23
  it("inserts buttons before the matching label", () => {
28
24
  expect(
29
- insertBetweenLabels({ position: "above_label_2" }, buttons, above_labels)
30
- ).toEqual([above_labels[0], buttons, above_labels[1], above_labels[2]]);
25
+ insertBetweenLabels({ position: "above_text_label_2" }, buttons, slots)
26
+ ).toEqual([labels[0], buttons, labels[1], labels[2]]);
27
+ });
28
+
29
+ it("inserts buttons after the matching label on a plain name match", () => {
30
+ expect(
31
+ insertBetweenLabels({ position: "text_label_2" }, buttons, slots)
32
+ ).toEqual([labels[0], labels[1], buttons, labels[2]]);
33
+ });
34
+
35
+ it("keeps the slot when its label is empty (null element)", () => {
36
+ const slotsWithEmpty = [
37
+ { name: "text_label_1", element: { id: "label_1" } },
38
+ { name: "text_label_2", element: null },
39
+ { name: "text_label_3", element: { id: "label_3" } },
40
+ ];
41
+
42
+ expect(
43
+ insertBetweenLabels(
44
+ { position: "above_text_label_2" },
45
+ buttons,
46
+ slotsWithEmpty
47
+ )
48
+ ).toEqual([{ id: "label_1" }, buttons, { id: "label_3" }]);
49
+
50
+ expect(
51
+ insertBetweenLabels(
52
+ { position: "below_text_label_2" },
53
+ buttons,
54
+ slotsWithEmpty
55
+ )
56
+ ).toEqual([{ id: "label_1" }, buttons, { id: "label_3" }]);
31
57
  });
32
58
 
33
59
  it("prepends buttons only when on_top is allowed", () => {
@@ -35,17 +61,17 @@ describe("ActionButtonsCore placement", () => {
35
61
  insertBetweenLabels(
36
62
  { position: "on_top", allowOnTop: true },
37
63
  buttons,
38
- below_labels
64
+ slots
39
65
  )
40
- ).toEqual([buttons, ...below_labels]);
66
+ ).toEqual([buttons, ...labels]);
41
67
 
42
68
  expect(
43
69
  insertBetweenLabels(
44
70
  { position: "on_top", allowOnTop: false },
45
71
  buttons,
46
- below_labels
72
+ slots
47
73
  )
48
- ).toEqual(below_labels);
74
+ ).toEqual(labels);
49
75
  });
50
76
 
51
77
  it("appends buttons when appendWhenMissing is enabled", () => {
@@ -53,9 +79,9 @@ describe("ActionButtonsCore placement", () => {
53
79
  insertBetweenLabels(
54
80
  { position: "unknown", appendWhenMissing: true },
55
81
  buttons,
56
- below_labels
82
+ slots
57
83
  )
58
- ).toEqual([...below_labels, buttons]);
84
+ ).toEqual([...labels, buttons]);
59
85
  });
60
86
 
61
87
  it("returns labels unchanged when appendWhenMissing is disabled", () => {
@@ -63,9 +89,9 @@ describe("ActionButtonsCore placement", () => {
63
89
  insertBetweenLabels(
64
90
  { position: "unknown", appendWhenMissing: false },
65
91
  buttons,
66
- below_labels
92
+ slots
67
93
  )
68
- ).toEqual(below_labels);
94
+ ).toEqual(labels);
69
95
  });
70
96
 
71
97
  const labelContainers = [
@@ -17,6 +17,11 @@ type InsertOptions = {
17
17
  appendWhenMissing?: boolean;
18
18
  };
19
19
 
20
+ type Slot = {
21
+ name: string;
22
+ element?: unknown;
23
+ };
24
+
20
25
  const hasLabelName = (value: unknown): value is Label =>
21
26
  !!value &&
22
27
  typeof value === "object" &&
@@ -100,8 +105,14 @@ const containsNestedLabel = (
100
105
  export const insertBetweenLabels = (
101
106
  { position, allowOnTop = false, appendWhenMissing = false }: InsertOptions,
102
107
  buttons: unknown,
103
- labels: Label[] = []
108
+ slots: Slot[] = []
104
109
  ) => {
110
+ // Slots are defined by the canonical label list, so an empty (null) label
111
+ // still keeps its position — buttons placed above/below it survive.
112
+ const labels = slots
113
+ .map((slot) => slot.element)
114
+ .filter((element) => element != null);
115
+
105
116
  if (buttons == null) {
106
117
  return labels;
107
118
  }
@@ -110,14 +121,31 @@ export const insertBetweenLabels = (
110
121
  return [buttons, ...labels];
111
122
  }
112
123
 
113
- const labelsWithButtons = withButtons(position, buttons, labels);
114
- const inserted = labelsWithButtons.length !== labels.length;
124
+ let inserted = false;
125
+ const result: unknown[] = [];
126
+
127
+ for (const { name, element } of slots) {
128
+ if (position === `above_${name}`) {
129
+ result.push(buttons);
130
+ inserted = true;
131
+ }
132
+
133
+ if (element != null) {
134
+ result.push(element);
135
+ }
136
+
137
+ // Insert after on `below_*` or a plain label-name match.
138
+ if (position === `below_${name}` || position === name) {
139
+ result.push(buttons);
140
+ inserted = true;
141
+ }
142
+ }
115
143
 
116
- if (!inserted && appendWhenMissing) {
117
- return [...labels, buttons];
144
+ if (!inserted) {
145
+ return appendWhenMissing ? [...labels, buttons] : labels;
118
146
  }
119
147
 
120
- return inserted ? labelsWithButtons : [...labels];
148
+ return result;
121
149
  };
122
150
 
123
151
  export const insertBetweenLabelContainers = (
@@ -1,13 +1,15 @@
1
- import React from "react";
1
+ import React, { PropsWithChildren } from "react";
2
2
  import { isVideoPreviewEnabled } from "@applicaster/zapp-react-native-ui-components/Components/MasterCell/utils";
3
3
  import { LiveImage } from "../LiveImage";
4
4
  import PureImage from "../Image";
5
5
  import { useIsScreenActive } from "@applicaster/zapp-react-native-utils/reactHooks";
6
6
 
7
- type Props = {
7
+ type Props = PropsWithChildren<{
8
8
  enable_video_preview: boolean;
9
9
  player_screen_id: string;
10
- };
10
+ uri?: string;
11
+ [key: string]: any;
12
+ }>;
11
13
 
12
14
  export const ImageContainer = (props: Props) => {
13
15
  const isActive = useIsScreenActive();
@@ -1,34 +1,54 @@
1
- import React from "react";
2
- import { TouchableOpacity } from "react-native";
1
+ import React, { useCallback } from "react";
2
+ import { Pressable, ViewStyle } from "react-native";
3
+ import { PressedStateContext } from "../contexts/PressedStateContext";
3
4
 
4
5
  type Props = {
5
6
  children?: React.ReactNode;
6
- style?: Record<string, unknown>;
7
+ style?: ViewStyle | ViewStyle[];
8
+ pressedStyle?: ViewStyle | ViewStyle[];
7
9
  testID?: string;
8
10
  accessibilityLabel?: string;
9
11
  accessibilityHint?: string;
10
12
  onPress?: () => void;
13
+ testOnly_pressed?: boolean;
11
14
  };
12
15
 
13
16
  export function PressableView({
14
17
  children,
15
- style = {},
18
+ style,
16
19
  testID,
17
20
  accessibilityLabel,
18
21
  accessibilityHint,
22
+ pressedStyle,
19
23
  onPress,
24
+ testOnly_pressed = false,
20
25
  }: Props) {
21
26
  return (
22
- <TouchableOpacity
23
- activeOpacity={1}
27
+ <Pressable
28
+ testOnly_pressed={testOnly_pressed}
24
29
  onPress={onPress}
25
30
  testID={testID}
26
31
  accessibilityLabel={accessibilityLabel}
27
32
  accessibilityHint={accessibilityHint}
28
33
  accessible={!!(testID || accessibilityLabel)}
29
- style={style}
34
+ style={useCallback(
35
+ ({ pressed }) => [
36
+ style,
37
+ pressed && {
38
+ opacity: 1,
39
+ },
40
+ pressed && pressedStyle,
41
+ ],
42
+ [style, pressedStyle]
43
+ )}
30
44
  >
31
- {children}
32
- </TouchableOpacity>
45
+ {({ pressed }) => {
46
+ return (
47
+ <PressedStateContext.Provider value={pressed}>
48
+ {children}
49
+ </PressedStateContext.Provider>
50
+ );
51
+ }}
52
+ </Pressable>
33
53
  );
34
54
  }
@@ -83,6 +83,10 @@ export const useTextLabel = ({ label, entry }): string => {
83
83
  return prepareHebrewText(label, isRTL);
84
84
  };
85
85
 
86
+ /**
87
+ * Uses `otherProps.state` ("focused" | "default") to select between `focusedStyles` and `normalStyles`.
88
+ * For mobile action buttons, map `usePressedState()` (boolean) to this state value (e.g. pressed ? "focused" : "default").
89
+ */
86
90
  export const withFocusedStyles = ({ style, otherProps }) => {
87
91
  const state = R.path(["state"], otherProps);
88
92
 
@@ -1,5 +1,6 @@
1
- import React from "react";
1
+ import React, { useCallback } from "react";
2
2
  import { PressableView } from "../../PressableView";
3
+ import { usePressedState } from "../../../hooks";
3
4
 
4
5
  import { ActionButtonController } from "../../ActionButtonsCore/components";
5
6
 
@@ -20,7 +21,137 @@ const isValidElement = (
20
21
  ): child is React.ReactElement<ChildElementProps> =>
21
22
  React.isValidElement(child);
22
23
 
23
- export const ActionButton = ({ style, children, action, entry, ...props }) => {
24
+ type ActionButtonContentProps = {
25
+ style: any;
26
+ children: React.ReactNode;
27
+ action: any;
28
+ focusedStyles: any;
29
+ entry: any;
30
+ props: Record<string, any>;
31
+ actionContext: any;
32
+ actionState: any;
33
+ isActive: boolean;
34
+ onPress: () => any;
35
+ };
36
+
37
+ const ActionButtonContent = ({
38
+ children,
39
+ action,
40
+ entry,
41
+ actionContext,
42
+ actionState,
43
+ isActive,
44
+ }: ActionButtonContentProps) => {
45
+ const isPressed = usePressedState();
46
+
47
+ const supportsEntryState =
48
+ typeof actionContext?.initialEntryState === "function";
49
+
50
+ const shouldRenderAsset = Boolean(
51
+ supportsEntryState ? actionState?.mobileButtonAssets : false
52
+ );
53
+
54
+ const shouldRenderLabel = Boolean(
55
+ supportsEntryState && resolveLabelText(actionState?.label)
56
+ );
57
+
58
+ const _cloneChildrenWithState = useCallback(
59
+ (nodes?: React.ReactNode): React.ReactNode => {
60
+ return React.Children.map(nodes, (child) => {
61
+ if (!isValidElement(child)) {
62
+ return child;
63
+ }
64
+
65
+ const role = child.props.mobileActionRole;
66
+
67
+ const nextChildren = _cloneChildrenWithState(child.props.children);
68
+
69
+ // Prevents of the asset rendering when the action doesn't provide asset for current entry state
70
+ if (role === "asset" && !shouldRenderAsset) {
71
+ return null;
72
+ }
73
+
74
+ // Prevents of the label rendering when the action doesn't provide label for current entry state.
75
+ // Also prevents of the label container when it doesn't have children to avoid unnecessary empty space.
76
+ if (role === "label" && !shouldRenderLabel) {
77
+ return null;
78
+ }
79
+
80
+ // Prevents of the label container rendering when it doesn't have children to avoid unnecessary empty space.
81
+ if (
82
+ role === "label_container" &&
83
+ React.Children.count(nextChildren) === 0
84
+ ) {
85
+ return null;
86
+ }
87
+
88
+ const nextProps: Partial<ChildElementProps> = {};
89
+
90
+ // Inject asset or uri to Asset component with role asset
91
+ if (role === "asset") {
92
+ const resolvedAsset = selectByAssetFlavour(
93
+ actionState,
94
+ action.flavour,
95
+ isActive
96
+ );
97
+
98
+ if (typeof resolvedAsset === "function") {
99
+ const AssetComponent = resolvedAsset as CellActionAssetComponent;
100
+
101
+ nextProps.asset = (
102
+ <AssetComponent
103
+ flavour={action.flavour || "flavour_1"}
104
+ width={action.width}
105
+ height={action.height}
106
+ />
107
+ );
108
+ } else {
109
+ nextProps.uri = resolvedAsset;
110
+ }
111
+ }
112
+
113
+ // Inject state and entry to Text component with role label
114
+ // Use isPressed state for mobile buttons to set focused state on mobile
115
+ if (role === "label") {
116
+ nextProps.state = isActive || isPressed ? "focused" : "default";
117
+ nextProps.entry = entry;
118
+ }
119
+
120
+ if (nextChildren !== child.props.children) {
121
+ nextProps.children = nextChildren;
122
+ }
123
+
124
+ return React.cloneElement(child, nextProps);
125
+ });
126
+ },
127
+ [
128
+ shouldRenderAsset,
129
+ shouldRenderLabel,
130
+ actionState,
131
+ action.flavour,
132
+ action.width,
133
+ action.height,
134
+ isActive,
135
+ isPressed,
136
+ entry,
137
+ ]
138
+ );
139
+
140
+ if (!shouldRenderAsset && !shouldRenderLabel) {
141
+ return null;
142
+ }
143
+
144
+ return _cloneChildrenWithState(children);
145
+ };
146
+
147
+ export const ActionButton = ({
148
+ style,
149
+ children,
150
+ action,
151
+ focusedStyles,
152
+ entry,
153
+ ...props
154
+ }) => {
24
155
  return (
25
156
  <ActionButtonController
26
157
  action={action}
@@ -31,105 +162,28 @@ export const ActionButton = ({ style, children, action, entry, ...props }) => {
31
162
  );
32
163
  }}
33
164
  >
34
- {({ actionContext, actionState, isActive, onPress }) => {
35
- const supportsEntryState =
36
- typeof actionContext?.initialEntryState === "function";
37
-
38
- const shouldRenderAsset = Boolean(
39
- supportsEntryState ? actionState?.mobileButtonAssets : false
40
- );
41
-
42
- const shouldRenderLabel = Boolean(
43
- supportsEntryState && resolveLabelText(actionState?.label)
44
- );
45
-
46
- const _cloneChildrenWithState = (
47
- nodes?: React.ReactNode
48
- ): React.ReactNode => {
49
- return React.Children.map(nodes, (child) => {
50
- if (!isValidElement(child)) {
51
- return child;
52
- }
53
-
54
- const role = child.props.mobileActionRole;
55
-
56
- const nextChildren = _cloneChildrenWithState(child.props.children);
57
-
58
- // Prevents of the asset rendering when the action doesn't provide asset for current entry state
59
- if (role === "asset" && !shouldRenderAsset) {
60
- return null;
61
- }
62
-
63
- // Prevents of the label rendering when the action doesn't provide label for current entry state.
64
- // Also prevents of the label container when it doesn't have children to avoid unnecessary empty space.
65
- if (role === "label" && !shouldRenderLabel) {
66
- return null;
67
- }
68
-
69
- // Prevents of the label container rendering when it doesn't have children to avoid unnecessary empty space.
70
- if (
71
- role === "label_container" &&
72
- React.Children.count(nextChildren) === 0
73
- ) {
74
- return null;
75
- }
76
-
77
- const nextProps: Partial<ChildElementProps> = {};
78
-
79
- // Inject asset or uri to Asset component with role asset
80
- if (role === "asset") {
81
- const resolvedAsset = selectByAssetFlavour(
82
- actionState,
83
- action.flavour,
84
- isActive
85
- );
86
-
87
- if (typeof resolvedAsset === "function") {
88
- const AssetComponent =
89
- resolvedAsset as CellActionAssetComponent;
90
-
91
- nextProps.asset = (
92
- <AssetComponent
93
- flavour={action.flavour || "flavour_1"}
94
- width={action.width}
95
- height={action.height}
96
- />
97
- );
98
- } else {
99
- nextProps.uri = resolvedAsset;
100
- }
101
- }
102
-
103
- // Inject state and entry to Text component with role label
104
- if (role === "label") {
105
- nextProps.state = isActive ? "focused" : "default";
106
- nextProps.entry = entry;
107
- }
108
-
109
- if (nextChildren !== child.props.children) {
110
- nextProps.children = nextChildren;
111
- }
112
-
113
- return React.cloneElement(child, nextProps);
114
- });
115
- };
116
-
117
- if (!shouldRenderAsset && !shouldRenderLabel) {
118
- return null;
119
- }
120
-
121
- return (
122
- <PressableView
123
- testID={props.testID || `${entry?.id}`}
124
- style={isActive ? { ...style, ...props.focusedStyles } : style}
125
- onPress={onPress}
126
- accessibilityLabel={props.accessibilityLabel || `${entry?.id}`}
127
- accessibilityHint={props.accessibilityHint}
165
+ {(renderProps) => (
166
+ <PressableView
167
+ testOnly_pressed={props.testOnly_pressed}
168
+ testID={props.testID || `${entry?.id}`}
169
+ style={style}
170
+ pressedStyle={focusedStyles}
171
+ onPress={renderProps.onPress}
172
+ accessibilityLabel={props.accessibilityLabel || `${entry?.id}`}
173
+ accessibilityHint={props.accessibilityHint}
174
+ >
175
+ <ActionButtonContent
176
+ style={style}
177
+ action={action}
178
+ focusedStyles={focusedStyles}
179
+ entry={entry}
180
+ props={props}
181
+ {...renderProps}
128
182
  >
129
- {_cloneChildrenWithState(children)}
130
- </PressableView>
131
- );
132
- }}
183
+ {children}
184
+ </ActionButtonContent>
185
+ </PressableView>
186
+ )}
133
187
  </ActionButtonController>
134
188
  );
135
189
  };
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { View } from "react-native";
2
+ import { StyleSheet, View } from "react-native";
3
3
  import { ImageContainer } from "../../ImageContainer";
4
4
 
5
5
  type Props = {
@@ -10,13 +10,24 @@ type Props = {
10
10
  cellUUID?: string;
11
11
  };
12
12
 
13
+ const styles = StyleSheet.create({
14
+ assetContainer: {
15
+ flexShrink: 0,
16
+ justifyContent: "center",
17
+ alignItems: "center",
18
+ },
19
+ });
20
+
13
21
  export const AssetComponent = (props: Props & Record<string, unknown>) => {
14
22
  return props.asset && React.isValidElement(props.asset) ? (
15
- <View style={props.style} testID={props.testID}>
23
+ <View style={[styles.assetContainer, props.style]} testID={props.testID}>
16
24
  {React.cloneElement(props.asset, { cellUUID: props.cellUUID })}
17
25
  </View>
18
26
  ) : (
19
- // @ts-ignore
20
- <ImageContainer {...props} uri={props.uri} />
27
+ <ImageContainer
28
+ style={[styles.assetContainer, props.style]}
29
+ {...(props as any)}
30
+ uri={props.uri}
31
+ />
21
32
  );
22
33
  };