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

JitsiModal.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { KeyboardAvoidingView, SafeAreaView } from 'react-native';
  4. import { ColorSchemeRegistry } from '../../color-scheme';
  5. import { HeaderWithNavigation, SlidingView } from '../../react';
  6. import { connect } from '../../redux';
  7. import { StyleType } from '../../styles';
  8. import { setActiveModalId } from '../actions';
  9. import styles from './styles';
  10. type Props = {
  11. /**
  12. * The color schemed style of the common header component.
  13. */
  14. _headerStyles: StyleType,
  15. /**
  16. * True if the modal should be shown, false otherwise.
  17. */
  18. _show: boolean,
  19. /**
  20. * The color schemed style of the modal.
  21. */
  22. _styles: StyleType,
  23. /**
  24. * The children component(s) of the Modal, to be rendered.
  25. */
  26. children: React$Node,
  27. /**
  28. * The Redux Dispatch function.
  29. */
  30. dispatch: Function,
  31. /**
  32. * Optional function that renders a footer component, if needed.
  33. */
  34. footerComponent?: Function,
  35. /**
  36. * Props to be passed over to the header.
  37. *
  38. * See {@code HeaderWithNavigation} for more details.
  39. */
  40. headerProps: Object,
  41. /**
  42. * The ID of the modal that is being rendered. This is used to show/hide the modal.
  43. */
  44. modalId: string,
  45. /**
  46. * Callback to be invoked when the modal closes.
  47. */
  48. onClose?: Function,
  49. /**
  50. * The position from where the modal should be opened. This is derived from the
  51. * props of the {@code SlidingView} with the same name.
  52. */
  53. position?: string,
  54. /**
  55. * Additional style to be appended to the View containing the content of the modal.
  56. */
  57. style?: StyleType
  58. };
  59. /**
  60. * Implements a custom Jitsi Modal that doesn't use the built in native
  61. * Modal component of React Native.
  62. */
  63. class JitsiModal extends PureComponent<Props> {
  64. static defaultProps = {
  65. position: 'bottom'
  66. };
  67. /**
  68. * Instantiates a new component.
  69. *
  70. * @inheritdoc
  71. */
  72. constructor(props: Props) {
  73. super(props);
  74. this._onRequestClose = this._onRequestClose.bind(this);
  75. }
  76. /**
  77. * Implements {@code PureComponent#render}.
  78. *
  79. * @inheritdoc
  80. */
  81. render() {
  82. const { _headerStyles, _show, _styles, children, footerComponent, headerProps, position, style } = this.props;
  83. return (
  84. <SlidingView
  85. onHide = { this._onRequestClose }
  86. position = { position }
  87. show = { _show }>
  88. <KeyboardAvoidingView
  89. behavior = 'height'
  90. style = { [
  91. _headerStyles.page,
  92. _styles.page,
  93. style
  94. ] }>
  95. <HeaderWithNavigation
  96. { ...headerProps }
  97. onPressBack = { this._onRequestClose } />
  98. <SafeAreaView style = { styles.safeArea }>
  99. { children }
  100. </SafeAreaView>
  101. { footerComponent && footerComponent() }
  102. </KeyboardAvoidingView>
  103. </SlidingView>
  104. );
  105. }
  106. _onRequestClose: () => boolean;
  107. /**
  108. * Callback to be invoked when the SlidingView requests closing.
  109. *
  110. * @returns {boolean}
  111. */
  112. _onRequestClose() {
  113. const { _show, dispatch, onClose } = this.props;
  114. let shouldCloseModal = true;
  115. if (_show) {
  116. if (typeof onClose === 'function') {
  117. shouldCloseModal = onClose();
  118. }
  119. shouldCloseModal && dispatch(setActiveModalId());
  120. return shouldCloseModal;
  121. }
  122. return false;
  123. }
  124. }
  125. /**
  126. * Maps part of the Redix state to the props of this component.
  127. *
  128. * @param {Object} state - The Redux state.
  129. * @param {Props} ownProps - The own props of the component.
  130. * @returns {Props}
  131. */
  132. function _mapStateToProps(state, ownProps): $Shape<Props> {
  133. return {
  134. _headerStyles: ColorSchemeRegistry.get(state, 'Header'),
  135. _show: state['features/base/modal'].activeModalId === ownProps.modalId,
  136. _styles: ColorSchemeRegistry.get(state, 'Modal')
  137. };
  138. }
  139. export default connect(_mapStateToProps)(JitsiModal);