Skip to content

Commit 0731998

Browse files
committed
implement ghost style prop
1 parent 91cf07d commit 0731998

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

lib/AnySizeDragSortableView.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default class AnySizeDragSortableView extends React.PureComponent {
175175
const curLayout = this.layoutMap.get(key)
176176
const firstOffsetY = (this.curScrollData && this.curScrollData.offsetY) || 0
177177
const initTop = parseInt(curLayout.y - firstOffsetY + headerViewHeight + 0.5)
178-
this.setState({
178+
this.setState({
179179
scrollEnabled: false,
180180
selectedItem: item,
181181
selectedKey: key,
@@ -280,7 +280,7 @@ export default class AnySizeDragSortableView extends React.PureComponent {
280280
break
281281
}
282282
// When sliding to the end, there is no assistance
283-
if (!this.isUpdating && nextLineLastLayout &&
283+
if (!this.isUpdating && nextLineLastLayout &&
284284
moveX1 >= nextLineLastLayout.x + nextLineLastLayout.width && (moveY2 + moveY1) / 2 > nextLineLastLayout.y
285285
) {
286286
this.move(curLayout.key, nextLineLastLayout.key, vy, curLayout.y !== nextLineLastLayout.y)
@@ -295,7 +295,7 @@ export default class AnySizeDragSortableView extends React.PureComponent {
295295
if (preLeft !== nextLeft || preTop !== nextTop) {
296296
this.setState({
297297
selectedPosition: {
298-
...selectedPosition,
298+
...selectedPosition,
299299
left: nextLeft,
300300
top: nextTop
301301
}
@@ -314,7 +314,7 @@ export default class AnySizeDragSortableView extends React.PureComponent {
314314
return
315315
}
316316
if (
317-
this.preMoveKeyObj && this.preMoveKeyObj.fromKey === fromKey && this.preMoveKeyObj.toKey === toKey &&
317+
this.preMoveKeyObj && this.preMoveKeyObj.fromKey === fromKey && this.preMoveKeyObj.toKey === toKey &&
318318
isDiffline && ((toIndex - fromIndex > 0 && vy <= 0.01) || (toIndex - fromIndex < 0 && vy >= -0.01))
319319
) {
320320
this.isUpdating = false
@@ -395,7 +395,8 @@ export default class AnySizeDragSortableView extends React.PureComponent {
395395

396396
render() {
397397
const {selectedItem, selectedPosition, scrollEnabled} = this.state
398-
const {dataSource, keyExtractor, renderItem, movedWrapStyle} = this.props
398+
const {ghostStyle, dataSource, keyExtractor, renderItem, movedWrapStyle} = this.props
399+
const selectedKey = selectedItem && keyExtractor(selectedItem);
399400
return (
400401
<View style={styles.box}>
401402
{
@@ -417,7 +418,7 @@ export default class AnySizeDragSortableView extends React.PureComponent {
417418
scrollEnabled = {scrollEnabled}
418419
onScroll={this.onScrollListener}
419420
style={styles.scroll}>
420-
{this.props.renderHeaderView ? this.props.renderHeaderView : null}
421+
{this.props.renderHeaderView ? this.props.renderHeaderView : null}
421422
<View style={styles.container}>
422423
{
423424
dataSource.map((item, index) => {
@@ -426,6 +427,7 @@ export default class AnySizeDragSortableView extends React.PureComponent {
426427
return (
427428
<View
428429
key={key}
430+
style={selectedKey === key ? ghostStyle : undefined}
429431
{...this._panResponder.panHandlers}
430432
onLayout={event => this._setLayoutData(key, event)}
431433
>
@@ -440,7 +442,7 @@ export default class AnySizeDragSortableView extends React.PureComponent {
440442
</View>
441443
)
442444
}
443-
445+
444446
}
445447

446448
AnySizeDragSortableView.propTypes = {
@@ -465,9 +467,10 @@ AnySizeDragSortableView.propTypes = {
465467
onScrollRef: PropTypes.func,
466468
areaOverlapRatio: PropTypes.number,
467469
movedWrapStyle: PropTypes.object,
468-
/**
470+
ghostStyle: PropTypes.object,
471+
/**
469472
* childMarginxx: Must be greater than > 0
470-
* Optimize the calculation of the size of the rectangle where the two components
473+
* Optimize the calculation of the size of the rectangle where the two components
471474
* intersect to prevent repeated switching caused by triggering the critical point .
472475
*/
473476
childMarginTop: PropTypes.number,
@@ -492,6 +495,9 @@ AnySizeDragSortableView.defaultProps = {
492495
backgroundColor: 'blue',
493496
zIndex: 999,
494497
},
498+
ghostStyle: {
499+
opacity: 0.5
500+
},
495501
childMarginTop: 10,
496502
childMarginBottom: 10,
497503
childMarginLeft: 10,
@@ -511,4 +517,4 @@ const styles = StyleSheet.create({
511517
flexDirection: 'row',
512518
flexWrap: 'wrap'
513519
}
514-
});
520+
});

lib/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ interface AnySizeIProps{
6161
onScrollRef?: (ref: any) => void
6262
areaOverlapRatio?: number,
6363
movedWrapStyle: StyleProp<ViewStyle>,
64+
ghostStyle: StyleProp<ViewStyle>,
6465
childMarginTop?: number,
6566
childMarginBottom?: number,
6667
childMarginLeft?: number,

0 commit comments

Comments
 (0)