forked from obipawan/react-native-dash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDash.js
52 lines (47 loc) · 1.08 KB
/
Dash.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
/*
* Draws fully customizable dashed lines vertically or horizontally
*
* @providesModule Dash
*/
import React from 'react'
import PropTypes from 'prop-types'
import { View, StyleSheet, ViewPropTypes } 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.row : styles.column ] }
>
{ dash }
</View>
)
}
const styles = StyleSheet.create({
row: { flexDirection: 'row' },
column: { flexDirection: 'column' },
})
Dash.defaultProps = {
dashGap: 2,
dashLength: 4,
dashThickness: 2,
dashColor: 'black',
}
export default MeasureMeHOC(Dash)