@applicaster/zapp-react-native-ui-components 15.0.0-rc.135 → 15.0.0-rc.136

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.
@@ -13,8 +13,8 @@ import {
13
13
  type ChildElementProps = {
14
14
  children?: React.ReactNode;
15
15
  mobileActionRole?: string;
16
- state?: string;
17
- [key: string]: unknown;
16
+ uri?: string;
17
+ state?: "default" | "focused";
18
18
  };
19
19
 
20
20
  type Props = {
@@ -22,6 +22,7 @@ type Props = {
22
22
  item: ZappEntry | ZappFeed;
23
23
  action?: {
24
24
  identifier?: string;
25
+ flavour?: "flavour_1" | "flavour_2";
25
26
  };
26
27
  style?: Record<string, unknown>;
27
28
  focusedStyles?: Record<string, unknown>;
@@ -35,6 +36,62 @@ const isValidElement = (
35
36
  ): child is React.ReactElement<ChildElementProps> =>
36
37
  React.isValidElement(child);
37
38
 
39
+ /** retrieves asset uri for a given flavour,
40
+ * if flavour is not provided, returns the default asset from `asset` or selected state asset (if available)
41
+ * asset can be:
42
+ * provided as asset path,
43
+ * provided as [default || flavour_1, alternative || flavour_2] array.
44
+ * mobileButtonAssets asset can be:
45
+ * provided as asset path,
46
+ * provided as [default || flavour_1, alternative || flavour_2] array,
47
+ * provided as [[] as flavour_1, [] as flavour_2] array for multiple flavours, where each flavour can be either a path or [default, alternative] array.
48
+ *
49
+ * isActive reflect the state of the action and can be used to render different asset for active/inactive state if asset is provided as array
50
+ *
51
+ * */
52
+ const selectByAssetFlavour = (
53
+ actionState: {
54
+ asset?: string | [string, string];
55
+ mobileButtonAssets?: [string, string] | [string, string][];
56
+ },
57
+ flavour?: "flavour_1" | "flavour_2",
58
+ isActive?: boolean
59
+ ) => {
60
+ if (actionState.mobileButtonAssets) {
61
+ if (flavour) {
62
+ if (flavour === "flavour_1") {
63
+ if (typeof actionState.mobileButtonAssets[0] === "string") {
64
+ return actionState.mobileButtonAssets[0];
65
+ }
66
+
67
+ if (Array.isArray(actionState.mobileButtonAssets[0])) {
68
+ return actionState.mobileButtonAssets[0][isActive ? 1 : 0];
69
+ }
70
+
71
+ return actionState.mobileButtonAssets[0];
72
+ } else if (flavour === "flavour_2") {
73
+ if (typeof actionState.mobileButtonAssets[1] === "string") {
74
+ return actionState.mobileButtonAssets[1];
75
+ }
76
+
77
+ if (Array.isArray(actionState.mobileButtonAssets[1])) {
78
+ return actionState.mobileButtonAssets[1][isActive ? 1 : 0];
79
+ }
80
+
81
+ return actionState.mobileButtonAssets[1];
82
+ }
83
+ }
84
+
85
+ return Array.isArray(actionState.mobileButtonAssets[0])
86
+ ? actionState.mobileButtonAssets[0][isActive ? 1 : 0]
87
+ : actionState.mobileButtonAssets[0];
88
+ } else {
89
+ return typeof actionState?.asset === "string"
90
+ ? actionState.asset
91
+ : actionState.asset[isActive ? 1 : 0];
92
+ }
93
+ };
94
+
38
95
  export function PressableView({
39
96
  children,
40
97
  item,
@@ -97,7 +154,9 @@ export function PressableView({
97
154
  : "";
98
155
 
99
156
  const shouldRenderAsset = Boolean(
100
- supportsEntryState ? actionState?.asset : false
157
+ supportsEntryState
158
+ ? actionState?.asset && actionState?.mobileButtonAssets
159
+ : false
101
160
  );
102
161
 
103
162
  const shouldRenderLabel = Boolean(labelText);
@@ -129,7 +188,13 @@ export function PressableView({
129
188
  const nextProps: Partial<ChildElementProps> = {};
130
189
 
131
190
  if (role === "asset") {
132
- nextProps.state = isActive ? "active" : "inactive";
191
+ if (action.flavour) {
192
+ nextProps.uri = selectByAssetFlavour(
193
+ actionState,
194
+ action.flavour,
195
+ isActive
196
+ );
197
+ }
133
198
  }
134
199
 
135
200
  if (role === "label") {
@@ -3,11 +3,11 @@ import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/nu
3
3
  type Props = {
4
4
  prefix: string;
5
5
  value: Function;
6
- actionIdentifier: string;
7
6
  testID?: string;
8
7
  };
9
8
 
10
- export const Asset = ({ prefix, value, actionIdentifier, testID }: Props) => {
9
+ /** Asset used in conjunction with PressableView inside mobile action buttons, uri is provided by PressableView */
10
+ export const Asset = ({ prefix, value, testID }: Props) => {
11
11
  if (!value(`${prefix}_asset_enabled`)) {
12
12
  return null;
13
13
  }
@@ -35,10 +35,6 @@ export const Asset = ({ prefix, value, actionIdentifier, testID }: Props) => {
35
35
  },
36
36
  ],
37
37
  additionalProps: {
38
- source: {
39
- context: actionIdentifier,
40
- },
41
- state: "inactive",
42
38
  mobileActionRole: "asset",
43
39
  testID: testID ? `${testID}-asset` : undefined,
44
40
  },
@@ -49,6 +49,7 @@ export const Button = ({
49
49
  const testID = `mobile_action_button_${index + 1}`;
50
50
  const actionIdentifier = value(`${specificPrefix}_assign_action`);
51
51
  const assetAlignment = value(`${stylePrefix}_asset_alignment`) || "left";
52
+ const actionAssetFlavour = value(`${stylePrefix}_action_asset_flavour`);
52
53
 
53
54
  const contentsAlignment =
54
55
  value(`${stylePrefix}_contents_alignment`) || "center";
@@ -93,6 +94,7 @@ export const Button = ({
93
94
  additionalProps: {
94
95
  action: {
95
96
  identifier: actionIdentifier,
97
+ flavour: actionAssetFlavour,
96
98
  },
97
99
  focusedStyles: {
98
100
  backgroundColor: value(`${stylePrefix}_focused_background_color`),
@@ -104,7 +106,6 @@ export const Button = ({
104
106
  Asset({
105
107
  prefix: stylePrefix,
106
108
  value,
107
- actionIdentifier,
108
109
  testID,
109
110
  }),
110
111
  Spacer(),
@@ -57,6 +57,10 @@ const buildActionContext = (entryState = {}) => ({
57
57
  inactive: "https://example.com/image-inactive.png",
58
58
  active: "https://example.com/image-active.png",
59
59
  },
60
+ mobileButtonAssets: [
61
+ "https://example.com/image-inactive.png",
62
+ "https://example.com/image-active.png",
63
+ ],
60
64
  label: {
61
65
  label_1: "Play",
62
66
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "15.0.0-rc.135",
3
+ "version": "15.0.0-rc.136",
4
4
  "description": "Applicaster Zapp React Native ui components for the Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "15.0.0-rc.135",
32
- "@applicaster/zapp-react-native-bridge": "15.0.0-rc.135",
33
- "@applicaster/zapp-react-native-redux": "15.0.0-rc.135",
34
- "@applicaster/zapp-react-native-utils": "15.0.0-rc.135",
31
+ "@applicaster/applicaster-types": "15.0.0-rc.136",
32
+ "@applicaster/zapp-react-native-bridge": "15.0.0-rc.136",
33
+ "@applicaster/zapp-react-native-redux": "15.0.0-rc.136",
34
+ "@applicaster/zapp-react-native-utils": "15.0.0-rc.136",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "url": "^0.11.0",