Skip to content

Commit

Permalink
[TIMOB-24327] iOS: Add "allowsMultipleSelectionWhenEditing" and "getS…
Browse files Browse the repository at this point in the history
…electedRow" in ListView (#9557)

* Enable Multiple Selection in List View

* Added method setAllowsMultipleSelectionDuringEditing
* Added method getSelectedRows
* Added test case

* Update TiUIListView.m

* Update TiUIListViewProxy.m

* Update app.js

* Update ListView.yml

* Update TiUIListViewProxy.m

* Update ListView.yml

* Add unit-tests, fix kroll-thread usage

* [TIMOB-24327] Apply clang-format

* [TIMOB-24327] Update unit-tests from test-suite

* Update ListView.yml
  • Loading branch information
hansemannn authored and ewieberappc committed Nov 10, 2017
1 parent 50f7a4c commit 1cbd357
Show file tree
Hide file tree
Showing 5 changed files with 970 additions and 15 deletions.
19 changes: 16 additions & 3 deletions apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -705,12 +705,19 @@ properties:
platforms: [iphone, ipad]

- name: allowsSelectionDuringEditing
summary: Determines whether this list View rows can be selected while editing the table.
summary: Determines whether this list view items can be selected while editing the table.
type: Boolean
default: false
since: "5.4.0"
platforms: [iphone, ipad]

- name: allowsMultipleSelectionDuringEditing
summary: Determines whether multiple items of this list view can be selected at the same time while editing the table.
type: Boolean
default: false
since: "7.0.0"
platforms: [iphone, ipad]

- name: lazyLoadingEnabled
summary: Determines if the list view should use lazy loading to load remote images.
description: |
Expand Down Expand Up @@ -955,7 +962,7 @@ properties:
default: true

- name: separatorColor
summary: Separator line color between rows, as a color name or hex triplet.
summary: Separator line color between items, as a color name or hex triplet.
description: |
To make the line invisible, set this property to `transparent`, or the same value as the
[backgroundColor](Titanium.UI.ListView.backgroundColor) property.
Expand Down Expand Up @@ -1115,7 +1122,13 @@ properties:
since: 6.1.0
platforms: [iphone, ipad]
availability: creation


- name: selectedItems
summary: Returns the selected list view items.
type: Array<ListItemEventType>
since: "7.0.0"
platforms: [iphone, ipad]

methods:
- name: scrollToItem
summary: Scrolls to a specific item.
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUIListView.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- (void)updateIndicesForVisibleRows;

+ (UITableViewRowAnimation)animationStyleForProperties:(NSDictionary *)properties;
- (NSIndexPath *)pathForSearchPath:(NSIndexPath *)indexPath;

@end

Expand Down
10 changes: 10 additions & 0 deletions iphone/Classes/TiUIListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,16 @@ - (void)setDisableBounce_:(id)value
[[self tableView] setBounces:![TiUtils boolValue:value def:NO]];
}

- (void)setAllowsMultipleSelectionDuringEditing_:(id)value
{
ENSURE_TYPE(value, NSNumber);
[[self proxy] replaceValue:value forKey:@"allowsMultipleSelectionDuringEditing" notification:NO];

[[self tableView] beginUpdates];
[[self tableView] setAllowsMultipleSelectionDuringEditing:[TiUtils boolValue:value]];
[[self tableView] endUpdates];
}

#pragma mark - Search Support
- (void)setCaseInsensitiveSearch_:(id)args
{
Expand Down
57 changes: 45 additions & 12 deletions iphone/Classes/TiUIListViewProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -426,25 +426,28 @@ - (void)scrollToItem:(id)args

- (void)selectItem:(id)args
{
ENSURE_ARG_COUNT(args, 2);

if (view != nil) {
ENSURE_ARG_COUNT(args, 2);
NSUInteger sectionIndex = [TiUtils intValue:[args objectAtIndex:0]];
NSUInteger itemIndex = [TiUtils intValue:[args objectAtIndex:1]];

if ([_sections count] <= sectionIndex) {
DebugLog(@"[WARN] ListView: Select section index is out of range");
return;
}
TiUIListSectionProxy *section = [_sections objectAtIndex:sectionIndex];
if (section.itemCount <= itemIndex) {
DebugLog(@"[WARN] ListView: Select item index is out of range");
return;
}
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:itemIndex inSection:sectionIndex];

TiThreadPerformOnMainThread(^{
if ([_sections count] <= sectionIndex) {
DebugLog(@"[WARN] ListView: Select section index is out of range");
return;
}
TiUIListSectionProxy *section = [_sections objectAtIndex:sectionIndex];
if (section.itemCount <= itemIndex) {
DebugLog(@"[WARN] ListView: Select item index is out of range");
return;
}
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:itemIndex inSection:sectionIndex];
[self.listView.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
[self.listView.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionNone animated:YES];
},
NO);
[NSThread isMainThread]);
}
}

Expand Down Expand Up @@ -505,6 +508,36 @@ - (void)setContentInsets:(id)args
[NSThread isMainThread]);
}

- (NSMutableArray *)selectedItems
{
NSMutableArray *result = [[NSMutableArray alloc] init];
NSArray *selectedRows = [[self.listView tableView] indexPathsForSelectedRows];

if (selectedRows != nil) {
TiThreadPerformOnMainThread(^{
for (NSIndexPath *indexPath in [self.listView.tableView indexPathsForSelectedRows]) {
NSIndexPath *realIndexPath = [self.listView pathForSearchPath:indexPath];
TiUIListSectionProxy *section = [self sectionForIndex:realIndexPath.section];
NSDictionary *item = [section itemAtIndex:realIndexPath.row];
NSMutableDictionary *eventObject = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
section, @"section",
NUMINTEGER(realIndexPath.section), @"sectionIndex",
NUMINTEGER(realIndexPath.row), @"itemIndex",
nil];
id propertiesValue = [item objectForKey:@"properties"];
NSDictionary *properties = ([propertiesValue isKindOfClass:[NSDictionary class]]) ? propertiesValue : nil;
id itemId = [properties objectForKey:@"itemId"];
if (itemId != nil) {
[eventObject setObject:itemId forKey:@"itemId"];
}
[result addObject:eventObject];
}
},
YES);
}
return result;
}

#pragma mark - Marker Support

- (NSIndexPath *)indexPathFromDictionary:(NSDictionary *)args
Expand Down

0 comments on commit 1cbd357

Please sign in to comment.