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 1.9KB

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