Skip to content

Commit

Permalink
fix(performance): add missing useMemo on useSpatialNavigatorFocusable…
Browse files Browse the repository at this point in the history
…AccessibilityProps
  • Loading branch information
pierpo committed Feb 14, 2024
1 parent 7fcd004 commit 6b759c7
Showing 1 changed file with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import { useMemo } from 'react';
import { useParentId } from '../context/ParentIdContext';
import { useSpatialNavigator } from '../context/SpatialNavigatorContext';

export const useSpatialNavigatorFocusableAccessibilityProps = () => {
const spatialNavigator = useSpatialNavigator();
const id = useParentId();

return {
accessible: true,
accessibilityRole: 'button' as const,
accessibilityActions: [{ name: 'activate' }] as const,
onAccessibilityAction: () => {
const currentNode = spatialNavigator.getCurrentFocusNode();
const accessibilityProps = useMemo(
() => ({
accessible: true,
accessibilityRole: 'button' as const,
accessibilityActions: [{ name: 'activate' }] as const,
onAccessibilityAction: () => {
const currentNode = spatialNavigator.getCurrentFocusNode();

if (currentNode?.id === id) {
spatialNavigator.getCurrentFocusNode()?.onSelect?.(currentNode);
} else {
spatialNavigator.grabFocus(id);
}
},
};
if (currentNode?.id === id) {
spatialNavigator.getCurrentFocusNode()?.onSelect?.(currentNode);
} else {
spatialNavigator.grabFocus(id);
}
},
}),
[id, spatialNavigator],
);

return accessibilityProps;
};

0 comments on commit 6b759c7

Please sign in to comment.