@crossed/primitive
Version:
A universal & performant styling library for React Native, Next.js & React
37 lines (36 loc) • 1.01 kB
JavaScript
import { jsx } from "react/jsx-runtime";
import { View } from "react-native";
import ReactFocusLock, { useFocusScope } from "react-focus-lock";
import { useCallback } from "react";
const Focus = ({ children, ...props }) => {
return /* @__PURE__ */ jsx(ReactFocusLock, { lockProps: props, disabled: true, as: View, children });
};
const useFocus = ({ onPress }) => {
const { focusNext, focusPrev } = useFocusScope();
const onKey = useCallback(
(event) => {
if (event.code === "ArrowDown") {
focusNext();
event.stopPropagation();
event.preventDefault();
}
if (event.code === "ArrowUp") {
event.stopPropagation();
event.preventDefault();
focusPrev();
}
if (event.code === "Space") {
onPress();
event.stopPropagation();
event.preventDefault();
}
},
[focusNext, focusPrev, onPress]
);
return { onKeyDown: onKey };
};
export {
Focus,
useFocus
};
//# sourceMappingURL=Focus.web.js.map