@kitten-team/react-native-sortable-grid
Advanced tools
Comparing version 2.0.5 to 2.0.6
63
index.js
@@ -8,3 +8,4 @@ import * as React from 'react' | ||
Image, | ||
View | ||
View, | ||
Platform, | ||
} from 'react-native' | ||
@@ -16,3 +17,3 @@ | ||
const ITEMS_PER_ROW = 4 | ||
const DRAG_ACTIVATION_TRESHOLD = 200 // Milliseconds | ||
const DRAG_ACTIVATION_TRESHOLD = 350 // Milliseconds | ||
const BLOCK_TRANSITION_DURATION = 300 // Milliseconds | ||
@@ -22,3 +23,3 @@ const ACTIVE_BLOCK_CENTERING_DURATION = 200 // Milliseconds | ||
const NULL_FN = () => {} | ||
const ROW_MARGIN = 10 | ||
const ROW_MARGIN = 0 | ||
@@ -30,3 +31,3 @@ class Block extends React.Component { | ||
this.setState({ | ||
animatedValue: new Animated.Value(0), | ||
animatedValue: new Animated.Value(0.01), | ||
}); | ||
@@ -314,3 +315,2 @@ } else { | ||
this.deleteBlocks([ activeBlock ]) | ||
this.afterDragRelease() | ||
}) | ||
@@ -322,6 +322,16 @@ }) | ||
this.state.deleteBlockScale.setValue(1) | ||
let toValue = { | ||
toValue:0, | ||
duration:200, | ||
}; | ||
if (Platform.OS === 'android') { | ||
toValue = { | ||
toValue:0.01, | ||
duration:350 | ||
}; | ||
} | ||
return new Promise( (resolve, reject) => { | ||
Animated.timing( | ||
this.state.deleteBlockScale, | ||
{ toValue: 0, duration: 200} | ||
toValue, | ||
).start(resolve) | ||
@@ -332,3 +342,9 @@ }) | ||
animateBlockMove = (blockIndex, position) => { | ||
this._getBlock(blockIndex).currentPosition.setValue(position); | ||
Animated.timing( | ||
this._getBlock(blockIndex).currentPosition, | ||
{ | ||
toValue:position, | ||
duration:100, | ||
} | ||
).start(); | ||
} | ||
@@ -369,8 +385,8 @@ | ||
this.itemsPerRow = Math.floor(nativeEvent.layout.width / this.props.itemWidth) | ||
this.blockWidth = nativeEvent.layout.width / this.itemsPerRow | ||
this.blockWidth = nativeEvent.layout.width / this.itemsPerRow - 2 | ||
this.blockHeight = this.props.itemHeight || this.blockWidth | ||
} | ||
else { | ||
this.blockWidth = nativeEvent.layout.width / this.itemsPerRow | ||
this.blockHeight = this.blockWidth | ||
this.blockWidth = nativeEvent.layout.width / this.itemsPerRow - 2 | ||
this.blockHeight = this.props.itemHeight || this.blockWidth | ||
} | ||
@@ -465,2 +481,3 @@ if (this.state.gridLayout != nativeEvent.layout) { | ||
let hadInitNewPositionsWhenAddItems = true; | ||
const needRemoveItem = items.length < this.items.length; | ||
items.forEach( (item, index) => { | ||
@@ -503,3 +520,3 @@ const foundKey = _.findKey(this.itemOrder, oldItem => oldItem.key === item.key); | ||
}) | ||
if (this.firstInitDone && hadInsert) { | ||
if (this.firstInitDone && (hadInsert || needRemoveItem) ) { | ||
setTimeout(() => { | ||
@@ -540,3 +557,9 @@ this.resetPositionsWhenResetItemOrder(lastItemOrder); | ||
blockPositions[index].origin = origin; | ||
blockPositions[index].currentPosition.setValue(origin); | ||
Animated.timing( | ||
blockPositions[index].currentPosition, | ||
{ | ||
toValue:origin, | ||
duration:200, | ||
} | ||
).start(); | ||
}); | ||
@@ -589,3 +612,3 @@ this.setState({blockPositions,hadInitNewPositionsWhenAddItems:true}); | ||
_animateGridHeight = () => { | ||
this.gridHeightTarget = this.rows * this.state.blockHeight | ||
this.gridHeightTarget = this.rows * this.state.blockHeight + 50 | ||
if (this.gridHeightTarget === this.state.gridLayout.height || this.state.gridLayout.height === 0) | ||
@@ -685,7 +708,9 @@ this.state.gridHeight.setValue(this.gridHeightTarget) | ||
_getGridStyle = () => [ | ||
styles.sortableGrid, | ||
this.props.style, | ||
this._blockPositionsSet() && { height: this.state.gridHeight } | ||
] | ||
_getGridStyle = () => { | ||
return [ | ||
styles.sortableGrid, | ||
this._blockPositionsSet() && { height: this.state.gridHeight}, | ||
this.props.style, | ||
] | ||
} | ||
@@ -731,4 +756,2 @@ _getDeletionView = (key) => { | ||
height: this.state.blockHeight, | ||
justifyContent: 'center', | ||
marginBottom:ROW_MARGIN, | ||
}, | ||
@@ -735,0 +758,0 @@ this._blockPositionsSet() && (this.initialDragDone || this.state.deleteModeOn || this.resetOrder) && |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "2.0.5", | ||
"version": "2.0.6", | ||
"description": "Drag-and-drop sortable grid view for React Native.", | ||
@@ -20,4 +20,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"lodash": "^4.16.4" | ||
"lodash": "^4.16.4", | ||
"react":"*" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
207398
972
2