Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Toolbox.tsx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import React from 'react';
  2. import { View, ViewStyle } from 'react-native';
  3. import { SafeAreaView } from 'react-native-safe-area-context';
  4. import { connect, useSelector } from 'react-redux';
  5. import { IReduxState, IStore } from '../../../app/types';
  6. import ColorSchemeRegistry from '../../../base/color-scheme/ColorSchemeRegistry';
  7. import Platform from '../../../base/react/Platform.native';
  8. import { iAmVisitor } from '../../../visitors/functions';
  9. import { customButtonPressed } from '../../actions.native';
  10. import { getVisibleNativeButtons, isToolboxVisible } from '../../functions.native';
  11. import { useNativeToolboxButtons } from '../../hooks.native';
  12. import { IToolboxNativeButton } from '../../types';
  13. import styles from './styles';
  14. /**
  15. * The type of {@link Toolbox}'s React {@code Component} props.
  16. */
  17. interface IProps {
  18. /**
  19. * Whether we are in visitors mode.
  20. */
  21. _iAmVisitor: boolean;
  22. /**
  23. * The color-schemed stylesheet of the feature.
  24. */
  25. _styles: any;
  26. /**
  27. * The indicator which determines whether the toolbox is visible.
  28. */
  29. _visible: boolean;
  30. /**
  31. * Redux store dispatch method.
  32. */
  33. dispatch: IStore['dispatch'];
  34. }
  35. /**
  36. * Implements the conference Toolbox on React Native.
  37. *
  38. * @param {Object} props - The props of the component.
  39. * @returns {React$Element}
  40. */
  41. function Toolbox(props: IProps) {
  42. const {
  43. _iAmVisitor,
  44. _styles,
  45. _visible,
  46. dispatch
  47. } = props;
  48. if (!_visible) {
  49. return null;
  50. }
  51. const { clientWidth } = useSelector((state: IReduxState) => state['features/base/responsive-ui']);
  52. const { customToolbarButtons } = useSelector((state: IReduxState) => state['features/base/config']);
  53. const {
  54. mainToolbarButtonsThresholds,
  55. toolbarButtons
  56. } = useSelector((state: IReduxState) => state['features/toolbox']);
  57. const allButtons = useNativeToolboxButtons(customToolbarButtons);
  58. const { mainMenuButtons } = getVisibleNativeButtons({
  59. allButtons,
  60. clientWidth,
  61. mainToolbarButtonsThresholds,
  62. toolbarButtons
  63. });
  64. const bottomEdge = Platform.OS === 'ios' && _visible;
  65. const { buttonStylesBorderless, hangupButtonStyles } = _styles;
  66. const style = { ...styles.toolbox };
  67. // We have only hangup and raisehand button in _iAmVisitor mode
  68. if (_iAmVisitor) {
  69. style.justifyContent = 'center';
  70. }
  71. const renderToolboxButtons = () => {
  72. if (!mainMenuButtons?.length) {
  73. return;
  74. }
  75. return (
  76. <>
  77. {
  78. mainMenuButtons?.map(({ Content, key, text, ...rest }: IToolboxNativeButton) => (
  79. <Content
  80. { ...rest }
  81. /* eslint-disable react/jsx-no-bind */
  82. handleClick = { () => dispatch(customButtonPressed(key, text)) }
  83. isToolboxButton = { true }
  84. key = { key }
  85. styles = { key === 'hangup' ? hangupButtonStyles : buttonStylesBorderless } />
  86. ))
  87. }
  88. </>
  89. );
  90. };
  91. return (
  92. <View
  93. style = { styles.toolboxContainer as ViewStyle }>
  94. <SafeAreaView
  95. accessibilityRole = 'toolbar'
  96. // @ts-ignore
  97. edges = { [ bottomEdge && 'bottom' ].filter(Boolean) }
  98. pointerEvents = 'box-none'
  99. style = { style as ViewStyle }>
  100. { renderToolboxButtons() }
  101. </SafeAreaView>
  102. </View>
  103. );
  104. }
  105. /**
  106. * Maps parts of the redux state to {@link Toolbox} (React {@code Component})
  107. * props.
  108. *
  109. * @param {Object} state - The redux state of which parts are to be mapped to
  110. * {@code Toolbox} props.
  111. * @private
  112. * @returns {IProps}
  113. */
  114. function _mapStateToProps(state: IReduxState) {
  115. return {
  116. _iAmVisitor: iAmVisitor(state),
  117. _styles: ColorSchemeRegistry.get(state, 'Toolbox'),
  118. _visible: isToolboxVisible(state),
  119. };
  120. }
  121. export default connect(_mapStateToProps)(Toolbox);