Github user cxfeng1 commented on a diff in the pull request:

    https://github.com/apache/incubator-weex/pull/539#discussion_r129747478
  
    --- Diff: ios/sdk/WeexSDK/Sources/Component/Recycler/WXRecyclerComponent.m 
---
    @@ -655,6 +707,166 @@ - (void)fixFlicker
         });
     }
     
    +#pragma mark - dragMethod
    +- (void)longPressMethod:(UILongPressGestureRecognizer*)gesture
    +{
    +    if (_isDragable) {
    +        switch (gesture.state) {
    +            case UIGestureRecognizerStateBegan:
    +                [self dragBegin:gesture];
    +                break;
    +            case UIGestureRecognizerStateChanged:
    +                [self dragChanged:gesture];
    +                break;
    +            case UIGestureRecognizerStateEnded:
    +                [self dragEnd:gesture];
    +                break;
    +            default:
    +                break;
    +        }
    +    }
    +}
    +
    +- (void)dragBegin:(UILongPressGestureRecognizer *)gesture{
    +    
    +    CGPoint point = [gesture locationInView:_collectionView];
    +    
    +    _startIndexPath = [self getDragingIndexPathWithPoint:point];
    +    if (!_startIndexPath) {
    +        return;
    +    }
    +    
    +    [self fireEvent:@"dragstart" params:@{@"fromIndex":[NSString 
stringWithFormat:@"%ld",(long)_startIndexPath.row]}];
    +    
    +    _dragingIndexPath = [self getDragingIndexPathWithPoint:point];
    +    if (!_dragingIndexPath) {
    +        return;
    +    }
    +    
    +    [_collectionView bringSubviewToFront:_dragingCell];
    +    _dragingCell.frame = [_collectionView 
cellForItemAtIndexPath:_dragingIndexPath].frame;
    +    _dragingCell.hidden = false;
    +    [UIView animateWithDuration:0.3 animations:^{
    +        [_dragingCell setTransform:CGAffineTransformMakeScale(1.2, 1.2)];
    +    }];
    +}
    +
    +- (void)dragChanged:(UILongPressGestureRecognizer *)gesture{
    +    
    +    if (!_startIndexPath) {
    +        return;
    +    }
    +    CGPoint point = [gesture locationInView:_collectionView];
    +    _dragingCell.center = point;
    +    _targetIndexPath = [self getTargetIndexPathWithPoint:point];
    +    
    +    if (_targetIndexPath && _dragingIndexPath && (_targetIndexPath.section 
== _startIndexPath.section)){
    +        [_collectionView moveItemAtIndexPath:_dragingIndexPath 
toIndexPath:_targetIndexPath];
    +        _dragingIndexPath = _targetIndexPath;
    +    }
    +}
    +
    +- (void)dragEnd:(UILongPressGestureRecognizer *)gesture{
    +    
    +    if (!_startIndexPath || !_dragingIndexPath) {
    +        return;
    +    }
    +    
    +    [self fireEvent:@"dragend" params:@{@"toIndex":[NSString 
stringWithFormat:@"%ld",(long)_dragingIndexPath.row],@"fromIndex":[NSString 
stringWithFormat:@"%ld",(long)_startIndexPath.row]}];
    +    
    +    CGRect endFrame = [_collectionView 
cellForItemAtIndexPath:_dragingIndexPath].frame;
    +    
    +    __weak typeof(self) weakSelf = self;
    +    [UIView animateWithDuration:0.3 animations:^{
    +        [weakSelf.dragingCell setTransform:CGAffineTransformMakeScale(1.0, 
1.0)];
    +        weakSelf.dragingCell.frame = endFrame;
    +    } completion:^(BOOL finished) {
    +        weakSelf.dragingCell.hidden = YES;
    +        NSMutableArray *oldComponents = [[NSMutableArray alloc] 
initWithArray:weakSelf.dataController.sections[weakSelf.startIndexPath.section].cellComponents];
    +        if(oldComponents.count > 1){
    +            WXCellComponent *startComponent = 
weakSelf.dataController.sections[weakSelf.startIndexPath.section].cellComponents[weakSelf.startIndexPath.item];
    +            [oldComponents removeObject:startComponent];
    +            [oldComponents insertObject:startComponent 
atIndex:weakSelf.targetIndexPath.item];
    +            
weakSelf.dataController.sections[weakSelf.startIndexPath.section].cellComponents
 = oldComponents;
    +        }
    +    }];
    +}
    +
    +- (NSIndexPath *)getDragingIndexPathWithPoint:(CGPoint)point{
    +    NSIndexPath *dragingIndexPath = nil;
    +    for (NSIndexPath *indexPath in [_collectionView 
indexPathsForVisibleItems]){
    +        if (CGRectContainsPoint([_collectionView 
cellForItemAtIndexPath:indexPath].frame,point)) {
    +            dragingIndexPath = indexPath;
    +            break;
    +        }
    +    }
    +    
    +    BOOL isExcluded = NO;
    +    if (dragingIndexPath) {
    +        for (NSIndexPath *indexPath in _excludedAry) {
    +            if (indexPath.row == dragingIndexPath.row) {
    +                isExcluded = YES;
    +            }
    +        }
    +    }
    +    return isExcluded?nil:dragingIndexPath;
    +}
    +
    +- (NSIndexPath *)getTargetIndexPathWithPoint:(CGPoint)point{
    +    NSIndexPath *targetIndexPath = nil;
    +    for (NSIndexPath *indexPath in 
_collectionView.indexPathsForVisibleItems) {
    +        if (CGRectContainsPoint([_collectionView 
cellForItemAtIndexPath:indexPath].frame, point)) {
    +            targetIndexPath = indexPath;
    +        }
    +    }
    +    return targetIndexPath;
    +}
    +
    +
    +- (void)goThroughAnchor:(WXComponent *)wxComponent indexPath:(NSIndexPath 
*)indexPath{
    +    if (wxComponent.attributes && [wxComponent.attributes[@"dragExcluded"] 
boolValue]){
    +        [_excludedAry addObject:indexPath];
    +        NSSet *set = [NSSet setWithArray:_excludedAry];
    +        [_excludedAry removeAllObjects];
    +        [_excludedAry addObjectsFromArray:[set allObjects]];
    +    }
    +    
    +    //遍历获取锚点
    --- End diff --
    
    No Chinese comment.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to