Skip to content

Commit

Permalink
feat: add ellipsize props to ListItem (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkmyr authored and ferrannp committed Mar 22, 2019
1 parent e899c55 commit 00457a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/components/List/ListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ type Props = $RemoveChildren<typeof TouchableRipple> & {|
* Style that is passed to Description element.
*/
descriptionStyle?: TextStyleProp,
/**
* Ellipsize Mode for the Title
*/
titleEllipsizeMode?: 'head' | 'middle' | 'tail' | 'clip',
/**
* Ellipsize Mode for the Description
*/
descriptionEllipsizeMode?: 'head' | 'middle' | 'tail' | 'clip',
|};

/**
Expand Down Expand Up @@ -90,6 +98,8 @@ class ListItem extends React.Component<Props> {
style,
titleStyle,
descriptionStyle,
titleEllipsizeMode,
descriptionEllipsizeMode,
...rest
} = this.props;
const titleColor = color(theme.colors.text)
Expand All @@ -111,13 +121,15 @@ class ListItem extends React.Component<Props> {
{left ? left({ color: descriptionColor }) : null}
<View style={[styles.item, styles.content]} pointerEvents="none">
<Text
ellipsizeMode={titleEllipsizeMode}
numberOfLines={1}
style={[styles.title, { color: titleColor }, titleStyle]}
>
{title}
</Text>
{description ? (
<Text
ellipsizeMode={descriptionEllipsizeMode}
numberOfLines={2}
style={[
styles.description,
Expand Down
2 changes: 2 additions & 0 deletions typings/components/List.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface ItemProps extends TouchableRipplePropsWithoutChildren {
right?: (props: { color: string }) => React.ReactNode;
titleStyle?: StyleProp<TextStyle>;
descriptionStyle?: StyleProp<TextStyle>;
titleEllipsizeMode?: 'head' | 'middle' | 'tail' | 'clip';
descriptionEllipsizeMode?: 'head' | 'middle' | 'tail' | 'clip';
}

export declare class Item extends React.Component<ItemProps> {}
Expand Down

0 comments on commit 00457a9

Please sign in to comment.