UNPKG

react-native-a11y

Version:

Improvements of a11y for ReactNative, this library improve work with reader and keyboard focus and reader in general.

61 lines (60 loc) 2.03 kB
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); } /** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * * @format */ import React from "react"; import { Pressable as RNPressable } from "react-native"; import { KeyboardFocusView } from "../KeyboardFocusView"; const ANDROID_SPACE_KEY_CODE = 62; export const Pressable = /*#__PURE__*/React.forwardRef((_ref, ref) => { let { canBeFocused, focusStyle, style, onFocusChange, onPress, onLongPress, onKeyDownPress, ...props } = _ref; const onKeyUpPressHandler = React.useCallback(e => { const { nativeEvent: { keyCode, isLongPress } } = e; if (keyCode === ANDROID_SPACE_KEY_CODE) { if (isLongPress) { onLongPress === null || onLongPress === void 0 ? void 0 : onLongPress(e); } else { onPress === null || onPress === void 0 ? void 0 : onPress(e); } } }, [onLongPress, onPress]); const onPressablePressHandler = event => { if (event.nativeEvent.identifier !== undefined) { onPress === null || onPress === void 0 ? void 0 : onPress(event); } }; return /*#__PURE__*/React.createElement(KeyboardFocusView, { style: style, focusStyle: focusStyle, ref: ref, withView: false, onKeyUpPress: onKeyUpPressHandler, onKeyDownPress: onKeyDownPress, canBeFocused: canBeFocused, onFocusChange: onFocusChange }, /*#__PURE__*/React.createElement(RNPressable, _extends({ onPress: onPressablePressHandler, onLongPress: onLongPress }, props))); }); //# sourceMappingURL=Pressable.android.js.map