-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
46 lines (37 loc) · 1.54 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var StyleSheet = require('react-native').StyleSheet;
var merge = require('merge');
var assign = require('object-assign');
function randomHexColor() {
return '#'+('00000'+(Math.random()*16777216<<0).toString(16)).substr(-6);
};
function createDebugStylesheet(debugOptions) {
return {
create: (styleObject) => {
for (var styleClass in styleObject) {
var propertiesForStyleClass = {};
for (var debugProperty in debugOptions) {
// Apply the function to get a value unique to this styleClass for the property
if (typeof debugOptions[debugProperty] == 'function') {
var value = debugOptions[debugProperty].call(this, styleClass, debugProperty, styleObject[styleClass][debugProperty]);
if (value != null && (typeof value !== 'undefined')) {
propertiesForStyleClass[debugProperty] = value;
}
// Otherwise just set the value
} else {
propertiesForStyleClass[debugProperty] = debugOptions[debugProperty];
}
}
styleObject[styleClass] = merge(styleObject[styleClass], propertiesForStyleClass);
}
return StyleSheet.create(styleObject);
}
}
}
var DefaultDebugStylesheet = createDebugStylesheet({borderColor: randomHexColor, borderWidth: 1});
module.exports = assign(
DefaultDebugStylesheet,
{ Borders: DefaultDebugStylesheet,
Backgrounds: createDebugStylesheet({backgroundColor: randomHexColor, opacity: 0.85}),
createDebugStylesheet: createDebugStylesheet,
randomHexColor: randomHexColor }
)