Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PagedList.android.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. const { pageIndex } = this.state;
  39. return (
  40. <View
  41. style = { [
  42. styles.pagedListContainer,
  43. disabled ? styles.pagedListContainerDisabled : null
  44. ] }>
  45. <ViewPagerAndroid
  46. initialPage = { DEFAULT_PAGE }
  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
  56. disabled = { disabled }
  57. displayed = { pageIndex === 1 } />
  58. </View>
  59. </ViewPagerAndroid>
  60. <View style = { styles.pageIndicatorContainer }>
  61. <TouchableOpacity
  62. disabled = { disabled }
  63. onPress = { this._onSelectPage(0) }
  64. style = { styles.pageIndicator } >
  65. <View style = { styles.pageIndicator }>
  66. <Icon
  67. name = 'restore'
  68. style = { [
  69. styles.pageIndicatorIcon,
  70. this._getIndicatorStyle(0)
  71. ] } />
  72. <Text
  73. style = { [
  74. styles.pageIndicatorText,
  75. this._getIndicatorStyle(0)
  76. ] }>
  77. History
  78. </Text>
  79. </View>
  80. </TouchableOpacity>
  81. <TouchableOpacity
  82. disabled = { disabled }
  83. onPress = { this._onSelectPage(1) }
  84. style = { styles.pageIndicator } >
  85. <View style = { styles.pageIndicator }>
  86. <Icon
  87. name = 'event_note'
  88. style = { [
  89. styles.pageIndicatorIcon,
  90. this._getIndicatorStyle(1)
  91. ] } />
  92. <Text
  93. style = { [
  94. styles.pageIndicatorText,
  95. this._getIndicatorStyle(1)
  96. ] }>
  97. Calendar
  98. </Text>
  99. </View>
  100. </TouchableOpacity>
  101. </View>
  102. </View>
  103. );
  104. }
  105. _getIndicatorStyle: number => Object;
  106. /**
  107. * Constructs the style of an indicator.
  108. *
  109. * @private
  110. * @param {number} indicatorIndex - The index of the indicator.
  111. * @returns {Object}
  112. */
  113. _getIndicatorStyle(indicatorIndex) {
  114. if (this.state.pageIndex === indicatorIndex) {
  115. return styles.pageIndicatorTextActive;
  116. }
  117. return null;
  118. }
  119. _onPageSelected: Object => void;
  120. /**
  121. * Updates the index of the currently selected page.
  122. *
  123. * @private
  124. * @param {Object} event - The native event of the callback.
  125. * @returns {void}
  126. */
  127. _onPageSelected({ nativeEvent: { position } }) {
  128. if (this.state.pageIndex !== position) {
  129. this.setState({
  130. pageIndex: position
  131. });
  132. }
  133. }
  134. _onSelectPage: number => Function
  135. /**
  136. * Constructs a function to be used as a callback for the tab bar.
  137. *
  138. * @private
  139. * @param {number} pageIndex - The index of the page to activate via the
  140. * callback.
  141. * @returns {Function}
  142. */
  143. _onSelectPage(pageIndex) {
  144. return () => {
  145. this._viewPager.setPage(pageIndex);
  146. this.setState({
  147. pageIndex
  148. });
  149. };
  150. }
  151. _setPagerReference: Object => void
  152. /**
  153. * Sets the pager's reference for direct modification.
  154. *
  155. * @private
  156. * @param {React@Node} component - The pager component.
  157. * @returns {void}
  158. */
  159. _setPagerReference(component) {
  160. this._viewPager = component;
  161. }
  162. }