Skip to content

Commit 378b6a3

Browse files
committed
Fixed the [email protected] issue
1 parent cdb9cc9 commit 378b6a3

File tree

5 files changed

+39
-15
lines changed

5 files changed

+39
-15
lines changed

Example/app/widget/AutoDragSortableView.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ export default class AutoDragSortableView extends Component{
203203

204204
if (!this.props.sortable) return
205205

206-
if (this.sortRefs.has(touchIndex)) {
206+
const key = this._getKey(touchIndex);
207+
if (this.sortRefs.has(key)) {
207208

208209
// Initialization data
209210
if (this.isStartupAuto()) {
@@ -225,7 +226,7 @@ export default class AutoDragSortableView extends Component{
225226
}
226227
).start(()=>{
227228
this.touchCurItem = {
228-
ref: this.sortRefs.get(touchIndex),
229+
ref: this.sortRefs.get(key),
229230
index: touchIndex,
230231
originLeft: this.state.dataSource[touchIndex].originLeft,
231232
originTop: this.state.dataSource[touchIndex].originTop,
@@ -607,6 +608,11 @@ export default class AutoDragSortableView extends Component{
607608
)
608609
}
609610

611+
_getKey = (index) => {
612+
const item = this.state.dataSource[index];
613+
return this.props.keyExtractor ? this.props.keyExtractor(item.data, index) : item.originIndex;
614+
}
615+
610616
_renderItemView = () => {
611617
return this.state.dataSource.map((item,index)=>{
612618
const transformObj = {}
@@ -615,7 +621,7 @@ export default class AutoDragSortableView extends Component{
615621
return (
616622
<Animated.View
617623
key={key}
618-
ref={(ref) => this.sortRefs.set(index,ref)}
624+
ref={(ref) => this.sortRefs.set(key,ref)}
619625
{...this._panResponder.panHandlers}
620626
style={[styles.item,{
621627
marginTop: this.props.marginChildrenTop,

Example/app/widget/DragSortableView.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export default class DragSortableView extends Component{
115115

116116
if (!this.props.sortable) return
117117

118-
if (this.sortRefs.has(touchIndex)) {
118+
const key = this._getKey(touchIndex);
119+
if (this.sortRefs.has(key)) {
119120
if (this.props.onDragStart) {
120121
this.props.onDragStart(touchIndex)
121122
}
@@ -128,7 +129,7 @@ export default class DragSortableView extends Component{
128129
}
129130
).start(()=>{
130131
this.touchCurItem = {
131-
ref: this.sortRefs.get(touchIndex),
132+
ref: this.sortRefs.get(key),
132133
index: touchIndex,
133134
originLeft: this.state.dataSource[touchIndex].originLeft,
134135
originTop: this.state.dataSource[touchIndex].originTop,
@@ -416,15 +417,20 @@ export default class DragSortableView extends Component{
416417
)
417418
}
418419

420+
_getKey = (index) => {
421+
const item = this.state.dataSource[index];
422+
return this.props.keyExtractor ? this.props.keyExtractor(item.data, index) : item.originIndex;
423+
}
424+
419425
_renderItemView = () => {
420426
return this.state.dataSource.map((item,index)=>{
421427
const transformObj = {}
422428
transformObj[this.props.scaleStatus] = item.scaleValue
423-
const key = this.props.keyExtractor ? this.props.keyExtractor(item.data,index) : item.originIndex
429+
const key = this._getKey(index);
424430
return (
425431
<Animated.View
426432
key={key}
427-
ref={(ref) => this.sortRefs.set(index,ref)}
433+
ref={(ref) => this.sortRefs.set(key,ref)}
428434
{...this._panResponder.panHandlers}
429435
style={[styles.item,{
430436
marginTop: this.props.marginChildrenTop,

lib/AutoDragSortableView.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,8 @@ export default class AutoDragSortableView extends Component{
203203

204204
if (!this.props.sortable) return
205205

206-
if (this.sortRefs.has(touchIndex)) {
206+
const key = this._getKey(touchIndex);
207+
if (this.sortRefs.has(key)) {
207208

208209
// Initialization data
209210
if (this.isStartupAuto()) {
@@ -225,7 +226,7 @@ export default class AutoDragSortableView extends Component{
225226
}
226227
).start(()=>{
227228
this.touchCurItem = {
228-
ref: this.sortRefs.get(touchIndex),
229+
ref: this.sortRefs.get(key),
229230
index: touchIndex,
230231
originLeft: this.state.dataSource[touchIndex].originLeft,
231232
originTop: this.state.dataSource[touchIndex].originTop,
@@ -607,6 +608,11 @@ export default class AutoDragSortableView extends Component{
607608
)
608609
}
609610

611+
_getKey = (index) => {
612+
const item = this.state.dataSource[index];
613+
return this.props.keyExtractor ? this.props.keyExtractor(item.data, index) : item.originIndex;
614+
}
615+
610616
_renderItemView = () => {
611617
return this.state.dataSource.map((item,index)=>{
612618
const transformObj = {}
@@ -615,7 +621,7 @@ export default class AutoDragSortableView extends Component{
615621
return (
616622
<Animated.View
617623
key={key}
618-
ref={(ref) => this.sortRefs.set(index,ref)}
624+
ref={(ref) => this.sortRefs.set(key,ref)}
619625
{...this._panResponder.panHandlers}
620626
style={[styles.item,{
621627
marginTop: this.props.marginChildrenTop,

lib/DragSortableView.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ export default class DragSortableView extends Component{
115115

116116
if (!this.props.sortable) return
117117

118-
if (this.sortRefs.has(touchIndex)) {
118+
const key = this._getKey(touchIndex);
119+
if (this.sortRefs.has(key)) {
119120
if (this.props.onDragStart) {
120121
this.props.onDragStart(touchIndex)
121122
}
@@ -128,7 +129,7 @@ export default class DragSortableView extends Component{
128129
}
129130
).start(()=>{
130131
this.touchCurItem = {
131-
ref: this.sortRefs.get(touchIndex),
132+
ref: this.sortRefs.get(key),
132133
index: touchIndex,
133134
originLeft: this.state.dataSource[touchIndex].originLeft,
134135
originTop: this.state.dataSource[touchIndex].originTop,
@@ -416,15 +417,20 @@ export default class DragSortableView extends Component{
416417
)
417418
}
418419

420+
_getKey = (index) => {
421+
const item = this.state.dataSource[index];
422+
return this.props.keyExtractor ? this.props.keyExtractor(item.data, index) : item.originIndex;
423+
}
424+
419425
_renderItemView = () => {
420426
return this.state.dataSource.map((item,index)=>{
421427
const transformObj = {}
422428
transformObj[this.props.scaleStatus] = item.scaleValue
423-
const key = this.props.keyExtractor ? this.props.keyExtractor(item.data,index) : item.originIndex
429+
const key = this._getKey(index);
424430
return (
425431
<Animated.View
426432
key={key}
427-
ref={(ref) => this.sortRefs.set(index,ref)}
433+
ref={(ref) => this.sortRefs.set(key,ref)}
428434
{...this._panResponder.panHandlers}
429435
style={[styles.item,{
430436
marginTop: this.props.marginChildrenTop,

lib/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-drag-sort",
3-
"version": "2.2.4",
3+
"version": "2.3.4",
44
"description": "Drag and drop sort control for react-native",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)