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.

LocalVideoTrackUnderlay.native.js 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /* @flow */
  2. import React, { Component } from 'react';
  3. import { View } from 'react-native';
  4. import { connect } from 'react-redux';
  5. import { VideoTrack } from '../../base/media';
  6. import { TintedView } from '../../base/react';
  7. import { getLocalVideoTrack } from '../../base/tracks';
  8. import styles from './styles';
  9. /**
  10. * The type of the React {@code Component} props of
  11. * {@link LocalVideoTrackUnderlay}.
  12. */
  13. type Props = {
  14. /**
  15. * The redux representation of the local participant's video track.
  16. */
  17. _localVideoTrack: Object,
  18. /**
  19. * React Elements to display within the component.
  20. */
  21. children: React$Node,
  22. /**
  23. * The style, if any, to apply to {@link LocalVideoTrackUnderlay} in
  24. * addition to its default style.
  25. */
  26. style: Object
  27. };
  28. /**
  29. * The type of the React {@code Component} state of
  30. * {@link LocalVideoTrackUnderlay}.
  31. */
  32. type State = {
  33. /**
  34. * The style of {@code LocalVideoTrackUnderlay} which is a combination
  35. * of its default style and the consumer-specified style.
  36. */
  37. style: Object
  38. };
  39. /**
  40. * Implements a React {@code Component} which underlays the local video track,
  41. * if any, underneath its children.
  42. */
  43. class LocalVideoTrackUnderlay extends Component<Props, State> {
  44. /**
  45. * Initializes a new {@code LocalVideoTrackUnderlay} instance.
  46. *
  47. * @param {Object} props - The read-only React {@code Component} props with
  48. * which the new instance is to be initialized.
  49. */
  50. constructor(props) {
  51. super(props);
  52. this.componentWillReceiveProps(props);
  53. }
  54. /**
  55. * Notifies this mounted React {@code Component} that it will receive new
  56. * props. Forks (in Facebook/React speak) the prop {@code style} because its
  57. * value is to be combined with the default style.
  58. *
  59. * @inheritdoc
  60. * @param {Object} nextProps - The read-only React {@code Component} props
  61. * that this instance will receive.
  62. * @returns {void}
  63. */
  64. componentWillReceiveProps(nextProps) {
  65. // style
  66. const prevStyle = this.props && this.props.style;
  67. const nextStyle = nextProps && nextProps.style;
  68. const assignState = !this.state;
  69. if (prevStyle !== nextStyle || assignState) {
  70. const nextState = {
  71. style: {
  72. ...styles.localVideoTrackUnderlay,
  73. ...nextStyle
  74. }
  75. };
  76. if (assignState) {
  77. // eslint-disable-next-line react/no-direct-mutation-state
  78. this.state = nextState;
  79. } else {
  80. this.setState(nextState);
  81. }
  82. }
  83. }
  84. /**
  85. * Implements React's {@link Component#render()}.
  86. *
  87. * @inheritdoc
  88. * @override
  89. * @returns {ReactElement}
  90. */
  91. render() {
  92. return (
  93. <View style = { this.state.style }>
  94. <VideoTrack videoTrack = { this.props._localVideoTrack } />
  95. <TintedView>
  96. { this.props.children }
  97. </TintedView>
  98. </View>
  99. );
  100. }
  101. }
  102. /**
  103. * Maps (parts of) the redux state to the React {@code Component} props of
  104. * {@code LocalVideoTrackUnderlay}.
  105. *
  106. * @param {Object} state - The redux state.
  107. * @private
  108. * @returns {{
  109. * _localVideoTrack: (Track|undefined)
  110. * }}
  111. */
  112. function _mapStateToProps(state) {
  113. return {
  114. _localVideoTrack: getLocalVideoTrack(state['features/base/tracks'])
  115. };
  116. }
  117. export default connect(_mapStateToProps)(LocalVideoTrackUnderlay);