Skip to content

Commit

Permalink
Fixed the [email protected] issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mochixuan committed Aug 12, 2020
1 parent cdb9cc9 commit 378b6a3
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
12 changes: 9 additions & 3 deletions Example/app/widget/AutoDragSortableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ export default class AutoDragSortableView extends Component{

if (!this.props.sortable) return

if (this.sortRefs.has(touchIndex)) {
const key = this._getKey(touchIndex);
if (this.sortRefs.has(key)) {

// Initialization data
if (this.isStartupAuto()) {
Expand All @@ -225,7 +226,7 @@ export default class AutoDragSortableView extends Component{
}
).start(()=>{
this.touchCurItem = {
ref: this.sortRefs.get(touchIndex),
ref: this.sortRefs.get(key),
index: touchIndex,
originLeft: this.state.dataSource[touchIndex].originLeft,
originTop: this.state.dataSource[touchIndex].originTop,
Expand Down Expand Up @@ -607,6 +608,11 @@ export default class AutoDragSortableView extends Component{
)
}

_getKey = (index) => {
const item = this.state.dataSource[index];
return this.props.keyExtractor ? this.props.keyExtractor(item.data, index) : item.originIndex;
}

_renderItemView = () => {
return this.state.dataSource.map((item,index)=>{
const transformObj = {}
Expand All @@ -615,7 +621,7 @@ export default class AutoDragSortableView extends Component{
return (
<Animated.View
key={key}
ref={(ref) => this.sortRefs.set(index,ref)}
ref={(ref) => this.sortRefs.set(key,ref)}
{...this._panResponder.panHandlers}
style={[styles.item,{
marginTop: this.props.marginChildrenTop,
Expand Down
14 changes: 10 additions & 4 deletions Example/app/widget/DragSortableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export default class DragSortableView extends Component{

if (!this.props.sortable) return

if (this.sortRefs.has(touchIndex)) {
const key = this._getKey(touchIndex);
if (this.sortRefs.has(key)) {
if (this.props.onDragStart) {
this.props.onDragStart(touchIndex)
}
Expand All @@ -128,7 +129,7 @@ export default class DragSortableView extends Component{
}
).start(()=>{
this.touchCurItem = {
ref: this.sortRefs.get(touchIndex),
ref: this.sortRefs.get(key),
index: touchIndex,
originLeft: this.state.dataSource[touchIndex].originLeft,
originTop: this.state.dataSource[touchIndex].originTop,
Expand Down Expand Up @@ -416,15 +417,20 @@ export default class DragSortableView extends Component{
)
}

_getKey = (index) => {
const item = this.state.dataSource[index];
return this.props.keyExtractor ? this.props.keyExtractor(item.data, index) : item.originIndex;
}

_renderItemView = () => {
return this.state.dataSource.map((item,index)=>{
const transformObj = {}
transformObj[this.props.scaleStatus] = item.scaleValue
const key = this.props.keyExtractor ? this.props.keyExtractor(item.data,index) : item.originIndex
const key = this._getKey(index);
return (
<Animated.View
key={key}
ref={(ref) => this.sortRefs.set(index,ref)}
ref={(ref) => this.sortRefs.set(key,ref)}
{...this._panResponder.panHandlers}
style={[styles.item,{
marginTop: this.props.marginChildrenTop,
Expand Down
12 changes: 9 additions & 3 deletions lib/AutoDragSortableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ export default class AutoDragSortableView extends Component{

if (!this.props.sortable) return

if (this.sortRefs.has(touchIndex)) {
const key = this._getKey(touchIndex);
if (this.sortRefs.has(key)) {

// Initialization data
if (this.isStartupAuto()) {
Expand All @@ -225,7 +226,7 @@ export default class AutoDragSortableView extends Component{
}
).start(()=>{
this.touchCurItem = {
ref: this.sortRefs.get(touchIndex),
ref: this.sortRefs.get(key),
index: touchIndex,
originLeft: this.state.dataSource[touchIndex].originLeft,
originTop: this.state.dataSource[touchIndex].originTop,
Expand Down Expand Up @@ -607,6 +608,11 @@ export default class AutoDragSortableView extends Component{
)
}

_getKey = (index) => {
const item = this.state.dataSource[index];
return this.props.keyExtractor ? this.props.keyExtractor(item.data, index) : item.originIndex;
}

_renderItemView = () => {
return this.state.dataSource.map((item,index)=>{
const transformObj = {}
Expand All @@ -615,7 +621,7 @@ export default class AutoDragSortableView extends Component{
return (
<Animated.View
key={key}
ref={(ref) => this.sortRefs.set(index,ref)}
ref={(ref) => this.sortRefs.set(key,ref)}
{...this._panResponder.panHandlers}
style={[styles.item,{
marginTop: this.props.marginChildrenTop,
Expand Down
14 changes: 10 additions & 4 deletions lib/DragSortableView.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ export default class DragSortableView extends Component{

if (!this.props.sortable) return

if (this.sortRefs.has(touchIndex)) {
const key = this._getKey(touchIndex);
if (this.sortRefs.has(key)) {
if (this.props.onDragStart) {
this.props.onDragStart(touchIndex)
}
Expand All @@ -128,7 +129,7 @@ export default class DragSortableView extends Component{
}
).start(()=>{
this.touchCurItem = {
ref: this.sortRefs.get(touchIndex),
ref: this.sortRefs.get(key),
index: touchIndex,
originLeft: this.state.dataSource[touchIndex].originLeft,
originTop: this.state.dataSource[touchIndex].originTop,
Expand Down Expand Up @@ -416,15 +417,20 @@ export default class DragSortableView extends Component{
)
}

_getKey = (index) => {
const item = this.state.dataSource[index];
return this.props.keyExtractor ? this.props.keyExtractor(item.data, index) : item.originIndex;
}

_renderItemView = () => {
return this.state.dataSource.map((item,index)=>{
const transformObj = {}
transformObj[this.props.scaleStatus] = item.scaleValue
const key = this.props.keyExtractor ? this.props.keyExtractor(item.data,index) : item.originIndex
const key = this._getKey(index);
return (
<Animated.View
key={key}
ref={(ref) => this.sortRefs.set(index,ref)}
ref={(ref) => this.sortRefs.set(key,ref)}
{...this._panResponder.panHandlers}
style={[styles.item,{
marginTop: this.props.marginChildrenTop,
Expand Down
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-drag-sort",
"version": "2.2.4",
"version": "2.3.4",
"description": "Drag and drop sort control for react-native",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 378b6a3

Please sign in to comment.