Skip to content

Commit

Permalink
feat: Pass origin of selected cell in onPress callback (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
emielvanliere authored and iRoachie committed Jan 17, 2019
1 parent b76367d commit 5498570
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions RNTableView/RNTableView.m
Expand Up @@ -530,6 +530,13 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
newValue[@"target"] = self.reactTag;
newValue[@"selectedIndex"] = [NSNumber numberWithInteger:indexPath.item];
newValue[@"selectedSection"] = [NSNumber numberWithInteger:indexPath.section];

CGRect selectedCellRect = [tableView rectForRowAtIndexPath:indexPath];
selectedCellRect = CGRectOffset(selectedCellRect, -tableView.contentOffset.x, -tableView.contentOffset.y);
newValue[@"selectedOrigin"] = @{
@"x": @(selectedCellRect.origin.x),
@"y": @(selectedCellRect.origin.y)
};

/*
* if allowToggle is enabled and we tap an already selected row, then remove the selection.
Expand Down
1 change: 1 addition & 0 deletions RNTableView/RNTableViewManager.m
Expand Up @@ -47,6 +47,7 @@ - (NSArray *)customDirectEventTypes
RCT_EXPORT_VIEW_PROPERTY(additionalItems, NSArray)
RCT_EXPORT_VIEW_PROPERTY(selectedIndex, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(selectedSection, NSInteger)
RCT_EXPORT_VIEW_PROPERTY(selectedOrigin, CGPoint)
RCT_EXPORT_VIEW_PROPERTY(cellHeight, float)
RCT_EXPORT_VIEW_PROPERTY(footerHeight, float)
RCT_EXPORT_VIEW_PROPERTY(headerHeight, float)
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Expand Up @@ -33,6 +33,7 @@ interface OnPressCallBack extends CallBack {
children: string
selectedIndex: number
selectedSection: number
selectedOrigin: PointPropType
footerLabel?: string
label?: string
}
Expand Down

0 comments on commit 5498570

Please sign in to comment.