使用Native-Base关闭FlatList中的SwipeRow

ljm*_*cic 3 react-native native-base

如何在FlatList中关闭SwipeRow?

这是ListView的简单方法,但由于下一个版本将使用FlatList,因此应该可以.

从阅读他们的源代码,它似乎还没有实现.

akh*_*ier 13

你能试试吗

import React, { Component } from 'react';
import { FlatList } from 'react-native';
import { Container, Header, Content, SwipeRow, View, Text, Icon, Button } from 'native-base';

export default class App extends Component {
  constructor(props) {
    super(props)
    this.state = { data: [{ key: 'a' }, { key: 'b' }] }
    this.component = [];
    this.selectedRow;
  }
  render() {
    return (
      <Container>
        <Header />
        <Content>
          <FlatList
            data={[{ key: 'a', value: 'Row one' }, { key: 'b', value: 'Row two' }, { key: 'c', value: 'Row three' }, { key: 'd', value: 'Row four' }, { key: 'e', value: 'Row five' }]}
            keyExtractor={(item) => item.key}
            renderItem={({ item }) => <SwipeRow
              ref={(c) => { this.component[item.key] = c }}
              leftOpenValue={75}
              rightOpenValue={-75}
              onRowOpen={() => {
                if (this.selectedRow && this.selectedRow !== this.component[item.key]) { this.selectedRow._root.closeRow(); }
                this.selectedRow = this.component[item.key]
              }}
              left={
                <Button success onPress={() => alert('Add')}>
                  <Icon active name="add" />
                </Button>
              }
              body={
                <View style={{ paddingLeft: 20 }}>
                  <Text>{item.value}</Text>
                </View>
              }
              right={
                <Button danger onPress={() => alert('Delete')}>
                  <Icon active name="trash" />
                </Button>
              }
            />}
          />
          <Button style={{ margin: 20 }} onPress={() => this.selectedRow._root.closeRow()}><Text>Close row</Text></Button>
        </Content>
      </Container>
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述