как создать фиксированную сетку из 4 столбцов - PullRequest
0 голосов
/ 08 мая 2020

С массивом чисел, как я могу создать фиксированную сетку из 4 столбцов, как показано на рисунке ниже, с границей и радиусом границы?

numbers grid

1 Ответ

0 голосов
/ 08 мая 2020

Вот ссылка на стиль:

import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';

export default function App() {
  return (
    <View style={styles.container}>
      <View style={styles.grid}>
        <View style={[styles.cell, styles.selectedCell]}><Text style={[styles.text, styles.selectedText]}>3</Text></View>
        <View style={styles.cell}><Text style={styles.text}>4</Text></View>
        <View style={styles.cell}><Text style={styles.text}>5</Text></View>
        <View style={styles.cell}><Text style={styles.text}>6</Text></View>
        <View style={styles.cell}><Text style={styles.text}>7</Text></View>
        <View style={styles.cell}><Text style={styles.text}>8</Text></View>
        <View style={styles.cell}><Text style={styles.text}>9</Text></View>
        <View style={styles.cell}><Text style={styles.text}>10</Text></View>
        <View style={styles.cell}><Text style={styles.text}>11</Text></View>
        <View style={styles.cell}><Text style={styles.text}>12</Text></View>
        <View style={styles.cell}><Text style={styles.text}>13</Text></View>
        <View style={styles.cell}><Text style={styles.text}>14</Text></View>
        <View style={styles.cell}><Text style={styles.text}>15</Text></View>
        <View style={styles.cell}><Text style={styles.text}>16</Text></View>
        <View style={styles.cell}><Text style={styles.text}>17</Text></View>
        <View style={styles.cell}><Text style={styles.text}>18</Text></View>
      </View>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
  grid: {
    flexWrap: 'wrap',
    flexDirection: 'row',
    borderWidth: 1,
    borderColor: '#F65',
    borderRadius: 10,
    overflow: 'hidden'
  },
  cell: {
    flex: 1,
    paddingVertical: 5,
    backgroundColor: '#ccc',
    flexBasis: '25%',
    color: '#F3C9C9',
    justifyContent: 'center',
    alignItems: 'center',
    borderWidth: 1,
    borderColor: '#F65',
    margin: -1
  },
  text: {
    color: '#F65',
    fontSize: 20
  },
  selectedCell: {
    backgroundColor: '#F65'
  },
  selectedText: {
    color: 'white'
  }
});

Результат:

enter image description here

Вы можете увидеть живой эффект здесь

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...