react-native-a11y
Version:
Improvements of a11y for ReactNative, this library improve work with reader and keyboard focus and reader in general.
39 lines • 1.75 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { useCallback } from "react";
import { useCanBeFocused } from "../../providers";
import { NativeFocusWrapper } from "./RCA11yFocusWrapper";
import { A11yModule } from "../../modules";
import { useFocusStyle } from "../../hooks";
export const KeyboardFocusView = /*#__PURE__*/React.forwardRef((_ref, ref) => {
let {
onFocusChange,
style,
focusStyle,
canBeFocused = true,
onKeyUpPress,
onKeyDownPress,
...props
} = _ref;
const canBecomeFocused = useCanBeFocused();
const setCurrentFocusTag = useCallback(e => {
var _e$nativeEvent;
A11yModule.currentFocusedTag = (e === null || e === void 0 ? void 0 : (_e$nativeEvent = e.nativeEvent) === null || _e$nativeEvent === void 0 ? void 0 : _e$nativeEvent.target) || undefined;
}, []);
const onFocus = useCallback(e => {
setCurrentFocusTag(e);
onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(e);
}, [onFocusChange, setCurrentFocusTag]);
const {
fStyle,
onFocusChangeHandler
} = useFocusStyle(focusStyle, onFocus);
return /*#__PURE__*/React.createElement(NativeFocusWrapper, _extends({
ref: ref,
style: [style, fStyle],
canBeFocused: canBecomeFocused && canBeFocused,
onKeyUpPress: onKeyUpPress,
onKeyDownPress: onKeyDownPress,
onFocusChange: onFocusChangeHandler
}, props));
});
//# sourceMappingURL=KeyboardFocusView.ios.js.map