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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import * as React from 'react';
  2. import { Text, View } from 'react-native';
  3. import { IState } from '../../../app/types';
  4. import {
  5. getParticipantById,
  6. getParticipantDisplayName
  7. } from '../../../base/participants/functions';
  8. import { connect } from '../../../base/redux/functions';
  9. // @ts-ignore
  10. import styles from './styles';
  11. type Props = {
  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<Props> {
  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 style = { this.props.contained ? styles.displayNamePadding : styles.displayNameBackdrop }>
  44. <Text
  45. numberOfLines = { 1 }
  46. style = { styles.displayNameText }>
  47. { this.props._participantName }
  48. </Text>
  49. </View>
  50. );
  51. }
  52. }
  53. /**
  54. * Maps part of the Redux state to the props of this component.
  55. *
  56. * @param {any} state - The Redux state.
  57. * @param {Props} ownProps - The own props of the component.
  58. * @returns {Props}
  59. */
  60. function _mapStateToProps(state: IState, ownProps: Partial<Props>) {
  61. const participant = getParticipantById(state, ownProps.participantId ?? '');
  62. return {
  63. _participantName: getParticipantDisplayName(state, ownProps.participantId ?? ''),
  64. _render: participant && (!participant?.local || ownProps.contained) && !participant?.fakeParticipant
  65. };
  66. }
  67. export default connect(_mapStateToProps)(DisplayNameLabel);