Skip to content

Instantly share code, notes, and snippets.

@CreatureSurvive
Created June 3, 2018 06:52
Show Gist options
  • Save CreatureSurvive/aebfac07aaa7fce3e2e245bf9070d58e to your computer and use it in GitHub Desktop.
Save CreatureSurvive/aebfac07aaa7fce3e2e245bf9070d58e to your computer and use it in GitHub Desktop.
-(id)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self getRowActions:tableView indexPath:indexPath];
}
-(id)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self getRowActions:tableView indexPath:indexPath];
}
-(id)getRowActions:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
if (@available(iOS 11, *)) {
UIContextualAction *delete = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive
title:@"DELETE"
handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
completionHandler(YES);
}];
delete.backgroundColor = [UIColor redColor];
delete.image = [HCMPlugin bundleImageWithName:@"contactInfoDelete20x20"];
UISwipeActionsConfiguration *swipeActionConfig = [UISwipeActionsConfiguration configurationWithActions:@[delete]];
swipeActionConfig.performsFirstActionWithFullSwipe = NO;
return swipeActionConfig;
}
else {
if (!self.isEditing || ![self allowSection:indexPath sections:nil]) {
return @[];
}
NSDictionary *data = TapTypeDictionaryOrNil([self dataAtIndexPath:indexPath]);
if ([self.deletedItems containsObject:data]) {
return @[];
}
NSMutableArray *rowActions = [NSMutableArray array];
NSDictionary *deleteAction = [self validAction:TapDataActionDeleteTypeKey indexPath:indexPath];
__weak HCMListOfListsLayoutControllerTUI *bself = self;
if (![self dataAtIndexPathIsPrimary:indexPath]) {
if (TapTypeDictionaryOrNil(deleteAction) || self.mode == HCMListOfListsChildListMode) {
/
UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:HCMContactRowInfoDummyTitle handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[bself performDeleteAtIndexPath:indexPath];
}];
delete.backgroundColor = [self.rowActionViewHandler getPatternedBackgroundFor:indexPath backgroundKey:@"deleteColor"];
[rowActions addObject:delete];
}
}
NSDictionary *editAction = TapTypeDictionaryOrNil([self validAction:TapDataActionEditTypeKey
indexPath:indexPath]);
if (!editAction) {
editAction = TapTypeDictionaryOrNil([self validAction:TapDataActionUpdateBoolTypeKey
indexPath:indexPath]);
}
UITableViewRowAction *edit = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:HCMContactRowInfoDummyTitle handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[bself editItemAtIndexPath:indexPath];
}];
edit.backgroundColor = [self.rowActionViewHandler getPatternedBackgroundFor:indexPath backgroundKey:@"editColor"];
[rowActions insertObject:edit atIndex:0];
return [rowActions copy];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment