This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
forked from Riglerr/react-native-hr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
79 lines (68 loc) · 1.67 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
import React, { Component } from 'react';
import PropTypes from 'prop-types'
import {
StyleSheet,
Text,
View,
TextInput
} from 'react-native';
const styles = StyleSheet.create({
line: {
flex: 1,
height: 1,
backgroundColor: 'black'
},
text: {
flex: 1,
textAlign: 'center',
marginLeft: 15,
marginRight: 15
}
});
class Hr extends Component {
constructor(props) {
super(props);
this.renderLine = this.renderLine.bind(this);
this.renderText = this.renderText.bind(this);
this.renderInner = this.renderInner.bind(this);
}
renderLine(key) {
return <View key={key} style={[styles.line, this.props.lineStyle]} />
}
renderText(key) {
return (
<View key={key} >
<Text style={[styles.text, this.props.textStyle]}>{this.props.text}</Text>
</View>
)
}
renderInner() {
if (!this.props.text) {
return this.renderLine()
}
return [
this.renderLine(1),
this.renderText(2),
this.renderLine(3)
]
}
render() {
return (
<View style={{ flexDirection: 'row', alignItems: 'center', marginLeft: this.props.marginLeft, marginRight: this.props.marginRight }}>
{this.renderInner()}
</View>
)
}
}
Hr.propTypes = {
lineStyle: PropTypes.shape({}),
text: PropTypes.string,
marginLeft: PropTypes.number,
marginRight: PropTypes.number,
textStyle: PropTypes.shape({})
};
Hr.defaultProps = {
marginLeft: 8,
marginRight: 8
};
export default Hr;