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.

DisplayNameLabel.tsx 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import * as React from 'react';
  2. import { Text, TextStyle, View, ViewStyle } from 'react-native';
  3. import { connect } from 'react-redux';
  4. import { IReduxState } from '../../../app/types';
  5. import {
  6. getParticipantById,
  7. getParticipantDisplayName,
  8. isScreenShareParticipant
  9. } from '../../../base/participants/functions';
  10. import styles from './styles';
  11. interface IProps {
  12. /**
  13. * The name of the participant to render.
  14. */
  15. _participantName: string;
  16. /**
  17. * True of the label needs to be rendered. False otherwise.
  18. */
  19. _render: boolean;
  20. /**
  21. * Whether or not the name is in a container.
  22. */
  23. contained?: boolean;
  24. /**
  25. * The ID of the participant to render the label for.
  26. */
  27. participantId: string;
  28. }
  29. /**
  30. * Renders a label with the display name of the on-stage participant.
  31. */
  32. class DisplayNameLabel extends React.Component<IProps> {
  33. /**
  34. * Implements {@code Component#render}.
  35. *
  36. * @inheritdoc
  37. */
  38. render() {
  39. if (!this.props._render) {
  40. return null;
  41. }
  42. return (
  43. <View
  44. style = { (this.props.contained ? styles.displayNamePadding : styles.displayNameBackdrop
  45. ) as ViewStyle }>
  46. <Text
  47. numberOfLines = { 1 }
  48. style = { styles.displayNameText as TextStyle }>
  49. { this.props._participantName }
  50. </Text>
  51. </View>
  52. );
  53. }
  54. }
  55. /**
  56. * Maps part of the Redux state to the props of this component.
  57. *
  58. * @param {any} state - The Redux state.
  59. * @param {IProps} ownProps - The own props of the component.
  60. * @returns {IProps}
  61. */
  62. function _mapStateToProps(state: IReduxState, ownProps: Partial<IProps>) {
  63. const participant = getParticipantById(state, ownProps.participantId ?? '');
  64. return {
  65. _participantName: getParticipantDisplayName(state, ownProps.participantId ?? ''),
  66. _render: Boolean(participant && (!participant?.local || ownProps.contained)
  67. && (!participant?.fakeParticipant || isScreenShareParticipant(participant)))
  68. };
  69. }
  70. export default connect(_mapStateToProps)(DisplayNameLabel);