forked from FormidableLabs/eslint-plugin-react-native-a11y
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisTouchable.js
47 lines (43 loc) · 1.06 KB
/
isTouchable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* Returns boolean indicating whether a JSXOpeningElement
* is a <Touchable*> element
* @flow
*/
import type { JSXOpeningElement } from 'ast-types-flow';
import { elementType } from 'jsx-ast-utils';
import type { ESLintContext } from '../../flow/eslint';
const defaultTouchables = {
Touchable: true,
TouchableOpacity: true,
TouchableHighlight: true,
TouchableWithoutFeedback: true,
TouchableNativeFeedback: true,
TouchableBounce: true,
Pressable: true,
};
export default function isTouchable(
element: JSXOpeningElement,
context: ESLintContext = {
id: '',
options: [],
report: () => {},
getSourceCode: () => ({
text: '',
}),
sourceCode: {
text: '',
},
}
) {
const { options } = context;
let extraTouchables = [];
if (
options[0] &&
Object.prototype.hasOwnProperty.call(options[0], 'touchables')
) {
const { touchables } = options[0];
extraTouchables = [...touchables];
}
const elType = elementType(element);
return defaultTouchables[elType] || extraTouchables.includes(elType);
}