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.android.js 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // @flow
  2. import React from 'react';
  3. import { View, ViewPagerAndroid } from 'react-native';
  4. import { MeetingList } from '../../calendar-sync';
  5. import { RecentList } from '../../recent-list';
  6. import AbstractPagedList, { DEFAULT_PAGE } from './AbstractPagedList';
  7. import styles from './styles';
  8. /**
  9. * A platform specific component to render a paged or tabbed list/view.
  10. *
  11. * @extends PagedList
  12. */
  13. export default class PagedList extends AbstractPagedList {
  14. /**
  15. * Constructor of the PagedList Component.
  16. *
  17. * @inheritdoc
  18. */
  19. constructor(props) {
  20. super(props);
  21. this._getIndicatorStyle = this._getIndicatorStyle.bind(this);
  22. this._onPageSelected = this._onPageSelected.bind(this);
  23. }
  24. /**
  25. * Renders the paged list.
  26. *
  27. * @inheritdoc
  28. */
  29. render() {
  30. const { disabled } = this.props;
  31. return (
  32. <View
  33. style = { [
  34. styles.pagedListContainer,
  35. disabled ? styles.pagedListContainerDisabled : null
  36. ] }>
  37. <ViewPagerAndroid
  38. initialPage = { DEFAULT_PAGE }
  39. keyboardDismissMode = 'on-drag'
  40. onPageSelected = { this._onPageSelected }
  41. peekEnabled = { true }
  42. style = { styles.pagedList }>
  43. <View key = { 0 }>
  44. <RecentList disabled = { disabled } />
  45. </View>
  46. <View key = { 1 }>
  47. <MeetingList disabled = { disabled } />
  48. </View>
  49. </ViewPagerAndroid>
  50. <View style = { styles.pageIndicatorContainer }>
  51. <View style = { this._getIndicatorStyle(0) } />
  52. <View style = { this._getIndicatorStyle(1) } />
  53. </View>
  54. </View>
  55. );
  56. }
  57. _getIndicatorStyle: number => Array<Object>;
  58. /**
  59. * Constructs the style array of an idicator.
  60. *
  61. * @private
  62. * @param {number} indicatorIndex - The index of the indicator.
  63. * @returns {Array<Object>}
  64. */
  65. _getIndicatorStyle(indicatorIndex) {
  66. const style = [
  67. styles.pageIndicator
  68. ];
  69. if (this.state.pageIndex === indicatorIndex) {
  70. style.push(styles.pageIndicatorActive);
  71. }
  72. return style;
  73. }
  74. _onPageSelected: Object => void;
  75. /**
  76. * Updates the index of the currently selected page.
  77. *
  78. * @private
  79. * @param {Object} event - The native event of the callback.
  80. * @returns {void}
  81. */
  82. _onPageSelected({ nativeEvent: { position } }) {
  83. if (this.state.pageIndex !== position) {
  84. this.setState({
  85. pageIndex: position
  86. });
  87. }
  88. }
  89. }