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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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}/>;
  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. ...this.props.style
  42. }}>
  43. {this.getGrid()}
  44. </View>
  45. );
  46. }
  47. }
  48. export default withTheme(GridComponent);