Skip to content

Commit 010d264

Browse files
authored
allow Identifiers in accessibilityActions (#113)
1 parent afe7b91 commit 010d264

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

__tests__/src/rules/has-valid-accessibility-actions-test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,24 @@ ruleTester.run('has-valid-accessibility-actions', rule, {
6262
onAccessibilityAction={useCallback()}
6363
/>`,
6464
},
65+
{
66+
code: `const onAccessibilityAction = (event) => {
67+
switch (event.nativeEvent.actionName) {
68+
case "delete":
69+
deleteAction();
70+
break;
71+
default:
72+
Alert.alert("Some text");
73+
}
74+
}
75+
76+
const accessibilityActionsList = [{ name: "delete", label: "Delete" }];
77+
78+
<TouchableOpacity
79+
accessibilityActions={accessibilityActionsList}
80+
onAccessibilityAction={onAccessibilityAction}
81+
/>`,
82+
},
6583
].map(parserOptionsMapper),
6684
invalid: [
6785
{

src/rules/has-valid-accessibility-actions.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ module.exports = {
4444
) {
4545
const handlerProp = getProp(node.attributes, 'onAccessibilityAction');
4646
const handlerPropType = handlerProp.value.expression.type;
47-
// CallExpressions are always assumed valid
48-
if (handlerPropType !== 'CallExpression') {
47+
// CallExpressions & Identifiers are always assumed valid
48+
if (
49+
handlerPropType !== 'CallExpression' &&
50+
handlerPropType !== 'Identifier'
51+
) {
4952
const handlerPropValue = getPropValue(handlerProp);
5053
if (typeof handlerPropValue !== 'function') {
5154
error(
@@ -56,8 +59,11 @@ module.exports = {
5659

5760
const actionsProp = getProp(node.attributes, 'accessibilityActions');
5861
const actionsPropType = actionsProp.value.expression.type;
59-
// CallExpressions are always assumed valid
60-
if (actionsPropType !== 'CallExpression') {
62+
// CallExpressions & Identifiers are always assumed valid
63+
if (
64+
actionsPropType !== 'CallExpression' &&
65+
actionsPropType !== 'Identifier'
66+
) {
6167
const attrValue = getPropValue(actionsProp);
6268

6369
if (!Array.isArray(attrValue)) {

0 commit comments

Comments
 (0)