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

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