-
Notifications
You must be signed in to change notification settings - Fork 61
/
Utils.js
54 lines (47 loc) · 1.5 KB
/
Utils.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
47
48
49
50
51
52
53
54
class Utils {
// Was causing crashes with RN > 0.55, removed for now.
//
// static isTextOnly(nodes) {
// if (nodes.length) {
// for (let i = 0; i < nodes.length; i++) {
// if (nodes[i] &&
// nodes[i].hasOwnProperty('type') &&
// nodes[i].type.hasOwnProperty('displayName')) {
// if (nodes[i].type.displayName !== 'Text') {
// return false;
// }
// }
// }
// }
// return true;
// }
static concatStyles(extras, newStyle) {
let newExtras;
if (extras) {
newExtras = JSON.parse(JSON.stringify(extras));
if (extras.style) {
newExtras.style.push(newStyle);
} else {
newExtras.style = [newStyle];
}
} else {
newExtras = {
style: [newStyle]
};
}
return newExtras;
}
static logDebug(nodeTree, level = 0) {
for (let i = 0; i < nodeTree.length; i++) {
const node = nodeTree[i];
if (node) {
let prefix = Array(level).join('-');
console.log(prefix + '> ' + node.key + ', NODE TYPE: ' + node.type.displayName);
if (Array.isArray(node.props.children)) {
this.logDebug(node.props.children, level + 1);
}
}
}
}
}
module.exports = Utils;