@react-native-ama/core 1.2.1 → 2.0.0-beta.1
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.
- package/dist/ReactNativeAma.types.d.ts +66 -0
- package/dist/ReactNativeAma.types.js +2 -0
- package/dist/ReactNativeAmaModule.d.ts +11 -0
- package/dist/ReactNativeAmaModule.js +5 -0
- package/dist/ReactNativeAmaModule.web.d.ts +9 -0
- package/dist/ReactNativeAmaModule.web.js +27 -0
- package/dist/ReactNativeAmaView.d.ts +3 -0
- package/dist/ReactNativeAmaView.js +32 -0
- package/dist/ReactNativeAmaView.web.d.ts +3 -0
- package/dist/ReactNativeAmaView.web.js +34 -0
- package/dist/{src/components → components}/AMAProvider.d.ts +4 -2
- package/dist/{src/components → components}/AMAProvider.js +19 -45
- package/dist/{src/components → components}/AutofocusContainer.d.ts +2 -1
- package/dist/{src/components → components}/HideChildrenFromAccessibilityTree.d.ts +1 -1
- package/dist/{src/components → components}/HideChildrenFromAccessibilityTree.js +7 -5
- package/dist/{src/hooks → hooks}/useFocus.js +10 -3
- package/dist/{src/index.d.ts → index.d.ts} +3 -2
- package/dist/index.js +38 -0
- package/dist/internals/checks/checkAriaLabel.d.ts +3 -0
- package/dist/internals/checks/checkAriaLabel.js +15 -0
- package/dist/internals/checks/checkAriaRole.d.ts +3 -0
- package/dist/internals/checks/checkAriaRole.js +48 -0
- package/dist/internals/checks/checkContrast.d.ts +3 -0
- package/dist/internals/checks/checkContrast.js +84 -0
- package/dist/internals/checks/checkImageAlt.d.ts +3 -0
- package/dist/internals/checks/checkImageAlt.js +20 -0
- package/dist/internals/checks/checkIsUppercase.d.ts +8 -0
- package/dist/internals/checks/checkIsUppercase.js +30 -0
- package/dist/internals/checks/checkLongNumber.d.ts +3 -0
- package/dist/internals/checks/checkLongNumber.js +31 -0
- package/dist/internals/checks/checkMinimumSize.d.ts +3 -0
- package/dist/internals/checks/checkMinimumSize.js +22 -0
- package/dist/internals/checks/checkTextInput.d.ts +3 -0
- package/dist/internals/checks/checkTextInput.js +51 -0
- package/dist/internals/checks/performChecks.d.ts +3 -0
- package/dist/internals/checks/performChecks.js +23 -0
- package/dist/internals/components/AMAErrorOverlay.d.ts +5 -0
- package/dist/internals/components/AMAErrorOverlay.js +334 -0
- package/dist/internals/components/AMARuleError.d.ts +7 -0
- package/dist/internals/components/AMARuleError.js +161 -0
- package/dist/internals/config.d.ts +23 -0
- package/dist/internals/config.js +33 -0
- package/dist/internals/types.d.ts +9 -0
- package/dist/internals/types.js +2 -0
- package/dist/internals/useAMADev.d.ts +8 -0
- package/dist/internals/useAMADev.dev.d.ts +2 -0
- package/dist/internals/useAMADev.dev.js +110 -0
- package/dist/internals/useAMADev.js +6 -0
- package/dist/internals/useAMADevNodeChecks.dev.d.ts +16 -0
- package/dist/internals/useAMADevNodeChecks.dev.js +115 -0
- package/dist/internals/useAMADevUiInteraction.dev.d.ts +7 -0
- package/dist/internals/useAMADevUiInteraction.dev.js +100 -0
- package/dist/internals/utils/amaClearHighlight.d.ts +2 -0
- package/dist/internals/utils/amaClearHighlight.js +12 -0
- package/dist/internals/utils/amaHighlightComponent.d.ts +3 -0
- package/dist/internals/utils/amaHighlightComponent.js +51 -0
- package/dist/internals/utils/constants.d.ts +3 -0
- package/dist/internals/utils/constants.js +32 -0
- package/dist/internals/utils/getErrorColor.d.ts +2 -0
- package/dist/internals/utils/getErrorColor.js +10 -0
- package/dist/internals/utils/getRuleAction.d.ts +2 -0
- package/dist/internals/utils/getRuleAction.js +40 -0
- package/dist/internals/utils/getRuleErrorInfo.d.ts +7 -0
- package/dist/internals/utils/getRuleErrorInfo.js +19 -0
- package/dist/internals/utils/ignoreContrastCheck.d.ts +1 -0
- package/dist/internals/utils/ignoreContrastCheck.js +15 -0
- package/dist/internals/utils/interpolateAnimationStates.d.ts +2 -0
- package/dist/internals/utils/interpolateAnimationStates.js +43 -0
- package/dist/internals/utils/isA11yLabelAllowed.d.ts +1 -0
- package/dist/internals/utils/isA11yLabelAllowed.js +14 -0
- package/dist/internals/utils/isRuleDisabled.d.ts +2 -0
- package/dist/internals/utils/isRuleDisabled.js +10 -0
- package/dist/internals/utils/logError.d.ts +2 -0
- package/dist/internals/utils/logError.js +36 -0
- package/dist/internals/utils/logFoundIssues.d.ts +2 -0
- package/dist/internals/utils/logFoundIssues.js +23 -0
- package/dist/internals/utils/logger.d.ts +6 -0
- package/dist/internals/utils/logger.js +15 -0
- package/dist/internals/utils/minimumTouchableSize.d.ts +1 -0
- package/dist/internals/utils/minimumTouchableSize.js +9 -0
- package/dist/internals/utils/platformHelpers.d.ts +2 -0
- package/dist/internals/utils/platformHelpers.js +6 -0
- package/dist/internals/utils/rules.d.ts +22 -0
- package/dist/internals/utils/rules.js +253 -0
- package/dist/scripts/create-config.js +4 -3
- package/package.json +62 -20
- package/src/ReactNativeAma.types.ts +70 -0
- package/src/ReactNativeAmaModule.ts +18 -0
- package/src/ReactNativeAmaModule.web.ts +14 -0
- package/src/ReactNativeAmaView.tsx +9 -0
- package/src/ReactNativeAmaView.web.tsx +15 -0
- package/src/__mocks__/ReactNativeAmaModule.ts +9 -0
- package/src/components/AMAProvider.integration.test.tsx +3 -96
- package/src/components/AMAProvider.test.tsx +9 -4
- package/src/components/AMAProvider.tsx +40 -76
- package/src/components/AutofocusContainer.test.tsx +4 -5
- package/src/components/AutofocusContainer.tsx +20 -5
- package/src/components/HideChildrenFromAccessibilityTree.test.tsx +23 -39
- package/src/components/HideChildrenFromAccessibilityTree.tsx +12 -11
- package/src/hooks/useFocus.test.ts +20 -20
- package/src/hooks/useFocus.ts +14 -6
- package/src/hooks/useTimedAction.android.test.ts +0 -1
- package/src/hooks/useTimedAction.ios.test.ts +0 -1
- package/src/hooks/useTimedAction.ts +0 -1
- package/src/index.ts +4 -2
- package/src/internals/checks/checkAriaLabel.test.ts +165 -0
- package/src/internals/checks/checkAriaLabel.ts +16 -0
- package/src/internals/checks/checkAriaRole.test.ts +429 -0
- package/src/internals/checks/checkAriaRole.ts +60 -0
- package/src/internals/checks/checkContrast.test.ts +278 -0
- package/src/internals/checks/checkContrast.ts +109 -0
- package/src/internals/checks/checkImageAlt.test.ts +125 -0
- package/src/internals/checks/checkImageAlt.ts +23 -0
- package/src/internals/checks/checkIsUppercase.test.ts +399 -0
- package/src/internals/checks/checkIsUppercase.ts +46 -0
- package/src/internals/checks/checkLongNumber.test.ts +111 -0
- package/src/internals/checks/checkLongNumber.ts +34 -0
- package/src/internals/checks/checkMinimumSize.test.ts +67 -0
- package/src/internals/checks/checkMinimumSize.ts +25 -0
- package/src/internals/checks/checkTextInput.ts +65 -0
- package/src/internals/checks/performChecks.test.ts +171 -0
- package/src/internals/checks/performChecks.ts +24 -0
- package/src/internals/components/AMAErrorOverlay.test.tsx +139 -0
- package/src/internals/components/AMAErrorOverlay.tsx +451 -0
- package/src/internals/components/AMARuleError.test.tsx +93 -0
- package/src/internals/components/AMARuleError.tsx +225 -0
- package/src/internals/config.ts +58 -0
- package/src/internals/types.ts +11 -0
- package/src/internals/useAMADev.dev.ts +153 -0
- package/src/internals/useAMADev.test.ts +260 -0
- package/src/internals/useAMADev.ts +17 -0
- package/src/internals/useAMADevNodeChecks.dev.ts +178 -0
- package/src/internals/useAMADevUiInteraction.dev.ts +164 -0
- package/src/internals/utils/amaClearHighlight.test.ts +21 -0
- package/src/internals/utils/amaClearHighlight.ts +8 -0
- package/src/internals/utils/amaHighlightComponent.test.ts +74 -0
- package/src/internals/utils/amaHighlightComponent.ts +46 -0
- package/src/internals/utils/constants.ts +33 -0
- package/src/internals/utils/devMode.test.ts +99 -0
- package/src/internals/utils/getErrorColor.test.ts +18 -0
- package/src/internals/utils/getErrorColor.ts +8 -0
- package/src/internals/utils/getRuleAction.ts +13 -0
- package/src/internals/utils/getRuleErrorInfo.test.ts +59 -0
- package/src/internals/utils/getRuleErrorInfo.ts +26 -0
- package/src/internals/utils/ignoreContrastCheck.test.ts +34 -0
- package/src/internals/utils/ignoreContrastCheck.ts +11 -0
- package/src/internals/utils/interpolateAnimation.test.ts +176 -0
- package/src/internals/utils/interpolateAnimationStates.ts +55 -0
- package/src/internals/utils/isA11yLabelAllowed.test.ts +39 -0
- package/src/internals/utils/isA11yLabelAllowed.ts +10 -0
- package/src/internals/utils/isRuleDisabled.test.ts +35 -0
- package/src/internals/utils/isRuleDisabled.ts +10 -0
- package/src/internals/utils/logError.test.ts +148 -0
- package/src/internals/utils/logError.ts +41 -0
- package/src/internals/utils/logFoundIssues.test.ts +98 -0
- package/src/internals/utils/logFoundIssues.ts +22 -0
- package/src/internals/utils/logger.test.ts +26 -0
- package/src/internals/utils/logger.ts +15 -0
- package/src/internals/utils/loggerMethods.test.ts +38 -0
- package/src/internals/utils/minimumTouchableSize.test.ts +28 -0
- package/src/internals/utils/minimumTouchableSize.tsx +9 -0
- package/src/internals/utils/platformHelpers.test.ts +11 -0
- package/src/internals/utils/platformHelpers.ts +4 -0
- package/src/internals/utils/rules.ts +363 -0
- package/src/scripts/create-config.ts +21 -0
- package/dist/src/hooks/useButtonChecks.d.ts +0 -6
- package/dist/src/hooks/useButtonChecks.js +0 -51
- package/dist/src/hooks/useChecks.d.ts +0 -15
- package/dist/src/hooks/useChecks.js +0 -152
- package/dist/src/index.js +0 -20
- package/src/hooks/useButtonChecks.ts +0 -73
- package/src/hooks/useChecks.test.ts +0 -214
- package/src/hooks/useChecks.ts +0 -207
- /package/dist/{src/components → components}/AutofocusContainer.js +0 -0
- /package/dist/{src/hooks → hooks}/useFocus.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useTimedAction.d.ts +0 -0
- /package/dist/{src/hooks → hooks}/useTimedAction.js +0 -0
- /package/dist/{src/utils → utils}/numerify.d.ts +0 -0
- /package/dist/{src/utils → utils}/numerify.js +0 -0
package/src/hooks/useChecks.ts
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ERROR_STYLE,
|
|
3
|
-
LogParams,
|
|
4
|
-
checkAccessibilityRole as checkAccessibilityRoleImplementation,
|
|
5
|
-
checkFocusTrap as checkFocusTrapImplementation,
|
|
6
|
-
checkForAccessibilityState,
|
|
7
|
-
checkMinimumSize as checkMinimumSizeImplementation,
|
|
8
|
-
contrastChecker as contrastCheckerImplementation,
|
|
9
|
-
getRuleAction,
|
|
10
|
-
logFailure,
|
|
11
|
-
noUndefinedProperty as noUndefinedPropertyImplementation,
|
|
12
|
-
uppercaseStringChecker as noUppercaseStringCheckerImplementation,
|
|
13
|
-
uppercaseChecker as uppercaseCheckerImplementation,
|
|
14
|
-
type CheckFocusTrap,
|
|
15
|
-
type CheckForAccessibilityState,
|
|
16
|
-
type ContrastChecker,
|
|
17
|
-
type NoUndefinedProperty,
|
|
18
|
-
type UppercaseChecker,
|
|
19
|
-
type UppercaseStringChecker,
|
|
20
|
-
} from '@react-native-ama/internal';
|
|
21
|
-
import * as React from 'react';
|
|
22
|
-
import {
|
|
23
|
-
AccessibilityRole,
|
|
24
|
-
InteractionManager,
|
|
25
|
-
LayoutChangeEvent,
|
|
26
|
-
} from 'react-native';
|
|
27
|
-
|
|
28
|
-
import { isDevContextValue, useAMAContext } from '../components/AMAProvider';
|
|
29
|
-
|
|
30
|
-
export const useChecks = () => {
|
|
31
|
-
const context = useAMAContext();
|
|
32
|
-
|
|
33
|
-
if (!isDevContextValue(context)) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Because the AMA Error view cannot be removed by default, this hacky solution
|
|
39
|
-
* allows the dev to hide it if all the issues have been solved.
|
|
40
|
-
*/
|
|
41
|
-
const fakeRandom = React.useRef('' + Date.now() + Math.random() * 42);
|
|
42
|
-
const hasErrors = React.useRef(false);
|
|
43
|
-
const failedTests = React.useRef<string[]>([]);
|
|
44
|
-
const shouldCheckLayout = React.useRef(true);
|
|
45
|
-
const layoutCheckTimeout = React.useRef<NodeJS.Timeout>();
|
|
46
|
-
const [minimumSizeFailed, setMinimumSizeFailed] = React.useState(false);
|
|
47
|
-
const [debugStyle, setDebugStyle] = React.useState<any>({});
|
|
48
|
-
|
|
49
|
-
const { trackError, removeError } = context;
|
|
50
|
-
|
|
51
|
-
const logResult = (
|
|
52
|
-
name: string,
|
|
53
|
-
result: LogParams | LogParams[] | null,
|
|
54
|
-
): Record<string, any> => {
|
|
55
|
-
const index = failedTests.current.indexOf(name);
|
|
56
|
-
|
|
57
|
-
if (result === null) {
|
|
58
|
-
if (index >= 0 && hasErrors.current) {
|
|
59
|
-
failedTests.current.splice(index);
|
|
60
|
-
|
|
61
|
-
hasErrors.current = false;
|
|
62
|
-
|
|
63
|
-
InteractionManager.runAfterInteractions(() => {
|
|
64
|
-
removeError(fakeRandom.current);
|
|
65
|
-
|
|
66
|
-
setTimeout(() => {
|
|
67
|
-
setDebugStyle({});
|
|
68
|
-
}, 100);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const results = Array.isArray(result) ? result : [result];
|
|
74
|
-
|
|
75
|
-
results.forEach(logParam => {
|
|
76
|
-
if (logParam === null) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const action = getRuleAction?.(logParam.rule);
|
|
81
|
-
const hasFailed = action === 'MUST_NOT' || action === 'MUST';
|
|
82
|
-
|
|
83
|
-
if (index < 0) {
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
logFailure?.({ action, ...logParam });
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (!hasFailed) {
|
|
89
|
-
return;
|
|
90
|
-
} else if (index >= 0) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
failedTests.current.push(name);
|
|
95
|
-
|
|
96
|
-
InteractionManager.runAfterInteractions(() => {
|
|
97
|
-
trackError(fakeRandom.current);
|
|
98
|
-
|
|
99
|
-
setDebugStyle(ERROR_STYLE);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
hasErrors.current = true;
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// @ts-ignore
|
|
106
|
-
return hasErrors.current ? ERROR_STYLE : {};
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const noUndefinedProperty = <T>(params: NoUndefinedProperty<T>) =>
|
|
110
|
-
logResult(
|
|
111
|
-
`noUndefinedProperty ${params.property as string}`,
|
|
112
|
-
noUndefinedPropertyImplementation(params),
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
const contrastChecker = (params: ContrastChecker) =>
|
|
116
|
-
logResult('contrastChecker', contrastCheckerImplementation(params));
|
|
117
|
-
|
|
118
|
-
const checkMinimumSize = (params: LayoutChangeEvent) => {
|
|
119
|
-
return logResult(
|
|
120
|
-
'checkMinimumSize',
|
|
121
|
-
checkMinimumSizeImplementation(params),
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const noUppercaseStringChecker = (params: UppercaseStringChecker) =>
|
|
126
|
-
logResult(
|
|
127
|
-
'accessibilityLabelChecker',
|
|
128
|
-
noUppercaseStringCheckerImplementation(params),
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const uppercaseChecker = (params: UppercaseChecker) =>
|
|
132
|
-
logResult('uppercaseChecker', uppercaseCheckerImplementation(params));
|
|
133
|
-
|
|
134
|
-
const checkFocusTrap = (params: CheckFocusTrap) => {
|
|
135
|
-
checkFocusTrapImplementation(params).then(result => {
|
|
136
|
-
logResult('checkFocusTrap', result);
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const checkAccessibilityRole = (param: AccessibilityRole) => {
|
|
141
|
-
logResult(
|
|
142
|
-
'checkAccessibilityRole',
|
|
143
|
-
checkAccessibilityRoleImplementation(param),
|
|
144
|
-
);
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const checkCompatibleAccessibilityState = (props: Record<string, any>) => {
|
|
148
|
-
const amaStates = ['checked', 'selected'];
|
|
149
|
-
|
|
150
|
-
const params: CheckForAccessibilityState = {
|
|
151
|
-
accessibilityRole: props.accessibilityRole,
|
|
152
|
-
accessibilityState: props?.accessibilityState,
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
amaStates.forEach(amaState => {
|
|
156
|
-
if (amaState in props) {
|
|
157
|
-
// @ts-ignore
|
|
158
|
-
params[amaState] = props[amaState];
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
logResult(
|
|
163
|
-
'checkCompatibleAccessibilityState',
|
|
164
|
-
checkForAccessibilityState(params),
|
|
165
|
-
);
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
const onLayout = (event: LayoutChangeEvent) => {
|
|
169
|
-
/**
|
|
170
|
-
* When the check fails there are situation when adding a border makes the
|
|
171
|
-
* component meet the minimum size requirement, and this causes a loop as the
|
|
172
|
-
* state is update continuously between true and false.
|
|
173
|
-
* To "avoid" that we wait at least 100ms before checking the size again, as
|
|
174
|
-
* this gives the dev time to hot-reload the changes.
|
|
175
|
-
*/
|
|
176
|
-
if (!shouldCheckLayout.current) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
shouldCheckLayout.current = false;
|
|
181
|
-
|
|
182
|
-
// @ts-ignore
|
|
183
|
-
clearTimeout(layoutCheckTimeout.current);
|
|
184
|
-
|
|
185
|
-
layoutCheckTimeout.current = setTimeout(() => {
|
|
186
|
-
shouldCheckLayout.current = true;
|
|
187
|
-
}, 1000);
|
|
188
|
-
|
|
189
|
-
const result = checkMinimumSize(event);
|
|
190
|
-
|
|
191
|
-
setMinimumSizeFailed(Object.keys(result).length > 0);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
logResult,
|
|
196
|
-
noUndefinedProperty,
|
|
197
|
-
contrastChecker,
|
|
198
|
-
onLayout,
|
|
199
|
-
noUppercaseStringChecker,
|
|
200
|
-
uppercaseChecker,
|
|
201
|
-
checkFocusTrap,
|
|
202
|
-
minimumSizeFailed,
|
|
203
|
-
checkCompatibleAccessibilityState,
|
|
204
|
-
checkAccessibilityRole,
|
|
205
|
-
debugStyle,
|
|
206
|
-
};
|
|
207
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|