1

我在 react-native-android 中创建了一个 2 列的 FLatlist

1    |    2
------------
3    |    4

我要这个

2    |    1
4    |    3

我试试这些:

<View style={{flex:1,flexDirection:'row-reverse'}}>
        <FlatList
            style={{flex:1,flexDirection:'row-reverse'}}

在渲染项目中我flexDirection:'row-reverse'也使用

但没有成功!

4

2 回答 2

5

你可以flexDirection: 'row-reverse'在里面使用columnWrapperStyle

<FlatList
  numColumns={2}
  columnWrapperStyle={{ flexDirection: 'row-reverse' }}
  data={data}
  renderItem={yourRenderFunction}
/>
于 2019-05-26T12:09:53.480 回答
1

我建议只修改数据的顺序:

例如,您可以引入一个arrayMove执行重新排序的函数。

例子:

  const data = [
        { 
          'id': 1 
        },
        { 
          'id': 2
        },
        { 
          'id': 3
        },
        { 
          'id': 4
        } 
   ];
  
  
function arrayMove(arr, fromIndex, toIndex) {
  var element = arr[fromIndex];
  arr.splice(fromIndex, 1);
  arr.splice(toIndex, 0, element);
}
console.log('data', data);
arrayMove(data, 1, 0);
arrayMove(data, 3, 2);
console.log('data permutated', data); 

输出:

工作博览会:

https://snack.expo.io/ryeNv5S2E

于 2019-05-12T12:54:34.237 回答