[TIMOB-23406] iOS/Android: Add 'scrolling' event to ListView to track scroll direction (up or down)
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-09-06T07:34:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 6.1.0 |
Components | Android, iOS |
Labels | n/a |
Reporter | Richard Lustemberg |
Assignee | Hans Knöchel |
Created | 2016-05-18T16:25:43.000+0000 |
Updated | 2016-12-02T19:25:42.000+0000 |
Description
At the moment is not possible to determine the scroll direction of a ListView natively and as the view is scrolling. Very common effects such as the hiding of the navigation bar when scrolling (like on the Facebook app) become impossible to achieve without cumbersome workarounds.
I will send a PR with a modification to the SDK core.
Probably some modifications like coding style and naming will be necessary (By no means I am an Objective C dev).
Most of the code I took straight from Stackoverflow [link Stackoverflow](http://stackoverflow.com/a/21263997/436785)
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
{
if (!decelerate) {
if ([self isLazyLoadingEnabled]) {
[[ImageLoader sharedLoader] resume];
}
[self fireScrollEnd:(UITableView *)scrollView];
}
if ([self.proxy _hasListeners:@"dragend"]) {
[self.proxy fireEvent:@"dragend" withObject:nil withSource:self.proxy propagate:NO reportSuccess:NO errorCode:0 message:nil];
}
if ([self.proxy _hasListeners:@"pullend"]) {
if ( (_pullViewProxy != nil) && (pullActive == YES) ) {
pullActive = NO;
[self.proxy fireEvent:@"pullend" withObject:nil withSource:self.proxy propagate:NO reportSuccess:NO errorCode:0 message:nil];
}
}
}
Sorry, I put the wrong snippett ;) And the file modified is iphone/Classes/TIUIListView.m
This will solve lot of our problems :)
@Richard Lustemberg you actually tested the code, and if yes that worked?
Yes, I am using it [It's here ](https://github.com/appcelerator/titanium_mobile/pull/8005) I guess that to make it production ready some extra thoughts should be given to the event name, at the very least ;)
I know is there :) you js code is ?:
yes, exactly that.
Can we do the same for Android?
http://stackoverflow.com/a/17017477/5537752 looks promising. Although it seems like we cannot get the velocity and targetContentOffset, we get at least say if its scrolling up or down. Anyone interesting in implementing that?
Btw, iOS PR (for linking): https://github.com/appcelerator/titanium_mobile/pull/8005
I'll try to do that. The project I'm working on needs it :)
Done: https://github.com/appcelerator/titanium_mobile/pull/8031 ;) *Edit:* have to change it, at the moment it fires the whole time while scrolling (so it will detect chaging the direction during scrolling). In the yml file it says it will only fire when lifting the finger
I've changed the doc to: {quote}On iOS no event is fired when the finger is not released.{quote} since it will fire when the finger is down on Android, too.
[~msamah] or [~hpham] to review the Android-side? Looks good to me.
Reviewed code, left some comments.
Waiting for m1ga aka [~michael] to provide updates for this. For the moment, I believe he doesn't have time to look throughly at it.
Sorry, at the moment I can't compile the source since my normal work environment is under linux. I'll try to setup a windows machine to get things running though.
No worries.
Updated the code and made a new PR: https://github.com/appcelerator/titanium_mobile/pull/8216
Android PR https://github.com/appcelerator/titanium_mobile/pull/8216 merged.
Verified the implementation.
scrolling
event is fired successfully & it gives the direction asup
ordown
. Closing. Appc Studio : 4.8.1.201611291132 SDK Version : 6.1.0.v20161202104721 Mac OS Version : 10.12 Xcode Version : Xcode 8.1 Build version 8B62 Appc CLI AND Appc NPM : {"NPM":"4.2.9-1","CLI":"6.1.0-302"} Ti CLI : 5.0.11 Alloy : 1.9.4 Node : v4.6.0 Device: running 7.1Pixel IOS simulator : Iphone 7 plus running IOS 10