@kitten-team/react-native-sortable-grid
Advanced tools
Comparing version 2.0.6 to 2.0.7
57
index.js
@@ -82,3 +82,3 @@ import * as React from 'react' | ||
style={ this._getGridStyle() } | ||
onLayout={this.assessGridSize} | ||
onLayout={this.onGridLayout} | ||
> | ||
@@ -162,2 +162,3 @@ { this.state.gridLayout && | ||
} | ||
this.debouncedAssessGridSize = _.debounce(this.assessGridSize, 200); | ||
} | ||
@@ -306,11 +307,10 @@ | ||
deleteBlock = (deleteBlock) => { | ||
let activeBlock = deleteBlock ? deleteBlock : this.state.activeBlock | ||
this.setState({ deleteBlock: activeBlock }) | ||
this.blockAnimateFadeOut() | ||
.then( () => { | ||
this.setState({ activeBlock: null, deleteBlock: null }, () => { | ||
this.onDeleteItem({ item: this.itemOrder[ activeBlock ] }) | ||
this.deleteBlocks([ activeBlock ]) | ||
}) | ||
}) | ||
this.setState({ deleteBlock, }, () => { | ||
this.blockAnimateFadeOut() | ||
.then( () => { | ||
this.onDeleteItem({ item: this.itemOrder[ deleteBlock ] }); | ||
this.deleteBlocks([ deleteBlock ]); | ||
this.setState({deleteBlock:null, activeBlock:null}); | ||
}); | ||
}); | ||
} | ||
@@ -327,3 +327,3 @@ | ||
toValue:0.01, | ||
duration:350 | ||
duration:250 | ||
}; | ||
@@ -379,3 +379,12 @@ } | ||
assessGridSize = ({nativeEvent}) => { | ||
onGridLayout = (params) => { | ||
const nativeEvent = _.cloneDeep(params.nativeEvent); | ||
if (this.firstInitDone) { | ||
this.debouncedAssessGridSize(nativeEvent); | ||
} else { | ||
this.assessGridSize(nativeEvent); | ||
} | ||
} | ||
assessGridSize = (nativeEvent) => { | ||
if (this.props.itemWidth && this.props.itemWidth < nativeEvent.layout.width) { | ||
@@ -405,6 +414,8 @@ this.itemsPerRow = Math.floor(nativeEvent.layout.width / this.props.itemWidth) | ||
init_block_positions_set_count = 0; | ||
init_block_positions = []; | ||
saveBlockPositions = (key) => ({nativeEvent}) => { | ||
let blockPositions = this.state.blockPositions | ||
let blockPositions = this.init_block_positions | ||
if (!blockPositions[key]) { | ||
let blockPositionsSetCount = blockPositions[key] ? this.state.blockPositionsSetCount : ++this.state.blockPositionsSetCount | ||
let blockPositionsSetCount = blockPositions[key] ? this.init_block_positions_set_count : ++this.init_block_positions_set_count | ||
let thisPosition = { | ||
@@ -418,5 +429,10 @@ x: nativeEvent.layout.x, | ||
} | ||
this.setState({ blockPositions, blockPositionsSetCount }) | ||
this.init_block_positions = blockPositions; | ||
this.init_block_positions_set_count = blockPositionsSetCount; | ||
if (this._blockPositionsSet()) { | ||
if (blockPositionsSetCount === this.items.length) { | ||
this.setState({ | ||
blockPositions, | ||
blockPositionsSetCount, | ||
}) | ||
this.setGhostPositions() | ||
@@ -481,2 +497,4 @@ this.initialLayoutDone = true | ||
const needRemoveItem = items.length < this.items.length; | ||
let blockPositions = this.state.blockPositions; | ||
let blockPositionsSetCount= this.state.blockPositionsSetCount; | ||
items.forEach( (item, index) => { | ||
@@ -502,4 +520,3 @@ const foundKey = _.findKey(this.itemOrder, oldItem => oldItem.key === item.key); | ||
else { | ||
let blockPositions = this.state.blockPositions | ||
let blockPositionsSetCount = ++this.state.blockPositionsSetCount | ||
++blockPositionsSetCount; | ||
let thisPosition = this.getNextBlockCoordinates() | ||
@@ -514,3 +531,2 @@ blockPositions.push({ | ||
} | ||
this.setState({ blockPositions, blockPositionsSetCount, hadInitNewPositionsWhenAddItems}); | ||
this.setGhostPositions() | ||
@@ -521,2 +537,5 @@ } | ||
}) | ||
if (blockPositionsSetCount != this.state.blockPositionsSetCount) { | ||
this.setState({ blockPositions, blockPositionsSetCount, hadInitNewPositionsWhenAddItems}); | ||
} | ||
if (this.firstInitDone && (hadInsert || needRemoveItem) ) { | ||
@@ -523,0 +542,0 @@ setTimeout(() => { |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "2.0.6", | ||
"version": "2.0.7", | ||
"description": "Drag-and-drop sortable grid view for React Native.", | ||
@@ -11,0 +11,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
1030
206733