您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

RecentList.native.tsx 3.6KB

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