Skip to content

Updated edit behavior of TableView item #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions RNTableView/RNTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,12 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd

self.onChange(newValue);

[_sections[indexPath.section][@"items"] removeObjectAtIndex:indexPath.row];
[self.tableView reloadData];
if ([newValue[@"shouldOnlyEdit"] boolValue]) {
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
} else {
[_sections[indexPath.section][@"items"] removeObjectAtIndex:indexPath.row];
[self.tableView reloadData];
}
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
NSMutableDictionary *newValue = [self dataForRow:indexPath.item section:indexPath.section];
newValue[@"target"] = self.reactTag;
Expand All @@ -618,6 +622,11 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
}
}

- (nullable NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
NSDictionary *item = [self dataForRow:indexPath.item section:indexPath.section];
return item[@"buttonTitleOnEdit"] ? item[@"buttonTitleOnEdit"]: @"Delete";
}

-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return self.tableViewCellEditingStyle;
Expand Down
12 changes: 11 additions & 1 deletion src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,20 @@ interface ItemProps {
canMove?: boolean

/**
* If cell can be deleted in editing mode
* If cell can be deleted or edited in editing mode
*/
canEdit?: boolean

/**
* If cell should be only edited without deletion of the cell in editing mode
*/
shouldOnlyEdit?: boolean

/**
* Custom button title in editing mode, default is "Delete" without localization support
*/
buttonTitleOnEdit?: string

/**
* Cell selection style
*/
Expand Down