-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathDash.js
More file actions
74 lines (68 loc) · 1.65 KB
/
Copy pathDash.js
File metadata and controls
74 lines (68 loc) · 1.65 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
63
64
65
66
67
68
69
70
71
72
73
74
/*
* 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 fullDashesCount = Math.floor(length / (props.dashGap + props.dashLength))
const lastDashSize = length - fullDashesCount * (props.dashGap + props.dashLength);
const calculatedDashStyles = getDashStyle(props)
const calculatedLastDashStyle = getDashStyle(props, lastDashSize)
let dash = []
for (let i = 0; i < fullDashesCount; i++) {
dash.push(
<View
key={ i }
style={ [
calculatedDashStyles,
props.dashStyle,
] }
/>
)
}
if (lastDashSize > 0) {
dash.push(
<View
key={ fullDashesCount }
style={ [
calculatedLastDashStyle,
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.propTypes = {
style: ViewPropTypes.style,
dashGap: PropTypes.number.isRequired,
dashLength: PropTypes.number.isRequired,
dashThickness: PropTypes.number.isRequired,
dashColor: PropTypes.string,
dashStyle: ViewPropTypes.style,
}
Dash.defaultProps = {
dashGap: 2,
dashLength: 4,
dashThickness: 2,
dashColor: 'black',
}
export default MeasureMeHOC(Dash)