@applicaster/zapp-react-native-utils 15.0.0-alpha.5219062121 → 15.0.0-alpha.5262500595

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 (58) hide show
  1. package/README.md +0 -6
  2. package/actionUtils/index.ts +7 -0
  3. package/actionsExecutor/ActionExecutorContext.tsx +83 -6
  4. package/appUtils/HooksManager/index.ts +35 -0
  5. package/appUtils/focusManagerAux/utils/index.ts +12 -6
  6. package/appUtils/focusManagerAux/utils/utils.ios.ts +6 -3
  7. package/appUtils/localizationsHelper.ts +4 -0
  8. package/appUtils/playerManager/index.ts +9 -0
  9. package/appUtils/playerManager/player.ts +1 -1
  10. package/appUtils/playerManager/usePlayer.tsx +5 -3
  11. package/cellUtils/__tests__/cellUtils.test.ts +39 -0
  12. package/cellUtils/index.ts +11 -1
  13. package/componentsUtils/index.ts +8 -0
  14. package/dateUtils/__tests__/dayjs.test.ts +0 -3
  15. package/dateUtils/index.ts +2 -0
  16. package/manifestUtils/_internals/__tests__/index.test.js +41 -0
  17. package/manifestUtils/_internals/index.js +33 -0
  18. package/manifestUtils/defaultManifestConfigurations/player.js +6 -0
  19. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +49 -0
  20. package/manifestUtils/fieldUtils/index.js +54 -0
  21. package/manifestUtils/index.js +2 -0
  22. package/manifestUtils/keys.js +228 -0
  23. package/manifestUtils/mobileAction/button/__tests__/mobileActionButton.test.js +168 -0
  24. package/manifestUtils/mobileAction/button/index.js +140 -0
  25. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +102 -0
  26. package/manifestUtils/mobileAction/container/index.js +73 -0
  27. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +127 -0
  28. package/manifestUtils/mobileAction/groups/defaults.js +76 -0
  29. package/manifestUtils/mobileAction/groups/index.js +80 -0
  30. package/numberUtils/__tests__/toNumber.test.ts +27 -12
  31. package/numberUtils/__tests__/toPositiveNumber.test.ts +32 -4
  32. package/numberUtils/index.ts +5 -1
  33. package/package.json +3 -3
  34. package/reactHooks/casting/index.ts +1 -0
  35. package/reactHooks/casting/useIsCasting.tsx +57 -0
  36. package/reactHooks/cell-click/index.ts +2 -1
  37. package/reactHooks/feed/index.ts +0 -2
  38. package/reactHooks/feed/useInflatedUrl.ts +1 -1
  39. package/reactHooks/resolvers/useComponentResolver.ts +11 -1
  40. package/reactHooks/screen/__tests__/useCurrentScreenIsHook.test.ts +103 -0
  41. package/reactHooks/screen/__tests__/useCurrentScreenIsStartupHook.test.ts +94 -0
  42. package/reactHooks/screen/index.ts +4 -0
  43. package/reactHooks/screen/useCurrentScreenIsHook.ts +9 -0
  44. package/reactHooks/screen/useCurrentScreenIsStartupHook.ts +8 -0
  45. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  46. package/reactHooks/state/index.ts +2 -0
  47. package/reactHooks/state/useComponentScreenState.ts +45 -0
  48. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +206 -0
  49. package/refreshUtils/RefreshCoordinator/index.ts +245 -0
  50. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  51. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  52. package/screenPickerUtils/index.ts +5 -0
  53. package/utils/__tests__/clone.test.ts +158 -0
  54. package/utils/__tests__/path.test.ts +7 -0
  55. package/utils/clone.ts +7 -0
  56. package/utils/index.ts +2 -1
  57. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  58. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -0,0 +1,102 @@
1
+ import { mobileActionButtonsContainer } from "..";
2
+
3
+ describe("mobileActionButtonsContainer", () => {
4
+ it("generates container fields with inferred conditionals", () => {
5
+ const result = mobileActionButtonsContainer({
6
+ label: "Mobile Buttons Container",
7
+ description: "container",
8
+ defaults: {
9
+ buttonsEnabled: false,
10
+ position: ["over_image", "text_label_1", "text_label_2"],
11
+ align: "left",
12
+ overImagePosition: "bottom_left",
13
+ marginTop: 0,
14
+ marginRight: 20,
15
+ marginBottom: 0,
16
+ marginLeft: 20,
17
+ stacking: "horizontal",
18
+ horizontalGutter: 8,
19
+ verticalGutter: 8,
20
+ independentStyles: true,
21
+ },
22
+ });
23
+
24
+ expect(result.group).toBe(true);
25
+ expect(result.label).toBe("Mobile Buttons Container");
26
+
27
+ const enabledField = result.fields.find(
28
+ (field) => field.key === "mobile_buttons_container_buttons_enabled"
29
+ );
30
+
31
+ expect(enabledField).toBeTruthy();
32
+ expect(enabledField.type).toBe("switch");
33
+
34
+ const positionField = result.fields.find(
35
+ (field) => field.key === "mobile_buttons_container_position"
36
+ );
37
+
38
+ expect(positionField.options).toEqual([
39
+ "over_image",
40
+ "text_label_1",
41
+ "text_label_2",
42
+ ]);
43
+
44
+ expect(positionField.conditional_fields).toEqual([
45
+ {
46
+ key: "styles/mobile_buttons_container_buttons_enabled",
47
+ condition_value: true,
48
+ },
49
+ ]);
50
+
51
+ const overImagePositionField = result.fields.find(
52
+ (field) => field.key === "mobile_buttons_container_over_image_position"
53
+ );
54
+
55
+ expect(overImagePositionField.rules).toBe("all_conditions");
56
+
57
+ expect(overImagePositionField.conditional_fields).toEqual([
58
+ {
59
+ key: "styles/mobile_buttons_container_buttons_enabled",
60
+ condition_value: true,
61
+ },
62
+ {
63
+ key: "styles/mobile_buttons_container_position",
64
+ condition_value: "over_image",
65
+ },
66
+ ]);
67
+
68
+ const horizontalGutterField = result.fields.find(
69
+ (field) => field.key === "mobile_buttons_container_horizontal_gutter"
70
+ );
71
+
72
+ expect(horizontalGutterField.rules).toBe("all_conditions");
73
+
74
+ expect(horizontalGutterField.conditional_fields).toEqual([
75
+ {
76
+ key: "styles/mobile_buttons_container_buttons_enabled",
77
+ condition_value: true,
78
+ },
79
+ {
80
+ key: "styles/mobile_buttons_container_stacking",
81
+ condition_value: "horizontal",
82
+ },
83
+ ]);
84
+
85
+ const verticalGutterField = result.fields.find(
86
+ (field) => field.key === "mobile_buttons_container_vertical_gutter"
87
+ );
88
+
89
+ expect(verticalGutterField.rules).toBe("all_conditions");
90
+
91
+ expect(verticalGutterField.conditional_fields).toEqual([
92
+ {
93
+ key: "styles/mobile_buttons_container_buttons_enabled",
94
+ condition_value: true,
95
+ },
96
+ {
97
+ key: "styles/mobile_buttons_container_stacking",
98
+ condition_value: "vertical",
99
+ },
100
+ ]);
101
+ });
102
+ });
@@ -0,0 +1,73 @@
1
+ const { mobileActionButtonContainerFields } = require("../../keys");
2
+
3
+ const {
4
+ isKeyHasSuffix,
5
+ toSnakeCase,
6
+ generateFieldsFromDefaultsWithoutPrefixedLabel,
7
+ getKeyWithPrefixGenerator,
8
+ } = require("../../_internals");
9
+
10
+ const { withConditional, createConditionalField } = require("../../fieldUtils");
11
+
12
+ const { fieldsGroup } = require("../../utils");
13
+
14
+ /**
15
+ * Builds the manifest group for the mobile action buttons container and wires
16
+ * child field visibility to the container-level toggles and layout selections.
17
+ *
18
+ * @param {object} options
19
+ * @param {string} options.label
20
+ * @param {string} options.description
21
+ * @param {object} options.defaults
22
+ * @returns {object}
23
+ */
24
+ function mobileActionButtonsContainer({ label, description, defaults }) {
25
+ const containerKeyFromLabel = toSnakeCase(label); // "Mobile Buttons Container" -> "mobile_buttons_container"
26
+
27
+ const generatedFields = generateFieldsFromDefaultsWithoutPrefixedLabel(
28
+ label,
29
+ defaults,
30
+ mobileActionButtonContainerFields(defaults.position)
31
+ );
32
+
33
+ const keyPrefixGenerator = getKeyWithPrefixGenerator(containerKeyFromLabel);
34
+
35
+ const enabledKey = keyPrefixGenerator("buttons_enabled");
36
+ const positionKey = keyPrefixGenerator("position");
37
+ const stackingKey = keyPrefixGenerator("stacking");
38
+
39
+ const defaultConditions = [createConditionalField(enabledKey, true)];
40
+
41
+ const fields = generatedFields.map((field) => {
42
+ const key = field.key;
43
+
44
+ if (isKeyHasSuffix("buttons_enabled", key)) {
45
+ return field;
46
+ }
47
+
48
+ const conditions = [...defaultConditions];
49
+
50
+ // over_image_position depends on [positionKey: over_image]
51
+ if (isKeyHasSuffix("over_image_position", key)) {
52
+ conditions.push(createConditionalField(positionKey, "over_image"));
53
+ }
54
+
55
+ // horizontal_gutter depends on [stackingKey: horizontal]
56
+ if (isKeyHasSuffix("horizontal_gutter", key)) {
57
+ conditions.push(createConditionalField(stackingKey, "horizontal"));
58
+ }
59
+
60
+ // vertical_gutter depends on [stackingKey: vertical]
61
+ if (isKeyHasSuffix("vertical_gutter", key)) {
62
+ conditions.push(createConditionalField(stackingKey, "vertical"));
63
+ }
64
+
65
+ return withConditional(conditions)(field);
66
+ });
67
+
68
+ return fieldsGroup(label, description, fields);
69
+ }
70
+
71
+ module.exports = {
72
+ mobileActionButtonsContainer,
73
+ };
@@ -0,0 +1,127 @@
1
+ import { buildMobileActionButtonGroups } from "..";
2
+
3
+ describe("buildMobileActionButtonGroups", () => {
4
+ it("builds the container and three button groups with shared defaults", () => {
5
+ const groups = buildMobileActionButtonGroups({
6
+ containerDefaults: {
7
+ position: ["over_image", "text_label_1", "text_label_2"],
8
+ },
9
+ });
10
+
11
+ expect(groups).toHaveLength(4);
12
+
13
+ expect(groups.map((group) => group.label)).toEqual([
14
+ "Mobile Buttons Container",
15
+ "Mobile Button 1",
16
+ "Mobile Button 2",
17
+ "Mobile Button 3",
18
+ ]);
19
+
20
+ const containerFields = groups[0].fields;
21
+
22
+ const positionField = containerFields.find(
23
+ (field) => field.key === "mobile_buttons_container_position"
24
+ );
25
+
26
+ const buttonsEnabledField = containerFields.find(
27
+ (field) => field.key === "mobile_buttons_container_buttons_enabled"
28
+ );
29
+
30
+ expect(positionField.options).toEqual([
31
+ "over_image",
32
+ "text_label_1",
33
+ "text_label_2",
34
+ ]);
35
+
36
+ expect(buttonsEnabledField.initial_value).toBe(false);
37
+
38
+ const button1Fields = groups[1].fields;
39
+
40
+ const button1EnabledField = button1Fields.find(
41
+ (field) => field.key === "mobile_button_1_button_enabled"
42
+ );
43
+
44
+ const button1AssignActionField = button1Fields.find(
45
+ (field) => field.key === "mobile_button_1_assign_action"
46
+ );
47
+
48
+ const button1BackgroundColorField = button1Fields.find(
49
+ (field) => field.key === "mobile_button_1_background_color"
50
+ );
51
+
52
+ expect(button1EnabledField.initial_value).toBe(true);
53
+ expect(button1AssignActionField.initial_value).toBe("navigation_action");
54
+
55
+ expect(button1BackgroundColorField.initial_value).toBe(
56
+ "rgba(254, 20, 72, 1)"
57
+ );
58
+
59
+ const button2Fields = groups[2].fields;
60
+
61
+ const button2EnabledField = button2Fields.find(
62
+ (field) => field.key === "mobile_button_2_button_enabled"
63
+ );
64
+
65
+ const button2AssignActionField = button2Fields.find(
66
+ (field) => field.key === "mobile_button_2_assign_action"
67
+ );
68
+
69
+ expect(button2EnabledField.initial_value).toBe(false);
70
+ expect(button2AssignActionField.initial_value).toBe("secondary_navigation");
71
+
72
+ const button3Fields = groups[3].fields;
73
+
74
+ const button3EnabledField = button3Fields.find(
75
+ (field) => field.key === "mobile_button_3_button_enabled"
76
+ );
77
+
78
+ const button3AssignActionField = button3Fields.find(
79
+ (field) => field.key === "mobile_button_3_assign_action"
80
+ );
81
+
82
+ expect(button3EnabledField.initial_value).toBe(false);
83
+
84
+ expect(button3AssignActionField.initial_value).toBe(
85
+ "local_storage_favourites_action"
86
+ );
87
+ });
88
+
89
+ it("merges container, shared button, and per-button overrides", () => {
90
+ const groups = buildMobileActionButtonGroups({
91
+ containerDefaults: {
92
+ align: "center",
93
+ position: ["over_image"],
94
+ },
95
+ sharedButtonDefaults: {
96
+ assetAlignment: "right",
97
+ },
98
+ buttonOverrides: {
99
+ 2: {
100
+ buttonEnabled: true,
101
+ assignAction: "downloads",
102
+ },
103
+ },
104
+ });
105
+
106
+ const alignField = groups[0].fields.find(
107
+ (field) => field.key === "mobile_buttons_container_align"
108
+ );
109
+
110
+ const button1AssetAlignmentField = groups[1].fields.find(
111
+ (field) => field.key === "mobile_button_1_asset_alignment"
112
+ );
113
+
114
+ const button2EnabledField = groups[2].fields.find(
115
+ (field) => field.key === "mobile_button_2_button_enabled"
116
+ );
117
+
118
+ const button2AssignActionField = groups[2].fields.find(
119
+ (field) => field.key === "mobile_button_2_assign_action"
120
+ );
121
+
122
+ expect(alignField.initial_value).toBe("center");
123
+ expect(button1AssetAlignmentField.initial_value).toBe("right");
124
+ expect(button2EnabledField.initial_value).toBe(true);
125
+ expect(button2AssignActionField.initial_value).toBe("downloads");
126
+ });
127
+ });
@@ -0,0 +1,76 @@
1
+ const DEFAULT_MOBILE_ACTION_BUTTONS_CONTAINER_DEFAULTS = {
2
+ buttonsEnabled: false,
3
+
4
+ align: "left",
5
+ overImagePosition: "bottom_left",
6
+ marginTop: 0,
7
+ marginRight: 20,
8
+ marginBottom: 0,
9
+ marginLeft: 20,
10
+ stacking: "horizontal",
11
+ horizontalGutter: 8,
12
+ verticalGutter: 8,
13
+ independentStyles: true,
14
+ };
15
+
16
+ const DEFAULT_MOBILE_ACTION_BUTTON_SHARED_DEFAULTS = {
17
+ displayMode: "dynamic",
18
+ width: 140,
19
+ contentsAlignment: "center",
20
+ backgroundColor: "rgba(62, 62, 62, 1)",
21
+ focusedBackgroundColor: "rgba(46, 46, 46, 1)",
22
+ borderColor: "rgba(0, 0, 0, 0)",
23
+ focusedBorderColor: "rgba(0, 0, 0, 0)",
24
+ borderSize: 0,
25
+ cornerRadius: 8,
26
+ paddingTop: 14,
27
+ paddingRight: 24,
28
+ paddingBottom: 14,
29
+ paddingLeft: 16,
30
+ assetEnabled: true,
31
+ actionAssetFlavour: "flavour_1",
32
+ assetAlignment: "left",
33
+ assetHeight: 24,
34
+ assetWidth: 24,
35
+ assetMarginTop: 0,
36
+ assetMarginRight: 6,
37
+ assetMarginBottom: 0,
38
+ assetMarginLeft: 0,
39
+ labelEnabled: true,
40
+ fontColor: "rgba(239, 239, 239, 1)",
41
+ focusedFontColor: "rgba(239, 239, 239, 1)",
42
+ iosFontFamily: "Ubuntu-Bold",
43
+ androidFontFamily: "Ubuntu-Bold",
44
+ fontSize: 15,
45
+ lineHeight: 24,
46
+ iosLetterSpacing: -0.2,
47
+ androidLetterSpacing: -0.2,
48
+ textTransform: "default",
49
+ marginTop: 0,
50
+ marginRight: 0,
51
+ marginBottom: 0,
52
+ marginLeft: 0,
53
+ };
54
+
55
+ const DEFAULT_MOBILE_ACTION_BUTTON_PRESETS = {
56
+ 1: {
57
+ buttonEnabled: true,
58
+ assignAction: "navigation_action",
59
+ backgroundColor: "rgba(254, 20, 72, 1)",
60
+ focusedBackgroundColor: "rgba(213, 8, 54, 1)",
61
+ },
62
+ 2: {
63
+ buttonEnabled: false,
64
+ assignAction: "secondary_navigation",
65
+ },
66
+ 3: {
67
+ buttonEnabled: false,
68
+ assignAction: "local_storage_favourites_action",
69
+ },
70
+ };
71
+
72
+ module.exports = {
73
+ DEFAULT_MOBILE_ACTION_BUTTONS_CONTAINER_DEFAULTS,
74
+ DEFAULT_MOBILE_ACTION_BUTTON_SHARED_DEFAULTS,
75
+ DEFAULT_MOBILE_ACTION_BUTTON_PRESETS,
76
+ };
@@ -0,0 +1,80 @@
1
+ const { mobileActionButtonsContainer } = require("../container");
2
+ const { mobileActionButton } = require("../button");
3
+
4
+ const {
5
+ DEFAULT_MOBILE_ACTION_BUTTONS_CONTAINER_DEFAULTS,
6
+ DEFAULT_MOBILE_ACTION_BUTTON_SHARED_DEFAULTS,
7
+ DEFAULT_MOBILE_ACTION_BUTTON_PRESETS,
8
+ } = require("./defaults");
9
+
10
+ const CONTAINER_GROUP_LABEL = "Mobile Buttons Container"; // NOTE: used as key – "Mobile Buttons Container" -> "mobile_buttons_container"
11
+
12
+ const CONTAINER_GROUP_DESCRIPTION =
13
+ "Configuration for mobile action buttons container";
14
+
15
+ const BUTTON_GROUPS = [
16
+ {
17
+ index: 1,
18
+ label: "Mobile Button 1",
19
+ description: "Primary mobile action button",
20
+ },
21
+ {
22
+ index: 2,
23
+ label: "Mobile Button 2",
24
+ description: "Secondary mobile action button",
25
+ },
26
+ {
27
+ index: 3,
28
+ label: "Mobile Button 3",
29
+ description: "Tertiary mobile action button",
30
+ },
31
+ ];
32
+
33
+ /**
34
+ * Builds the shared mobile action button manifest groups while letting each
35
+ * plugin supply only its supported insertion positions and explicit overrides.
36
+ *
37
+ * @param {object} options
38
+ * @param {object} [options.containerDefaults={}]
39
+ * @param {object} [options.sharedButtonDefaults={}]
40
+ * @param {Record<number, object>} [options.buttonOverrides={}]
41
+ * @returns {object[]}
42
+ */
43
+ function buildMobileActionButtonGroups({
44
+ containerDefaults = {},
45
+ sharedButtonDefaults = {},
46
+ buttonOverrides = {},
47
+ }) {
48
+ const groups = [
49
+ mobileActionButtonsContainer({
50
+ label: CONTAINER_GROUP_LABEL,
51
+ description: CONTAINER_GROUP_DESCRIPTION,
52
+ defaults: {
53
+ ...DEFAULT_MOBILE_ACTION_BUTTONS_CONTAINER_DEFAULTS,
54
+ ...containerDefaults,
55
+ },
56
+ }),
57
+ ];
58
+
59
+ BUTTON_GROUPS.forEach(({ index, label, description }) => {
60
+ groups.push(
61
+ mobileActionButton({
62
+ isFirstButton: index === 1,
63
+ label,
64
+ description,
65
+ defaults: {
66
+ ...DEFAULT_MOBILE_ACTION_BUTTON_SHARED_DEFAULTS,
67
+ ...sharedButtonDefaults,
68
+ ...DEFAULT_MOBILE_ACTION_BUTTON_PRESETS[index],
69
+ ...(buttonOverrides[index] || {}),
70
+ },
71
+ })
72
+ );
73
+ });
74
+
75
+ return groups;
76
+ }
77
+
78
+ module.exports = {
79
+ buildMobileActionButtonGroups,
80
+ };
@@ -11,16 +11,6 @@ describe("toNumber", () => {
11
11
  });
12
12
  });
13
13
 
14
- it("return number if input is BigInt", () => {
15
- const inputs = [5n, -5n];
16
- expect.assertions(inputs.length);
17
-
18
- inputs.forEach((input) => {
19
- const output = toNumber(input);
20
- expect(output).toBe(Number(input));
21
- });
22
- });
23
-
24
14
  it("return number if input is string as number", () => {
25
15
  const inputs = ["-1", "0", "1", "100", "0.2"];
26
16
  expect.assertions(inputs.length);
@@ -34,6 +24,8 @@ describe("toNumber", () => {
34
24
  it("return undefined if input is not a number", () => {
35
25
  const inputs = [
36
26
  "vfdvf",
27
+ "5n",
28
+ "-5n",
37
29
  null,
38
30
  undefined,
39
31
  NaN,
@@ -42,8 +34,6 @@ describe("toNumber", () => {
42
34
  { test: 1 },
43
35
  [],
44
36
  [1],
45
- "5n",
46
- "-5n",
47
37
  ];
48
38
 
49
39
  expect.assertions(inputs.length);
@@ -53,4 +43,29 @@ describe("toNumber", () => {
53
43
  expect(output).toBeUndefined();
54
44
  });
55
45
  });
46
+
47
+ describe("BigInt support", () => {
48
+ // Conditional test based on BigInt availability
49
+ const isBigIntSupported = typeof BigInt !== "undefined";
50
+
51
+ if (isBigIntSupported) {
52
+ it("converts BigInt to number when BigInt is supported", () => {
53
+ expect(toNumber(BigInt(5))).toBe(5);
54
+ expect(toNumber(BigInt(0))).toBe(0);
55
+ expect(toNumber(BigInt(-10))).toBe(-10);
56
+ expect(toNumber(BigInt(1000))).toBe(1000);
57
+ });
58
+
59
+ it("handles large BigInt values that may lose precision", () => {
60
+ const largeBigInt = BigInt(Number.MAX_SAFE_INTEGER) + BigInt(1);
61
+ const result = toNumber(largeBigInt);
62
+ expect(result).toBe(Number(largeBigInt));
63
+ });
64
+ } else {
65
+ it("skips BigInt tests when BigInt is not supported", () => {
66
+ // Placeholder test to indicate BigInt is not available
67
+ expect(typeof BigInt).toBe("undefined");
68
+ });
69
+ }
70
+ });
56
71
  });
@@ -156,10 +156,38 @@ describe("toPositiveNumber", () => {
156
156
  it("handles Symbol values", () => {
157
157
  expect(toPositiveNumber(Symbol("test"))).toBeUndefined();
158
158
  });
159
+ });
159
160
 
160
- it("converts BigInt values", () => {
161
- expect(toPositiveNumber(5n)).toBe(5);
162
- expect(toPositiveNumber(-5n)).toBeUndefined();
163
- });
161
+ describe("BigInt support", () => {
162
+ // Conditional test based on BigInt availability
163
+ const isBigIntSupported = typeof BigInt !== "undefined";
164
+
165
+ if (isBigIntSupported) {
166
+ it("converts positive BigInt values to numbers when BigInt is supported", () => {
167
+ expect(toPositiveNumber(BigInt(5))).toBe(5);
168
+ expect(toPositiveNumber(BigInt(100))).toBe(100);
169
+ expect(toPositiveNumber(BigInt(1000))).toBe(1000);
170
+ });
171
+
172
+ it("returns undefined for zero BigInt", () => {
173
+ expect(toPositiveNumber(BigInt(0))).toBeUndefined();
174
+ });
175
+
176
+ it("returns undefined for negative BigInt values", () => {
177
+ expect(toPositiveNumber(BigInt(-5))).toBeUndefined();
178
+ expect(toPositiveNumber(BigInt(-100))).toBeUndefined();
179
+ });
180
+
181
+ it("handles large positive BigInt values", () => {
182
+ const largeBigInt = BigInt(Number.MAX_SAFE_INTEGER);
183
+ const result = toPositiveNumber(largeBigInt);
184
+ expect(result).toBe(Number(largeBigInt));
185
+ });
186
+ } else {
187
+ it("skips BigInt tests when BigInt is not supported", () => {
188
+ // Placeholder test to indicate BigInt is not available
189
+ expect(typeof BigInt).toBe("undefined");
190
+ });
191
+ }
164
192
  });
165
193
  });
@@ -8,7 +8,11 @@ export const toNumber = (value: unknown): number | undefined => {
8
8
  return undefined;
9
9
  }
10
10
 
11
- if (R.is(Number, value) || R.is(BigInt, value) || R.is(String, value)) {
11
+ // Feature-detect BigInt support to avoid ReferenceError on older runtimes
12
+ const isBigIntSupported = typeof BigInt !== "undefined";
13
+ const isBigIntValue = isBigIntSupported && R.is(BigInt, value);
14
+
15
+ if (R.is(Number, value) || isBigIntValue || R.is(String, value)) {
12
16
  const numberOrNan = Number(value);
13
17
 
14
18
  return Number.isNaN(numberOrNan) ? undefined : numberOrNan;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "15.0.0-alpha.5219062121",
3
+ "version": "15.0.0-alpha.5262500595",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,11 +27,11 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "15.0.0-alpha.5219062121",
30
+ "@applicaster/applicaster-types": "15.0.0-alpha.5262500595",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
34
- "handlebars": "4.7.8",
34
+ "handlebars": "4.7.9",
35
35
  "memoizee": "0.4.15",
36
36
  "prop-types": "^15.0.0"
37
37
  },
@@ -0,0 +1 @@
1
+ export { useIsCasting } from "./useIsCasting";
@@ -0,0 +1,57 @@
1
+ import React from "react";
2
+ import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
3
+ import { useAppState } from "@applicaster/zapp-react-native-utils/reactHooks/app";
4
+ import { isApplePlatform } from "@applicaster/zapp-react-native-utils/reactUtils";
5
+
6
+ const CHROMECAST_IDENTIFIER = "quick-brick-chromecast-action";
7
+
8
+ const fakeEntry: any = {
9
+ title: "Chromecast use is casting fake entry",
10
+ id: "quick-brick-use-is-casting-fake-entry",
11
+ };
12
+
13
+ /**
14
+ * Returns the cast action state connection status, does not update when app is in background on Apple platforms
15
+ * On other platforms, it continues to check the cast action state even when the app is in background
16
+ */
17
+ export const useIsCasting = () => {
18
+ const actionContext = useActions(CHROMECAST_IDENTIFIER);
19
+ const appState = useAppState();
20
+ const isAppInForeground = appState === "active";
21
+ const shouldOnlyUpdateInForeground = isApplePlatform();
22
+
23
+ const [castActionState, setCastActionState] = React.useState(
24
+ !actionContext ? null : actionContext.initialEntryState(fakeEntry)
25
+ );
26
+
27
+ React.useEffect(() => {
28
+ if (!shouldOnlyUpdateInForeground || isAppInForeground) {
29
+ if (actionContext && castActionState === null) {
30
+ setCastActionState(actionContext.initialEntryState(fakeEntry));
31
+ }
32
+ }
33
+ }, [
34
+ actionContext,
35
+ setCastActionState,
36
+ isAppInForeground,
37
+ shouldOnlyUpdateInForeground,
38
+ ]);
39
+
40
+ React.useEffect(() => {
41
+ if (typeof actionContext?.addListener === "function") {
42
+ return actionContext?.addListener(String(fakeEntry.id), (state) => {
43
+ // Only check foreground state on Apple platforms
44
+ if (!shouldOnlyUpdateInForeground || isAppInForeground) {
45
+ setCastActionState(state);
46
+ }
47
+ });
48
+ }
49
+ }, [
50
+ setCastActionState,
51
+ actionContext,
52
+ isAppInForeground,
53
+ shouldOnlyUpdateInForeground,
54
+ ]);
55
+
56
+ return !!castActionState?.connected;
57
+ };
@@ -54,7 +54,7 @@ export const useCellClick = ({
54
54
  component?.rules?.component_cells_selectable
55
55
  );
56
56
 
57
- const [__, setEntryContext] =
57
+ const [entryContext, setEntryContext] =
58
58
  ZappPipesEntryContext.useZappPipesContext(pathname);
59
59
 
60
60
  const logTimestamp = useProfilerLogging();
@@ -89,6 +89,7 @@ export const useCellClick = ({
89
89
  screenState,
90
90
  screenRoute: pathname,
91
91
  screenStateStore,
92
+ entryContext,
92
93
  });
93
94
  }
94
95
 
@@ -1,5 +1,3 @@
1
- export { useFeedRefresh, feedRefreshLogger } from "./useFeedRefresh";
2
-
3
1
  export { useFeedLoader } from "./useFeedLoader";
4
2
 
5
3
  export { getSearchContext, getInflatedDataSourceUrl } from "./useInflatedUrl";