forked from GeekyAnts/NativeBase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomputeProps.js
More file actions
42 lines (26 loc) · 1.09 KB
/
computeProps.js
File metadata and controls
42 lines (26 loc) · 1.09 KB
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
var React = require('react-native');
var StyleSheetRegistry = require('react-native/Libraries/StyleSheet/StyleSheetRegistry');
module.exports = function(incomingProps, defaultProps) {
// External props has a higher precedence
var computedProps = {};
incomingProps = _.clone(incomingProps);
if(incomingProps)
delete incomingProps.children;
// console.log(defaultProps, incomingProps);
if(incomingProps)
_.merge(computedProps, defaultProps, incomingProps);
else
computedProps = defaultProps;
// Pass the merged Style Object instead
if(incomingProps && incomingProps.style) {
if(typeof incomingProps.style == 'number') {
var incomingPropsStyle = StyleSheetRegistry.getStyleByID(incomingProps.style);
computedProps.style = {};
} else {
var incomingPropsStyle = incomingProps.style;
}
_.merge(computedProps.style, defaultProps.style, incomingPropsStyle);
}
// console.log("computedProps ", computedProps);
return incomingProps ? computedProps : defaultProps;
}