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.

GridComponent.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // @flow
  2. import * as React from 'react';
  3. import {View} from 'react-native';
  4. import {withTheme} from 'react-native-paper';
  5. import type {Cell} from "./CellComponent";
  6. import CellComponent from "./CellComponent";
  7. import type {ViewStyle} from "react-native/Libraries/StyleSheet/StyleSheet";
  8. export type Grid = Array<Array<CellComponent>>;
  9. type Props = {
  10. grid: Array<Array<Object>>,
  11. height: number,
  12. width: number,
  13. style: ViewStyle,
  14. }
  15. class GridComponent extends React.Component<Props> {
  16. getRow(rowNumber: number) {
  17. let cells = this.props.grid[rowNumber].map(this.getCellRender);
  18. return (
  19. <View
  20. style={{flexDirection: 'row',}}
  21. key={rowNumber.toString()}
  22. >
  23. {cells}
  24. </View>
  25. );
  26. }
  27. getCellRender = (item: Cell) => {
  28. return <CellComponent cell={item} key={item.key}/>;
  29. };
  30. getGrid() {
  31. let rows = [];
  32. for (let i = 0; i < this.props.height; i++) {
  33. rows.push(this.getRow(i));
  34. }
  35. return rows;
  36. }
  37. render() {
  38. return (
  39. <View style={{
  40. aspectRatio: this.props.width / this.props.height,
  41. borderRadius: 4,
  42. ...this.props.style
  43. }}>
  44. {this.getGrid()}
  45. </View>
  46. );
  47. }
  48. }
  49. export default withTheme(GridComponent);