Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] iOS Touch Effects cause weird behavior with multiple selection enabled in CollectionView items #1157

Closed
meJevin opened this issue Apr 1, 2021 · 14 comments
Labels
bug Something isn't working. Breaky break. need-more-information Need more information to investigate a bug or proposal.

Comments

@meJevin
Copy link

meJevin commented Apr 1, 2021

Description

In my project I have the following scenario: I have a CollectionView with a custom ItemTemplate. My custom ItemTemplate has TouchEffects applied on it. There is an option to disable those touch effects via a binding. I create a BindableProperty for my custom ItemTemplate and set a binding on it which can be controlled from outside. When that property changes I remove/add the TouchEffects.

Everything is OK on Android. But on iOS the LongPressCommand doesn't seem to go away for some reason.

I've isolated the problem into a separate project and put it into a github repo, so you guys could inspect it better.
https://github.com/meJevin/TouchEffectBug

Please pay attention to Controls/TestTemplate.xaml and its code-behind file. This is my custom template. In code behind I have a bindable property, which, when changes, adds or removes touch effects.

You can see how I use that template in MainPage.xaml.

When run, application will not have any touch effects. Press the 'Change Template' button on the top in order to trigger a property change and therefore add effects to the ItemTemplate.

After that you will be able to long press it.

Press the button at the top again to trigger the removal of touch effects.

On Android everything works as expected. On iOS however, long pressing an item still calls the LongPressCommand (that we removed).

Steps to Reproduce

  1. Go to https://github.com/meJevin/TouchEffectBug
  2. Clone repo to your PC
  3. Run application on Android emulator (or device)
  4. Verify that there are no TouchEffects on current ItemTemplate by long pressing a CollectionView item (nothing should happen)
  5. Press 'Change Template' to add TouchEffects (including LongPressCommand)
  6. Verify that TouchEffects have been applied to CollectionView Items by long pressing one of them.
  7. Press 'Change Template' to remove TouchEffects
  8. Verify that there are no TouchEffects on current ItemTemplate by long pressing a CollectionView item (nothing should happen)
  9. Repeat steps 3-8 on an iOS device and you will fail on the 8th step. Because LongPressCommand still fires.

Expected Behavior

Android and iOS behavior is the same

Actual Behavior

iOS can not remove LongPressCommand

Basic Information

  • Version with issue: 1.1.0
  • Last known good version: -
  • iOS: 14.4.2
  • Nuget Packages: Xamarin.Forms 5.0.0.2012, Xamarin.Essentials 1.6.1, Xamarin.CommunityToolkit 1.1.0
  • Affected Devices: iPhone 11

Reproduction Link

https://github.com/meJevin/TouchEffectBug

@meJevin meJevin added bug Something isn't working. Breaky break. s/unverified This issue needs verification/reproduction by a team member. PRs cannot be accepted/merged. labels Apr 1, 2021
@meJevin
Copy link
Author

meJevin commented Apr 1, 2021

Update:
the following commit fixed this issue meJevin/TouchEffectBug@a098a5a

@meJevin meJevin closed this as completed Apr 1, 2021
@meJevin meJevin reopened this Apr 1, 2021
@meJevin
Copy link
Author

meJevin commented Apr 1, 2021

Ok. So I've isolated the problem a little too much. The stuff I was complaining about was fixed via meJevin/TouchEffectBug@a098a5a

However. There is one more issue. When changing selection mode of the CollectionView with my custom ItemTemplate. Multiple selection is behaving weird on iOS.

I've updated the repo. Check it out.

Steps to reproduce

  1. Run app on iOS device
  2. Verify that you can select items 0,1,2,3 (Background will be blue)
  3. Verify that you can deselect items 0,1,2,3 (Background will be red)
  4. Press 'Change Template'
  5. Verify that you can not select items and touch effects are added
  6. Press 'Change Template'
  7. Items 0,1,2,3 are still selected, that's OK and expected.
  8. Deselect items 0,1,2,3
  9. Select items 0,1,2,3. You are unable to select them for some reason.

Step 9 is really weird. Sometimes the items will be selected again, sometimes not. Sometimes you need to click them multiple times to select. Sometimes you need to select some of the items you've not touched in order to be able to select item 0,1,2,3. Really weird

This is the real issue I have.

Really waiting for your help guys.

@meJevin meJevin changed the title [Bug] Unable to remove LongPressCommand on iOS [Bug] iOS Touch Effects cause weird behavior with multiple selection is enable in CollectionView items Apr 1, 2021
@meJevin
Copy link
Author

meJevin commented Apr 1, 2021

Screen.Recording.2021-04-01.at.15.56.40.mp4

@meJevin meJevin changed the title [Bug] iOS Touch Effects cause weird behavior with multiple selection is enable in CollectionView items [Bug] iOS Touch Effects cause weird behavior with multiple selection enabled in CollectionView items Apr 1, 2021
@meJevin
Copy link
Author

meJevin commented Apr 1, 2021

Note: this doesn't happen on Android.

@AndreiMisiukevich
Copy link
Contributor

@meJevin hello.
Frankly speaking, I don't think it's related to TouchEffect.
Can you try to remove "TouchEffect" from another template.
Does the issue remain?

@AndreiMisiukevich AndreiMisiukevich added the need-more-information Need more information to investigate a bug or proposal. label Apr 1, 2021
@meJevin
Copy link
Author

meJevin commented Apr 1, 2021

@AndreiMisiukevich, removed everything related to TouchEffect in my code. Issue is not present anymore. Check out this branch of my repo for yourself https://github.com/meJevin/TouchEffectBug/tree/no-touch-effect (I commented out the parts in TestTemplate.xaml.cs related to the addition and removal of TouchEffect and everything works as expected)

@meJevin
Copy link
Author

meJevin commented Apr 1, 2021

So I'm pretty positive that this issue has something to do with TouchEffect. Maybe the way it intercepts OnTouchBegin on iOS or however it's implemented.. I think I saw an issue about this and people were discussing something along those lines.

@meJevin
Copy link
Author

meJevin commented Apr 1, 2021

Ну и вообще да.... на андроиде то работает елы палы

@AndreiMisiukevich
Copy link
Contributor

Then just remove the touch effect when it's not needed.

view.Effects.Clear();

@meJevin
Copy link
Author

meJevin commented Apr 1, 2021

That's almost exactly what I'm doing in my code. No luck though. Multi selection is still broken.

@AndreiMisiukevich
Copy link
Contributor

@AndreiMisiukevich https://github.com/meJevin/TouchEffectBug/blob/320cd64f803b51eaf7637d2ce7c3d4f3f8a44067/TouchEffectBug/TouchEffectBug/Controls/TestTemplate.xaml.cs#L44

Спасибо, Миша) Филл фри кидать PR если знаешь, как пофиксить

Thanks Michael, feel free to submit PR if you know how to fix it)

@meJevin
Copy link
Author

meJevin commented Apr 1, 2021

I'll try to dig my way in and figure this out, if I can. But multi selection is actually broken in a really peculiar way too.. When I remove the effect, I am able to select (or deselect if its already selected) an item once, but no further interaction is possible with it afterwards, the item seems to ignore the clicks somehow.

@pictos pictos removed the s/unverified This issue needs verification/reproduction by a team member. PRs cannot be accepted/merged. label Apr 5, 2021
@jfversluis
Copy link
Member

We believe this might be fixed in https://github.com/xamarin/XamarinCommunityToolkit/releases/tag/2.0.6

If not, please let uw know, open a new issue and link this one. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working. Breaky break. need-more-information Need more information to investigate a bug or proposal.
Projects
None yet
Development

No branches or pull requests

4 participants