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.

JitsiModal.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { KeyboardAvoidingView, Platform, 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. * True if the header with navigation should be shown, false otherwise.
  56. */
  57. showHeaderWithNavigation: boolean,
  58. /**
  59. * Additional style to be appended to the View containing the content of the modal.
  60. */
  61. style?: StyleType
  62. };
  63. /**
  64. * Implements a custom Jitsi Modal that doesn't use the built in native
  65. * Modal component of React Native.
  66. */
  67. class JitsiModal extends PureComponent<Props> {
  68. static defaultProps = {
  69. position: 'bottom'
  70. };
  71. /**
  72. * Instantiates a new component.
  73. *
  74. * @inheritdoc
  75. */
  76. constructor(props: Props) {
  77. super(props);
  78. this._onRequestClose = this._onRequestClose.bind(this);
  79. }
  80. /**
  81. * Implements {@code PureComponent#render}.
  82. *
  83. * @inheritdoc
  84. */
  85. render() {
  86. const {
  87. _headerStyles,
  88. _show,
  89. _styles,
  90. children,
  91. footerComponent,
  92. headerProps,
  93. position,
  94. showHeaderWithNavigation,
  95. style
  96. } = this.props;
  97. return (
  98. <SlidingView
  99. onHide = { this._onRequestClose }
  100. position = { position }
  101. show = { _show }>
  102. <KeyboardAvoidingView
  103. behavior =
  104. {
  105. Platform.OS === 'ios'
  106. ? 'padding' : 'height'
  107. }
  108. enabled = { true }
  109. style = { [
  110. _headerStyles.page,
  111. _styles.page,
  112. style
  113. ] }>
  114. {showHeaderWithNavigation
  115. && <HeaderWithNavigation
  116. { ...headerProps }
  117. onPressBack = { this._onRequestClose } />}
  118. <SafeAreaView style = { styles.safeArea }>
  119. { children }
  120. </SafeAreaView>
  121. { footerComponent && footerComponent() }
  122. </KeyboardAvoidingView>
  123. </SlidingView>
  124. );
  125. }
  126. _onRequestClose: () => boolean;
  127. /**
  128. * Callback to be invoked when the SlidingView requests closing.
  129. *
  130. * @returns {boolean}
  131. */
  132. _onRequestClose() {
  133. const { _show, dispatch, onClose } = this.props;
  134. let shouldCloseModal = true;
  135. if (_show) {
  136. if (typeof onClose === 'function') {
  137. shouldCloseModal = onClose();
  138. }
  139. shouldCloseModal && dispatch(setActiveModalId());
  140. return shouldCloseModal;
  141. }
  142. return false;
  143. }
  144. }
  145. /**
  146. * Maps part of the Redix state to the props of this component.
  147. *
  148. * @param {Object} state - The Redux state.
  149. * @param {Props} ownProps - The own props of the component.
  150. * @returns {Props}
  151. */
  152. function _mapStateToProps(state, ownProps): $Shape<Props> {
  153. return {
  154. _headerStyles: ColorSchemeRegistry.get(state, 'Header'),
  155. _show: state['features/base/modal'].activeModalId === ownProps.modalId,
  156. _styles: ColorSchemeRegistry.get(state, 'Modal')
  157. };
  158. }
  159. export default connect(_mapStateToProps)(JitsiModal);