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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. this.state = nextState;
  65. } else {
  66. this.setState(nextState);
  67. }
  68. }
  69. }
  70. /**
  71. * Implements React's {@link Component#render()}.
  72. *
  73. * @inheritdoc
  74. * @override
  75. * @returns {ReactElement}
  76. */
  77. render() {
  78. return (
  79. <View style = { this.state.style }>
  80. <VideoTrack videoTrack = { this.props._localVideoTrack } />
  81. <View style = { styles.localVideoTrackOverlay }>
  82. { this.props.children }
  83. </View>
  84. </View>
  85. );
  86. }
  87. }
  88. /**
  89. * Maps (parts of) the redux state to the React {@code Component} props of
  90. * {@code LocalVideoTrackUnderlay}.
  91. *
  92. * @param {Object} state - The redux state.
  93. * @private
  94. * @returns {{
  95. * _localVideoTrack: (Track|undefined)
  96. * }}
  97. */
  98. function _mapStateToProps(state) {
  99. return {
  100. _localVideoTrack: getLocalVideoTrack(state['features/base/tracks'])
  101. };
  102. }
  103. export default connect(_mapStateToProps)(LocalVideoTrackUnderlay);