-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCardView.android.js
More file actions
43 lines (39 loc) · 1.39 KB
/
CardView.android.js
File metadata and controls
43 lines (39 loc) · 1.39 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
43
import React from 'react'
import {StyleSheet} from 'react-native'
import RNCardView from './RNCardView'
import PropTypes from 'prop-types'
export default class CardView extends React.Component {
static propTypes = {
cardElevation: PropTypes.number,
maxCardElevation: PropTypes.number,
radius: PropTypes.number,
backgroundColor: PropTypes.string,
}
render() {
const {children, style, ...props} = this.props
const finalStyle = getFinalStyle(this.props, style)
return(
<RNCardView style={finalStyle} {...props}>
{children}
</RNCardView>
)
}
}
const getFinalStyle = (props, style = {}) => {
const {cardElevation = 0, radius = 0} = props
const paddingBottom = 2 * cardElevation + radius
const computedStyle = StyleSheet.flatten(style)
const keys = Object.keys(computedStyle)
if (!keys || keys.length === 0) return {paddingBottom}
const len = keys.length
let additionalStyle = {paddingBottom}
for (let i = len - 1; i >= 0; i--) {
const styleKey = keys[i]
const styleValue = computedStyle[keys[i]]
if (styleKey === 'paddingBottom' || styleKey === 'paddingVertical' || styleKey === 'padding') {
additionalStyle = {paddingBottom: styleValue + paddingBottom}
break
}
}
return [computedStyle, additionalStyle]
}