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

feat(ios): add direction to ListView scrolling #14130

Merged
merged 6 commits into from
Oct 5, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy)
payload.put(TiC.PROPERTY_DIRECTION, "up");
} else if (dy < 0) {
payload.put(TiC.PROPERTY_DIRECTION, "down");
} else {
payload.put(TiC.PROPERTY_DIRECTION, "unknown");
}
payload.put(TiC.EVENT_PROPERTY_VELOCITY, 0);
if (continuousUpdate) {
Expand Down
2 changes: 1 addition & 1 deletion apidoc/Titanium/UI/ListView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ events:
ipad: 5.4.0
properties:
- name: direction
summary: Direction of the scroll either 'up', or 'down'.
summary: Direction of the scroll either 'up', 'down' or 'unknown'.
type: String

- name: velocity
Expand Down
2 changes: 1 addition & 1 deletion apidoc/Titanium/UI/TableView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ events:
since: { android: "2.1.0", iphone: "2.1.0", ipad: "2.1.0" }
properties:
- name: direction
summary: Direction of the swipe, either `left` or `right`.
summary: Direction of the swipe, either `left`, `right` or `unknown`.
type: String

- name: index
Expand Down
18 changes: 15 additions & 3 deletions iphone/Classes/TiUIListView.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ @interface TiUIListView ()
@property (nonatomic, readonly) TiUIListViewProxy *listViewProxy;
@property (nonatomic, copy, readwrite) NSString *searchString;
@property (nonatomic, copy, readwrite) NSString *searchedString;
@property (nonatomic, assign) CGFloat lastContentOffset;
@end

static TiViewProxy *FindViewProxyWithBindIdContainingPoint(UIView *view, CGPoint point);
Expand Down Expand Up @@ -79,8 +80,8 @@ @implementation TiUIListView {
BOOL isSearched;
UIView *dimmingView;
BOOL isSearchBarInNavigation;
int lastVisibleItem;
int lastVisibleSection;
NSInteger lastVisibleItem;
NSInteger lastVisibleSection;
BOOL forceUpdates;
}

Expand Down Expand Up @@ -2011,6 +2012,15 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
TiUIListSectionProxy *section;
CGFloat topSpacing = scrollView.contentOffset.y + scrollView.adjustedContentInset.top;

NSString *direction = @"unknown";

if (self.lastContentOffset > scrollView.contentOffset.y) {
direction = @"down";
} else if (self.lastContentOffset < scrollView.contentOffset.y) {
direction = @"up";
}
self.lastContentOffset = scrollView.contentOffset.y;

if ([indexPaths count] > 0) {
NSIndexPath *indexPath = [self pathForSearchPath:[indexPaths objectAtIndex:0]];
NSUInteger visibleItemCount = [indexPaths count];
Expand All @@ -2022,6 +2032,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
[eventArgs setValue:section forKey:@"firstVisibleSection"];
[eventArgs setValue:[section itemAtIndex:[indexPath row]] forKey:@"firstVisibleItem"];
[eventArgs setValue:NUMINTEGER(topSpacing) forKey:@"top"];
[eventArgs setValue:direction forKey:@"direction"];

if (lastVisibleItem != [indexPath row] || lastVisibleSection != [indexPath section] || forceUpdates) {
// only log if the item changes or forced
Expand All @@ -2038,6 +2049,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
[eventArgs setValue:section forKey:@"firstVisibleSection"];
[eventArgs setValue:NUMINTEGER(-1) forKey:@"firstVisibleItem"];
[eventArgs setValue:NUMINTEGER(topSpacing) forKey:@"top"];
[eventArgs setValue:direction forKey:@"direction"];
}
});
}
Expand Down Expand Up @@ -2110,7 +2122,7 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
if ([[self proxy] _hasListeners:@"scrolling"]) {
NSString *direction = nil;
NSString *direction = @"unknown";

if (velocity.y > 0) {
direction = @"up";
Expand Down
Loading