Переглянути джерело

ref(video): calculate tint styles at render

master
Leonard Kim 7 роки тому
джерело
коміт
f83d609f1a

+ 12
- 71
react/features/base/react/components/native/TintedView.js Переглянути файл

@@ -40,23 +40,11 @@ type Props = {
40 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 44
  * Implements a component aimed at covering another view and tinting it with
57 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 49
      * Default values for the component's props.
62 50
      */
@@ -66,62 +54,6 @@ export default class TintedView extends Component<Props, State> {
66 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 58
      * Implements React's {@link Component#render()}.
127 59
      *
@@ -129,6 +61,8 @@ export default class TintedView extends Component<Props, State> {
129 61
      * @returns {ReactElement}
130 62
      */
131 63
     render() {
64
+        const { children, color, opacity, style } = this.props;
65
+
132 66
         // XXX Don't tint the children, tint the background only.
133 67
         return (
134 68
             <View
@@ -136,11 +70,18 @@ export default class TintedView extends Component<Props, State> {
136 70
                 style = { BASE_STYLE }>
137 71
                 <View
138 72
                     pointerEvents = 'none'
139
-                    style = { this.state.style } />
73
+                    style = { [
74
+                        BASE_STYLE,
75
+                        style,
76
+                        {
77
+                            backgroundColor: color,
78
+                            opacity
79
+                        }
80
+                    ] } />
140 81
                 <View
141 82
                     pointerEvents = 'box-none'
142 83
                     style = { BASE_STYLE }>
143
-                    { this.props.children }
84
+                    { children }
144 85
                 </View>
145 86
             </View>
146 87
         );

Завантаження…
Відмінити
Зберегти