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

RecentList.native.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // @flow
  2. import React from 'react';
  3. import { TouchableWithoutFeedback, View } from 'react-native';
  4. import type { Dispatch } from 'redux';
  5. import { getDefaultURL } from '../../app/functions';
  6. import { openDialog } from '../../base/dialog/actions';
  7. import { translate } from '../../base/i18n';
  8. import { NavigateSectionList, type Section } from '../../base/react';
  9. import { connect } from '../../base/redux';
  10. import styles from '../../welcome/components/styles';
  11. import { isRecentListEnabled, toDisplayableList } from '../functions';
  12. import AbstractRecentList from './AbstractRecentList';
  13. import RecentListItemMenu from './RecentListItemMenu.native';
  14. /**
  15. * The type of the React {@code Component} props of {@link RecentList}.
  16. */
  17. type Props = {
  18. /**
  19. * Renders the list disabled.
  20. */
  21. disabled: boolean,
  22. /**
  23. * The redux store's {@code dispatch} function.
  24. */
  25. dispatch: Dispatch<any>,
  26. /**
  27. * Callback to be invoked when pressing the list container.
  28. */
  29. onListContainerPress?: Function,
  30. /**
  31. * The translate function.
  32. */
  33. t: Function,
  34. /**
  35. * The default server URL.
  36. */
  37. _defaultServerURL: string,
  38. /**
  39. * The recent list from the Redux store.
  40. */
  41. _recentList: Array<Section>
  42. };
  43. /**
  44. * A class that renders the list of the recently joined rooms.
  45. *
  46. */
  47. class RecentList extends AbstractRecentList<Props> {
  48. _getRenderListEmptyComponent: () => React$Node;
  49. _onPress: string => {};
  50. /**
  51. * Initializes a new {@code RecentList} instance.
  52. *
  53. * @inheritdoc
  54. */
  55. constructor(props: Props) {
  56. super(props);
  57. // Bind event handlers so they are only bound once per instance.
  58. this._onLongPress = this._onLongPress.bind(this);
  59. }
  60. /**
  61. * Implements the React Components's render method.
  62. *
  63. * @inheritdoc
  64. */
  65. render() {
  66. if (!isRecentListEnabled()) {
  67. return null;
  68. }
  69. const {
  70. disabled,
  71. onListContainerPress,
  72. t,
  73. _defaultServerURL,
  74. _recentList
  75. } = this.props;
  76. const recentList = toDisplayableList(_recentList, t, _defaultServerURL);
  77. return (
  78. <TouchableWithoutFeedback
  79. onPress = { onListContainerPress }>
  80. <View style = { disabled ? styles.recentListDisabled : styles.recentList }>
  81. <NavigateSectionList
  82. disabled = { disabled }
  83. onLongPress = { this._onLongPress }
  84. onPress = { this._onPress }
  85. renderListEmptyComponent
  86. = { this._getRenderListEmptyComponent() }
  87. sections = { recentList } />
  88. </View>
  89. </TouchableWithoutFeedback>
  90. );
  91. }
  92. _onLongPress: (Object) => void;
  93. /**
  94. * Handles the list's navigate action.
  95. *
  96. * @private
  97. * @param {Object} item - The item which was long pressed.
  98. * @returns {void}
  99. */
  100. _onLongPress(item) {
  101. this.props.dispatch(openDialog(RecentListItemMenu, { item }));
  102. }
  103. }
  104. /**
  105. * Maps redux state to component props.
  106. *
  107. * @param {Object} state - The redux state.
  108. * @returns {Props}
  109. */
  110. export function _mapStateToProps(state: Object) {
  111. return {
  112. _defaultServerURL: getDefaultURL(state),
  113. _recentList: state['features/recent-list']
  114. };
  115. }
  116. export default translate(connect(_mapStateToProps)(RecentList));