Skip to content

Commit

Permalink
Merge pull request #7388 from hansemannn/TIMOB-19763
Browse files Browse the repository at this point in the history
[TIMOB-19763] Support item-specific peek for previewContext on ListView
  • Loading branch information
pec1985 committed Nov 4, 2015
2 parents 80f2c5c + 4dac340 commit b9362fa
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 86 deletions.
1 change: 1 addition & 0 deletions apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ properties:
improves the loading of images, but can also cause trouble in list views having a lot of
remote images, because every remote image opens a new HTTP request.
default: true
type: Boolean
since: 5.1.0
platforms: [iphone, ipad]

Expand Down
1 change: 1 addition & 0 deletions apidoc/Titanium/UI/View.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,7 @@ properties:
It is ignored on older devices and can manually be checked using <Titanium.UI.iOS.forceTouchSupported>.
platforms: [iphone]
since: "5.1.0"
type: Titanium.UI.View
osver: {ios: {min: "9.0"}}

- name: right
Expand Down
21 changes: 16 additions & 5 deletions apidoc/Titanium/UI/iOS/PreviewAction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,29 @@ events:
summary: Fired when the device detects a click against a preview action.
description: |
This event provides different properties depending on the view the <Titanium.UI.iOS.PreviewContext>
is assigned to. For example, the <Titanium.UI.ListView> and <Titanium.UI.TableView> provide the
additional properties `itemIndex` and `sectionIndex` to identify the previewed row and
section, respectively.
is assigned to. Every event has the `index` property to identify the clicked action. If the <Titanium.UI.iOS.PreviewContext>
is assigned to a <Titanium.UI.ListView>, the event provides the additional properties `itemIndex`, `sectionIndex`
and `itemId` to identify the previewed row and section, respectively.
properties:
- name: index
summary: |
The index of the clicked action.
type: Number

- name: itemIndex
summary: |
The index of the clicked row, if the `previewContext` property of the <Titanium.UI.iOS.PreviewContext>
is either a <Titanium.UI.ListView> or a <Titanium.UI.TableView>.
is a <Titanium.UI.ListView>.
type: Number

- name: sectionIndex
summary: |
The index of the clicked section, if the `previewContext` property of the <Titanium.UI.iOS.PreviewContext>
is either a <Titanium.UI.ListView> or a <Titanium.UI.TableView>.
is a <Titanium.UI.ListView>.
type: Number

- name: itemId
summary: |
The item ID of cell, if the `previewContext` property of the <Titanium.UI.iOS.PreviewContext>
is a <Titanium.UI.ListView>.
type: String
130 changes: 88 additions & 42 deletions apidoc/Titanium/UI/iOS/PreviewContext.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,81 @@ properties:
type: Number
default: The available height of the screen.

- name: pop
summary: The callback after popping the preview.
description: |
Called after the user the preview is popped. You will most likely open a window in here.
type: Callback<PreviewPopResponse>

- name: preview
summary: The preview view.
description: |
Provides the preview for "peeking". This view is independent from the window which can be openend after
"popping" the preview to give you the change to provide different layouts for the preview and the full
window.
"popping" the preview to give you the ability to provide different layouts for the preview and the full
window. If you want to adjust the preview inside the `peek` event, change the view assigned to this property.
type: Titanium.UI.View

events:
- name: peek
summary: Fired when the user peeks the preview. You can configure the preview
description: |
You can configure the preview in this event before it is displayed. If the preview context is assigned to a
normal view like a <Ti.UI.Button> the `preview` property can be received here to change the content of it
before displaying. If the preview context is assigned to a <Titanium.UI.ListView>, you can also receive the
properties `sectionIndex`, `itemIndex` and `itemId` here to access item-specific data to display.
Note: Don't do asynchronous operations like HTTP requests here, since the preview will not wait for the
operations to complete.
properties:

- name: preview
summary: The view to be previewed.
type: Titanium.UI.View

- name: sectionIndex
summary: |
The section index of the ListView to identify the selected section.
Note: This property is only available if the preview context is assigned to a <Titanium.UI.ListView>.
type: Number

- name: itemIndex
summary: |
The item index of the ListView to identify the selected item.
Note: This property is only available if the preview context is assigned to a <Titanium.UI.ListView>.
type: Number

- name: itemId
summary: The item ID bound to the list item that generated the event.
type: String

- name: pop
summary: Fired when the user pop the preview. You will most likely open a fullscreen window here.
description: |
You can open a window here or update your current UI. If the preview context is assigned to a
normal view like a <Ti.UI.Button> the `preview` property can be received here to change the content of it
before displaying. If the preview context is assigned to a <Titanium.UI.ListView>, you can also receive the
properties `sectionIndex`, `itemIndex` and `itemId` here to access item-specific data to display.
Note: Don't do asynchronous operations like HTTP requests here, since the preview will not wait for the
operations to complete.
properties:

- name: preview
summary: The view to be previewed.
type: Titanium.UI.View

- name: sectionIndex
summary: |
The section index of the ListView to identify the selected section.
Note: This property is only available if the preview context is assigned to a <Titanium.UI.ListView>.
type: Number

- name: itemIndex
summary: |
The item index of the ListView to identify the selected item.
Note: This property is only available if the preview context is assigned to a <Titanium.UI.ListView>.
type: Number

- name: itemId
summary: The item ID bound to the list item that generated the event.
type: String

examples:
- title: PreviewContext example using a <Titanium.UI.Button> as receiver.
- title: PreviewContext example using a Button as receiver.
example: |
The example below creates a new preview context and assigns a `window`, `actions` and a `contentHeight`.
After that, we assign the preview context to a view which will trigger the "peeking" of it. Note, that this
Expand Down Expand Up @@ -109,10 +168,12 @@ examples:
var context = Ti.UI.iOS.createPreviewContext({
preview: previewView,
actions: actions, // Can have both Ti.UI.iOS.PreviewAction + Ti.UI.iOS.PreviewActionGroup
contentHeight: 300, // When unspecified, we use the available height
pop: function() { // Called after popping the preview
detailWindow.open();
}
contentHeight: 300 // When unspecified, we use the available height
});
// Fired after popping the preview
context.addEventListener("pop", function(e) {
detailWindow.open();
});
// Assign the preview context
Expand All @@ -128,7 +189,7 @@ examples:
win.add(button);
win.open();
- title: PreviewContext example using a <Titanium.UI.ListView> as receiver.
- title: PreviewContext example using a ListView as receiver.
example: |
var actions = [];
var win = Ti.UI.createWindow({
Expand Down Expand Up @@ -171,12 +232,19 @@ examples:
var context = Ti.UI.iOS.createPreviewContext({
preview: previewView,
actions: actions, // Can have both Ti.UI.iOS.PreviewAction + Ti.UI.iOS.PreviewActionGroup
contentHeight: 300, // When unspecified, we use the available height
pop: function(e) { // Called after popping the preview
Ti.API.warn("sectionIndex: " + e.sectionIndex); // Index of the ListView section
Ti.API.warn("itemIndex: " + e.itemIndex); // Index of the ListView row
detailWindow.open();
}
contentHeight: 300 // When unspecified, we use the available height
});
// Fired after peeking the preview
// Use this event to configure the preview depending on the sectionIndex / itemIndex
context.addEventListener("peek", function(e) {
Ti.API.warn("sectionIndex: " + e.sectionIndex);
Ti.API.warn("itemIndex: " + e.itemIndex);
});
// Fired after popping the preview
context.addEventListener("pop", function(e) {
detailWindow.open();
});
// Assign the preview context
Expand Down Expand Up @@ -208,25 +276,3 @@ examples:
win.add(listView);
win.open();
---
name: PreviewPopResponse
summary: Properties passed to the callback when the user pops the preview.
since: 5.1.0
platforms: [iphone]
properties:
- name: preview
type: Titanium.UI.View
summary: The <Titanium.UI.View> of the preview, that is shown on "peeking".

- name: itemIndex
summary: |
The index of the clicked row, if the `previewContext` property of the <Titanium.UI.iOS.PreviewContext>
is either a <Titanium.UI.ListView> or a <Titanium.UI.TableView>.
type: Number

- name: sectionIndex
summary: |
The index of the clicked section, if the `previewContext` property of the <Titanium.UI.iOS.PreviewContext>
is either a <Titanium.UI.ListView> or a <Titanium.UI.TableView>.
type: Number
1 change: 1 addition & 0 deletions apidoc/Titanium/WatchSession/WatchSession.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ methods:
transfers are queued.
parameters:
- name: params
type: Dictionary
summary: |
Pass an object with the following key-value pairs:
Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/TiPreviewingDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
@property(nonatomic, assign) TiViewProxy* preview;
@property(nonatomic, assign) TiViewProxy* sourceView;
@property(nonatomic, retain) NSArray* actions;
@property(nonatomic, retain) KrollCallback* popCallback;
@property(nonatomic) int contentHeight;
@property(nonatomic, retain) NSIndexPath* currentIndexPath;
@property(nonatomic, retain) NSDictionary* listViewEvent;

- (instancetype)initWithPreviewContext:(TiUIiOSPreviewContextProxy*)previewContext;
- (CGRect)createSourceRectWithLocation:(CGPoint*)location;
Expand Down
63 changes: 37 additions & 26 deletions iphone/Classes/TiPreviewingDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#import "TiPreviewingDelegate.h"
#import "TiUIListViewProxy.h"
#import "TiUIListView.h"
#import "TiUITableViewProxy.h"
#import "TiUITableView.h"

@implementation TiPreviewingDelegate

Expand All @@ -27,7 +25,6 @@ -(instancetype)initWithPreviewContext:(TiUIiOSPreviewContextProxy*)previewContex
_sourceView = [_previewContext sourceView];
_actions = [_previewContext actions];
_contentHeight = [_previewContext contentHeight];
_popCallback = [_previewContext popCallback];
}

return self;
Expand All @@ -43,17 +40,12 @@ -(void)dealloc

-(void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
{
NSMutableDictionary * propertiesDict = [[NSMutableDictionary alloc] initWithDictionary:@{ @"preview" : _preview }];

if ([self currentIndexPath] != nil) {
[propertiesDict setValue:NUMINTEGER([self currentIndexPath].section) forKey:@"sectionIndex"];
[propertiesDict setValue:NUMINTEGER([self currentIndexPath].row) forKey:@"itemIndex"];
}
NSMutableDictionary * propertiesDict = [[NSMutableDictionary alloc] initWithDictionary:[self listViewEvent]];
[propertiesDict setObject:_preview forKey:@"preview"];

NSArray * invocationArray = [[NSArray alloc] initWithObjects:&propertiesDict count:1];

[_popCallback call:invocationArray thisObject:_previewContext];
[invocationArray release];
[[self previewContext] fireEvent:@"pop" withObject:propertiesDict];
}

- (UIViewController*)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
Expand All @@ -70,28 +62,27 @@ - (UIViewController*)previewingContext:(id<UIViewControllerPreviewing>)previewin
}

UITableView *tableView = [self ensureTableView];
UITableViewCell *cell = nil;

// Handle UITableView and touches on non-cells
if (tableView != nil) {
cell = [tableView cellForRowAtIndexPath:[tableView indexPathForRowAtPoint:location]];

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

[self setListViewEvent:[self receiveListViewEventFromIndexPath:[tableView indexPathForRowAtPoint:location]]];
[[self previewContext] fireEvent:@"peek" withObject:[self listViewEvent]];
} else {
[self setCurrentIndexPath:nil];
[[self previewContext] fireEvent:@"peek" withObject:@{@"preview": _preview}];
}

for (id item in _actions) {
if ([item isKindOfClass:[TiUIiOSPreviewActionProxy class]] == YES) {
[item setActionIndex:actionIndex];

if (cell != nil) {
[self setCurrentIndexPath:[tableView indexPathForRowAtPoint:location]];
[item setTableViewIndexPath:[self currentIndexPath]];
if ([self listViewEvent] != nil) {
[item setListViewEvent:[self listViewEvent]];
}

[result addObject:[item action]];
Expand Down Expand Up @@ -132,18 +123,38 @@ -(UITableView*)ensureTableView
if ([_sourceView isKindOfClass:[TiUIListViewProxy class]] == YES) {
TiUIListViewProxy* listProxy = (TiUIListViewProxy*)_sourceView;
TiUIListView *view = (TiUIListView*)[listProxy view];

return [view tableView];
}
#endif

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

return nil;
}

-(NSDictionary*)receiveListViewEventFromIndexPath:(NSIndexPath*)indexPath
{
#ifdef USE_TI_UILISTVIEW
if ([_sourceView isKindOfClass:[TiUIListViewProxy class]] == YES) {
TiUIListViewProxy* listProxy = (TiUIListViewProxy*)_sourceView;

TiUIListSectionProxy *theSection = [listProxy sectionForIndex:indexPath.section];
NSDictionary *theItem = [theSection itemAtIndex:indexPath.row];

NSMutableDictionary *eventObject = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
NUMINTEGER(indexPath.section), @"sectionIndex",
NUMINTEGER(indexPath.row), @"itemIndex",
_preview, @"preview",
nil];
id propertiesValue = [theItem objectForKey:@"properties"];
NSDictionary *properties = ([propertiesValue isKindOfClass:[NSDictionary class]]) ? propertiesValue : nil;
id itemId = [properties objectForKey:@"itemId"];
if (itemId != nil) {
[eventObject setObject:itemId forKey:@"itemId"];
}

return eventObject;
}
#endif

return nil;
}

Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUIiOSPreviewActionProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
The indexPath for accessing section and item of
the tableView if specified.
*/
@property(nonatomic, retain) NSIndexPath *tableViewIndexPath;
@property(nonatomic, retain) NSDictionary *listViewEvent;

/**
Returns a configured preview action.
Expand Down
7 changes: 4 additions & 3 deletions iphone/Classes/TiUIiOSPreviewActionProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ -(void)fireEventWithAction:(UIPreviewAction*)action
@"style" : NUMINT([self style])
}];

if ([self tableViewIndexPath] != nil) {
[event setValue:NUMINTEGER([self tableViewIndexPath].section) forKey:@"sectionIndex"];
[event setValue:NUMINTEGER([self tableViewIndexPath].row) forKey:@"itemIndex"];
if ([self listViewEvent] != nil) {
[event setValue:NUMINTEGER([TiUtils intValue:[[self listViewEvent] valueForKey:@"sectionIndex"]]) forKey:@"sectionIndex"];
[event setValue:NUMINTEGER([TiUtils intValue:[[self listViewEvent] valueForKey:@"itemIndex"]]) forKey:@"itemIndex"];
[event setValue:[[self listViewEvent] valueForKey:@"itemId"] forKey:@"itemId"];
}

[self fireEvent:@"click" withObject:event];
Expand Down
5 changes: 0 additions & 5 deletions iphone/Classes/TiUIiOSPreviewContextProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@
*/
@property(nonatomic) int contentHeight;

/**
The callback to be triggered after "popping" the window.
*/
@property(nonatomic,retain) KrollCallback *popCallback;

/**
Connectes the collected preview data to the iOS delegates.
*/
Expand Down

0 comments on commit b9362fa

Please sign in to comment.