jiti-meet/react/features/toolbox/components/native/ScreenSharingIosButton.js

153 lines
4.0 KiB
JavaScript
Raw Normal View History

// @flow
import React from 'react';
import { findNodeHandle, NativeModules, Platform } from 'react-native';
import { ScreenCapturePickerView } from 'react-native-webrtc';
import { getFeatureFlag, IOS_SCREENSHARING_ENABLED } from '../../../base/flags';
import { translate } from '../../../base/i18n';
import { IconShareDesktop } from '../../../base/icons';
import { connect } from '../../../base/redux';
import { AbstractButton, type AbstractButtonProps } from '../../../base/toolbox/components';
import { isLocalVideoTrackDesktop } from '../../../base/tracks';
/**
* The type of the React {@code Component} props of {@link ScreenSharingIosButton}.
*/
type Props = AbstractButtonProps & {
/**
* True if the button needs to be disabled.
*/
_disabled: boolean,
/**
* Whether video is currently muted or not.
*/
_screensharing: boolean,
/**
* The redux {@code dispatch} function.
*/
dispatch: Function
};
const styles = {
screenCapturePickerView: {
display: 'none'
}
};
/**
* An implementation of a button for toggling screen sharing on iOS.
*/
class ScreenSharingIosButton extends AbstractButton<Props, *> {
2021-11-04 21:10:43 +00:00
_nativeComponent: ?Object;
_setNativeComponent: Function;
2021-11-04 21:10:43 +00:00
accessibilityLabel = 'toolbar.accessibilityLabel.shareYourScreen';
icon = IconShareDesktop;
label = 'toolbar.startScreenSharing';
toggledLabel = 'toolbar.stopScreenSharing';
2021-11-04 21:10:43 +00:00
/**
* Initializes a new {@code ScreenSharingIosButton} instance.
*
* @param {Object} props - The React {@code Component} props to initialize
* the new {@code ScreenSharingIosButton} instance with.
*/
2021-11-04 21:10:43 +00:00
constructor(props) {
super(props);
2021-11-04 21:10:43 +00:00
this._nativeComponent = null;
2021-11-04 21:10:43 +00:00
// Bind event handlers so they are only bound once per instance.
this._setNativeComponent = this._setNativeComponent.bind(this);
}
2021-11-04 21:10:43 +00:00
/**
* Sets the internal reference to the React Component wrapping the
* {@code RPSystemBroadcastPickerView} component.
*
* @param {ReactComponent} component - React Component.
* @returns {void}
*/
2021-11-04 21:10:43 +00:00
_setNativeComponent(component) {
this._nativeComponent = component;
}
2021-11-04 21:10:43 +00:00
/**
* Handles clicking / pressing the button.
*
* @override
* @protected
* @returns {void}
*/
2021-11-04 21:10:43 +00:00
_handleClick() {
const handle = findNodeHandle(this._nativeComponent);
2021-11-04 21:10:43 +00:00
NativeModules.ScreenCapturePickerViewManager.show(handle);
}
2021-11-04 21:10:43 +00:00
/**
* Returns a boolean value indicating if this button is disabled or not.
*
* @protected
* @returns {boolean}
*/
2021-11-04 21:10:43 +00:00
_isDisabled() {
return this.props._disabled;
}
2021-11-04 21:10:43 +00:00
/**
* Indicates whether this button is in toggled state or not.
*
* @override
* @protected
* @returns {boolean}
*/
2021-11-04 21:10:43 +00:00
_isToggled() {
return this.props._screensharing;
}
2021-11-04 21:10:43 +00:00
/**
* Helper function to be implemented by subclasses, which may return a
* new React Element to be appended at the end of the button.
*
* @protected
* @returns {ReactElement|null}
*/
2021-11-04 21:10:43 +00:00
_getElementAfter() {
return (
<ScreenCapturePickerView
ref = { this._setNativeComponent }
style = { styles.screenCapturePickerView } />
);
}
}
/**
* Maps (parts of) the redux state to the associated props for the
* {@code ScreenSharingIosButton} component.
*
* @param {Object} state - The Redux state.
* @private
* @returns {{
* _disabled: boolean,
* }}
*/
function _mapStateToProps(state): Object {
const enabled = getFeatureFlag(state, IOS_SCREENSHARING_ENABLED, false);
return {
_screensharing: isLocalVideoTrackDesktop(state),
// TODO: this should work on iOS 12 too, but our trick to show the picker doesn't work.
2022-01-07 10:54:42 +00:00
visible: enabled
&& Platform.OS === 'ios'
&& Number.parseInt(Platform.Version.split('.')[0], 10) >= 14
};
}
export default translate(connect(_mapStateToProps)(ScreenSharingIosButton));