@applicaster/zapp-react-native-ui-components 16.0.0-rc.6 → 16.0.0-rc.60

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 (129) hide show
  1. package/Components/AudioPlayer/tv/__tests__/audioPlayer.test.js +19 -0
  2. package/Components/AudioPlayer/tv/__tests__/index.test.tsx +120 -0
  3. package/Components/AudioPlayer/tv/index.tsx +5 -1
  4. package/Components/BackgroundImage/BackgroundImage.android.tv.tsx +28 -0
  5. package/Components/BackgroundImage/BackgroundImage.ios.tv.tsx +24 -0
  6. package/Components/BackgroundImage/BackgroundImage.tsx +42 -0
  7. package/Components/BackgroundImage/index.ts +1 -0
  8. package/Components/CellRendererResolver/index.ts +2 -2
  9. package/Components/ComponentResolver/__tests__/componentResolver.test.js +1 -1
  10. package/Components/FocusableGroup/FocusableTvOS.tsx +11 -7
  11. package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +39 -0
  12. package/Components/GeneralContentScreen/__tests__/GeneralContentScreenHookAdapter.test.tsx +64 -0
  13. package/Components/GeneralContentScreen/__tests__/HookContentFocusGroup.web.test.tsx +91 -0
  14. package/Components/GeneralContentScreen/hookAdapter/__tests__/networkService.test.ts +74 -0
  15. package/Components/GeneralContentScreen/hookAdapter/__tests__/runInBackground.test.ts +139 -0
  16. package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +124 -0
  17. package/Components/GeneralContentScreen/hookAdapter/logger.ts +6 -0
  18. package/Components/GeneralContentScreen/hookAdapter/networkService.ts +53 -0
  19. package/Components/GeneralContentScreen/hookAdapter/runInBackground.ts +48 -0
  20. package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +72 -0
  21. package/Components/GeneralContentScreen/hookFocus/index.tsx +13 -0
  22. package/Components/GeneralContentScreen/hookFocus/index.web.tsx +69 -0
  23. package/Components/GeneralContentScreen/index.ts +2 -0
  24. package/Components/Layout/FullWidthRow.tsx +38 -0
  25. package/Components/Layout/TV/ScreenContainer.tsx +5 -0
  26. package/Components/Layout/TV/__tests__/__snapshots__/index.test.tsx.snap +0 -1
  27. package/Components/Layout/TV/index.tsx +3 -4
  28. package/Components/Layout/TV/index.web.tsx +2 -3
  29. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +16 -5
  30. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +47 -21
  31. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +34 -6
  32. package/Components/MasterCell/DefaultComponents/ButtonContainerView/index.tsx +1 -1
  33. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts +420 -125
  34. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/index.ts +114 -19
  35. package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +19 -8
  36. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +5 -3
  37. package/Components/MasterCell/DefaultComponents/PressableView.tsx +29 -9
  38. package/Components/MasterCell/DefaultComponents/Text/hooks/useText.ts +4 -0
  39. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +154 -100
  40. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/AssetComponent.tsx +15 -4
  41. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +56 -22
  42. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +6 -4
  43. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +3 -1
  44. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +32 -21
  45. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +15 -4
  46. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +23 -16
  47. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +8 -3
  48. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +2 -2
  49. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/insertButtonsBetweenLabels.test.ts +45 -13
  50. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +2 -2
  51. package/Components/MasterCell/contexts/PressedStateContext.ts +3 -0
  52. package/Components/MasterCell/dataAdapter.ts +15 -5
  53. package/Components/MasterCell/hooks/index.ts +2 -0
  54. package/Components/MasterCell/hooks/usePressedState.ts +4 -0
  55. package/Components/MasterCell/index.tsx +30 -5
  56. package/Components/MasterCell/utils/__tests__/resolveColor.test.js +169 -132
  57. package/Components/MasterCell/utils/__tests__/resolveColorForProp.test.js +92 -0
  58. package/Components/MasterCell/utils/index.ts +85 -46
  59. package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +314 -0
  60. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +395 -0
  61. package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +763 -0
  62. package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +653 -0
  63. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +874 -0
  64. package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +89 -0
  65. package/Components/ModalComponent/AudioPlayer/Components/index.ts +11 -0
  66. package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +199 -0
  67. package/Components/ModalComponent/BottomSheetDragArea.tsx +33 -0
  68. package/Components/ModalComponent/BottomSheetModalContent.tsx +386 -42
  69. package/Components/ModalComponent/Button/index.tsx +5 -3
  70. package/Components/ModalComponent/Header/index.tsx +20 -7
  71. package/Components/ModalComponent/Header/utils.ts +1 -1
  72. package/Components/ModalComponent/ModalBlocksStyleContext.tsx +10 -0
  73. package/Components/ModalComponent/SortableList.tsx +142 -0
  74. package/Components/ModalComponent/TextInputContent.tsx +100 -0
  75. package/Components/ModalComponent/__tests__/BottomSheetDragArea.test.tsx +74 -0
  76. package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +238 -0
  77. package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +120 -0
  78. package/Components/ModalComponent/__tests__/showTextInput.test.ts +95 -0
  79. package/Components/ModalComponent/index.tsx +11 -0
  80. package/Components/ModalComponent/presets/__tests__/getCell.test.ts +66 -0
  81. package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +78 -0
  82. package/Components/ModalComponent/presets/index.ts +27 -0
  83. package/Components/ModalComponent/presets/selectableCell.tsx +28 -0
  84. package/Components/ModalComponent/presets/standardCell.tsx +41 -0
  85. package/Components/ModalComponent/presets/types.ts +35 -0
  86. package/Components/ModalComponent/showTextInput.ts +43 -0
  87. package/Components/ModalComponent/utils.ts +76 -20
  88. package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +4 -85
  89. package/Components/OfflineHandler/__tests__/index.test.tsx +78 -18
  90. package/Components/OfflineHandler/hooks.ts +123 -0
  91. package/Components/OfflineHandler/index.tsx +51 -73
  92. package/Components/OfflineHandler/utils/index.ts +1 -13
  93. package/Components/PlayerContainer/PlayerContainer.tsx +25 -17
  94. package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -4
  95. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +337 -0
  96. package/Components/PreloaderWrapper/index.tsx +1 -1
  97. package/Components/River/ComponentsMap/ComponentsMap.tsx +2 -2
  98. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +3 -15
  99. package/Components/Screen/TV/hooks/__tests__/useAfterPaint.test.ts +60 -0
  100. package/Components/Screen/TV/hooks/index.ts +2 -0
  101. package/Components/Screen/TV/hooks/useAfterPaint.ts +23 -0
  102. package/Components/Screen/TV/index.web.tsx +16 -7
  103. package/Components/Screen/index.tsx +8 -4
  104. package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +5 -3
  105. package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +1 -1
  106. package/Components/ScreenRevealManager/Overlay.tsx +34 -0
  107. package/Components/ScreenRevealManager/__tests__/Overlay.test.tsx +88 -0
  108. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +8 -19
  109. package/Components/TopCutoffOverlay/index.tsx +2 -2
  110. package/Components/Transitioner/Transitioner.tsx +28 -17
  111. package/Components/VideoLive/LiveImageManager.ts +41 -43
  112. package/Components/VideoModal/utils.ts +6 -1
  113. package/Components/ZappFrameworkComponents/BarView/BarView.tsx +12 -5
  114. package/Components/ZappFrameworkComponents/BarView/__tests__/BarView.test.tsx +2 -2
  115. package/Contexts/CachedDimensionsContext/__tests__/index.test.ts +154 -0
  116. package/Contexts/CachedDimensionsContext/index.ts +17 -2
  117. package/Helpers/ComponentCellSelectionHelper/index.js +0 -6
  118. package/Helpers/index.js +7 -40
  119. package/package.json +6 -5
  120. package/Components/Layout/TV/LayoutBackground.tsx +0 -31
  121. package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +0 -112
  122. package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +0 -107
  123. package/Components/OfflineHandler/NotificationView/NotificationView.tsx +0 -153
  124. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +0 -66
  125. package/Components/OfflineHandler/NotificationView/utils.ts +0 -34
  126. package/Components/Screen/utils.ts +0 -16
  127. package/Helpers/Analytics/index.js +0 -95
  128. /package/Components/MasterCell/DefaultComponents/ButtonContainerView/{index.tv.android.tsx → index.android.tv.tsx} +0 -0
  129. /package/Decorators/ZappPipesDataConnector/__tests__/{Hero.js → Hero.tsx} +0 -0
@@ -1,15 +1,85 @@
1
- import {
2
- toFiniteNumberWithDefault,
3
- toNumber,
4
- } from "@applicaster/zapp-react-native-utils/numberUtils";
1
+ import { toFiniteNumberWithDefault } from "@applicaster/zapp-react-native-utils/numberUtils";
5
2
  import { isNil } from "ramda";
3
+ import { coreLogger } from "@applicaster/zapp-react-native-utils/logger";
6
4
 
7
- const dimensionRegex = /\b(width|height)=(\d+)\b/gi;
5
+ const imageResizingLogger = coreLogger
6
+ ?.addSubsystem("components")
7
+ ?.addSubsystem("ImageResizing");
8
8
 
9
+ const TEMPLATE_REGEX = /{{(width|height)}}/gi;
10
+ const UNRESOLVED_PLACEHOLDER_REGEX = /{{[^}]*}}?/;
11
+ const INVALID_PLACEHOLDER_EXTRACT_REGEX = /{{([^}]*)}}?/g;
12
+ const ALLOWED_PLACEHOLDERS = ["width", "height"];
13
+
14
+ /**
15
+ * Merges query-param string `paramsString` into `baseUrl`.
16
+ * Params from `paramsString` override any existing params with the same key.
17
+ */
18
+ export const mergeQueryParams = (
19
+ baseUrl: string,
20
+ paramsString: string
21
+ ): string => {
22
+ try {
23
+ const urlObj = new URL(baseUrl);
24
+ const newParams = new URLSearchParams(paramsString);
25
+
26
+ newParams.forEach((value, key) => {
27
+ urlObj.searchParams.set(key, value);
28
+ });
29
+
30
+ return urlObj.toString();
31
+ } catch {
32
+ // If URL parsing fails, return original
33
+ return baseUrl;
34
+ }
35
+ };
36
+
37
+ /**
38
+ * Extracts unresolved placeholder names from a param pair and logs a warning.
39
+ */
40
+ const logInvalidPlaceholders = (pair: string): void => {
41
+ const invalidNames: string[] = [];
42
+ let match: RegExpExecArray | null;
43
+
44
+ // Reset lastIndex before using the global regex
45
+ INVALID_PLACEHOLDER_EXTRACT_REGEX.lastIndex = 0;
46
+
47
+ while ((match = INVALID_PLACEHOLDER_EXTRACT_REGEX.exec(pair)) !== null) {
48
+ const name = match[1];
49
+
50
+ if (!ALLOWED_PLACEHOLDERS.includes(name?.toLowerCase())) {
51
+ invalidNames.push(name);
52
+ }
53
+ }
54
+
55
+ if (invalidNames.length > 0) {
56
+ imageResizingLogger?.warning({
57
+ message: `Image resizing: invalid placeholder(s) found: ${invalidNames.map((n) => `{{${n}}}`).join(", ")}. Allowed placeholders are: {{width}}, {{height}}. The param "${pair}" was ignored.`,
58
+ data: { pair, invalidNames, allowedPlaceholders: ALLOWED_PLACEHOLDERS },
59
+ });
60
+ }
61
+ };
62
+
63
+ /**
64
+ * Parses a dimension mapping template string (query param format) and injects
65
+ * the resolved width/height values into the given URL.
66
+ *
67
+ * The template uses `{{width}}` and `{{height}}` placeholders.
68
+ * It is treated as query-param key=value pairs (e.g. "w={{width}}&h={{height}}"
69
+ * or "size={{width}}x{{height}}").
70
+ *
71
+ * Resolved params are **merged** into the original URL – existing params with
72
+ * the same key are replaced; new ones are appended.
73
+ *
74
+ * Invalid mappings (containing unresolved placeholders like `{{heit}}` or
75
+ * malformed `{{heit}`) are silently dropped and logged as warnings.
76
+ * A leading `?` in the template is stripped.
77
+ */
9
78
  export const withDimensions = (
10
79
  url: Option<string>,
11
80
  width: Option<number | string>,
12
- height: Option<number | string>
81
+ height: Option<number | string>,
82
+ dimensionMappingTemplate?: Option<string>
13
83
  ) => {
14
84
  if (isNil(url)) {
15
85
  return url;
@@ -22,23 +92,48 @@ export const withDimensions = (
22
92
  const newWidth = Math.trunc(toFiniteNumberWithDefault(0, width));
23
93
  const newHeight = Math.trunc(toFiniteNumberWithDefault(0, height));
24
94
 
25
- return url.replace(dimensionRegex, (match, name, originalValue) => {
26
- if (name.toLocaleLowerCase() === "width" && newWidth > 0) {
27
- const originalWidth = toNumber(originalValue);
95
+ if (newWidth <= 0 && newHeight <= 0) {
96
+ return url;
97
+ }
98
+
99
+ // Strip leading `?` and whitespace from the template
100
+ const template = dimensionMappingTemplate?.trim()?.replace(/^\?/, "");
28
101
 
29
- if (originalWidth > 0 && originalWidth > newWidth) {
30
- return `${name}=${newWidth}`;
31
- }
32
- }
102
+ if (!template) {
103
+ return url;
104
+ }
33
105
 
34
- if (name.toLocaleLowerCase() === "height" && newHeight > 0) {
35
- const originalHeight = toNumber(originalValue);
106
+ // Replace {{width}} / {{height}} placeholders in the template
107
+ const resolvedTemplate = template.replace(TEMPLATE_REGEX, (_match, name) => {
108
+ if (name.toLowerCase() === "width") {
109
+ return newWidth > 0 ? String(newWidth) : _match;
110
+ }
36
111
 
37
- if (originalHeight > 0 && originalHeight > newHeight) {
38
- return `${name}=${newHeight}`;
39
- }
112
+ if (name.toLowerCase() === "height") {
113
+ return newHeight > 0 ? String(newHeight) : _match;
40
114
  }
41
115
 
42
- return match;
116
+ return _match;
43
117
  });
118
+
119
+ // Filter out param pairs that still contain unresolved / malformed placeholders
120
+ const cleanedParams = resolvedTemplate
121
+ .split("&")
122
+ .filter((pair) => {
123
+ if (UNRESOLVED_PLACEHOLDER_REGEX.test(pair)) {
124
+ logInvalidPlaceholders(pair);
125
+
126
+ return false;
127
+ }
128
+
129
+ return true;
130
+ })
131
+ .join("&");
132
+
133
+ if (!cleanedParams) {
134
+ return url;
135
+ }
136
+
137
+ // Parse the resolved template as query params and merge into URL
138
+ return mergeQueryParams(url, cleanedParams);
44
139
  };
@@ -14,25 +14,36 @@ type Style = {
14
14
  height: Option<number | string>;
15
15
  };
16
16
 
17
- const withAppliedDimensions = (style: Style) => (source: Source) => ({
18
- ...source,
19
- uri: withDimensions(source?.uri, style?.width, style?.height),
20
- });
17
+ const withAppliedDimensions =
18
+ (style: Style, dimensionMappingTemplate: string) => (source: Source) => ({
19
+ ...source,
20
+ uri: withDimensions(
21
+ source?.uri,
22
+ style?.width,
23
+ style?.height,
24
+ dimensionMappingTemplate
25
+ ),
26
+ });
21
27
 
22
28
  export const withDimensionsHOC = (Component) => {
23
29
  return function WithDimensions(props: Record<string, unknown>) {
24
30
  const theme = useTheme<BaseThemePropertiesMobile>();
25
31
 
26
- const useDownScalingImages = toBooleanWithDefaultFalse(
27
- theme.use_downscaling_images
32
+ const useImageResizing = toBooleanWithDefaultFalse(
33
+ theme.use_image_resizing ?? theme.use_downscaling_images
28
34
  );
29
35
 
36
+ const dimensionMappingTemplate = theme.image_resizing_template;
37
+
30
38
  return (
31
39
  <Component
32
40
  {...props}
33
41
  withDimensions={
34
- useDownScalingImages
35
- ? withAppliedDimensions((props?.style || {}) as Style)
42
+ useImageResizing
43
+ ? withAppliedDimensions(
44
+ (props?.style || {}) as Style,
45
+ dimensionMappingTemplate
46
+ )
36
47
  : identity
37
48
  }
38
49
  />
@@ -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
  };