UNPKG

2.97 kBJavaScriptView Raw
1var __rest = (this && this.__rest) || function (s, e) {
2 var t = {};
3 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4 t[p] = s[p];
5 if (s != null && typeof Object.getOwnPropertySymbols === "function")
6 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8 t[p[i]] = s[p[i]];
9 }
10 return t;
11};
12import React, { useRef } from 'react';
13import { Platform, StyleSheet, TouchableHighlight, View, } from 'react-native';
14import { withTheme } from '../config';
15const ListItemBase = (props) => {
16 var _a, _b;
17 const { containerStyle, onPress, onLongPress, Component = onPress || onLongPress ? TouchableHighlight : View, disabled, disabledStyle, bottomDivider, topDivider, pad = 16, linearGradientProps, ViewComponent = View, theme, children } = props, attributes = __rest(props, ["containerStyle", "onPress", "onLongPress", "Component", "disabled", "disabledStyle", "bottomDivider", "topDivider", "pad", "linearGradientProps", "ViewComponent", "theme", "children"]);
18 if (props.linearGradientProps && !props.ViewComponent) {
19 console.error("You need to pass a ViewComponent to use linearGradientProps !\nExample: ViewComponent={require('react-native-linear-gradient')}");
20 }
21 return (<Component {...attributes} onPress={onPress} onLongPress={onLongPress} disabled={disabled}>
22 <PadView Component={ViewComponent} {...linearGradientProps} style={StyleSheet.flatten([
23 Object.assign(Object.assign({}, Platform.select({
24 ios: {
25 padding: 14,
26 },
27 default: {
28 padding: 16,
29 },
30 })), { flexDirection: 'row', alignItems: 'center', backgroundColor: (_a = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _a === void 0 ? void 0 : _a.white, borderColor: (_b = theme === null || theme === void 0 ? void 0 : theme.colors) === null || _b === void 0 ? void 0 : _b.divider }),
31 topDivider && { borderTopWidth: StyleSheet.hairlineWidth },
32 bottomDivider && { borderBottomWidth: StyleSheet.hairlineWidth },
33 containerStyle,
34 disabled && disabledStyle,
35 ])} pad={pad}>
36 {children}
37 </PadView>
38 </Component>);
39};
40const PadView = (_a) => {
41 var { children, pad, Component } = _a, props = __rest(_a, ["children", "pad", "Component"]);
42 const _root = useRef(null);
43 const childrens = React.Children.toArray(children);
44 const { length } = childrens;
45 const Container = Component || View;
46 return (<Container {...props} ref={_root} testID="padView">
47 {React.Children.map(childrens, (child, index) => child && [
48 child,
49 index !== length - 1 && <View style={{ paddingLeft: pad }}/>,
50 ])}
51 </Container>);
52};
53export { ListItemBase };
54export default withTheme(ListItemBase, 'ListItem');
55
\No newline at end of file