import React, { useContext } from 'react'; import { useSafeAreaInsets } from 'react-native-safe-area-context'; import { Dimensions, StyleSheet, View } from 'react-native'; import { ApplicationContext } from '../Context'; import { Colors, Spacing } from '../Consts'; import { GridContextProps } from './types'; import { useGridSystem } from './utils'; const GridSystem: React.FC = ({ width = Dimensions.get('window').width, useMargin = true, gutterSize = Spacing.M, screenGrid = true, gridColor = Colors.blue_07, }) => { const { theme } = useContext(ApplicationContext); const { numberOfColumns } = useGridSystem(); const margin = useMargin ? Spacing.M : 0; const widthSection = width - margin * 2; const totalGutterSize = gutterSize * (numberOfColumns - 1); const sizePerSpan = (widthSection - totalGutterSize) / numberOfColumns; const grid: GridContextProps = { numberOfColumns, gutterSize, sizePerSpan, getSizeSpan: span => { return span * sizePerSpan + (span - 1) * gutterSize; }, }; const insets = useSafeAreaInsets(); const list: number[] = []; for (let i = 1; i <= grid.numberOfColumns; i++) { list.push(i); } return ( <> {list.map((_, index) => { return ( {index !== 0 && } ); })} {screenGrid && ( <> )} ); }; const styles = StyleSheet.create({ gridContainer: { position: 'absolute', top: 0, bottom: 0, left: 0, right: 0, flexDirection: 'row', borderWidth: 1, }, gridColumn: { height: '100%', opacity: 0.2, }, dangerTopContainer: { opacity: 0.2, backgroundColor: Colors.red_03, width: '100%', top: 0, position: 'absolute', }, dangerBottomContainer: { opacity: 0.2, backgroundColor: Colors.red_03, width: '100%', bottom: 0, position: 'absolute', }, dangerLeftContainer: { opacity: 0.2, backgroundColor: Colors.red_03, width: Spacing.M, height: '100%', left: 0, position: 'absolute', }, dangerRightContainer: { opacity: 0.2, backgroundColor: Colors.red_03, width: Spacing.M, height: '100%', right: 0, position: 'absolute', }, }); export default GridSystem;