@react-native-ama/lists 1.0.0

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 (82) hide show
  1. package/dist/core/src/components/AMAProvider.d.ts +26 -0
  2. package/dist/core/src/components/AMAProvider.js +147 -0
  3. package/dist/core/src/components/AutofocusContainer.d.ts +9 -0
  4. package/dist/core/src/components/AutofocusContainer.js +58 -0
  5. package/dist/core/src/components/HideChildrenFromAccessibilityTree.d.ts +6 -0
  6. package/dist/core/src/components/HideChildrenFromAccessibilityTree.js +40 -0
  7. package/dist/core/src/hooks/useButtonChecks.d.ts +6 -0
  8. package/dist/core/src/hooks/useButtonChecks.js +51 -0
  9. package/dist/core/src/hooks/useChecks.d.ts +15 -0
  10. package/dist/core/src/hooks/useChecks.js +152 -0
  11. package/dist/core/src/hooks/useFocus.d.ts +4 -0
  12. package/dist/core/src/hooks/useFocus.js +55 -0
  13. package/dist/core/src/hooks/useTimedAction.d.ts +3 -0
  14. package/dist/core/src/hooks/useTimedAction.js +63 -0
  15. package/dist/core/src/index.d.ts +7 -0
  16. package/dist/core/src/index.js +20 -0
  17. package/dist/internal/src/checks/checkAccessibilityRole.d.ts +3 -0
  18. package/dist/internal/src/checks/checkAccessibilityRole.js +32 -0
  19. package/dist/internal/src/checks/checkFocusTrap.d.ts +8 -0
  20. package/dist/internal/src/checks/checkFocusTrap.js +34 -0
  21. package/dist/internal/src/checks/checkForAccessibilityState.d.ts +7 -0
  22. package/dist/internal/src/checks/checkForAccessibilityState.js +48 -0
  23. package/dist/internal/src/checks/checkMinimumSize.d.ts +3 -0
  24. package/dist/internal/src/checks/checkMinimumSize.js +29 -0
  25. package/dist/internal/src/checks/contrastChecker.d.ts +8 -0
  26. package/dist/internal/src/checks/contrastChecker.js +77 -0
  27. package/dist/internal/src/checks/noUndefinedProperty.d.ts +8 -0
  28. package/dist/internal/src/checks/noUndefinedProperty.js +14 -0
  29. package/dist/internal/src/checks/uppercaseChecker.d.ts +8 -0
  30. package/dist/internal/src/checks/uppercaseChecker.js +18 -0
  31. package/dist/internal/src/checks/uppercaseStringChecker.d.ts +8 -0
  32. package/dist/internal/src/checks/uppercaseStringChecker.js +29 -0
  33. package/dist/internal/src/index.d.ts +20 -0
  34. package/dist/internal/src/index.js +56 -0
  35. package/dist/internal/src/types.d.ts +17 -0
  36. package/dist/internal/src/types.js +2 -0
  37. package/dist/internal/src/utils/applyStyle.d.ts +9 -0
  38. package/dist/internal/src/utils/applyStyle.js +33 -0
  39. package/dist/internal/src/utils/constants.d.ts +3 -0
  40. package/dist/internal/src/utils/constants.js +32 -0
  41. package/dist/internal/src/utils/error.style.d.ts +6 -0
  42. package/dist/internal/src/utils/error.style.js +11 -0
  43. package/dist/internal/src/utils/generateAccessibilityStateFromProp.d.ts +9 -0
  44. package/dist/internal/src/utils/generateAccessibilityStateFromProp.js +35 -0
  45. package/dist/internal/src/utils/getPropertyFromStyle.d.ts +2 -0
  46. package/dist/internal/src/utils/getPropertyFromStyle.js +10 -0
  47. package/dist/internal/src/utils/interpolateAnimationStates.d.ts +2 -0
  48. package/dist/internal/src/utils/interpolateAnimationStates.js +43 -0
  49. package/dist/internal/src/utils/isFocused.d.ts +2 -0
  50. package/dist/internal/src/utils/isFocused.js +7 -0
  51. package/dist/internal/src/utils/logger.d.ts +16 -0
  52. package/dist/internal/src/utils/logger.js +53 -0
  53. package/dist/internal/src/utils/logger.rules.d.ts +15 -0
  54. package/dist/internal/src/utils/logger.rules.js +74 -0
  55. package/dist/internal/src/utils/maybeGenerateStringFromElement.d.ts +2 -0
  56. package/dist/internal/src/utils/maybeGenerateStringFromElement.js +51 -0
  57. package/dist/internal/src/utils/minimumTouchableSize.d.ts +3 -0
  58. package/dist/internal/src/utils/minimumTouchableSize.js +9 -0
  59. package/dist/lists/src/components/DynamicFlatList.d.ts +7 -0
  60. package/dist/lists/src/components/DynamicFlatList.js +36 -0
  61. package/dist/lists/src/components/FlatList.d.ts +10 -0
  62. package/dist/lists/src/components/FlatList.js +24 -0
  63. package/dist/lists/src/components/ListWrapper.d.ts +7 -0
  64. package/dist/lists/src/components/ListWrapper.js +45 -0
  65. package/dist/lists/src/components/StaticFlatList.d.ts +7 -0
  66. package/dist/lists/src/components/StaticFlatList.js +34 -0
  67. package/dist/lists/src/hooks/useDynamicList.d.ts +16 -0
  68. package/dist/lists/src/hooks/useDynamicList.js +62 -0
  69. package/dist/lists/src/index.d.ts +5 -0
  70. package/dist/lists/src/index.js +15 -0
  71. package/package.json +58 -0
  72. package/src/components/DynamicFlatList.test.tsx +58 -0
  73. package/src/components/DynamicFlatList.tsx +48 -0
  74. package/src/components/FlatList.test.tsx +378 -0
  75. package/src/components/FlatList.tsx +29 -0
  76. package/src/components/ListWrapper.android.test.tsx +20 -0
  77. package/src/components/ListWrapper.ios.test.tsx +15 -0
  78. package/src/components/ListWrapper.tsx +35 -0
  79. package/src/components/StaticFlatList.tsx +32 -0
  80. package/src/hooks/useDynamicFlatList.test.ts +50 -0
  81. package/src/hooks/useDynamicList.ts +84 -0
  82. package/src/index.ts +8 -0
@@ -0,0 +1,2 @@
1
+ import type { StyleProp } from 'react-native';
2
+ export declare const getPropertyFromStyle: (style: StyleProp<any> | StyleProp<any>[] | null, key: keyof StyleProp<any>) => any;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPropertyFromStyle = void 0;
4
+ const getPropertyFromStyle = (style, key) => {
5
+ var _a, _b, _c;
6
+ return Array.isArray(style)
7
+ ? (_c = (_b = (_a = style.filter(theStyle => theStyle === null || theStyle === void 0 ? void 0 : theStyle[key])) === null || _a === void 0 ? void 0 : _a.slice(-1)) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c[key]
8
+ : style === null || style === void 0 ? void 0 : style[key];
9
+ };
10
+ exports.getPropertyFromStyle = getPropertyFromStyle;
@@ -0,0 +1,2 @@
1
+ import type { Animated } from 'react-native';
2
+ export declare const interpolateAnimationStates: (from: Record<string, any>, to: Record<string, any>, isReduceMotionEnabled: boolean, progressValue: Animated.Value, reduceMotionProgressValue: Animated.Value) => Record<string, any>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.interpolateAnimationStates = void 0;
15
+ const constants_1 = require("./constants");
16
+ const interpolateAnimationStates = (from, to, isReduceMotionEnabled, progressValue, reduceMotionProgressValue) => {
17
+ return Object.keys(from).reduce((outputAnimation, key) => {
18
+ const isMotionAnimation = constants_1.MOTION_ANIMATIONS.includes(key);
19
+ const progressKey = isReduceMotionEnabled && isMotionAnimation
20
+ ? reduceMotionProgressValue
21
+ : progressValue;
22
+ if (Array.isArray(from[key])) {
23
+ outputAnimation[key] = from[key].map((animationObject, index) => {
24
+ const _a = (0, exports.interpolateAnimationStates)(animationObject, to[key][index], isReduceMotionEnabled, progressValue, reduceMotionProgressValue), { __hasOnlyMotionAnimation } = _a, style = __rest(_a, ["__hasOnlyMotionAnimation"]);
25
+ outputAnimation.__hasOnlyMotionAnimation =
26
+ outputAnimation.__hasOnlyMotionAnimation &&
27
+ __hasOnlyMotionAnimation;
28
+ return style;
29
+ });
30
+ }
31
+ else {
32
+ outputAnimation[key] = progressKey.interpolate({
33
+ inputRange: [0, 1],
34
+ // @ts-ignore
35
+ outputRange: [from[key], to[key]],
36
+ });
37
+ outputAnimation.__hasOnlyMotionAnimation =
38
+ outputAnimation.__hasOnlyMotionAnimation && isMotionAnimation;
39
+ }
40
+ return outputAnimation;
41
+ }, { __hasOnlyMotionAnimation: true });
42
+ };
43
+ exports.interpolateAnimationStates = interpolateAnimationStates;
@@ -0,0 +1,2 @@
1
+ import type { TextInput } from 'react-native';
2
+ export declare const isFocused: (input: TextInput | undefined | null) => boolean | undefined;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFocused = void 0;
4
+ const isFocused = (input) => {
5
+ return input === null || input === void 0 ? void 0 : input.isFocused();
6
+ };
7
+ exports.isFocused = isFocused;
@@ -0,0 +1,16 @@
1
+ import { Rule, RuleAction } from './logger.rules';
2
+ export type LogParams = {
3
+ rule: Rule;
4
+ message: string;
5
+ extra?: any;
6
+ };
7
+ export declare const getRuleAction: ((rule: Rule) => RuleAction) | null;
8
+ type LogFailure = LogParams & {
9
+ action: RuleAction;
10
+ };
11
+ type CHECK_STATUS = 'ERROR' | 'WARNING';
12
+ export declare const logFailure: (({ action, rule, message, extra }: LogFailure) => CHECK_STATUS) | null;
13
+ export declare const getContrastCheckerMaxDepth: (() => RuleAction | 5) | null;
14
+ export declare const shouldIgnoreContrastCheckForDisabledElement: (() => false | RuleAction) | null;
15
+ export declare const isAccessibilityLabelAllowed: ((accessibilityLabel: string) => boolean) | null;
16
+ export {};
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isAccessibilityLabelAllowed = exports.shouldIgnoreContrastCheckForDisabledElement = exports.getContrastCheckerMaxDepth = exports.logFailure = exports.getRuleAction = void 0;
4
+ const logger_rules_1 = require("./logger.rules");
5
+ const logger_rules_2 = require("./logger.rules");
6
+ const overrideRules = require('./../ama.rules.json');
7
+ exports.getRuleAction = __DEV__
8
+ ? (rule) => {
9
+ var _a;
10
+ const customRule = (logger_rules_1.canRuleBeOverridden === null || logger_rules_1.canRuleBeOverridden === void 0 ? void 0 : (0, logger_rules_1.canRuleBeOverridden)(rule))
11
+ ? (_a = overrideRules === null || overrideRules === void 0 ? void 0 : overrideRules.rules) === null || _a === void 0 ? void 0 : _a[rule]
12
+ : undefined;
13
+ return customRule || logger_rules_2.LOGGER_RULES[rule];
14
+ }
15
+ : null;
16
+ exports.logFailure = __DEV__
17
+ ? ({ action, rule, message, extra = '' }) => {
18
+ // @ts-ignore
19
+ const formattedMessage = `❌ ${logger_rules_1.SHELL_COLORS.BG_RED}[ AMA ]${logger_rules_1.SHELL_COLORS.RESET}: ${logger_rules_1.SHELL_COLORS.BLUE}${rule}${logger_rules_1.SHELL_COLORS.RESET} - ${logger_rules_1.SHELL_COLORS.YELLOW}${message}${logger_rules_1.SHELL_COLORS.RESET}\n\n${logger_rules_2.RULES_HELP[rule]}\n\n`;
20
+ switch (action) {
21
+ case 'MUST_NOT':
22
+ case 'MUST':
23
+ console.info(formattedMessage, extra || '', '\n');
24
+ return 'ERROR';
25
+ case 'PLEASE_FORGIVE_ME':
26
+ return 'WARNING';
27
+ case 'SHOULD_NOT':
28
+ default:
29
+ console.warn(formattedMessage, extra || '', '\n');
30
+ return 'WARNING';
31
+ }
32
+ }
33
+ : null;
34
+ exports.getContrastCheckerMaxDepth = __DEV__
35
+ ? () => {
36
+ var _a;
37
+ return (((_a = overrideRules === null || overrideRules === void 0 ? void 0 : overrideRules.rules) === null || _a === void 0 ? void 0 : _a.CONTRAST_CHECKER_MAX_DEPTH) ||
38
+ logger_rules_2.CONTRAST_CHECKER_MAX_DEPTH);
39
+ }
40
+ : null;
41
+ exports.shouldIgnoreContrastCheckForDisabledElement = __DEV__
42
+ ? () => {
43
+ var _a;
44
+ return (((_a = overrideRules === null || overrideRules === void 0 ? void 0 : overrideRules.rules) === null || _a === void 0 ? void 0 : _a.IGNORE_CONTRAST_FOR_DISABLED_ELEMENTS) ||
45
+ logger_rules_1.IGNORE_CONTRAST_FOR_DISABLED_ELEMENTS);
46
+ }
47
+ : null;
48
+ exports.isAccessibilityLabelAllowed = __DEV__
49
+ ? (accessibilityLabel) => {
50
+ var _a;
51
+ return (_a = overrideRules === null || overrideRules === void 0 ? void 0 : overrideRules.accessibilityLabelExceptions) === null || _a === void 0 ? void 0 : _a.includes(accessibilityLabel);
52
+ }
53
+ : null;
@@ -0,0 +1,15 @@
1
+ export type Rule = 'BOTTOM_SHEET_CLOSE_ACTION' | 'CONTRAST_FAILED' | 'CONTRAST_FAILED_AAA' | 'FLATLIST_NO_COUNT_IN_PLURAL_MESSAGE' | 'FLATLIST_NO_COUNT_IN_SINGULAR_MESSAGE' | 'MINIMUM_SIZE' | 'NO_ACCESSIBILITY_LABEL' | 'NO_ACCESSIBILITY_ROLE' | 'NO_FORM_ERROR' | 'NO_FORM_LABEL' | 'NO_KEYBOARD_TRAP' | 'NO_UNDEFINED' | 'NO_UPPERCASE_TEXT' | 'INCOMPATIBLE_ACCESSIBILITY_STATE' | 'INCOMPATIBLE_ACCESSIBILITY_ROLE' | 'NO_FORM_LABEL_ENDING_WITH_ASTERISK' | 'UPPERCASE_TEXT_NO_ACCESSIBILITY_LABEL';
2
+ export type RuleAction = 'SHOULD_NOT' | 'MUST_NOT' | 'MUST' | 'SHOULD' | 'PLEASE_FORGIVE_ME';
3
+ export declare const NON_OVERRIDABLE_RULES: string[] | undefined;
4
+ export declare const LOGGER_RULES: Record<Rule, RuleAction> | null;
5
+ export declare const CONTRAST_CHECKER_MAX_DEPTH = 5;
6
+ export declare const IGNORE_CONTRAST_FOR_DISABLED_ELEMENTS = false;
7
+ export declare const RULES_HELP: Record<Rule, string> | null;
8
+ export declare const canRuleBeOverridden: ((rule: Rule) => boolean) | null;
9
+ export declare const SHELL_COLORS: {
10
+ RED: string;
11
+ YELLOW: string;
12
+ RESET: string;
13
+ BLUE: string;
14
+ BG_RED: string;
15
+ } | undefined;
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SHELL_COLORS = exports.canRuleBeOverridden = exports.RULES_HELP = exports.IGNORE_CONTRAST_FOR_DISABLED_ELEMENTS = exports.CONTRAST_CHECKER_MAX_DEPTH = exports.LOGGER_RULES = exports.NON_OVERRIDABLE_RULES = void 0;
4
+ exports.NON_OVERRIDABLE_RULES = __DEV__
5
+ ? [
6
+ 'NO_ACCESSIBILITY_ROLE',
7
+ 'NO_ACCESSIBILITY_LABEL',
8
+ 'NO_KEYBOARD_TRAP',
9
+ 'NO_UNDEFINED',
10
+ 'NO_FORM_LABEL',
11
+ 'FLATLIST_NO_COUNT_IN_PLURAL_MESSAGE',
12
+ 'BOTTOM_SHEET_CLOSE_ACTION',
13
+ 'INCOMPATIBLE_ACCESSIBILITY_STATE',
14
+ 'INCOMPATIBLE_ACCESSIBILITY_ROLE',
15
+ ]
16
+ : undefined;
17
+ exports.LOGGER_RULES = __DEV__
18
+ ? {
19
+ CONTRAST_FAILED: 'MUST',
20
+ CONTRAST_FAILED_AAA: 'SHOULD',
21
+ FLATLIST_NO_COUNT_IN_SINGULAR_MESSAGE: 'SHOULD',
22
+ FLATLIST_NO_COUNT_IN_PLURAL_MESSAGE: 'MUST',
23
+ MINIMUM_SIZE: 'MUST',
24
+ NO_ACCESSIBILITY_LABEL: 'MUST',
25
+ NO_ACCESSIBILITY_ROLE: 'MUST',
26
+ NO_FORM_LABEL: 'MUST',
27
+ NO_FORM_ERROR: 'MUST',
28
+ NO_KEYBOARD_TRAP: 'MUST_NOT',
29
+ NO_UNDEFINED: 'MUST_NOT',
30
+ UPPERCASE_TEXT_NO_ACCESSIBILITY_LABEL: 'MUST_NOT',
31
+ NO_UPPERCASE_TEXT: 'MUST_NOT',
32
+ BOTTOM_SHEET_CLOSE_ACTION: 'MUST',
33
+ INCOMPATIBLE_ACCESSIBILITY_STATE: 'MUST',
34
+ NO_FORM_LABEL_ENDING_WITH_ASTERISK: 'MUST_NOT',
35
+ INCOMPATIBLE_ACCESSIBILITY_ROLE: 'MUST_NOT',
36
+ }
37
+ : null;
38
+ exports.CONTRAST_CHECKER_MAX_DEPTH = 5;
39
+ exports.IGNORE_CONTRAST_FOR_DISABLED_ELEMENTS = false;
40
+ exports.RULES_HELP = __DEV__
41
+ ? {
42
+ NO_UNDEFINED: '',
43
+ CONTRAST_FAILED: 'https://formidable.com/open-source/react-native-ama/guidelines/contrast',
44
+ CONTRAST_FAILED_AAA: 'https://formidable.com/open-source/react-native-ama/guidelines/contrast',
45
+ MINIMUM_SIZE: 'https://formidable.com/open-source/react-native-ama/guidelines/minimum-size',
46
+ UPPERCASE_TEXT_NO_ACCESSIBILITY_LABEL: 'https://formidable.com/open-source/react-native-ama/guidelines/text',
47
+ NO_UPPERCASE_TEXT: 'https://formidable.com/open-source/react-native-ama/guidelines/text',
48
+ NO_ACCESSIBILITY_LABEL: 'https://formidable.com/open-source/react-native-ama/guidelines/accessibility-labels',
49
+ NO_ACCESSIBILITY_ROLE: 'https://formidable.com/open-source/react-native-ama/guidelines/accessibility-role',
50
+ NO_KEYBOARD_TRAP: 'https://formidable.com/open-source/react-native-ama/guidelines/forms',
51
+ NO_FORM_LABEL: 'https://formidable.com/open-source/react-native-ama/guidelines/forms',
52
+ NO_FORM_ERROR: 'https://formidable.com/open-source/react-native-ama/guidelines/forms',
53
+ FLATLIST_NO_COUNT_IN_SINGULAR_MESSAGE: 'https://formidable.com/open-source/react-native-ama/guidelines/lists-grids#number-of-results',
54
+ FLATLIST_NO_COUNT_IN_PLURAL_MESSAGE: 'https://formidable.com/open-source/react-native-ama/guidelines/lists-grids#number-of-results',
55
+ BOTTOM_SHEET_CLOSE_ACTION: 'https://formidable.com/open-source/react-native-ama/guidelines/bottomsheet',
56
+ INCOMPATIBLE_ACCESSIBILITY_STATE: 'https://formidable.com/open-source/react-native-ama/guidelines/accessibility-role',
57
+ INCOMPATIBLE_ACCESSIBILITY_ROLE: 'https://formidable.com/open-source/react-native-ama/guidelines/accessibility-role',
58
+ NO_FORM_LABEL_ENDING_WITH_ASTERISK: 'https://formidable.com/open-source/react-native-ama/guidelines/forms#labels',
59
+ }
60
+ : null;
61
+ exports.canRuleBeOverridden = __DEV__
62
+ ? (rule) => {
63
+ return !exports.NON_OVERRIDABLE_RULES.includes(rule);
64
+ }
65
+ : null;
66
+ exports.SHELL_COLORS = __DEV__
67
+ ? {
68
+ RED: '\x1b[31m',
69
+ YELLOW: '\x1b[33m',
70
+ RESET: '\x1b[0m',
71
+ BLUE: '\x1b[36m',
72
+ BG_RED: '\x1b[41m',
73
+ }
74
+ : undefined;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare const maybeGenerateStringFromElement: (element?: JSX.Element, alternativeString?: string | null) => string;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.maybeGenerateStringFromElement = void 0;
27
+ const React = __importStar(require("react"));
28
+ const maybeGenerateStringFromElement = (element, alternativeString) => {
29
+ var _a;
30
+ if (alternativeString || element == null) {
31
+ return alternativeString || '';
32
+ }
33
+ const pieces = extractPieces(element);
34
+ if (pieces == null || (pieces === null || pieces === void 0 ? void 0 : pieces.length) === 0) {
35
+ console.error(`Cannot generate the string from ${element} prop. Please provide one!`);
36
+ }
37
+ return (_a = pieces === null || pieces === void 0 ? void 0 : pieces.join(' ')) === null || _a === void 0 ? void 0 : _a.replace(/\*$/, '');
38
+ };
39
+ exports.maybeGenerateStringFromElement = maybeGenerateStringFromElement;
40
+ const extractPieces = (component) => {
41
+ return React.Children.map(component, child => {
42
+ if (!React.isValidElement(child)) {
43
+ return '';
44
+ }
45
+ const children = child.props.children;
46
+ if (React.isValidElement(children) || Array.isArray(children)) {
47
+ return extractPieces(children);
48
+ }
49
+ return children;
50
+ });
51
+ };
@@ -0,0 +1,3 @@
1
+ export declare const ANDROID_MINIMUM_TOUCHABLE_SIZE = 48;
2
+ export declare const IOS_MINIMUM_TOUCHABLE_SIZE = 44;
3
+ export declare const MINIMUM_TOUCHABLE_SIZE: number;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MINIMUM_TOUCHABLE_SIZE = exports.IOS_MINIMUM_TOUCHABLE_SIZE = exports.ANDROID_MINIMUM_TOUCHABLE_SIZE = void 0;
4
+ const react_native_1 = require("react-native");
5
+ exports.ANDROID_MINIMUM_TOUCHABLE_SIZE = 48;
6
+ exports.IOS_MINIMUM_TOUCHABLE_SIZE = 44;
7
+ exports.MINIMUM_TOUCHABLE_SIZE = react_native_1.Platform.OS === 'android'
8
+ ? exports.ANDROID_MINIMUM_TOUCHABLE_SIZE
9
+ : exports.IOS_MINIMUM_TOUCHABLE_SIZE;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { FlatList, FlatListProps } from 'react-native';
3
+ export declare const DynamicFlatList: React.ForwardRefExoticComponent<FlatListProps<any> & {
4
+ singularMessage: string;
5
+ pluralMessage: string;
6
+ isPlural?: ((count: number) => boolean) | undefined;
7
+ } & React.RefAttributes<FlatList<any>>>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.DynamicFlatList = void 0;
18
+ const react_1 = __importDefault(require("react"));
19
+ const react_native_1 = require("react-native");
20
+ const useDynamicList_1 = require("../hooks/useDynamicList");
21
+ const ListWrapper_1 = require("./ListWrapper");
22
+ exports.DynamicFlatList = react_1.default.forwardRef((_a, forwardedRef) => {
23
+ var { data, singularMessage, pluralMessage, isPlural } = _a, rest = __rest(_a, ["data", "singularMessage", "pluralMessage", "isPlural"]);
24
+ const dynamicList = (0, useDynamicList_1.useDynamicList)({
25
+ data: data !== null && data !== void 0 ? data : [],
26
+ pluralMessage,
27
+ singularMessage,
28
+ numColumns: rest.numColumns,
29
+ isPlural,
30
+ });
31
+ return __DEV__ ? (<ListWrapper_1.ListWrapper rowsCount={dynamicList.rowsCount} columnsCount={dynamicList.columnsCount}>
32
+ <react_native_1.FlatList data={data} {...rest} ref={forwardedRef} style={dynamicList.style}/>
33
+ </ListWrapper_1.ListWrapper>) : (<ListWrapper_1.ListWrapper rowsCount={dynamicList.rowsCount} columnsCount={dynamicList.columnsCount}>
34
+ <react_native_1.FlatList data={data} {...rest} ref={forwardedRef}/>
35
+ </ListWrapper_1.ListWrapper>);
36
+ });
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ import type { FlatList as RNFlatList, FlatListProps as RNFlatListProps } from 'react-native';
3
+ import type { UseDynamicList } from '../hooks/useDynamicList';
4
+ import { StaticFlatListProps } from './StaticFlatList';
5
+ export type FlatListProps<T> = RNFlatListProps<T> & (({
6
+ listType: 'static';
7
+ } & StaticFlatListProps) | ({
8
+ listType: 'dynamic';
9
+ } & UseDynamicList));
10
+ export declare const FlatList: React.ForwardRefExoticComponent<FlatListProps<any> & React.RefAttributes<RNFlatList<any>>>;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.FlatList = void 0;
18
+ const react_1 = __importDefault(require("react"));
19
+ const DynamicFlatList_1 = require("./DynamicFlatList");
20
+ const StaticFlatList_1 = require("./StaticFlatList");
21
+ exports.FlatList = react_1.default.forwardRef((_a, forwardRef) => {
22
+ var { listType } = _a, rest = __rest(_a, ["listType"]);
23
+ return listType === 'dynamic' ? (<DynamicFlatList_1.DynamicFlatList ref={forwardRef} {...rest}/>) : (<StaticFlatList_1.StaticFlatList ref={forwardRef} {...rest}/>);
24
+ });
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ type FlatListWrapperProps = React.PropsWithChildren<{
3
+ rowsCount: number;
4
+ columnsCount?: number;
5
+ }>;
6
+ export declare const ListWrapper: ({ children, rowsCount, columnsCount, }: FlatListWrapperProps) => React.JSX.Element;
7
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.ListWrapper = void 0;
27
+ const React = __importStar(require("react"));
28
+ const react_native_1 = require("react-native");
29
+ const isAndroid = react_native_1.Platform.OS === 'android';
30
+ const ListWrapper = ({ children, rowsCount, columnsCount = 1, }) => {
31
+ return (<AMAFlatListWrapper rowsCount={rowsCount} columnsCount={columnsCount}>
32
+ {children}
33
+ </AMAFlatListWrapper>);
34
+ };
35
+ exports.ListWrapper = ListWrapper;
36
+ /*
37
+ * Used instead of React.Fragment to avoid the warning:
38
+ * ...React.Fragment can only have `key` and `children` props.
39
+ */
40
+ const EmptyComponent = ({ children, }) => {
41
+ return <>{children}</>;
42
+ };
43
+ const AMAFlatListWrapper = isAndroid
44
+ ? (0, react_native_1.requireNativeComponent)('AmaFlatListWrapper')
45
+ : EmptyComponent;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import { FlatList, FlatListProps } from 'react-native';
3
+ export type StaticFlatListProps = {
4
+ rowsCount?: number;
5
+ numColumns?: number;
6
+ };
7
+ export declare const StaticFlatList: React.ForwardRefExoticComponent<FlatListProps<any> & StaticFlatListProps & React.RefAttributes<FlatList<any>>>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.StaticFlatList = void 0;
18
+ const react_1 = __importDefault(require("react"));
19
+ const react_native_1 = require("react-native");
20
+ const ListWrapper_1 = require("./ListWrapper");
21
+ exports.StaticFlatList = react_1.default.forwardRef((_a, ref) => {
22
+ var { data, numColumns, rowsCount } = _a, rest = __rest(_a, ["data", "numColumns", "rowsCount"]);
23
+ const columns = numColumns || 1;
24
+ const rows = react_1.default.useMemo(() => {
25
+ if (rowsCount) {
26
+ return rowsCount;
27
+ }
28
+ const length = (data === null || data === void 0 ? void 0 : data.length) || 0;
29
+ return Math.ceil(columns > 1 && length > 0 ? length / columns : length);
30
+ }, [columns, data === null || data === void 0 ? void 0 : data.length, rowsCount]);
31
+ return (<ListWrapper_1.ListWrapper rowsCount={rows} columnsCount={columns}>
32
+ <react_native_1.FlatList data={data} {...rest} ref={ref}/>
33
+ </ListWrapper_1.ListWrapper>);
34
+ });
@@ -0,0 +1,16 @@
1
+ export type UseDynamicList = {
2
+ data: ArrayLike<any>;
3
+ singularMessage: string;
4
+ pluralMessage: string;
5
+ isPlural?: (count: number) => boolean;
6
+ numColumns?: number;
7
+ };
8
+ export declare const useDynamicList: ({ data, singularMessage, pluralMessage, isPlural, numColumns, }: UseDynamicList) => {
9
+ rowsCount: number;
10
+ columnsCount: number;
11
+ style: any;
12
+ } | {
13
+ rowsCount: number;
14
+ columnsCount: number;
15
+ style?: undefined;
16
+ };
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useDynamicList = void 0;
7
+ const core_1 = require("@react-native-ama/core");
8
+ const react_1 = __importDefault(require("react"));
9
+ const react_native_1 = require("react-native");
10
+ const useDynamicList = ({ data, singularMessage, pluralMessage, isPlural = simpleIsPlural, numColumns = 1, }) => {
11
+ const isFirstRender = react_1.default.useRef(true);
12
+ const initialCount = react_1.default.useRef(data === null || data === void 0 ? void 0 : data.length);
13
+ const lastItemsCount = react_1.default.useRef(null);
14
+ const checks = __DEV__ ? core_1.useChecks === null || core_1.useChecks === void 0 ? void 0 : (0, core_1.useChecks)() : null;
15
+ __DEV__ &&
16
+ react_1.default.useEffect(() => {
17
+ if (!(singularMessage === null || singularMessage === void 0 ? void 0 : singularMessage.includes('%count%'))) {
18
+ checks === null || checks === void 0 ? void 0 : checks.logResult('useDynamicFlatList', {
19
+ rule: 'FLATLIST_NO_COUNT_IN_SINGULAR_MESSAGE',
20
+ message: 'Special string %count% not found in singularMessage',
21
+ extra: singularMessage,
22
+ });
23
+ }
24
+ if (!(pluralMessage === null || pluralMessage === void 0 ? void 0 : pluralMessage.includes('%count%'))) {
25
+ checks === null || checks === void 0 ? void 0 : checks.logResult('useDynamicFlatList', {
26
+ rule: 'FLATLIST_NO_COUNT_IN_PLURAL_MESSAGE',
27
+ message: 'Special string %count% not found in pluralMessage',
28
+ extra: pluralMessage,
29
+ });
30
+ }
31
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
+ }, [pluralMessage, singularMessage, checks === null || checks === void 0 ? void 0 : checks.logResult]);
33
+ react_1.default.useEffect(() => {
34
+ const itemsCount = (data === null || data === void 0 ? void 0 : data.length) || 0;
35
+ if (isFirstRender.current ||
36
+ itemsCount === initialCount.current ||
37
+ itemsCount === lastItemsCount.current) {
38
+ isFirstRender.current = false;
39
+ lastItemsCount.current = null;
40
+ return;
41
+ }
42
+ const message = isPlural(itemsCount) ? pluralMessage : singularMessage;
43
+ const messageToAnnounce = message.replace('%count%', itemsCount.toString());
44
+ react_native_1.AccessibilityInfo.announceForAccessibility(messageToAnnounce);
45
+ lastItemsCount.current = itemsCount;
46
+ }, [pluralMessage, singularMessage, data, isPlural]);
47
+ const rowsCount = lastItemsCount.current || initialCount.current || 0;
48
+ return __DEV__
49
+ ? {
50
+ rowsCount: rowsCount / numColumns,
51
+ columnsCount: numColumns,
52
+ style: checks === null || checks === void 0 ? void 0 : checks.debugStyle,
53
+ }
54
+ : {
55
+ rowsCount: rowsCount / numColumns,
56
+ columnsCount: numColumns,
57
+ };
58
+ };
59
+ exports.useDynamicList = useDynamicList;
60
+ function simpleIsPlural(count) {
61
+ return count !== 1;
62
+ }
@@ -0,0 +1,5 @@
1
+ export { DynamicFlatList } from './components/DynamicFlatList';
2
+ export { FlatList } from './components/FlatList';
3
+ export { ListWrapper } from './components/ListWrapper';
4
+ export { StaticFlatList } from './components/StaticFlatList';
5
+ export { useDynamicList } from './hooks/useDynamicList';
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useDynamicList = exports.StaticFlatList = exports.ListWrapper = exports.FlatList = exports.DynamicFlatList = void 0;
4
+ // Components
5
+ var DynamicFlatList_1 = require("./components/DynamicFlatList");
6
+ Object.defineProperty(exports, "DynamicFlatList", { enumerable: true, get: function () { return DynamicFlatList_1.DynamicFlatList; } });
7
+ var FlatList_1 = require("./components/FlatList");
8
+ Object.defineProperty(exports, "FlatList", { enumerable: true, get: function () { return FlatList_1.FlatList; } });
9
+ var ListWrapper_1 = require("./components/ListWrapper");
10
+ Object.defineProperty(exports, "ListWrapper", { enumerable: true, get: function () { return ListWrapper_1.ListWrapper; } });
11
+ var StaticFlatList_1 = require("./components/StaticFlatList");
12
+ Object.defineProperty(exports, "StaticFlatList", { enumerable: true, get: function () { return StaticFlatList_1.StaticFlatList; } });
13
+ // Hooks
14
+ var useDynamicList_1 = require("./hooks/useDynamicList");
15
+ Object.defineProperty(exports, "useDynamicList", { enumerable: true, get: function () { return useDynamicList_1.useDynamicList; } });