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.

EnterPictureInPictureToolbarButton.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { ToolbarButton } from '../../../toolbox';
  5. import { enterPictureInPicture } from '../actions';
  6. /**
  7. * The type of {@link EnterPictureInPictureToobarButton}'s React
  8. * {@code Component} props.
  9. */
  10. type Props = {
  11. /**
  12. * Enters (or rather initiates entering) picture-in-picture.
  13. *
  14. * @protected
  15. */
  16. _onEnterPictureInPicture: Function,
  17. /**
  18. * The indicator which determines whether Picture-in-Picture is enabled.
  19. *
  20. * @protected
  21. */
  22. _pictureInPictureEnabled: boolean
  23. };
  24. /**
  25. * Implements a {@link ToolbarButton} to enter Picture-in-Picture.
  26. */
  27. class EnterPictureInPictureToolbarButton extends Component<Props> {
  28. /**
  29. * Implements React's {@link Component#render()}.
  30. *
  31. * @inheritdoc
  32. * @returns {ReactElement}
  33. */
  34. render() {
  35. const {
  36. _onEnterPictureInPicture,
  37. _pictureInPictureEnabled,
  38. ...props
  39. } = this.props;
  40. if (!_pictureInPictureEnabled) {
  41. return null;
  42. }
  43. return (
  44. <ToolbarButton
  45. iconName = { 'menu-down' }
  46. onClick = { _onEnterPictureInPicture }
  47. { ...props } />
  48. );
  49. }
  50. }
  51. /**
  52. * Maps redux actions to {@link EnterPictureInPictureToolbarButton}'s React
  53. * {@code Component} props.
  54. *
  55. * @param {Function} dispatch - The redux action {@code dispatch} function.
  56. * @returns {{
  57. * }}
  58. * @private
  59. */
  60. function _mapDispatchToProps(dispatch) {
  61. return {
  62. /**
  63. * Requests Picture-in-Picture mode.
  64. *
  65. * @private
  66. * @returns {void}
  67. * @type {Function}
  68. */
  69. _onEnterPictureInPicture() {
  70. dispatch(enterPictureInPicture());
  71. }
  72. };
  73. }
  74. /**
  75. * Maps (parts of) the redux state to
  76. * {@link EnterPictureInPictureToolbarButton}'s React {@code Component} props.
  77. *
  78. * @param {Object} state - The redux store/state.
  79. * @private
  80. * @returns {{
  81. * }}
  82. */
  83. function _mapStateToProps(state) {
  84. const { app } = state['features/app'];
  85. return {
  86. /**
  87. * The indicator which determines whether Picture-in-Picture is enabled.
  88. *
  89. * @protected
  90. * @type {boolean}
  91. */
  92. _pictureInPictureEnabled:
  93. Boolean(app && app.props.pictureInPictureEnabled)
  94. };
  95. }
  96. export default connect(_mapStateToProps, _mapDispatchToProps)(
  97. EnterPictureInPictureToolbarButton);