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-13927] Send out row info when availabe in swipe event #4404

Merged
merged 1 commit into from
Jun 19, 2013
Merged
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
79 changes: 79 additions & 0 deletions iphone/Classes/TiUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,85 @@ -(void)handleListenerAddedWithEvent:(NSString *)event
[super handleListenerAddedWithEvent:event];
}

-(void)recognizedSwipe:(UISwipeGestureRecognizer *)recognizer
{
if ([[self proxy] _hasListeners:@"swipe"]) {

NSString* swipeString;
switch ([recognizer direction]) {
case UISwipeGestureRecognizerDirectionUp:
swipeString = @"up";
break;
case UISwipeGestureRecognizerDirectionDown:
swipeString = @"down";
break;
case UISwipeGestureRecognizerDirectionLeft:
swipeString = @"left";
break;
case UISwipeGestureRecognizerDirectionRight:
swipeString = @"right";
break;
default:
swipeString = @"unknown";
break;
}



BOOL viaSearch = [searchController isActive];
UITableView* theTableView = viaSearch ? [searchController searchResultsTableView] : [self tableView];
CGPoint point = [recognizer locationInView:theTableView];
CGPoint pointInView = [recognizer locationInView:self];
NSIndexPath* indexPath = nil;

if (viaSearch) {
NSIndexPath* index = [theTableView indexPathForRowAtPoint:point];
if (index != nil) {
indexPath = [self indexPathFromSearchIndex:[index row]];
}
} else {
indexPath = [theTableView indexPathForRowAtPoint:point];
}


NSMutableDictionary *event = [[TiUtils pointToDictionary:pointInView] mutableCopy];
[event setValue:swipeString forKey:@"direction"];
[event setObject:NUMBOOL(NO) forKey:@"detail"];
[event setObject:NUMBOOL(viaSearch) forKey:@"search"];

if (indexPath != nil) {
//We have index path. Let us fill out section and row information. Also since the
int sectionIdx = [indexPath section];
NSArray * sections = [(TiUITableViewProxy *)[self proxy] internalSections];
TiUITableViewSectionProxy *section = [self sectionForIndex:sectionIdx];

int rowIndex = [indexPath row];
int dataIndex = 0;
int c = 0;
TiUITableViewRowProxy *row = [section rowAtIndex:rowIndex];

// unfortunately, we have to scan to determine our row index
for (TiUITableViewSectionProxy *section in sections)
{
if (c == sectionIdx)
{
dataIndex += rowIndex;
break;
}
dataIndex += [section rowCount];
c++;
}
[event setObject:section forKey:@"section"];
[event setObject:row forKey:@"row"];
[event setObject:row forKey:@"rowData"];
[event setObject:NUMINT(dataIndex) forKey:@"index"];

}
[[self proxy] fireEvent:@"swipe" withObject:event];
[event release];
}
}

-(void)longPressGesture:(UILongPressGestureRecognizer *)recognizer
{
if([[self proxy] _hasListeners:@"longpress"] && [recognizer state] == UIGestureRecognizerStateBegan)
Expand Down