UNPKG

2.16 kBJavaScriptView Raw
1function _extends() { _extends = Object.assign || 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); }
2
3function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
5/**
6 * TouchableItem renders a touchable that looks native on both iOS and Android.
7 *
8 * It provides an abstraction on top of TouchableNativeFeedback and
9 * TouchableOpacity.
10 *
11 * On iOS you can pass the props of TouchableOpacity, on Android pass the props
12 * of TouchableNativeFeedback.
13 */
14import * as React from 'react';
15import { Platform, TouchableNativeFeedback, TouchableOpacity, View } from 'react-native';
16const ANDROID_VERSION_LOLLIPOP = 21;
17export default class TouchableItem extends React.Component {
18 render() {
19 /*
20 * TouchableNativeFeedback.Ripple causes a crash on old Android versions,
21 * therefore only enable it on Android Lollipop and above.
22 *
23 * All touchables on Android should have the ripple effect according to
24 * platform design guidelines.
25 * We need to pass the background prop to specify a borderless ripple effect.
26 */
27 if (Platform.OS === 'android' && Platform.Version >= ANDROID_VERSION_LOLLIPOP) {
28 const {
29 style,
30 ...rest
31 } = this.props;
32 return /*#__PURE__*/React.createElement(TouchableNativeFeedback, _extends({}, rest, {
33 style: null,
34 background: TouchableNativeFeedback.Ripple(this.props.pressColor, this.props.borderless)
35 }), /*#__PURE__*/React.createElement(View, {
36 style: style
37 }, React.Children.only(this.props.children)));
38 }
39
40 return /*#__PURE__*/React.createElement(TouchableOpacity, this.props, this.props.children);
41 }
42
43}
44
45_defineProperty(TouchableItem, "defaultProps", {
46 borderless: false,
47 pressColor: 'rgba(0, 0, 0, .32)'
48});
49//# sourceMappingURL=TouchableItem.js.map
\No newline at end of file