您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

LocalVideoTrackUnderlay.native.js 3.2KB

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