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

ScreenSharingIosButton.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. // @flow
  2. import React from 'react';
  3. import { findNodeHandle, NativeModules, Platform } from 'react-native';
  4. import { ScreenCapturePickerView } from 'react-native-webrtc';
  5. import { getFeatureFlag, IOS_SCREENSHARING_ENABLED } from '../../../base/flags';
  6. import { translate } from '../../../base/i18n';
  7. import { IconShareDesktop } from '../../../base/icons';
  8. import { connect } from '../../../base/redux';
  9. import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
  10. import { isLocalVideoTrackDesktop } from '../../../base/tracks';
  11. /**
  12. * The type of the React {@code Component} props of {@link ScreenSharingIosButton}.
  13. */
  14. type Props = AbstractButtonProps & {
  15. /**
  16. * Whether video is currently muted or not.
  17. */
  18. _screensharing: boolean,
  19. /**
  20. * The redux {@code dispatch} function.
  21. */
  22. dispatch: Function
  23. };
  24. const styles = {
  25. screenCapturePickerView: {
  26. display: 'none'
  27. }
  28. };
  29. /**
  30. * An implementation of a button for toggling screen sharing on iOS.
  31. */
  32. class ScreenSharingIosButton extends AbstractButton<Props, *> {
  33. _nativeComponent: ?Object;
  34. _setNativeComponent: Function;
  35. accessibilityLabel = 'toolbar.accessibilityLabel.shareYourScreen';
  36. icon = IconShareDesktop;
  37. label = 'toolbar.startScreenSharing';
  38. toggledLabel = 'toolbar.stopScreenSharing';
  39. /**
  40. * Initializes a new {@code ScreenSharingIosButton} instance.
  41. *
  42. * @param {Object} props - The React {@code Component} props to initialize
  43. * the new {@code ScreenSharingIosButton} instance with.
  44. */
  45. constructor(props) {
  46. super(props);
  47. this._nativeComponent = null;
  48. // Bind event handlers so they are only bound once per instance.
  49. this._setNativeComponent = this._setNativeComponent.bind(this);
  50. }
  51. /**
  52. * Sets the internal reference to the React Component wrapping the
  53. * {@code RPSystemBroadcastPickerView} component.
  54. *
  55. * @param {ReactComponent} component - React Component.
  56. * @returns {void}
  57. */
  58. _setNativeComponent(component) {
  59. this._nativeComponent = component;
  60. }
  61. /**
  62. * Handles clicking / pressing the button.
  63. *
  64. * @override
  65. * @protected
  66. * @returns {void}
  67. */
  68. _handleClick() {
  69. const handle = findNodeHandle(this._nativeComponent);
  70. NativeModules.ScreenCapturePickerViewManager.show(handle);
  71. }
  72. /**
  73. * Indicates whether this button is in toggled state or not.
  74. *
  75. * @override
  76. * @protected
  77. * @returns {boolean}
  78. */
  79. _isToggled() {
  80. return this.props._screensharing;
  81. }
  82. /**
  83. * Helper function to be implemented by subclasses, which may return a
  84. * new React Element to be appended at the end of the button.
  85. *
  86. * @protected
  87. * @returns {ReactElement|null}
  88. */
  89. _getElementAfter() {
  90. return (
  91. <ScreenCapturePickerView
  92. ref = { this._setNativeComponent }
  93. style = { styles.screenCapturePickerView } />
  94. );
  95. }
  96. }
  97. /**
  98. * Maps (parts of) the redux state to the associated props for the
  99. * {@code ScreenSharingIosButton} component.
  100. *
  101. * @param {Object} state - The Redux state.
  102. * @private
  103. * @returns {{
  104. * _disabled: boolean,
  105. * }}
  106. */
  107. function _mapStateToProps(state): Object {
  108. const enabled = getFeatureFlag(state, IOS_SCREENSHARING_ENABLED, false);
  109. return {
  110. _screensharing: isLocalVideoTrackDesktop(state),
  111. // TODO: this should work on iOS 12 too, but our trick to show the picker doesn't work.
  112. visible: enabled && Platform.OS === 'ios' && Platform.Version.split('.')[0] >= 14
  113. };
  114. }
  115. export default translate(connect(_mapStateToProps)(ScreenSharingIosButton));