Browse Source

ref(video): calculate tint styles at render

master
Leonard Kim 7 years ago
parent
commit
f83d609f1a
1 changed files with 12 additions and 71 deletions
  1. 12
    71
      react/features/base/react/components/native/TintedView.js

+ 12
- 71
react/features/base/react/components/native/TintedView.js View File

40
     style: Object
40
     style: Object
41
 };
41
 };
42
 
42
 
43
-/**
44
- * {@code TintedView}'s React {@code Component} state.
45
- */
46
-type State = {
47
-
48
-    /**
49
-     * The style of {@code TintedView} which is a combination of its default
50
-     * style, the consumer-specified style.
51
-     */
52
-    style: Object
53
-};
54
-
55
 /**
43
 /**
56
  * Implements a component aimed at covering another view and tinting it with
44
  * Implements a component aimed at covering another view and tinting it with
57
  * the given color and opacity.
45
  * the given color and opacity.
58
  */
46
  */
59
-export default class TintedView extends Component<Props, State> {
47
+export default class TintedView extends Component<Props> {
60
     /**
48
     /**
61
      * Default values for the component's props.
49
      * Default values for the component's props.
62
      */
50
      */
66
         style: {}
54
         style: {}
67
     };
55
     };
68
 
56
 
69
-    /**
70
-     * Initializes a new {@code TintedView} instance.
71
-     *
72
-     * @param {Object} props - The read-only React {@code Component} props with
73
-     * which the new instance is to be initialized.
74
-     */
75
-    constructor(props: Object) {
76
-        super(props);
77
-
78
-        this.componentWillReceiveProps(props);
79
-    }
80
-
81
-    /**
82
-     * Notifies this mounted React {@code Component} that it will receive new
83
-     * props. Forks (in Facebook/React speak) the prop {@code style} because its
84
-     * value is to be combined with the default style.
85
-     *
86
-     * @inheritdoc
87
-     * @param {Object} nextProps - The read-only React {@code Component} props
88
-     * that this instance will receive.
89
-     * @returns {void}
90
-     */
91
-    componentWillReceiveProps(nextProps: Object) {
92
-        // style
93
-        const prevColor = this.props && this.props.color;
94
-        const prevOpacity = this.props && this.props.opacity;
95
-        const prevStyle = this.props && this.props.style;
96
-
97
-        const nextColor = nextProps && nextProps.color;
98
-        const nextOpacity = nextProps && nextProps.opacity;
99
-        const nextStyle = nextProps && nextProps.style;
100
-
101
-        const assignState = !this.state;
102
-
103
-        if (assignState
104
-                || prevColor !== nextColor
105
-                || prevOpacity !== nextOpacity
106
-                || prevStyle !== nextStyle) {
107
-            const nextState = {
108
-                style: {
109
-                    ...BASE_STYLE,
110
-                    ...nextStyle,
111
-                    backgroundColor: nextColor,
112
-                    opacity: nextOpacity
113
-                }
114
-            };
115
-
116
-            if (assignState) {
117
-                // eslint-disable-next-line react/no-direct-mutation-state
118
-                this.state = nextState;
119
-            } else {
120
-                this.setState(nextState);
121
-            }
122
-        }
123
-    }
124
-
125
     /**
57
     /**
126
      * Implements React's {@link Component#render()}.
58
      * Implements React's {@link Component#render()}.
127
      *
59
      *
129
      * @returns {ReactElement}
61
      * @returns {ReactElement}
130
      */
62
      */
131
     render() {
63
     render() {
64
+        const { children, color, opacity, style } = this.props;
65
+
132
         // XXX Don't tint the children, tint the background only.
66
         // XXX Don't tint the children, tint the background only.
133
         return (
67
         return (
134
             <View
68
             <View
136
                 style = { BASE_STYLE }>
70
                 style = { BASE_STYLE }>
137
                 <View
71
                 <View
138
                     pointerEvents = 'none'
72
                     pointerEvents = 'none'
139
-                    style = { this.state.style } />
73
+                    style = { [
74
+                        BASE_STYLE,
75
+                        style,
76
+                        {
77
+                            backgroundColor: color,
78
+                            opacity
79
+                        }
80
+                    ] } />
140
                 <View
81
                 <View
141
                     pointerEvents = 'box-none'
82
                     pointerEvents = 'box-none'
142
                     style = { BASE_STYLE }>
83
                     style = { BASE_STYLE }>
143
-                    { this.props.children }
84
+                    { children }
144
                 </View>
85
                 </View>
145
             </View>
86
             </View>
146
         );
87
         );

Loading…
Cancel
Save