nativescript-community / ui-collectionview

Allows you to easily add a collection view (grid list view) to your projects. Supports vertical and horizontal modes, templating, and more.
Apache License 2.0
59 stars 18 forks source link

fixes touch event forwarding #31

Closed cjohn001 closed 2 years ago

cjohn001 commented 2 years ago

This PR fixes

https://github.com/nativescript-community/ui-collectionview/issues/29

demo-ng-swiping.zip

Note: I tried to keep the changes as non-intrusive as possible and put all required changes into an external class (SingleScrollDirectionEnforcer). You can use the attached demo to try out the bugfix. Relevant touch events are now correctly forwarded to child views of the ui-collectionview and Nativescript gesture recognition is now working correctly. Please note, It seems like there is another bug in the plugin which is related to reorderLongPressEnabled="true". I cannot get it working. The attached demo also shows how I tried to subscribe to the relevant events, but they are not firing. However, this has nothing to do with the bugfix I provided, it already does not work with the original sources. In case the TouchEventHandlers of reorderLongPress should interfere, what I do not think they will do, one could simply disable the SingleScrollDirectionEnforcer class in this situation. It has two methods for it.

installSingleScrollDirectionEnforcerInView uninstallSingleScrollDirectionEnforcerInView

Which for example could go into this section:

https://github.com/nativescript-community/ui-collectionview/blob/92a1b63dc9e243bb137d59b727e50c3576be1b9b/src/collectionview/collectionview.android.ts#L616

But to my understanding, mutliple listeners can be installed at the same time, so the enforcer should always work correctly.

farfromrefug commented 2 years ago

@cjohn001 thanks for the PR. But i wont integrate this in the plugin itself. I dont want all users to have (and i am the first one) an intercept of touch events. It is almost never useful and even more in all my use cases the issue actually never happened. @naticescript-community/ui-pager works perfectly fine with the collectionview plugin. What i would suggest is to reopen that PR as a "sub" plugin in this repo (like waterfall). Collectionview is meant to be the smallest plugin possible to avoid becoming what the proui was.

cjohn001 commented 2 years ago

@cjohn001 thanks for the PR. But i wont integrate this in the plugin itself. I dont want all users to have (and i am the first one) an intercept of touch events. It is almost never useful and even more in all my use cases the issue actually never happened. @naticescript-community/ui-pager works perfectly fine with the collectionview plugin. What i would suggest is to reopen that PR as a "sub" plugin in this repo (like waterfall). Collectionview is meant to be the smallest plugin possible to avoid becoming what the proui was.

@farfromrefug: Well, this is disappointing, I think it would be very helpful for others. I spent a lot of time trying to use the collection view in the right way. And it is not obvious, that one needs to work around the Nativescript event handling in order to get the plugin working. However, I checked the Waterfall. Unfortunately, I do not understand how this subplugin thing works. May I ask you to integrate it? I have not found out yet, how I could derive a class from ui-collectionview. Just extending seems not to work with angular. I assume this would be the way to go?

farfromrefug commented 2 years ago

@cjohn001 sorry i replied on the issue as this is where you first replied And i just want to point out that if you have to "work around N gesture handling " then maybe there is an issue there? Again recyclerview works perfectly fine with viewpager2 using this plugin which goes against what your article was saying.plus my gestures plugin also work perfectly fine without having to use any trick. You can ask my to add code for everyone when the need is not there "for everyone" , and i wont add code which might have side effects. Intercepting touch events should be done as rarely as possible

cjohn001 commented 2 years ago

@farfromrefug : Well

"work around N gesture handling " then maybe there is an issue there.

I see exactly the behavior on Android, IOS is working for me without issues. What I understand from the gesture handling plugin is, that it does intercept the native events, hence therefore that likely works. However, can you explain, how this plugin thing shall work? As mentioned, I do not know how I could extend the collection view class.

I did a export myclass extends CollectionView

and I have read that I need to use registerElement like described here https://v6.docs.nativescript.org/angular/plugins/angular-third-party

But as mentioned that did not work. I do not understand how the waterfall stuff is working. Do you know about a description somewhere how this can be done? Or a plugin where I can check sources that does something close to what I need.

As a matter of principle, I assume I just need to extend the CollectionView class and overwrite initNativeView and disposeNativeView that call install and uninstall on my class from the bugfix and call the methods of the super class

cjohn001 commented 2 years ago

Well, I think we discussed this already, hence I close the issue.