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

CollectionView programmatic SelectedItem and ScrollTo not working as expected on iOS #11179

Open
vsfeedback opened this issue Jun 23, 2020 · 6 comments
Labels
a/collectionview a/VSM feedback-ticket Issue originates from https://developercommunity.visualstudio.com p/iOS 🍎 p/tablet s/unverified New report that has yet to be verified t/bug 🐛

Comments

@vsfeedback
Copy link

vsfeedback commented Jun 23, 2020

This issue has been moved from a ticket on Developer Community.


I have CollectionView binded to simple string array (like "One", "Two", "Three". "Four", Five").
Labels with these text are inside Frame object.
I need background color of Frame to be Blue if selected and LightBlue if not selected.
I'm using VisualStateManager to assign background colors to Frame.
On initiation of form I need to selected item "Four" programmatically and scrollTo this item.

This works properly for Android device.

But, on iPadOS 13.5.1 device I've got different behavior:

  1. VisualState instructions are not applied to Frame object when item selected programmatically. It applies only when manually tapping items.
    I made background of Frame transparent and saw that programmatically selected item was changed to default grey background color.
    So, programmatical selection works, but but VisualStates were not applied.

  2. Instruction ScrollTo(index, position: ScrollToPosition.MakeVisible, animate: false ) not working on first programmatical attempt. However it starts working when selecting(tappimg) items manulally.

This behavior is for any XamarinForms releases. At present I'm using XF 4.7.0.968.


Original Comments

Visual Studio Feedback System on 6/22/2020, 00:51 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.


Original Solutions

(no solutions)

Reproduction

I've attached a brief demo to show this problem. When the app launches, the app automatically attempts to select one cell at random. That selects the cell with the collection view, but it does not trigger the VisualStateManager to style the cell. If the user then clicks the Random button in the header, the app will run the same code again to select a cell at random. This time, it will trigger the VSM to update the display.

Steps to Reproduce:

  1. Watch the Console logs as the app starts. It will show that a cell is selected. The VisualStateManager does not trigger the cell to be styled.
  2. Press the clear button. The app will write to Console what index was previously selected. It will report the same cell that was selected from Step 1.
  3. Press Random. The app will select a new cell at random using the same code as it did on startup. This time, the VisualStateManager will update the display of the cell correctly.

Edit: This seems to only happen on iOS.

CollectionViewBugDemo.zip

@samhouts samhouts added t/bug 🐛 feedback-ticket Issue originates from https://developercommunity.visualstudio.com s/unverified New report that has yet to be verified labels Jun 23, 2020
@samhouts
Copy link
Member

Can you please attach a small project that demonstrates this issue? Thanks!

@samhouts samhouts added s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Jun 26, 2020
@hollyschilling
Copy link

hollyschilling commented Jul 8, 2020

I've attached a brief demo to show this problem. When the app launches, the app automatically attempts to select one cell at random. That selects the cell with the collection view, but it does not trigger the VisualStateManager to style the cell. If the user then clicks the Random button in the header, the app will run the same code again to select a cell at random. This time, it will trigger the VSM to update the display.

Steps to Reproduce:

  1. Watch the Console logs as the app starts. It will show that a cell is selected. The VisualStateManager does not trigger the cell to be styled.
  2. Press the clear button. The app will write to Console what index was previously selected. It will report the same cell that was selected from Step 1.
  3. Press Random. The app will select a new cell at random using the same code as it did on startup. This time, the VisualStateManager will update the display of the cell correctly.

Edit: This seems to only happen on iOS.

CollectionViewBugDemo.zip

@PureWeen PureWeen removed s/needs-info ❓ A question has been asked that requires an answer before work can continue on this issue. s/needs-repro ❔ This reported issue doesn't include a sample project reproducing the issue. Please provide one. labels Jul 10, 2020
@justinasfour04
Copy link

I have the same issue now too on iOS. This visual state manager is working perfectly fine on Android but not iOS @samhouts
image

@samirgcofficial
Copy link

Not able to select item in Collection View. Please see the sample attached !
Xamarin Forms Version : 5.0.0.2012
VSMac : 8.9.10 (build 4)
https://github.com/samirgcofficial/CollectionViewBug

@LeoJHarris
Copy link

Any update? I'm guessing this will not be looked at having lower priority and the release of maui?

@Mous625
Copy link

Mous625 commented May 13, 2023

Any update? I'm guessing this will not be looked at having lower priority and the release of maui?

Its broken in Maui too lol

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/collectionview a/VSM feedback-ticket Issue originates from https://developercommunity.visualstudio.com p/iOS 🍎 p/tablet s/unverified New report that has yet to be verified t/bug 🐛
Projects
None yet
Development

No branches or pull requests

9 participants