Responsive Native Listview grid layout with Listview elements that are aligned and added independently

I have a problem aligning Listview elements, which should appear in a more box style than row style. In the picture, you can see the current state that is created using this StyleSheet code used in the Listview contentContainerStyle prop:

ListViewStyle: {
  flexDirection: 'row',
  flexWrap: 'wrap',
}

What I want to achieve is wrapped Listview elements without starting a new row after the line break and, as a result, without space at the top of the Listview element.

Any idea how to achieve this nice and clean? Thank!

+4
source share
1 answer

- . , ListView flex.

:

import React, { Component } from 'react';
import { AppRegistry, View } from 'react-native';

class AlignItemsBasics extends Component {
  render() {
    return (
      <View style={{flex: 1, flexDirection: 'row'}}>
        <View style={{
          flex: 1,
          flexDirection: 'column',
        }}>
          <View style={{flex:1, backgroundColor: 'red'}} />
          <View style={{flex: 2, backgroundColor: 'blue'}} />
          <View style={{flex:1, backgroundColor: 'green'}} />
          <View style={{flex:3, backgroundColor: 'grey'}} />
          <View style={{flex: 2, backgroundColor: 'skyblue'}} />

        </View>
        <View style={{
          flex: 1,
          flexDirection: 'column',
        }}>
          <View style={{flex:5, backgroundColor: 'pink'}} />
          <View style={{flex: 2, backgroundColor: 'red'}} />
        </View>
      </View>
    );
  }
};

AppRegistry.registerComponent('AwesomeProject', () => AlignItemsBasics);
Hide result

, , flex. , flex. , , . , .

+1

Source: https://habr.com/ru/post/1653580/


All Articles