Skip to content

Commit

Permalink
chore: Format the code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 31, 2021
1 parent a25d3b5 commit 61dc909
Showing 1 changed file with 56 additions and 21 deletions.
77 changes: 56 additions & 21 deletions components/List/Item.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import React, { Component } from 'react';
import { View, ViewProps, StyleSheet, StyleProp, TextStyle, ViewStyle, TouchableHighlight, TouchableWithoutFeedbackProps, Text, TextProps } from 'react-native';
import React, {Component} from 'react';
import {
View,
ViewProps,
StyleSheet,
StyleProp,
TextStyle,
ViewStyle,
TouchableHighlight,
TouchableWithoutFeedbackProps,
Text,
} from 'react-native';

export interface ListItemProps extends ViewProps, TouchableWithoutFeedbackProps {
export interface ListItemProps
extends ViewProps,
TouchableWithoutFeedbackProps {
underlayColor?: string;
paddingLeft?: number;
extra?: React.ReactNode;
Expand All @@ -17,50 +29,73 @@ export default class ListItem extends Component<ListItemProps> {
static defaultProps: ListItemProps = {
underlayColor: '#DADADA',
// paddingLeft: 16,
}
};
render() {
const { children, style, onPress, paddingLeft, underlayColor, extra, extraStyle, touchableStyle, size, ...otherProps } = this.props;
const {
children,
style,
onPress,
paddingLeft,
underlayColor,
extra,
extraStyle,
touchableStyle,
size,
...otherProps
} = this.props;
let sizeStyle = {};
if (size && styles[size]) {
sizeStyle = styles[size];
}
const cell = (
<View style={[styles.border, sizeStyle, style]} {...otherProps}>
<View style={{ flex: 1, flexDirection: 'row' }}>
<View style={{flex: 1, flexDirection: 'row'}}>
{React.Children.toArray(children).map((child, idx) => {
if (typeof children === 'string') {
return <Text key={idx}>{children}</Text>;
}
if (!React.isValidElement(child)) return null;
return React.cloneElement(child, { key: idx });
if (!React.isValidElement(child)) {
return null;
}
return React.cloneElement(child, {key: idx});
})}
</View>
{extra && (
<View style={{ paddingRight: 10 }}>
{typeof extra === 'string' ? <Text style={extraStyle}>{extra}</Text> : <View style={[{ flexDirection: 'row', alignItems: 'center' }, extraStyle]}>{extra}</View>}
<View style={{paddingRight: 10}}>
{typeof extra === 'string' ? (
<Text style={extraStyle}>{extra}</Text>
) : (
<View
style={[
{flexDirection: 'row', alignItems: 'center'},
extraStyle,
]}>
{extra}
</View>
)}
</View>
)}
</View>
);

if (onPress) {
return (
<TouchableHighlight underlayColor={underlayColor} style={[styles.warpper, { paddingLeft }, touchableStyle]} onPress={onPress} {...otherProps}>
<TouchableHighlight
underlayColor={underlayColor}
style={[styles.warpper, {paddingLeft}, touchableStyle]}
onPress={onPress}
{...otherProps}>
{cell}
</TouchableHighlight>
)
);
}
return (
<View style={[{ paddingLeft }, styles.warpper]}>
{cell}
</View>
);
return <View style={[{paddingLeft}, styles.warpper]}>{cell}</View>;
}
}

const styles = StyleSheet.create({
warpper: {
backgroundColor: '#fff'
backgroundColor: '#fff',
},
border: {
borderBottomWidth: StyleSheet.hairlineWidth,
Expand All @@ -69,12 +104,12 @@ const styles = StyleSheet.create({
alignItems: 'center',
},
default: {
paddingVertical: 12
paddingVertical: 12,
},
small: {
paddingVertical: 10
paddingVertical: 10,
},
large: {
paddingVertical: 16
paddingVertical: 16,
},
});

0 comments on commit 61dc909

Please sign in to comment.