react-native-sortable-list icon indicating copy to clipboard operation
react-native-sortable-list copied to clipboard

Getting current order of list

Open rendomnet opened this issue 6 years ago • 5 comments

I need to load some array of items to react-native-sortable-list. Reorder it and then get the reordered result back as array. Can I do it?

rendomnet avatar Apr 27 '18 11:04 rendomnet

你找到解决方案了吗?

sej1228 avatar Aug 09 '18 01:08 sej1228

Take a look at onChangeOrder and onReleaseRow, u can save the order and build reordered result by yourself

Daimension avatar Sep 01 '18 14:09 Daimension

Did anyone find a solution?

mayankbaiswar-CSE avatar Nov 28 '18 13:11 mayankbaiswar-CSE

@mayankbaiswar-CSE What @Daimension said. You can use onChangeOrder if you want the new order as you are dragging it around. You can use onReleaseRow if you just want the new order once dropped.

`onChangeOrder = (nextOrder) => { console.log('next order - ',nextOrder) }

onReleaseRow = (key, currentOrder) => { console.log('current order - ',currentOrder) }`

<SortableList style={styles.list} contentContainerStyle={styles.contentContainer} data={data} renderRow={this._renderRow} onChangeOrder={this.onChangeOrder} onReleaseRow={this.onReleaseRow} />

nh83012001 avatar Apr 15 '19 14:04 nh83012001

Further expanding on @nh83012001 and @Daimension's explanation using component state to rerender: Use in component:

<SortableList
    ...
    onReleaseRow={this.onRelease}
    ...
 />

onRelease function:

onRelease = (key, currentOrder) =>{
	let sorted = [];
	currentOrder.forEach(k => {
		this.state.items.forEach((item, index) => {
			if (index.toString() === k){
				sorted.push(item);
			}
		})
	})
	this.setState({ items: sorted })
}

garciaryan avatar Jun 21 '19 22:06 garciaryan