Skip to content

Commit 8eecf96

Browse files
committed
Allow custom render item to wrap touchable component
1 parent a75aced commit 8eecf96

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

lib/AutoDragSortableView.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -644,19 +644,27 @@ export default class AutoDragSortableView extends Component{
644644
opacity: item.scaleValue.interpolate({inputRange,outputRange}),
645645
transform: [transformObj]
646646
}]}>
647-
<TouchableOpacity
648-
activeOpacity = {1}
649-
delayLongPress={this.props.delayLongPress}
650-
onPressOut={()=> this.onPressOut()}
651-
onLongPress={()=>this.startTouch(index)}
652-
onPress={()=>{
653-
if (this.props.onClickItem) {
654-
this.isHasMeasure = true
655-
this.props.onClickItem(this.getOriginalData(),item.data,index)
656-
}
657-
}}>
658-
{this.props.renderItem(item.data,index)}
659-
</TouchableOpacity>
647+
{this.props.dontWrapItems ?
648+
this.props.renderItem(item.data, index, {
649+
delayLongPress: this.props.delayLongPress,
650+
onPressOut: () => this.onPressOut(),
651+
onLongPress: () => this.startTouch(index),
652+
}) :
653+
<TouchableOpacity
654+
activeOpacity = {1}
655+
delayLongPress={this.props.delayLongPress}
656+
onPressOut={()=> this.onPressOut()}
657+
onLongPress={()=>this.startTouch(index)}
658+
onPress={()=>{
659+
if (this.props.onClickItem) {
660+
this.isHasMeasure = true
661+
this.props.onClickItem(this.getOriginalData(),item.data,index)
662+
}
663+
}}>
664+
{this.props.renderItem(item.data,index)}
665+
</TouchableOpacity>
666+
}
667+
660668
</Animated.View>
661669
)
662670
})
@@ -682,6 +690,8 @@ AutoDragSortableView.propTypes = {
682690

683691
sortable: PropTypes.bool,
684692

693+
dontWrapItems: PropTypes.bool,
694+
685695
onClickItem: PropTypes.func,
686696
onDragStart: PropTypes.func,
687697
onDragEnd: PropTypes.func,

lib/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ interface IProps{
1414

1515
sortable?: boolean;
1616

17+
dontWrapItems?: boolean;
18+
1719
onClickItem?: (data: any[],item: any,index: number) => void;
1820
onDragStart?: (fromIndex: number) => void;
1921
onDragEnd?: (fromIndex: number,toIndex: number) => void;
2022
onDataChange?: (data: any[]) => void;
21-
renderItem: (item: any,index: number) => React.ReactElement<any>;
23+
renderItem: (item: any, index: number, touchableProps?: any) => React.ReactElement<any>;
2224
scaleStatus?: 'scale' | 'scaleX' |'scaleY';
2325
fixedItems?: number[];
2426
keyExtractor?: (item: any,index: number) => any;

0 commit comments

Comments
 (0)