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

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