Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Grid.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // @flow
  2. import * as React from 'react';
  3. import {View} from 'react-native';
  4. import {withTheme} from 'react-native-paper';
  5. import Cell from "./Cell";
  6. type Props = {
  7. navigation: Object,
  8. grid: Array<Array<Object>>,
  9. backgroundColor: string,
  10. height: number,
  11. width: number,
  12. containerMaxHeight: number|string,
  13. containerMaxWidth: number|string,
  14. }
  15. class Grid extends React.Component<Props>{
  16. colors: Object;
  17. constructor(props) {
  18. super(props);
  19. this.colors = props.theme.colors;
  20. }
  21. getRow(rowNumber: number) {
  22. let cells = [];
  23. for (let i = 0; i < this.props.width; i++) {
  24. let cell = this.props.grid[rowNumber][i];
  25. let key = rowNumber + ':' + i;
  26. cells.push(<Cell color={cell.color} isEmpty={cell.isEmpty} id={key}/>);
  27. }
  28. return(
  29. <View style={{
  30. flexDirection: 'row',
  31. backgroundColor: this.props.backgroundColor,
  32. }}>
  33. {cells}
  34. </View>
  35. );
  36. }
  37. getGrid() {
  38. let rows = [];
  39. for (let i = 0; i < this.props.height; i++) {
  40. rows.push(this.getRow(i));
  41. }
  42. return rows;
  43. }
  44. render() {
  45. return (
  46. <View style={{
  47. flexDirection: 'column',
  48. maxWidth: this.props.containerMaxWidth,
  49. maxHeight: this.props.containerMaxHeight,
  50. aspectRatio: this.props.width/this.props.height,
  51. marginLeft: 'auto',
  52. marginRight: 'auto',
  53. }}>
  54. {this.getGrid()}
  55. </View>
  56. );
  57. }
  58. }
  59. export default withTheme(Grid);