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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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() {
  20. super();
  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 style = { styles.pagedListContainer }>
  33. <ViewPagerAndroid
  34. initialPage = { DEFAULT_PAGE }
  35. keyboardDismissMode = 'on-drag'
  36. onPageSelected = { this._onPageSelected }
  37. peekEnabled = { true }
  38. style = { styles.pagedList }>
  39. <View key = { 0 }>
  40. <RecentList disabled = { disabled } />
  41. </View>
  42. <View key = { 1 }>
  43. <MeetingList disabled = { disabled } />
  44. </View>
  45. </ViewPagerAndroid>
  46. <View style = { styles.pageIndicatorContainer }>
  47. <View style = { this._getIndicatorStyle(0) } />
  48. <View style = { this._getIndicatorStyle(1) } />
  49. </View>
  50. </View>
  51. );
  52. }
  53. _getIndicatorStyle: number => Array<Object>;
  54. /**
  55. * Constructs the style array of an idicator.
  56. *
  57. * @private
  58. * @param {number} indicatorIndex - The index of the indicator.
  59. * @returns {Array<Object>}
  60. */
  61. _getIndicatorStyle(indicatorIndex) {
  62. const style = [
  63. styles.pageIndicator
  64. ];
  65. if (this.state.pageIndex === indicatorIndex) {
  66. style.push(styles.pageIndicatorActive);
  67. }
  68. return style;
  69. }
  70. _onPageSelected: Object => void;
  71. /**
  72. * Updates the index of the currently selected page.
  73. *
  74. * @private
  75. * @param {Object} event - The native event of the callback.
  76. * @returns {void}
  77. */
  78. _onPageSelected({ nativeEvent: { position } }) {
  79. if (this.state.pageIndex !== position) {
  80. this.setState({
  81. pageIndex: position
  82. });
  83. }
  84. }
  85. }