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

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