Skip to content

Commit

Permalink
updating const to let
Browse files Browse the repository at this point in the history
  • Loading branch information
Umair Ahmed authored and obipawan committed Jul 18, 2018
1 parent 9ea8cd1 commit ca868e8
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions util.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,43 @@
import { StyleSheet } from 'react-native'
import { StyleSheet } from 'react-native';

export const isStyleRow = (style) => {
const flatStyle = StyleSheet.flatten(style || {})
return flatStyle.flexDirection !== 'column'
}
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 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
}
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;
};

const 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 ]
}
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];
};

0 comments on commit ca868e8

Please sign in to comment.