Skip to content

Commit 42bdfa9

Browse files
Updated edit behavior of TableView item
Added support for edit and custom edit button title on editing of TableView item.
1 parent b8a9a68 commit 42bdfa9

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

RNTableView/RNTableView.m

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,12 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
604604

605605
self.onChange(newValue);
606606

607-
[_sections[indexPath.section][@"items"] removeObjectAtIndex:indexPath.row];
608-
[self.tableView reloadData];
607+
if ([newValue[@"shouldOnlyEdit"] boolValue]) {
608+
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
609+
} else {
610+
[_sections[indexPath.section][@"items"] removeObjectAtIndex:indexPath.row];
611+
[self.tableView reloadData];
612+
}
609613
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
610614
NSMutableDictionary *newValue = [self dataForRow:indexPath.item section:indexPath.section];
611615
newValue[@"target"] = self.reactTag;
@@ -618,6 +622,11 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
618622
}
619623
}
620624

625+
- (nullable NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
626+
NSDictionary *item = [self dataForRow:indexPath.item section:indexPath.section];
627+
return item[@"buttonTitleOnEdit"] ? item[@"buttonTitleOnEdit"]: @"Delete";
628+
}
629+
621630
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView
622631
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
623632
return self.tableViewCellEditingStyle;

src/index.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,20 @@ interface ItemProps {
187187
canMove?: boolean
188188

189189
/**
190-
* If cell can be deleted in editing mode
190+
* If cell can be deleted or edited in editing mode
191191
*/
192192
canEdit?: boolean
193193

194+
/**
195+
* If cell should be only edited without deletion of the cell in editing mode
196+
*/
197+
shouldOnlyEdit?: boolean
198+
199+
/**
200+
* Custom button title in editing mode, default is "Delete" without localization support
201+
*/
202+
buttonTitleOnEdit?: string
203+
194204
/**
195205
* Cell selection style
196206
*/

0 commit comments

Comments
 (0)