-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
43 lines (39 loc) · 1.06 KB
/
util.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
import { StyleSheet } from 'react-native';
export const isStyleRow = style => {
const flatStyle = StyleSheet.flatten(style || {});
return flatStyle.flexDirection !== 'column';
};
const getDashStyleId = (
{ dashGap, dashLength, dashThickness, dashColor },
isRow
) =>
`${dashGap}-${dashLength}-${dashThickness}-${dashColor}-${
isRow ? 'row' : 'column'
}`;
const createDashStyleSheet = (
{ dashGap, dashLength, dashThickness, dashColor },
isRow
) => {
const idStyle = new StyleSheet.create({
style: {
width: isRow ? dashLength : dashThickness,
height: isRow ? dashThickness : dashLength,
marginRight: isRow ? dashGap : 0,
marginBottom: isRow ? 0 : dashGap,
backgroundColor: dashColor,
},
});
return idStyle.style;
};
let stylesStore = {};
export const getDashStyle = props => {
const isRow = isStyleRow(props.style);
const id = getDashStyleId(props, isRow);
if (!stylesStore[id]) {
stylesStore = {
...stylesStore,
[id]: createDashStyleSheet(props, isRow),
};
}
return stylesStore[id];
};