Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tertiaryText Option #67

Merged
merged 2 commits into from
Jan 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/ListItem/ListItem.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const propTypes = {
PropTypes.shape({
primaryText: PropTypes.string.isRequired,
secondaryText: PropTypes.string,
tertiaryText: PropTypes.string,
}),
]),

Expand Down Expand Up @@ -65,7 +66,11 @@ function getNumberOfSecondaryTextLines(numberOfLines) {
function getNumberOfLines(props) {
const { numberOfLines, centerElement } = props;

if (centerElement && centerElement.secondaryText && (!numberOfLines || numberOfLines < 2)) {
if (centerElement && centerElement.secondaryText && centerElement.tertiaryText
&& (!numberOfLines || numberOfLines < 3)) {
return 3;
} else if (centerElement && centerElement.secondaryText &&
(!numberOfLines || numberOfLines < 2)) {
return 2;
}

Expand Down Expand Up @@ -160,6 +165,10 @@ function getStyles(props, context, state) {
listItem.secondaryText,
props.style.secondaryText,
],
tertiaryText: [
listItem.tertiaryText,
props.style.secondaryText,
],
rightElementContainer: [
listItem.rightElementContainer,
props.style.rightElementContainer,
Expand Down Expand Up @@ -244,23 +253,23 @@ class ListItem extends PureComponent {
renderCenterElement = (styles) => {
const { centerElement } = this.props;
const numberOfLines = getNumberOfSecondaryTextLines(this.state.numberOfLines);

let content = null;

if (React.isValidElement(centerElement)) {
content = centerElement;
} else if (centerElement) {
let primaryText = null;
let secondaryText = null;
let tertiaryText = null;

if (typeof centerElement === 'string') {
primaryText = centerElement;
} else {
primaryText = centerElement.primaryText;
secondaryText = centerElement.secondaryText;
tertiaryText = centerElement.tertiaryText;
}


const lineNumber = tertiaryText === undefined ? numberOfLines : 1;
content = (
<View style={styles.textViewContainer}>
<View style={styles.firstLine}>
Expand All @@ -272,16 +281,22 @@ class ListItem extends PureComponent {
</View>
{secondaryText &&
<View>
<Text numberOfLines={numberOfLines} style={styles.secondaryText}>
<Text numberOfLines={lineNumber} style={styles.secondaryText}>
{secondaryText}
</Text>
</View>
}
{tertiaryText &&
<View>
<Text numberOfLines={lineNumber} style={styles.secondaryText}>
{tertiaryText}
</Text>
</View>
}
</View>
);
}


return (
<View style={styles.centerElementContainer}>
{content}
Expand Down