You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractPagedList.native.js 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { View } from 'react-native';
  4. import { MeetingList } from '../../calendar-sync';
  5. import { RecentList } from '../../recent-list';
  6. import styles from './styles';
  7. /**
  8. * The page to be displayed on render.
  9. */
  10. export const DEFAULT_PAGE = 0;
  11. type Props = {
  12. /**
  13. * Indicates if the list is disabled or not.
  14. */
  15. disabled: boolean,
  16. /**
  17. * The Redux dispatch function.
  18. */
  19. dispatch: Function,
  20. /**
  21. * The i18n translate function
  22. */
  23. t: Function
  24. };
  25. type State = {
  26. /**
  27. * The currently selected page.
  28. */
  29. pageIndex: number
  30. };
  31. /**
  32. * Abstract class for the platform specific paged lists.
  33. */
  34. export default class AbstractPagedList extends Component<Props, State> {
  35. /**
  36. * The list of pages displayed in the component, referenced by page index.
  37. */
  38. _pages: Array<Object>;
  39. /**
  40. * Constructor of the component.
  41. *
  42. * @inheritdoc
  43. */
  44. constructor(props: Props) {
  45. super(props);
  46. this._pages = [];
  47. for (const component of [ RecentList, MeetingList ]) {
  48. // XXX Certain pages may be contributed by optional features. For
  49. // example, MeetingList is contributed by the calendar feature and
  50. // apps i.e. SDK consumers may not enable the calendar feature.
  51. component && this._pages.push(component);
  52. }
  53. this.state = {
  54. pageIndex: DEFAULT_PAGE
  55. };
  56. }
  57. /**
  58. * Renders the component.
  59. *
  60. * @inheritdoc
  61. */
  62. render() {
  63. const { disabled } = this.props;
  64. return (
  65. <View
  66. style = { [
  67. styles.pagedListContainer,
  68. disabled ? styles.pagedListContainerDisabled : null
  69. ] }>
  70. {
  71. this._pages.length > 1
  72. ? this._renderPagedList(disabled)
  73. : React.createElement(
  74. /* type */ this._pages[0],
  75. /* props */ {
  76. disabled,
  77. style: styles.pagedList
  78. })
  79. }
  80. </View>
  81. );
  82. }
  83. _renderPagedList: boolean => React$Node;
  84. _selectPage: number => void;
  85. /**
  86. * Sets the selected page.
  87. *
  88. * @param {number} pageIndex - The index of the active page.
  89. * @protected
  90. * @returns {void}
  91. */
  92. _selectPage(pageIndex: number) {
  93. this.setState({
  94. pageIndex
  95. });
  96. // The page's Component may have a refresh(dispatch) function which we
  97. // invoke when the page is selected.
  98. const selectedPageComponent = this._pages[pageIndex];
  99. if (selectedPageComponent) {
  100. const { refresh } = selectedPageComponent;
  101. typeof refresh === 'function' && refresh(this.props.dispatch);
  102. }
  103. }
  104. }