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

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