File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,23 @@ const Hello = React.createClass({
95
95
}
96
96
});
97
97
```
98
+
99
+ Dynamic styles are marked as used only if you use a local variable with the same name as the variable in the actual component .
100
+
101
+ ``` js
102
+ const getStyles = () => {
103
+ const styles = StyleSheet .create ({
104
+ name: {}
105
+ })
106
+ return styles;
107
+ }
108
+ const Hello = React .createClass ({
109
+ render : function () {
110
+ const styles = getStyles ();
111
+ return < Text textStyle= {styles .name }> Hello {this .props .name }< / Text > ;
112
+ }
113
+ });
114
+ ```
98
115
Rules are also marked as used when they are used in tags that contain the word ` style ` .
99
116
100
117
``` js
Original file line number Diff line number Diff line change @@ -31,6 +31,21 @@ const tests = {
31
31
}
32
32
});
33
33
` ,
34
+ } , {
35
+ code : `
36
+ const getStyles = () => {
37
+ const styles = StyleSheet.create({
38
+ name: {}
39
+ })
40
+ return styles;
41
+ }
42
+ const Hello = React.createClass({
43
+ render: function() {
44
+ const styles = getStyles();
45
+ return <Text textStyle={styles.name}>Hello {this.props.name}</Text>;
46
+ }
47
+ });
48
+ ` ,
34
49
} , {
35
50
code : `
36
51
const Hello = React.createClass({
@@ -231,6 +246,23 @@ const tests = {
231
246
errors : [ {
232
247
message : 'Unused style detected: styles.text' ,
233
248
} ] ,
249
+ } , {
250
+ code : `
251
+ const getStyles = () => {
252
+ return OtherStyleSheet.create({
253
+ text: {}
254
+ })
255
+ }
256
+ const Hi = React.createClass({
257
+ render: function() {
258
+ const globalStyles = getStyles();
259
+ return <Text textStyle={globalStyles.text}>Hi {this.props.name}</Text>;
260
+ }
261
+ });
262
+ ` ,
263
+ errors : [ {
264
+ message : 'Unused style detected: undefined.text' ,
265
+ } ] ,
234
266
} , {
235
267
code : `
236
268
const styles = StyleSheet.create({
You can’t perform that action at this time.
0 commit comments