import React from 'react'; import {GestureResponderEvent, Image, StyleProp, StyleSheet, Text, TouchableHighlight, View, ViewStyle} from 'react-native'; import Icon from '../icon'; import {WithTheme, WithThemeStyles} from '../style'; import {BriefProps as BriefBasePropsType, ListItemPropsType} from './PropsType'; import ListStyles, {ListStyle} from './style'; export interface ListItemProps extends ListItemPropsType, WithThemeStyles { onPress?: (event: GestureResponderEvent) => void; onPressIn?: (event: GestureResponderEvent) => void; onPressOut?: (event: GestureResponderEvent) => void; delayLongPress?: number; onLongPress?: (event: GestureResponderEvent) => void; style?: StyleProp; } export interface BriefProps extends BriefBasePropsType, WithThemeStyles> {} export class Brief extends React.Component { render() { const {children, style, wrap} = this.props; let numberOfLines = {}; if (wrap === false) { numberOfLines = { numberOfLines: 1, }; } return ( {(styles) => ( {children} )} ); } } export default class Item extends React.Component { static defaultProps: Partial = { multipleLine: false, wrap: false, delayLongPress: 500, onLongPress: () => {}, }; static Brief = Brief; render() { const { styles, children, multipleLine, thumb, extra, arrow, style, onPress, onPressIn, onPressOut, onLongPress, delayLongPress, wrap, disabled, align, ...restProps } = this.props; return ( {(itemStyles) => { let numberOfLines = {}; if (wrap === false) { numberOfLines = { numberOfLines: 1, }; } let underlayColor = {}; if (!disabled && onPress) { underlayColor = { underlayColor: StyleSheet.flatten(itemStyles.underlayColor).backgroundColor, activeOpacity: 0.5, }; } else { underlayColor = { activeOpacity: 1, }; } let alignStyle = {}; if (align === 'top') { alignStyle = { alignItems: 'flex-start', }; } else if (align === 'bottom') { alignStyle = { alignItems: 'flex-end', }; } let contentDom; if (Array.isArray(children)) { const tempContentDom: any[] = []; children.forEach((el, index) => { if (React.isValidElement(el)) { tempContentDom.push(el); } else { tempContentDom.push( {el} , ); } }); contentDom = {tempContentDom}; } else { if (children && React.isValidElement(children)) { contentDom = {children}; } else { contentDom = ( {children} ); } } let extraDom; if (extra) { extraDom = ( {extra} ); if (React.isValidElement(extra)) { const extraChildren = (extra.props as any).children; if (Array.isArray(extraChildren)) { const tempExtraDom: any[] = []; extraChildren.forEach((el, index) => { if (typeof el === 'string') { tempExtraDom.push( {el} , ); } else { tempExtraDom.push(el); } }); extraDom = {tempExtraDom}; } else { extraDom = extra; } } } const arrEnum = { horizontal: , down: , up: , }; const itemView = ( {typeof thumb === 'string' ? ( ) : ( thumb )} {contentDom} {extraDom} {arrow ? (arrEnum as any)[arrow] || : null} ); return ( {itemView} ); }} ); } }