Files
jitsi-meet/react/features/base/react/components/native/NavigateSectionListItem.js

132 lines
3.3 KiB
JavaScript
Raw Normal View History

2018-08-01 11:41:54 -05:00
// @flow
import React, { Component } from 'react';
2018-09-25 14:48:03 +02:00
import Swipeout from 'react-native-swipeout';
import { ColorPalette } from '../../../styles';
2018-08-01 11:41:54 -05:00
import type { Item } from '../../Types';
2019-02-13 10:39:40 +01:00
import AvatarListItem from './AvatarListItem';
2019-05-07 16:50:57 +02:00
import Text from './Text';
import styles from './styles';
2019-02-13 10:39:40 +01:00
2018-08-01 11:41:54 -05:00
type Props = {
/**
* item containing data to be rendered
*/
item: Item,
/**
* Function to be invoked when an Item is pressed. The Item's URL is passed.
*/
2018-09-04 09:29:48 +02:00
onPress: ?Function,
/**
* Function to be invoked when secondary action was performed on an Item.
*/
2018-09-25 14:48:03 +02:00
secondaryAction: ?Function,
/**
* Optional array of on-slide actions this list should support. For details
* see https://github.com/dancormier/react-native-swipeout.
*/
slideActions?: Array<Object>
2018-08-01 11:41:54 -05:00
}
/**
* Implements a React/Native {@link Component} that renders the Navigate Section
* List Item
*
* @extends Component
*/
export default class NavigateSectionListItem extends Component<Props> {
/**
* Constructor of the NavigateSectionList component.
*
* @inheritdoc
*/
constructor(props: Props) {
super(props);
2019-02-13 10:39:40 +01:00
2018-08-01 11:41:54 -05:00
this._renderItemLine = this._renderItemLine.bind(this);
this._renderItemLines = this._renderItemLines.bind(this);
}
_renderItemLine: (string, number) => React$Node;
/**
* Renders a single line from the additional lines.
*
* @param {string} line - The line text.
* @param {number} index - The index of the line.
* @private
* @returns {React$Node}
*/
_renderItemLine(line, index) {
if (!line) {
return null;
}
return (
<Text
key = { index }
numberOfLines = { 1 }
style = { styles.listItemText }>
{line}
</Text>
);
}
_renderItemLines: Array<string> => Array<React$Node>;
/**
* Renders the additional item lines, if any.
*
* @param {Array<string>} lines - The lines to render.
* @private
* @returns {Array<React$Node>}
*/
_renderItemLines(lines) {
return lines && lines.length ? lines.map(this._renderItemLine) : null;
}
/**
* Renders the content of this component.
*
* @returns {ReactElement}
*/
render() {
2019-02-13 10:39:40 +01:00
const { item, slideActions } = this.props;
const { id } = item;
2018-09-25 14:48:03 +02:00
let right;
// NOTE: The {@code Swipeout} component has an onPress prop encapsulated
// in the {@code right} array, but we need to bind it to the ID of the
// item too.
if (slideActions) {
right = [];
for (const slideAction of slideActions) {
right.push({
backgroundColor: slideAction.backgroundColor,
onPress: slideAction.onPress.bind(undefined, id),
text: slideAction.text
});
}
}
2018-08-01 11:41:54 -05:00
return (
2018-09-25 14:48:03 +02:00
<Swipeout
2019-05-07 16:50:57 +02:00
autoClose = { true }
2018-09-25 14:48:03 +02:00
backgroundColor = { ColorPalette.transparent }
right = { right }>
2019-02-13 10:39:40 +01:00
<AvatarListItem
item = { item }
2019-05-07 16:50:57 +02:00
onPress = { this.props.onPress } />
2018-09-25 14:48:03 +02:00
</Swipeout>
2018-08-01 11:41:54 -05:00
);
}
}