Created
April 7, 2017 14:47
-
-
Save mvbattan/ca8ed13958785886b2ecb4f397f077c8 to your computer and use it in GitHub Desktop.
SeparatorsLayer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { View, StyleSheet } from 'react-native'; | |
import LevelSeparator from './LevelSeparator'; | |
export const range = (n) => { | |
return [...Array(n).keys()]; | |
}; | |
function createSeparator(totalCount, topValue, index, height) { | |
return ( | |
<LevelSeparator | |
key={index} | |
label={topValue * (totalCount - index) / totalCount} | |
height={height / totalCount} | |
/> | |
); | |
} | |
function SeparatorsLayer({ topValue, separators, height, children, style }) { | |
return ( | |
<View style={[styles.container, style]}> | |
{range(separators + 1).map((separatorNumber) => { | |
return createSeparator(separators, topValue, separatorNumber, height); | |
})} | |
{children} | |
</View> | |
); | |
} | |
SeparatorsLayer.propTypes = { | |
topValue: React.PropTypes.number.isRequired, | |
separators: React.PropTypes.number.isRequired, | |
height: React.PropTypes.number.isRequired | |
}; | |
const styles = StyleSheet.create({ | |
container: { | |
position: 'absolute' | |
} | |
}); | |
export default SeparatorsLayer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment