Skip to content

Commit

Permalink
fix(ios): ListView/TableView multiselection events only fired when ta…
Browse files Browse the repository at this point in the history
…pping checkboxes (#13107)

* fix(ios): listview "itemsselected" event only fired when tapping checkboxes

Fixes TIMOB-28548

* fix(ios): tableview "rowsselected" event only fired when tapping checkboxes
  • Loading branch information
jquick-axway committed Oct 20, 2021
1 parent 09e3e0d commit 09e9044
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 48 deletions.
59 changes: 35 additions & 24 deletions iphone/Classes/TiUIListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1169,30 +1169,7 @@ - (void)tableView:(UITableView *)tableView didBeginMultipleSelectionInteractionA

- (void)tableViewDidEndMultipleSelectionInteraction:(UITableView *)tableView
{
if ([self.proxy _hasListeners:@"itemsselected"]) {
NSMutableArray *selectedItems = [NSMutableArray arrayWithCapacity:tableView.indexPathsForSelectedRows.count];
NSMutableDictionary *startingItem = [NSMutableDictionary dictionaryWithCapacity:1];

for (int i = 0; i < tableView.indexPathsForSelectedRows.count; i++) {
NSIndexPath *indexPath = tableView.indexPathsForSelectedRows[i];
NSIndexPath *realIndexPath = [self pathForSearchPath:indexPath];
TiUIListSectionProxy *theSection = [[self.listViewProxy sectionForIndex:realIndexPath.section] retain];

NSMutableDictionary *eventObject = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
theSection, @"section",
NUMINTEGER(realIndexPath.section), @"sectionIndex",
NUMINTEGER(realIndexPath.row), @"itemIndex",
nil];
if (i == 0) {
[startingItem setDictionary:eventObject];
}
[selectedItems addObject:eventObject];

RELEASE_TO_NIL(eventObject);
RELEASE_TO_NIL(theSection);
}
[self.proxy fireEvent:@"itemsselected" withObject:@{ @"selectedItems" : selectedItems, @"startingItem" : startingItem }];
}
[self fireItemsSelectedEvent];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down Expand Up @@ -1891,6 +1868,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
{
// send indexPath of tableView which could be self.tableView or searchController.searchResultsTableView
[self fireClickForItemAtIndexPath:indexPath tableView:tableView accessoryButtonTapped:NO];
[self fireItemsSelectedEvent];
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self fireItemsSelectedEvent];
}

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
Expand Down Expand Up @@ -2333,6 +2316,34 @@ - (void)fireClickForItemAtIndexPath:(NSIndexPath *)indexPath tableView:(UITableV
[eventObject release];
}

- (void)fireItemsSelectedEvent
{
if ((_tableView != nil) && [self.proxy _hasListeners:@"itemsselected"]) {
NSMutableArray *selectedItems = [NSMutableArray arrayWithCapacity:_tableView.indexPathsForSelectedRows.count];
NSMutableDictionary *startingItem = [NSMutableDictionary dictionaryWithCapacity:1];

for (int i = 0; i < _tableView.indexPathsForSelectedRows.count; i++) {
NSIndexPath *indexPath = _tableView.indexPathsForSelectedRows[i];
NSIndexPath *realIndexPath = [self pathForSearchPath:indexPath];
TiUIListSectionProxy *theSection = [[self.listViewProxy sectionForIndex:realIndexPath.section] retain];

NSMutableDictionary *eventObject = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
theSection, @"section",
NUMINTEGER(realIndexPath.section), @"sectionIndex",
NUMINTEGER(realIndexPath.row), @"itemIndex",
nil];
if (i == 0) {
[startingItem setDictionary:eventObject];
}
[selectedItems addObject:eventObject];

RELEASE_TO_NIL(eventObject);
RELEASE_TO_NIL(theSection);
}
[self.proxy fireEvent:@"itemsselected" withObject:@{ @"selectedItems" : selectedItems, @"startingItem" : startingItem }];
}
}

- (CGFloat)contentWidthForWidth:(CGFloat)width
{
return width;
Expand Down
70 changes: 46 additions & 24 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -2321,30 +2321,7 @@ - (void)tableView:(UITableView *)tableView didBeginMultipleSelectionInteractionA

- (void)tableViewDidEndMultipleSelectionInteraction:(UITableView *)tableView
{
if ([self.proxy _hasListeners:@"rowsselected"]) {
NSMutableArray *selectedItems = [NSMutableArray arrayWithCapacity:tableView.indexPathsForSelectedRows.count];
NSMutableDictionary *startingRowObject = [NSMutableDictionary dictionaryWithCapacity:1];

for (int i = 0; i < tableView.indexPathsForSelectedRows.count; i++) {
NSIndexPath *index = tableView.indexPathsForSelectedRows[i];
NSInteger sectionIdx = [index section];
NSArray *sections = [(TiUITableViewProxy *)[self proxy] internalSections];
TiUITableViewSectionProxy *section = [self sectionForIndex:sectionIdx];

NSInteger dataIndex = [self rowIndexForIndexPath:index andSections:sections];

TiUITableViewRowProxy *row = [section rowAtIndex:[index row]];

NSMutableDictionary *eventObject = [NSMutableDictionary dictionaryWithObjectsAndKeys:
section, @"section",
NUMINTEGER(dataIndex), @"index",
row, @"row",
row, @"rowData",
nil];
[selectedItems addObject:eventObject];
}
[self.proxy fireEvent:@"rowsselected" withObject:@{ @"selectedRows" : selectedItems, @"startingRow" : startingRowObject }];
}
[self fireRowsSelectedEvent];
}

#pragma mark Collation
Expand Down Expand Up @@ -2514,6 +2491,12 @@ - (void)tableView:(UITableView *)ourTableView didSelectRowAtIndexPath:(NSIndexPa
search = YES;
}
[self triggerActionForIndexPath:indexPath fromPath:nil tableView:ourTableView wasAccessory:NO search:search name:@"click"];
[self fireRowsSelectedEvent];
}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self fireRowsSelectedEvent];
}

- (void)tableView:(UITableView *)ourTableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
Expand Down Expand Up @@ -2781,6 +2764,45 @@ - (void)fireScrollEvent:(UIScrollView *)scrollView
}
}

- (void)fireRowsSelectedEvent
{
// Do not continue if TableView has been released.
if (!tableview) {
return;
}

// Do not continue if not in multi-selection edit mode.
if (!tableview.editing || !tableview.allowsMultipleSelectionDuringEditing) {
return;
}

// Do not continue if there aren't any listeners.
NSString *eventName = @"rowsselected";
if (![self.proxy _hasListeners:eventName]) {
return;
}

// Fire an event providing an array of all selected rows.
NSMutableArray *selectedItems = [NSMutableArray arrayWithCapacity:tableview.indexPathsForSelectedRows.count];
NSMutableDictionary *startingRowObject = [NSMutableDictionary dictionaryWithCapacity:1];
for (int i = 0; i < tableview.indexPathsForSelectedRows.count; i++) {
NSIndexPath *index = tableview.indexPathsForSelectedRows[i];
NSInteger sectionIdx = [index section];
NSArray *sections = [(TiUITableViewProxy *)[self proxy] internalSections];
TiUITableViewSectionProxy *section = [self sectionForIndex:sectionIdx];
NSInteger dataIndex = [self rowIndexForIndexPath:index andSections:sections];
TiUITableViewRowProxy *row = [section rowAtIndex:[index row]];
NSMutableDictionary *eventObject = [NSMutableDictionary dictionaryWithObjectsAndKeys:
section, @"section",
NUMINTEGER(dataIndex), @"index",
row, @"row",
row, @"rowData",
nil];
[selectedItems addObject:eventObject];
}
[self.proxy fireEvent:eventName withObject:@{ @"selectedRows" : selectedItems, @"startingRow" : startingRowObject }];
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if (scrollView.isDragging || scrollView.isDecelerating) {
Expand Down

0 comments on commit 09e9044

Please sign in to comment.