Skip to content
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

[TIMOB-19255] iOS: Fix empty ListView crashes with NSRangeException in 'scrollstart' #7046

Merged
merged 3 commits into from
Aug 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,15 @@ events:
type: Titanium.UI.ListSection

- name: firstVisibleItemIndex
summary: The index of the first visible item in the list view when the event fires; this item might not be fully visible.
summary: |
The index of the first visible item in the list view when the event fires; this item might not be fully visible.
Note: The index is `-1` when there are no items in the <Titanium.UI.ListView>.
type: Number

- name: firstVisibleSectionIndex
summary: The index of the first visible section in the list view when the event fires.
summary: |
The index of the first visible section in the list view when the event fires.
Note: The index is `-1` when there are no items in the <Titanium.UI.ListView>.
type: Number

- name: bubbles
Expand Down
34 changes: 22 additions & 12 deletions iphone/Classes/TiUIListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1688,19 +1688,29 @@ - (void)fireScrollEvent:(NSString*)eventName forTableView:(UITableView*)tableVie
if([(TiViewProxy*)[self proxy] _hasListeners:eventName checkParent:NO])
{
NSArray* indexPaths = [tableView indexPathsForVisibleRows];
NSIndexPath *indexPath = [self pathForSearchPath:[indexPaths objectAtIndex:0]];

NSUInteger visibleItemCount = [indexPaths count];

TiUIListSectionProxy* section = [[self listViewProxy] sectionForIndex: [indexPath section]];
NSMutableDictionary *eventArgs = [NSMutableDictionary dictionary];

[eventArgs setValue:NUMINTEGER([indexPath row]) forKey:@"firstVisibleItemIndex"];
[eventArgs setValue:NUMUINTEGER(visibleItemCount) forKey:@"visibleItemCount"];
[eventArgs setValue:NUMINTEGER([indexPath section]) forKey:@"firstVisibleSectionIndex"];
[eventArgs setValue:section forKey:@"firstVisibleSection"];
[eventArgs setValue:[section itemAtIndex:[indexPath row]] forKey:@"firstVisibleItem"];

TiUIListSectionProxy* section;

if ([indexPaths count] > 0) {
NSIndexPath *indexPath = [self pathForSearchPath:[indexPaths objectAtIndex:0]];
NSUInteger visibleItemCount = [indexPaths count];
section = [[self listViewProxy] sectionForIndex: [indexPath section]];

[eventArgs setValue:NUMINTEGER([indexPath row]) forKey:@"firstVisibleItemIndex"];
[eventArgs setValue:NUMUINTEGER(visibleItemCount) forKey:@"visibleItemCount"];
[eventArgs setValue:NUMINTEGER([indexPath section]) forKey:@"firstVisibleSectionIndex"];
[eventArgs setValue:section forKey:@"firstVisibleSection"];
[eventArgs setValue:[section itemAtIndex:[indexPath row]] forKey:@"firstVisibleItem"];
} else {
section = [[self listViewProxy] sectionForIndex: 0];

[eventArgs setValue:NUMINTEGER(-1) forKey:@"firstVisibleItemIndex"];
[eventArgs setValue:NUMUINTEGER(0) forKey:@"visibleItemCount"];
[eventArgs setValue:NUMINTEGER(0) forKey:@"firstVisibleSectionIndex"];
[eventArgs setValue:section forKey:@"firstVisibleSection"];
[eventArgs setValue:NUMINTEGER(-1) forKey:@"firstVisibleItem"];
}

[[self proxy] fireEvent:eventName withObject:eventArgs propagate:NO];
}
}
Expand Down