-
Notifications
You must be signed in to change notification settings - Fork 1
/
Container.js
64 lines (59 loc) · 1.54 KB
/
Container.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
55
56
57
58
59
60
61
62
63
64
import React, {Component} from 'react';
import {StyleSheet, View, Text, Platform} from 'react-native';
import PropTypes from 'prop-types';
import util from "./util";
export default class Container extends Component {
static propTypes = {
margin: PropTypes.any,
padding: PropTypes.any,
width: PropTypes.number,
height: PropTypes.number,
color: PropTypes.oneOfType([
PropTypes.number,
PropTypes.string,
]),
elevation: PropTypes.string,
borderRadius: PropTypes.any,
border: PropTypes.any,
}
static defaultProps = {
elevation: 0,
margin: {},
padding: {},
borderRadius: {},
border:{}
}
getPlatformElevation(elevation){
if(Platform.OS == "android")return { elevation }
return elevation == 0 ? {}
: {
shadowColor: "black",
shadowOpacity: 0.3,
shadowRadius: elevation,
shadowOffset: {
height: 2,
width: 0,
},
zIndex: 100,
}
}
render() {
const {width, height, color,margin,padding,border,borderRadius} = this.props;
let style = {
...util.getStyle(margin,"margin"),
...util.getStyle(padding,'padding'),
...util.getStyle(border, "border"),
...util.getStyle(borderRadius,"border","Radius"),
...this.getPlatformElevation(this.props.elevation),
}
width && (style.width = width);
height && (style.height = height);
color && (style.backgroundColor = color)
return (
<View
style={style}
children={this.props.children}
/>
)
}
}