項目中React NativeListView的長按刪除功能分享(基于ES5):
/**
*?Sample?React?Native?App
*?https://github.com/facebook/react-native
*?@flow
*/
importReact,?{Component}?from'react';
import{
AppRegistry,
StyleSheet,
Text,
View,
ListView,
TouchableOpacity
}?from'react-native';
vards?=newListView.DataSource({
rowHasChanged:?(r1,?r2)?=>?{
r1?!==?r2
}
});
varrows?=?['row?1','row?2','row?3','row?4','row?5','row?6'];
varXXX?=?React.createClass({
getInitialState()?{
return{
dataSource:?ds.cloneWithRows(rows),
};
},
_deleteRow(rowID)?{
deleterows[rowID];
this.setState({dataSource:?ds.cloneWithRows(rows)})
},
renderRow(rowData,?sectionID,?rowID)?{
returnthis._deleteRow(rowID)}
style={{height:?60,?flex:?1,?borderBottomWidth:?1}}>
{rowData}
},
render()?{
return(
dataSource={this.state.dataSource}
renderRow={this.renderRow}
/>
);
}
});
AppRegistry.registerComponent('XXX',?()?=>?XXX);
本文原創地址:http://blog.csdn.net/chichengjunma/article/details/53331160