-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
103 lines (96 loc) · 2.17 KB
/
index.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import React, { Component } from "react";
import PropTypes from "prop-types";
import {
Dimensions,
ImageBackground,
StyleSheet,
Text,
View,
Image,
ViewPropTypes
} from "react-native";
const { width } = Dimensions.get("window");
export default class ImageOverlay extends Component {
render() {
const {
blurRadius,
children,
containerStyle,
contentPosition,
height,
overlayAlpha,
overlayColor,
rounded,
source,
title,
titleStyle,
...props
} = this.props;
let justifyContent;
if (contentPosition == "top") {
justifyContent = "flex-start";
} else if (contentPosition == "bottom") {
justifyContent = "flex-end";
} else if (contentPosition == "center") {
justifyContent = "center";
}
return (
<ImageBackground
source={source}
style={[
styles.image,
{
borderRadius: rounded,
height: height,
justifyContent: justifyContent
},
containerStyle
]}
blurRadius={blurRadius}
>
<View
style={{
...StyleSheet.absoluteFillObject,
backgroundColor: overlayColor,
opacity: overlayAlpha
}}
/>
{!children &&
title && <Text style={[styles.title, titleStyle]}>{title}</Text>}
{children}
</ImageBackground>
);
}
}
const styles = StyleSheet.create({
image: {
width: width,
overflow: "hidden",
alignItems: "center"
},
title: {
margin: 20,
color: "white",
textAlign: "center",
fontSize: 16
}
});
ImageOverlay.propTypes = {
rounded: PropTypes.number,
source: Image.propTypes.source,
height: PropTypes.number,
title: PropTypes.string,
titleStyle: Text.propTypes.style,
overlayColor: PropTypes.string,
overlayAlpha: PropTypes.number,
contentPosition: PropTypes.oneOf(["top", "center", "bottom"]),
containerStyle: ViewPropTypes.style,
blurRadius: PropTypes.number,
children: PropTypes.element
};
ImageOverlay.defaultProps = {
height: 300,
overlayColor: "#000000",
overlayAlpha: 0.5,
contentPosition: "center"
};