forked from GeekyAnts/NativeBase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputeProps.js
46 lines (29 loc) · 1.15 KB
/
computeProps.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
'use_strict';
import _ from 'lodash';
import ReactNativePropRegistry from 'react/lib/ReactNativePropRegistry';
// For compatibility with RN 0.25
// import ReactNativePropRegistry from "react-native/Libraries/ReactNative/ReactNativePropRegistry";
module.exports = function(incomingProps, defaultProps) {
// External props has a higher precedence
var computedProps = {};
incomingProps = _.clone(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.style) {
var incomingPropsStyle;
if(typeof incomingProps.style == 'number') {
incomingPropsStyle = ReactNativePropRegistry.getByID(incomingProps.style);
computedProps.style = {};
} else {
incomingPropsStyle = incomingProps.style;
}
_.merge(computedProps.style, defaultProps.style, incomingPropsStyle);
}
// console.log("computedProps ", computedProps);
return computedProps;
}