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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 entire paged list if calendar is enabled.
  33. *
  34. * @param {boolean} disabled - True if the rendered lists should be
  35. * disabled.
  36. * @returns {ReactElement}
  37. */
  38. _renderPagedList(disabled) {
  39. const { pageIndex } = this.state;
  40. return (
  41. <View style = { styles.pagedListContainer }>
  42. <ViewPagerAndroid
  43. initialPage = { DEFAULT_PAGE }
  44. onPageSelected = { this._onPageSelected }
  45. peekEnabled = { true }
  46. ref = { this._setPagerReference }
  47. style = { styles.pagedList }>
  48. <View key = { 0 }>
  49. <RecentList disabled = { disabled } />
  50. </View>
  51. <View key = { 1 }>
  52. <MeetingList
  53. disabled = { disabled }
  54. displayed = { pageIndex === 1 } />
  55. </View>
  56. </ViewPagerAndroid>
  57. <View style = { styles.pageIndicatorContainer }>
  58. <TouchableOpacity
  59. disabled = { disabled }
  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. disabled = { disabled }
  80. onPress = { this._onSelectPage(1) }
  81. style = { styles.pageIndicator } >
  82. <View style = { styles.pageIndicator }>
  83. <Icon
  84. name = 'event_note'
  85. style = { [
  86. styles.pageIndicatorIcon,
  87. this._getIndicatorStyle(1)
  88. ] } />
  89. <Text
  90. style = { [
  91. styles.pageIndicatorText,
  92. this._getIndicatorStyle(1)
  93. ] }>
  94. Calendar
  95. </Text>
  96. </View>
  97. </TouchableOpacity>
  98. </View>
  99. </View>
  100. );
  101. }
  102. _getIndicatorStyle: number => Object;
  103. /**
  104. * Constructs the style of an indicator.
  105. *
  106. * @private
  107. * @param {number} indicatorIndex - The index of the indicator.
  108. * @returns {Object}
  109. */
  110. _getIndicatorStyle(indicatorIndex) {
  111. if (this.state.pageIndex === indicatorIndex) {
  112. return styles.pageIndicatorTextActive;
  113. }
  114. return null;
  115. }
  116. _onPageSelected: Object => void;
  117. /**
  118. * Updates the index of the currently selected page.
  119. *
  120. * @private
  121. * @param {Object} event - The native event of the callback.
  122. * @returns {void}
  123. */
  124. _onPageSelected({ nativeEvent: { position } }) {
  125. if (this.state.pageIndex !== position) {
  126. this.setState({
  127. pageIndex: position
  128. });
  129. }
  130. }
  131. _onSelectPage: number => Function
  132. /**
  133. * Constructs a function to be used as a callback for the tab bar.
  134. *
  135. * @private
  136. * @param {number} pageIndex - The index of the page to activate via the
  137. * callback.
  138. * @returns {Function}
  139. */
  140. _onSelectPage(pageIndex) {
  141. return () => {
  142. this._viewPager.setPage(pageIndex);
  143. this.setState({
  144. pageIndex
  145. });
  146. };
  147. }
  148. _setPagerReference: Object => void
  149. /**
  150. * Sets the pager's reference for direct modification.
  151. *
  152. * @private
  153. * @param {React@Node} component - The pager component.
  154. * @returns {void}
  155. */
  156. _setPagerReference(component) {
  157. this._viewPager = component;
  158. }
  159. }