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-19972] iOS: Fix previewContext for large table views #7441

Merged
merged 1 commit into from
Nov 16, 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
2 changes: 1 addition & 1 deletion iphone/Classes/TiPreviewingDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@property(nonatomic, retain) NSDictionary* listViewEvent;

- (instancetype)initWithPreviewContext:(TiUIiOSPreviewContextProxy*)previewContext;
- (CGRect)createSourceRectWithLocation:(CGPoint*)location;
- (CGRect)createSourceRectWithLocation:(CGPoint)location;

@end
#endif
Expand Down
47 changes: 28 additions & 19 deletions iphone/Classes/TiPreviewingDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#import "TiPreviewingDelegate.h"
#import "TiUIListViewProxy.h"
#import "TiUIListView.h"
#import "TiUITableViewProxy.h"
#import "TiUITableView.h"
#import "TiUIScrollView.h"

@implementation TiPreviewingDelegate

Expand Down Expand Up @@ -50,24 +53,12 @@ -(void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commi

- (UIViewController*)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{
TiViewController *controller = [[TiViewController alloc] initWithViewProxy:_preview];
[[_preview view] setFrame:[[controller view] bounds]];
[[controller view] addSubview:[_preview view]];

NSMutableArray *result = [NSMutableArray array];
int actionIndex = 0;

if (_contentHeight > 0) {
controller.preferredContentSize = CGSizeMake(0.0, _contentHeight);
}

UITableView *tableView = [self ensureTableView];

if (tableView != nil) {

// If the tap was not on a cell, don't continue
if ([tableView cellForRowAtIndexPath:[tableView indexPathForRowAtPoint:location]] == nil) {
RELEASE_TO_NIL(controller);
return nil;
}

Expand All @@ -77,6 +68,17 @@ - (UIViewController*)previewingContext:(id<UIViewControllerPreviewing>)previewin
[[self previewContext] fireEvent:@"peek" withObject:@{@"preview": _preview}];
}

TiViewController *controller = [[TiViewController alloc] initWithViewProxy:_preview];
[[_preview view] setFrame:[[controller view] bounds]];
[[controller view] addSubview:[_preview view]];

NSMutableArray *result = [NSMutableArray array];
int actionIndex = 0;

if (_contentHeight > 0) {
controller.preferredContentSize = CGSizeMake(0.0, _contentHeight);
}

for (id item in _actions) {
if ([item isKindOfClass:[TiUIiOSPreviewActionProxy class]] == YES) {
[item setActionIndex:actionIndex];
Expand All @@ -95,23 +97,22 @@ - (UIViewController*)previewingContext:(id<UIViewControllerPreviewing>)previewin
actionIndex++;
}
}

[previewingContext setSourceRect:[self createSourceRectWithLocation:&location]];

[controller setPreviewActions:result];
[_preview windowWillOpen];
[previewingContext setSourceRect:[self createSourceRectWithLocation:location]];

return controller;
}

-(CGRect)createSourceRectWithLocation:(CGPoint*)location
-(CGRect)createSourceRectWithLocation:(CGPoint)location
{
UITableView *tableView = [self ensureTableView];

if (tableView) {
NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:*location];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSIndexPath *indexPath = [tableView indexPathForRowAtPoint:location];
return [[tableView cellForRowAtIndexPath:indexPath] frame];

return cell.frame;
}

return CGRectZero; // The Frame is detected automatically on normal views
Expand All @@ -127,7 +128,15 @@ -(UITableView*)ensureTableView
return [view tableView];
}
#endif

#ifdef USE_TI_UITABLEVIEW
if ([_sourceView isKindOfClass:[TiUITableView class]] == YES) {
TiUITableViewProxy* listProxy = (TiUITableViewProxy*)_sourceView;
TiUITableView *view = (TiUITableView*)[listProxy view];

return [view tableView];
}
#endif

return nil;
}

Expand Down
29 changes: 28 additions & 1 deletion iphone/Classes/TiUIiOSPreviewContextProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#if IS_XCODE_7
#ifdef USE_TI_UIIOSPREVIEWCONTEXT
#import "TiUIiOSPreviewContextProxy.h"
#import "TiUIListView.h"
#import "TiUITableView.h"
#import "TiUIScrollView.h"

@implementation TiUIiOSPreviewContextProxy

Expand Down Expand Up @@ -56,9 +59,33 @@ -(void)dealloc

-(void)connectToDelegate
{
UIView *nativeSourceView = nil;

#ifdef USE_TI_UILISTVIEW
if ([[_sourceView view] isKindOfClass:[TiUIListView class]]) {
nativeSourceView = [(TiUIListView*)[_sourceView view] tableView];
}
#else
#ifdef USE_TI_UITABLEVIEW
if([[_sourceView view] isKindOfClass:[TiUITableView class]]) {
nativeSourceView = [(TiUITableView*)[_sourceView view] tableView];
}
#else
#ifdef USE_TI_UISCROLLVIEW
if([[_sourceView view] isKindOfClass:[TiUIScrollView class]]) {
nativeSourceView = [(TiUIScrollView*)[_sourceView view] scrollView];
}
#endif
#endif
#endif

if (nativeSourceView == nil) {
nativeSourceView = [_sourceView view];
}

UIViewController *controller = [[[TiApp app] controller] topPresentedController];
[controller registerForPreviewingWithDelegate:[[TiPreviewingDelegate alloc] initWithPreviewContext:self]
sourceView:[_sourceView view]];
sourceView:nativeSourceView];
}

@end
Expand Down