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.

NotificationsContainer.native.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. // @flow
  2. import React from 'react';
  3. import { View } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import {
  6. isNarrowAspectRatio,
  7. makeAspectRatioAware
  8. } from '../../base/responsive-ui';
  9. import { FILMSTRIP_SIZE, isFilmstripVisible } from '../../filmstrip';
  10. import { HANGUP_BUTTON_SIZE } from '../../toolbox';
  11. import AbstractNotificationsContainer, {
  12. _abstractMapStateToProps,
  13. type Props as AbstractProps
  14. } from './AbstractNotificationsContainer';
  15. import Notification from './Notification';
  16. import styles from './styles';
  17. type Props = AbstractProps & {
  18. /**
  19. * True if the {@code Filmstrip} is visible, false otherwise.
  20. */
  21. _filmstripVisible: boolean,
  22. /**
  23. * True if the {@ćode Toolbox} is visible, false otherwise.
  24. */
  25. _toolboxVisible: boolean
  26. };
  27. /**
  28. * The margin of the container to be kept from other components.
  29. */
  30. const CONTAINER_MARGIN = 10;
  31. /**
  32. * Implements a React {@link Component} which displays notifications and handles
  33. * automatic dismissmal after a notification is shown for a defined timeout
  34. * period.
  35. *
  36. * @extends {Component}
  37. */
  38. class NotificationsContainer extends AbstractNotificationsContainer<Props> {
  39. /**
  40. * Implements React's {@link Component#render()}.
  41. *
  42. * @inheritdoc
  43. * @returns {ReactElement}
  44. */
  45. render() {
  46. const { _notifications } = this.props;
  47. if (!_notifications || !_notifications.length) {
  48. return null;
  49. }
  50. return (
  51. <View
  52. pointerEvents = 'box-none'
  53. style = { styles.notificationOverlay }>
  54. <View
  55. pointerEvents = 'box-none'
  56. style = { [
  57. styles.notificationContainer,
  58. this._getContainerStyle()
  59. ] }>
  60. {
  61. _notifications.map(notification => {
  62. const { props, uid } = notification;
  63. return (
  64. <Notification
  65. { ...props }
  66. key = { uid }
  67. onDismissed = { this._onDismissed }
  68. uid = { uid } />
  69. );
  70. })
  71. }
  72. </View>
  73. </View>
  74. );
  75. }
  76. /**
  77. * Generates a style object that is to be used for the notification
  78. * container.
  79. *
  80. * @private
  81. * @returns {?Object}
  82. */
  83. _getContainerStyle() {
  84. const { _filmstripVisible, _toolboxVisible } = this.props;
  85. // The filmstrip only affects the position if we're on a narrow view.
  86. const _narrow = isNarrowAspectRatio(this);
  87. let bottom = 0;
  88. let right = 0;
  89. // The container needs additional distance from bottom when the
  90. // filmstrip or the toolbox is visible.
  91. _filmstripVisible && !_narrow && (right += FILMSTRIP_SIZE);
  92. _filmstripVisible && _narrow && (bottom += FILMSTRIP_SIZE);
  93. _toolboxVisible && (bottom += HANGUP_BUTTON_SIZE);
  94. bottom += CONTAINER_MARGIN;
  95. return {
  96. bottom,
  97. right
  98. };
  99. }
  100. _onDismissed: number => void;
  101. }
  102. /**
  103. * Maps (parts of) the Redux state to the associated NotificationsContainer's
  104. * props.
  105. *
  106. * @param {Object} state - The Redux state.
  107. * @private
  108. * @returns {{
  109. * _filmstripVisible: boolean,
  110. * _notifications: Array,
  111. * _showNotifications: boolean,
  112. * _toolboxVisible: boolean
  113. * }}
  114. */
  115. export function _mapStateToProps(state: Object) {
  116. return {
  117. ..._abstractMapStateToProps(state),
  118. _filmstripVisible: isFilmstripVisible(state),
  119. _toolboxVisible: state['features/toolbox'].visible
  120. };
  121. }
  122. export default connect(_mapStateToProps)(
  123. makeAspectRatioAware(NotificationsContainer));