forked from GeekyAnts/NativeBase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputeProps.js
50 lines (42 loc) · 1.67 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
47
48
49
50
'use_strict';
import _ from 'lodash';
import ReactNativePropRegistry from 'react-native/Libraries/Renderer/src/renderers/native/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;
var incomingPropsStyle = incomingProps.style;
delete incomingProps.style;
// console.log(defaultProps, incomingProps);
if(incomingProps) {
_.assign(computedProps, defaultProps, incomingProps);
} else
computedProps = defaultProps;
// Pass the merged Style Object instead
if(incomingPropsStyle) {
var computedPropsStyle = {};
computedProps.style = {};
if (Array.isArray(incomingPropsStyle)) {
_.forEach(incomingPropsStyle, (style)=>{
if(typeof style == 'number') {
_.merge(computedPropsStyle, ReactNativePropRegistry.getByID(style));
} else {
_.merge(computedPropsStyle, style);
}
})
}
else {
if(typeof incomingPropsStyle == 'number') {
computedPropsStyle = ReactNativePropRegistry.getByID(incomingPropsStyle);
} else {
computedPropsStyle = incomingPropsStyle;
}
}
_.merge(computedProps.style, defaultProps.style, computedPropsStyle);
}
// console.log("computedProps ", computedProps);
return computedProps;
}