jiti-meet/react/features/welcome/components/AbstractPagedList.native.js

127 lines
2.9 KiB
JavaScript
Raw Normal View History

2018-04-16 16:39:26 +00:00
// @flow
import React, { Component } from 'react';
import { View } from 'react-native';
import { MeetingList } from '../../calendar-sync';
2018-04-16 16:39:26 +00:00
import { RecentList } from '../../recent-list';
import styles from './styles';
/**
* The page to be displayed on render.
*/
export const DEFAULT_PAGE = 0;
type Props = {
/**
* Indicates if the list is disabled or not.
*/
disabled: boolean,
/**
* The Redux dispatch function.
*/
dispatch: Function,
/**
* The i18n translate function
*/
t: Function
};
2018-04-16 16:39:26 +00:00
type State = {
/**
* The currently selected page.
*/
pageIndex: number
};
2018-04-16 16:39:26 +00:00
/**
* Abstract class for the platform specific paged lists.
*/
export default class AbstractPagedList extends Component<Props, State> {
/**
* The list of pages displayed in the component, referenced by page index.
2018-04-16 16:39:26 +00:00
*/
_pages: Array<Object>;
2018-04-16 16:39:26 +00:00
/**
* Constructor of the component.
*
* @inheritdoc
*/
constructor(props: Props) {
super(props);
this._pages = [];
for (const component of [ RecentList, MeetingList ]) {
// XXX Certain pages may be contributed by optional features. For
// example, MeetingList is contributed by the calendar feature and
// apps i.e. SDK consumers may not enable the calendar feature.
component && this._pages.push(component);
}
2018-04-16 16:39:26 +00:00
this.state = {
pageIndex: DEFAULT_PAGE
};
}
/**
* Renders the component.
*
* @inheritdoc
*/
render() {
const { disabled } = this.props;
return (
<View
style = { [
styles.pagedListContainer,
disabled ? styles.pagedListContainerDisabled : null
] }>
{
this._pages.length > 1
? this._renderPagedList(disabled)
: React.createElement(
/* type */ this._pages[0],
/* props */ {
disabled,
style: styles.pagedList
})
2018-04-16 16:39:26 +00:00
}
</View>
);
}
_renderPagedList: boolean => React$Node;
2018-04-16 16:39:26 +00:00
_selectPage: number => void;
/**
* Sets the selected page.
*
* @param {number} pageIndex - The index of the active page.
* @protected
* @returns {void}
*/
_selectPage(pageIndex: number) {
this.setState({
pageIndex
});
// The page's Component may have a refresh(dispatch) function which we
// invoke when the page is selected.
const selectedPageComponent = this._pages[pageIndex];
if (selectedPageComponent) {
const { refresh } = selectedPageComponent;
typeof refresh === 'function' && refresh(this.props.dispatch);
}
}
2018-04-16 16:39:26 +00:00
}