iOS: update list beforeDragging & add itemCanDrag
This commit is contained in:
parent
ef4eb4d517
commit
8dd39398b9
@ -27,8 +27,15 @@ class ListDragDemo extends Panel {
|
|||||||
},
|
},
|
||||||
layoutConfig: layoutConfig().most(),
|
layoutConfig: layoutConfig().most(),
|
||||||
canDrag: true,
|
canDrag: true,
|
||||||
|
itemCanDrag: (from) => {
|
||||||
|
if (from === 0) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
},
|
||||||
beforeDragging: (from) => {
|
beforeDragging: (from) => {
|
||||||
loge(`beforeDragging from: ${from}`)
|
return [0, 1, 2]
|
||||||
},
|
},
|
||||||
onDragging: (from, to) => {
|
onDragging: (from, to) => {
|
||||||
loge(`onDragging from: ${from}, to: ${to}`)
|
loge(`onDragging from: ${from}, to: ${to}`)
|
||||||
|
@ -67,9 +67,11 @@ @interface DoricListNode () <UITableViewDataSource, UITableViewDelegate>
|
|||||||
@property(nonatomic, strong) UILongPressGestureRecognizer *longPress;
|
@property(nonatomic, strong) UILongPressGestureRecognizer *longPress;
|
||||||
@property(nonatomic, strong) NSIndexPath *initialDragIndexPath;
|
@property(nonatomic, strong) NSIndexPath *initialDragIndexPath;
|
||||||
@property(nonatomic, strong) NSIndexPath *currentDragIndexPath;
|
@property(nonatomic, strong) NSIndexPath *currentDragIndexPath;
|
||||||
|
@property(nonatomic, copy) NSString *itemCanDragFuncId;
|
||||||
@property(nonatomic, copy) NSString *beforeDraggingFuncId;
|
@property(nonatomic, copy) NSString *beforeDraggingFuncId;
|
||||||
@property(nonatomic, copy) NSString *onDraggingFuncId;
|
@property(nonatomic, copy) NSString *onDraggingFuncId;
|
||||||
@property(nonatomic, copy) NSString *onDraggedFuncId;
|
@property(nonatomic, copy) NSString *onDraggedFuncId;
|
||||||
|
@property(nonatomic, strong) NSArray *swapDisabled;
|
||||||
|
|
||||||
@property(nonatomic, assign) NSUInteger rowCount;
|
@property(nonatomic, assign) NSUInteger rowCount;
|
||||||
@property(nonatomic, assign) BOOL needReload;
|
@property(nonatomic, assign) BOOL needReload;
|
||||||
@ -119,11 +121,21 @@ - (void)longPressAction:(UILongPressGestureRecognizer *)sender {
|
|||||||
self.initialDragIndexPath = indexPath;
|
self.initialDragIndexPath = indexPath;
|
||||||
self.currentDragIndexPath = indexPath;
|
self.currentDragIndexPath = indexPath;
|
||||||
if (self.beforeDraggingFuncId != nil) {
|
if (self.beforeDraggingFuncId != nil) {
|
||||||
[self callJSResponse:self.beforeDraggingFuncId, @(indexPath.row), nil];
|
DoricAsyncResult *asyncResult = [self callJSResponse:self.beforeDraggingFuncId, @(indexPath.row), nil];
|
||||||
|
JSValue *model = [asyncResult waitUntilResult];
|
||||||
|
if (model.isArray) {
|
||||||
|
self.swapDisabled = [model toArray];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (sender.state == UIGestureRecognizerStateChanged) {
|
} else if (sender.state == UIGestureRecognizerStateChanged) {
|
||||||
if ((indexPath != nil) && (indexPath != self.currentDragIndexPath)) {
|
if ((indexPath != nil) && (indexPath != self.currentDragIndexPath)) {
|
||||||
|
for (int i = 0; i < self.swapDisabled.count; i++) {
|
||||||
|
if (indexPath.row == [self.swapDisabled[i] intValue]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NSString *fromValue = self.itemViewIds[@(self.currentDragIndexPath.row)];
|
NSString *fromValue = self.itemViewIds[@(self.currentDragIndexPath.row)];
|
||||||
NSString *toValue = self.itemViewIds[@(indexPath.row)];
|
NSString *toValue = self.itemViewIds[@(indexPath.row)];
|
||||||
self.itemViewIds[@(self.currentDragIndexPath.row)] = toValue;
|
self.itemViewIds[@(self.currentDragIndexPath.row)] = toValue;
|
||||||
@ -186,6 +198,8 @@ - (void)blendView:(UITableView *)view forPropName:(NSString *)name propValue:(id
|
|||||||
} else if ([@"canDrag" isEqualToString:name]) {
|
} else if ([@"canDrag" isEqualToString:name]) {
|
||||||
bool canDrag = [prop boolValue];
|
bool canDrag = [prop boolValue];
|
||||||
[self.longPress setEnabled:canDrag];
|
[self.longPress setEnabled:canDrag];
|
||||||
|
} else if ([@"itemCanDrag" isEqualToString:name]) {
|
||||||
|
self.itemCanDragFuncId = prop;
|
||||||
} else if ([@"beforeDragging" isEqualToString:name]) {
|
} else if ([@"beforeDragging" isEqualToString:name]) {
|
||||||
self.beforeDraggingFuncId = prop;
|
self.beforeDraggingFuncId = prop;
|
||||||
} else if ([@"onDragging" isEqualToString:name]) {
|
} else if ([@"onDragging" isEqualToString:name]) {
|
||||||
@ -535,6 +549,17 @@ - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
||||||
|
if (self.itemCanDragFuncId != nil) {
|
||||||
|
DoricAsyncResult *asyncResult = [self callJSResponse:self.itemCanDragFuncId, @(indexPath.row), nil];
|
||||||
|
JSValue *model = [asyncResult waitUntilResult];
|
||||||
|
if (model.isBoolean) {
|
||||||
|
return [model toBool];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSMutableSet<DoricDidScrollBlock> *)didScrollBlocks {
|
- (NSMutableSet<DoricDidScrollBlock> *)didScrollBlocks {
|
||||||
if (!_didScrollBlocks) {
|
if (!_didScrollBlocks) {
|
||||||
_didScrollBlocks = [NSMutableSet new];
|
_didScrollBlocks = [NSMutableSet new];
|
||||||
@ -591,6 +616,7 @@ - (void)reset {
|
|||||||
self.loadMoreViewId = nil;
|
self.loadMoreViewId = nil;
|
||||||
self.onScrollFuncId = nil;
|
self.onScrollFuncId = nil;
|
||||||
self.onScrollEndFuncId = nil;
|
self.onScrollEndFuncId = nil;
|
||||||
|
self.itemCanDragFuncId = nil;
|
||||||
self.beforeDraggingFuncId = nil;
|
self.beforeDraggingFuncId = nil;
|
||||||
self.onDraggingFuncId = nil;
|
self.onDraggingFuncId = nil;
|
||||||
self.onDraggedFuncId = nil;
|
self.onDraggedFuncId = nil;
|
||||||
|
Reference in New Issue
Block a user