您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

PictureInPictureButton.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // @flow
  2. import { NativeModules, Platform } from 'react-native';
  3. import { PIP_ENABLED, getFeatureFlag } from '../../../base/flags';
  4. import { translate } from '../../../base/i18n';
  5. import { IconMenuDown } from '../../../base/icons';
  6. import { connect } from '../../../base/redux';
  7. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  8. import { enterPictureInPicture } from '../actions';
  9. type Props = AbstractButtonProps & {
  10. /**
  11. * Whether Picture-in-Picture is enabled or not.
  12. */
  13. _enabled: boolean,
  14. /**
  15. * The redux {@code dispatch} function.
  16. */
  17. dispatch: Function
  18. };
  19. /**
  20. * An implementation of a button for entering Picture-in-Picture mode.
  21. */
  22. class PictureInPictureButton extends AbstractButton<Props, *> {
  23. accessibilityLabel = 'toolbar.accessibilityLabel.pip';
  24. icon = IconMenuDown;
  25. label = 'toolbar.pip';
  26. /**
  27. * Handles clicking / pressing the button.
  28. *
  29. * @protected
  30. * @returns {void}
  31. */
  32. _handleClick() {
  33. this.props.dispatch(enterPictureInPicture());
  34. }
  35. /**
  36. * Implements React's {@link Component#render()}.
  37. *
  38. * @inheritdoc
  39. * @returns {React$Node}
  40. */
  41. render() {
  42. return this.props._enabled ? super.render() : null;
  43. }
  44. }
  45. /**
  46. * Maps (parts of) the redux state to the associated props for the
  47. * {@code PictureInPictureButton} component.
  48. *
  49. * @param {Object} state - The Redux state.
  50. * @private
  51. * @returns {{
  52. * _enabled: boolean
  53. * }}
  54. */
  55. function _mapStateToProps(state): Object {
  56. const flag = Boolean(getFeatureFlag(state, PIP_ENABLED));
  57. let enabled = flag;
  58. // Override flag for Android, since it might be unsupported.
  59. if (Platform.OS === 'android' && !NativeModules.PictureInPicture.SUPPORTED) {
  60. enabled = false;
  61. }
  62. return {
  63. _enabled: enabled
  64. };
  65. }
  66. export default translate(connect(_mapStateToProps)(PictureInPictureButton));