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.

PagedList.ios.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // @flow
  2. import React from 'react';
  3. import { TabBarIOS } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { translate } from '../../base/i18n';
  6. import { MeetingList, refreshCalendar } from '../../calendar-sync';
  7. import { RecentList } from '../../recent-list';
  8. import AbstractPagedList from './AbstractPagedList';
  9. import styles from './styles';
  10. const CALENDAR_ICON = require('../../../../images/calendar.png');
  11. /**
  12. * A platform specific component to render a paged or tabbed list/view.
  13. *
  14. * @extends PagedList
  15. */
  16. class PagedList extends AbstractPagedList {
  17. /**
  18. * Constructor of the PagedList Component.
  19. *
  20. * @inheritdoc
  21. */
  22. constructor(props) {
  23. super(props);
  24. this._onTabSelected = this._onTabSelected.bind(this);
  25. }
  26. /**
  27. * Renders the entire paged list if calendar is enabled.
  28. *
  29. * @param {boolean} disabled - True if the rendered lists should be
  30. * disabled.
  31. * @returns {ReactElement}
  32. */
  33. _renderPagedList(disabled) {
  34. const { pageIndex } = this.state;
  35. const { t } = this.props;
  36. return (
  37. <TabBarIOS
  38. itemPositioning = 'fill'
  39. style = { styles.pagedList }>
  40. <TabBarIOS.Item
  41. onPress = { this._onTabSelected(0) }
  42. selected = { pageIndex === 0 }
  43. systemIcon = 'history' >
  44. <RecentList disabled = { disabled } />
  45. </TabBarIOS.Item>
  46. <TabBarIOS.Item
  47. icon = { CALENDAR_ICON }
  48. onPress = { this._onTabSelected(1) }
  49. selected = { pageIndex === 1 }
  50. title = { t('welcomepage.calendar') } >
  51. <MeetingList
  52. disabled = { disabled } />
  53. </TabBarIOS.Item>
  54. </TabBarIOS>
  55. );
  56. }
  57. _onTabSelected: number => Function;
  58. /**
  59. * Constructs a callback to update the selected tab.
  60. *
  61. * @private
  62. * @param {number} tabIndex - The selected tab.
  63. * @returns {Function}
  64. */
  65. _onTabSelected(tabIndex) {
  66. return () => {
  67. this.setState({
  68. pageIndex: tabIndex
  69. });
  70. if (tabIndex === 1) {
  71. /**
  72. * This is a workaround as TabBarIOS doesn't invoke
  73. * componentWillReciveProps on prop change of the MeetingList
  74. * component.
  75. */
  76. this.props.dispatch(refreshCalendar());
  77. }
  78. };
  79. }
  80. }
  81. export default translate(connect()(PagedList));