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 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. // @flow
  2. import React from 'react';
  3. import { Text, TouchableOpacity, View, ViewPagerAndroid } from 'react-native';
  4. import { Icon } from '../../base/font-icons';
  5. import { MeetingList } from '../../calendar-sync';
  6. import { RecentList } from '../../recent-list';
  7. import AbstractPagedList, { DEFAULT_PAGE } from './AbstractPagedList';
  8. import styles from './styles';
  9. /**
  10. * A platform specific component to render a paged or tabbed list/view.
  11. *
  12. * @extends PagedList
  13. */
  14. export default class PagedList extends AbstractPagedList {
  15. /**
  16. * A reference to the viewpager.
  17. */
  18. _viewPager: Object;
  19. /**
  20. * Constructor of the PagedList Component.
  21. *
  22. * @inheritdoc
  23. */
  24. constructor(props) {
  25. super(props);
  26. this._getIndicatorStyle = this._getIndicatorStyle.bind(this);
  27. this._onPageSelected = this._onPageSelected.bind(this);
  28. this._onSelectPage = this._onSelectPage.bind(this);
  29. this._setPagerReference = this._setPagerReference.bind(this);
  30. }
  31. /**
  32. * Renders the paged list.
  33. *
  34. * @inheritdoc
  35. */
  36. render() {
  37. const { disabled } = this.props;
  38. return (
  39. <View
  40. style = { [
  41. styles.pagedListContainer,
  42. disabled ? styles.pagedListContainerDisabled : null
  43. ] }>
  44. <ViewPagerAndroid
  45. initialPage = { DEFAULT_PAGE }
  46. keyboardDismissMode = 'on-drag'
  47. onPageSelected = { this._onPageSelected }
  48. peekEnabled = { true }
  49. ref = { this._setPagerReference }
  50. style = { styles.pagedList }>
  51. <View key = { 0 }>
  52. <RecentList disabled = { disabled } />
  53. </View>
  54. <View key = { 1 }>
  55. <MeetingList disabled = { disabled } />
  56. </View>
  57. </ViewPagerAndroid>
  58. <View style = { styles.pageIndicatorContainer }>
  59. <TouchableOpacity
  60. onPress = { this._onSelectPage(0) }
  61. style = { styles.pageIndicator } >
  62. <View style = { styles.pageIndicator }>
  63. <Icon
  64. name = 'restore'
  65. style = { [
  66. styles.pageIndicatorIcon,
  67. this._getIndicatorStyle(0)
  68. ] } />
  69. <Text
  70. style = { [
  71. styles.pageIndicatorText,
  72. this._getIndicatorStyle(0)
  73. ] }>
  74. History
  75. </Text>
  76. </View>
  77. </TouchableOpacity>
  78. <TouchableOpacity
  79. onPress = { this._onSelectPage(1) }
  80. style = { styles.pageIndicator } >
  81. <View style = { styles.pageIndicator }>
  82. <Icon
  83. name = 'event_note'
  84. style = { [
  85. styles.pageIndicatorIcon,
  86. this._getIndicatorStyle(1)
  87. ] } />
  88. <Text
  89. style = { [
  90. styles.pageIndicatorText,
  91. this._getIndicatorStyle(1)
  92. ] }>
  93. Calendar
  94. </Text>
  95. </View>
  96. </TouchableOpacity>
  97. </View>
  98. </View>
  99. );
  100. }
  101. _getIndicatorStyle: number => Object;
  102. /**
  103. * Constructs the style of an indicator.
  104. *
  105. * @private
  106. * @param {number} indicatorIndex - The index of the indicator.
  107. * @returns {Object}
  108. */
  109. _getIndicatorStyle(indicatorIndex) {
  110. if (this.state.pageIndex === indicatorIndex) {
  111. return styles.pageIndicatorTextActive;
  112. }
  113. return null;
  114. }
  115. _onPageSelected: Object => void;
  116. /**
  117. * Updates the index of the currently selected page.
  118. *
  119. * @private
  120. * @param {Object} event - The native event of the callback.
  121. * @returns {void}
  122. */
  123. _onPageSelected({ nativeEvent: { position } }) {
  124. if (this.state.pageIndex !== position) {
  125. this.setState({
  126. pageIndex: position
  127. });
  128. }
  129. }
  130. _onSelectPage: number => Function
  131. /**
  132. * Constructs a function to be used as a callback for the tab bar.
  133. *
  134. * @private
  135. * @param {number} pageIndex - The index of the page to activate via the
  136. * callback.
  137. * @returns {Function}
  138. */
  139. _onSelectPage(pageIndex) {
  140. return () => {
  141. this._viewPager.setPage(pageIndex);
  142. this.setState({
  143. pageIndex
  144. });
  145. };
  146. }
  147. _setPagerReference: Object => void
  148. /**
  149. * Sets the pager's reference for direct modification.
  150. *
  151. * @private
  152. * @param {React@Node} component - The pager component.
  153. * @returns {void}
  154. */
  155. _setPagerReference(component) {
  156. this._viewPager = component;
  157. }
  158. }