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.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 = this.props.grid[rowNumber].map(this.getCellRender);
  23. return (
  24. <View
  25. style={{
  26. flexDirection: 'row',
  27. backgroundColor: this.props.backgroundColor,
  28. }}
  29. key={rowNumber.toString()}
  30. >
  31. {cells}
  32. </View>
  33. );
  34. }
  35. getCellRender = (item: Object) => {
  36. return <Cell item={item} key={item.key}/>;
  37. };
  38. getGrid() {
  39. let rows = [];
  40. for (let i = 0; i < this.props.height; i++) {
  41. rows.push(this.getRow(i));
  42. }
  43. return rows;
  44. }
  45. render() {
  46. return (
  47. <View style={{
  48. flexDirection: 'column',
  49. maxWidth: this.props.containerMaxWidth,
  50. maxHeight: this.props.containerMaxHeight,
  51. aspectRatio: this.props.width / this.props.height,
  52. marginLeft: 'auto',
  53. marginRight: 'auto',
  54. }}>
  55. {this.getGrid()}
  56. </View>
  57. );
  58. }
  59. }
  60. export default withTheme(Grid);