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 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { SafeAreaView, View } 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. * The i18n label key of the header title.
  33. */
  34. headerLabelKey: string,
  35. /**
  36. * The ID of the modal that is being rendered. This is used to show/hide the modal.
  37. */
  38. modalId: string,
  39. /**
  40. * Callback to be invoked when the modal closes.
  41. */
  42. onClose?: Function,
  43. /**
  44. * The position from where the modal should be opened. This is derived from the
  45. * props of the {@code SlidingView} with the same name.
  46. */
  47. position?: string
  48. };
  49. /**
  50. * Implements a custom Jitsi Modal that doesn't use the built in native
  51. * Modal component of React Native.
  52. */
  53. class JitsiModal extends PureComponent<Props> {
  54. static defaultProps = {
  55. position: 'bottom'
  56. };
  57. /**
  58. * Instantiates a new component.
  59. *
  60. * @inheritdoc
  61. */
  62. constructor(props: Props) {
  63. super(props);
  64. this._onRequestClose = this._onRequestClose.bind(this);
  65. }
  66. /**
  67. * Implements {@code PureComponent#render}.
  68. *
  69. * @inheritdoc
  70. */
  71. render() {
  72. const { _headerStyles, _show, _styles, children, headerLabelKey, position } = this.props;
  73. return (
  74. <SlidingView
  75. onHide = { this._onRequestClose }
  76. position = { position }
  77. show = { _show }>
  78. <View
  79. style = { [
  80. _headerStyles.page,
  81. _styles.page
  82. ] }>
  83. <HeaderWithNavigation
  84. headerLabelKey = { headerLabelKey }
  85. onPressBack = { this._onRequestClose } />
  86. <SafeAreaView style = { styles.safeArea }>
  87. { children }
  88. </SafeAreaView>
  89. </View>
  90. </SlidingView>
  91. );
  92. }
  93. _onRequestClose: () => boolean;
  94. /**
  95. * Callback to be invoked when the SlidingView requests closing.
  96. *
  97. * @returns {boolean}
  98. */
  99. _onRequestClose() {
  100. const { _show, dispatch, onClose } = this.props;
  101. if (_show) {
  102. if (typeof onClose === 'function') {
  103. onClose();
  104. }
  105. dispatch(setActiveModalId());
  106. return true;
  107. }
  108. return false;
  109. }
  110. }
  111. /**
  112. * Maps part of the Redix state to the props of this component.
  113. *
  114. * @param {Object} state - The Redux state.
  115. * @param {Props} ownProps - The own props of the component.
  116. * @returns {Props}
  117. */
  118. function _mapStateToProps(state, ownProps): $Shape<Props> {
  119. return {
  120. _headerStyles: ColorSchemeRegistry.get(state, 'Header'),
  121. _show: state['features/base/modal'].activeModalId === ownProps.modalId,
  122. _styles: ColorSchemeRegistry.get(state, 'Modal')
  123. };
  124. }
  125. export default connect(_mapStateToProps)(JitsiModal);