dancormier / react-native-swipeout

iOS-style swipeout buttons behind component
MIT License
2.62k stars 649 forks source link

Swipeout'props of close doesn't works ,please help me! #210

Closed huanghaodong closed 7 years ago

huanghaodong commented 7 years ago
import React,{Component} from 'react';
import {
  AppRegistry,
  AsyncStorage,
  Button,
  StyleSheet,
  Text,
  View,
  ListView,
  TouchableWithoutFeedback
} from 'react-native';
import Swipeout from 'react-native-swipeout';
const rows = [1,2,3,4,5,6,7,8,9];
class deleteMe extends Component {

  constructor() {
    super();

    var ds = new ListView.DataSource({rowHasChanged: (row1, row2) => true});

    this.state = {
      dataSource: ds.cloneWithRows(rows),
      rowID: null,
    };
  }

  _renderRow(rowData, sectionID, rowID) {
    return (
      <Swipeout
        close={!(this.state.rowID === rowID)}//点其他行就关闭当前行的swipe
        right={[{text:'button'}]}
        rowID={rowID}
        autoClose={true}
        backgroundColor={'#fff'}
        onOpen={(rowID) => {
          this.setState({
            rowID,
          })
        }}
        onClose={() => console.log('===close') }
        scroll={event => console.log('scroll event') }
      >
        <TouchableWithoutFeedback onPress={() => console.log('press children')}>
          <View style={styles.li} >
            <Text>{rowData}</Text>
          </View>
        </TouchableWithoutFeedback>
      </Swipeout>
    );
  }

  render() {
    return (
      <View style={styles.container}>
        <ListView
          dataSource={this.state.dataSource}
          renderRow={this._renderRow.bind(this)}
        />
      </View>
    );
  }

}

const styles = StyleSheet.create({
  container:{
    backgroundColor:'#fff',
    flex:1
  },
  li:{
    height:60,
    borderColor:'#000',
    borderBottomWidth:1
  }
})
AppRegistry.registerComponent('deleteMe', () => deleteMe);
huanghaodong commented 7 years ago

image

silentcloud commented 7 years ago

@huanghaodong Try to run the example (https://github.com/dancormier/react-native-swipeout/blob/master/example/SwipeoutExample.js), be sure if it works well

huanghaodong commented 7 years ago

我运行SwipeoutExample.js没问题,点击其它行可以关闭另一行的swipeOut。但是我这个代码却无法关闭swipeOut。我甚至尝试直接将close属性设为true,仍然没有任何效果!

silentcloud commented 7 years ago

@huanghaodong The first argument of onOpen is sectionID, so you must change

onOpen={(rowID) => { to onOpen={(_, rowID) => {

huanghaodong commented 7 years ago

it works,Thank you gays!

vuyani-k commented 7 years ago

lol hooray gays?