From a7ac1d42103859289e61806b24727fc6844e5554 Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Thu, 3 Oct 2024 16:02:36 +0200 Subject: [PATCH 1/5] feat(ios): add direction to ListView scrolling --- iphone/Classes/TiUIListView.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/iphone/Classes/TiUIListView.m b/iphone/Classes/TiUIListView.m index ae821bb0393..e07ea91e108 100644 --- a/iphone/Classes/TiUIListView.m +++ b/iphone/Classes/TiUIListView.m @@ -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); @@ -2011,6 +2012,15 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView TiUIListSectionProxy *section; CGFloat topSpacing = scrollView.contentOffset.y + scrollView.adjustedContentInset.top; + NSString *direction = nil; + + 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]; @@ -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 @@ -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"]; } }); } From 6f7e07c10387ee27615e3f84c571d1f1f46bc7ba Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Sat, 5 Oct 2024 14:08:53 +0200 Subject: [PATCH 2/5] Update iphone/Classes/TiUIListView.m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Hans Knöchel --- iphone/Classes/TiUIListView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iphone/Classes/TiUIListView.m b/iphone/Classes/TiUIListView.m index e07ea91e108..a8c20c63f48 100644 --- a/iphone/Classes/TiUIListView.m +++ b/iphone/Classes/TiUIListView.m @@ -2012,7 +2012,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView TiUIListSectionProxy *section; CGFloat topSpacing = scrollView.contentOffset.y + scrollView.adjustedContentInset.top; - NSString *direction = nil; + NSString *direction = [NSNull null]; if (self.lastContentOffset > scrollView.contentOffset.y) { direction = @"down"; From 24acf7e299aefa3dbeab0229bb2618bf4c50046b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Kn=C3=B6chel?= Date: Sat, 5 Oct 2024 15:25:21 +0200 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20fix=20=E2=80=9Cdirection=E2=80=9D=20?= =?UTF-8?q?event=20attribute=20default?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iphone/Classes/TiUIListView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iphone/Classes/TiUIListView.m b/iphone/Classes/TiUIListView.m index a8c20c63f48..bd336a3412d 100644 --- a/iphone/Classes/TiUIListView.m +++ b/iphone/Classes/TiUIListView.m @@ -2012,7 +2012,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView TiUIListSectionProxy *section; CGFloat topSpacing = scrollView.contentOffset.y + scrollView.adjustedContentInset.top; - NSString *direction = [NSNull null]; + NSString *direction = @"unknown"; if (self.lastContentOffset > scrollView.contentOffset.y) { direction = @"down"; @@ -2122,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"; From d109bb5678a56247f2e4445675611caf96cc51c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Kn=C3=B6chel?= Date: Sat, 5 Oct 2024 15:25:36 +0200 Subject: [PATCH 4/5] fix: fix incorrect type --- iphone/Classes/TiUIListView.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iphone/Classes/TiUIListView.m b/iphone/Classes/TiUIListView.m index bd336a3412d..6a570920fc3 100644 --- a/iphone/Classes/TiUIListView.m +++ b/iphone/Classes/TiUIListView.m @@ -80,8 +80,8 @@ @implementation TiUIListView { BOOL isSearched; UIView *dimmingView; BOOL isSearchBarInNavigation; - int lastVisibleItem; - int lastVisibleSection; + NSInteger lastVisibleItem; + NSInteger lastVisibleSection; BOOL forceUpdates; } From e50586b7e090e88889dd078638bbeb81b51c6642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans=20Kn=C3=B6chel?= Date: Sat, 5 Oct 2024 15:32:41 +0200 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20align=20=E2=80=9Cunknown=E2=80=9D?= =?UTF-8?q?=20value=20with=20Android,=20update=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ti/modules/titanium/ui/widget/listview/TiListView.java | 2 ++ apidoc/Titanium/UI/ListView.yml | 2 +- apidoc/Titanium/UI/TableView.yml | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/TiListView.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/TiListView.java index 2efb68fd889..a169a10a0cc 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/TiListView.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/listview/TiListView.java @@ -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) { diff --git a/apidoc/Titanium/UI/ListView.yml b/apidoc/Titanium/UI/ListView.yml index 5cbb58e0f68..b6ac0a46f03 100644 --- a/apidoc/Titanium/UI/ListView.yml +++ b/apidoc/Titanium/UI/ListView.yml @@ -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 diff --git a/apidoc/Titanium/UI/TableView.yml b/apidoc/Titanium/UI/TableView.yml index 07837bbb172..6b53a579a52 100644 --- a/apidoc/Titanium/UI/TableView.yml +++ b/apidoc/Titanium/UI/TableView.yml @@ -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