[GitHub] incubator-weex pull request #539: +[ios] recyclerComponent add drag method

2017-08-08 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/incubator-weex/pull/539


---
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.
---


[GitHub] incubator-weex pull request #539: +[ios] recyclerComponent add drag method

2017-08-08 Thread cxfeng1
Github user cxfeng1 commented on a diff in the pull request:

https://github.com/apache/incubator-weex/pull/539#discussion_r129747806
  
--- Diff: ios/sdk/WeexSDK/Sources/Component/Recycler/WXRecyclerComponent.m 
---
@@ -89,6 +96,15 @@ @interface WXRecyclerComponent () 


[GitHub] incubator-weex pull request #539: +[ios] recyclerComponent add drag method

2017-08-08 Thread cxfeng1
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 
cel

[GitHub] incubator-weex pull request #539: +[ios] recyclerComponent add drag method

2017-07-25 Thread lcgithub
GitHub user lcgithub opened a pull request:

https://github.com/apache/incubator-weex/pull/539

+[ios] recyclerComponent add drag method

feature:

support both pan and longPress gesture to trigger drag-drop;
support liner/grid layout;
support dragStart/dragEnd event;
support excluded some cells when dragging;
extend attrs:

list:

draggable: whether draggable or not;
drag-trigger-type: which gesture type will trigger drag-drop;
cell:

drag-excluded: whether we should ignore current cell for dragging;
any component:

drag-anchor: the anchor that will trigger drag-drop

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/lcgithub/incubator-weex dev_recycle_drag

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/incubator-weex/pull/539.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #539


commit ddc99ccf14a388368bb1cff5bd84e4561a1d345e
Author: ximu 
Date:   2017-07-26T06:51:06Z

+[ios] recyclerComponent add drag method




---
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.
---