forked from obipawan/react-native-dash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDash.js
More file actions
62 lines (56 loc) · 1.32 KB
/
Dash.js
File metadata and controls
62 lines (56 loc) · 1.32 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Draws fully customizable dashed lines vertically or horizontally
*
* @providesModule Dash
*/
import React from 'react'
import PropTypes from 'prop-types'
import { View, StyleSheet } from 'react-native'
import MeasureMeHOC from 'react-native-measureme'
import { getDashStyle, isStyleRow } from './util'
const Dash = (props) => {
const isRow = isStyleRow(props.style)
const length = isRow ? props.width : props.height
const n = Math.ceil(length / (props.dashGap + props.dashLength))
const calculatedDashStyles = getDashStyle(props)
let dash = []
for (let i = 0; i < n; i++) {
dash.push(
<View
key={ i }
style={ [
calculatedDashStyles,
props.dashStyle,
] }
/>
)
}
return (
<View onLayout={props.onLayout} style={ [ props.style, isRow ? styles.dashRow : styles.dashColumn ] }>
{ dash }
</View>
)
}
const styles = StyleSheet.create({
dashRow: {
flexDirection: 'row',
},
dashColumn: {
flexDirection: 'column',
},
})
Dash.propTypes = {
style: View.propTypes.style,
dashGap: PropTypes.number.isRequired,
dashLength: PropTypes.number.isRequired,
dashThickness: PropTypes.number.isRequired,
dashColor: PropTypes.string,
dashStyle: View.propTypes.style,
}
Dash.defaultProps = {
dashGap: 2,
dashLength: 4,
dashThickness: 2,
dashColor: 'black',
}
module.exports = MeasureMeHOC(Dash)