Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CollectionView (and ListView) IsEnabled does not appear to work #19768

Open
beeradmoore opened this issue Jan 8, 2024 · 7 comments · May be fixed by #20102
Open

CollectionView (and ListView) IsEnabled does not appear to work #19768

beeradmoore opened this issue Jan 8, 2024 · 7 comments · May be fixed by #20102
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working
Milestone

Comments

@beeradmoore
Copy link
Contributor

beeradmoore commented Jan 8, 2024

Description

Settings IsEnabled=false on a CollectionView does not disable it. May be related heavily to #19771

Steps to Reproduce

  1. Create new MAUI application
  2. Add a CollectionView
  3. Add items, set SelectionMode=Single, set IsEnabled=false
  4. Run application
  5. Click on various items and see that each one is being selected

Link to public reproduction project repository

https://github.com/beeradmoore/maui-issue-CollectionViewIsEnabledTest

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, macOS

Affected platform versions

iOS 17.2.1, Android 13, macOS 14.2.1

Did you find any workaround?

Have not tried yet, but I am going to add a view over the top to prevent interaction (or just try prevent interaction) and drop CollectionView opacity to 50%

Relevant log output

No response

@beeradmoore beeradmoore added the t/bug Something isn't working label Jan 8, 2024
@beeradmoore beeradmoore changed the title CollectionView IsEnabled does not appear to work. CollectionView IsEnabled does not appear to work Jan 9, 2024
@jsuarezruiz jsuarezruiz added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Jan 9, 2024
@drasticactions
Copy link
Contributor

drasticactions commented Jan 9, 2024

FWIW I ported your code to Xamarin.Forms

image

It's exactly the same. So I don't think it's a "regression" in MAUI, it probably never worked this way.

e: The app in this case is Android through WSA. On Windows/UWP it does disable the view.

@beeradmoore
Copy link
Contributor Author

Could be related to this issue.

Odd that it never worked, but also I can't recall a situation that I've ever disabled any CollectionView (or ListView, ScrollView) so I get why it may fall through the cracks for so long.

@drasticactions
Copy link
Contributor

Instead of disabling the view, you could maybe set the SelectionMode to None. That value should be accessible dynamically and would functionally be what you want (Disable the user from selecting items).

IsEnabled, I think, does more in that it can update styles to make it very clear that you can't modify or update the control (Like, an entry field being locked off). As far as I can looking through the source code (Although I could 100% be missing context here), I'm not sure it's doing anything specific for CollectionView, beyond setting the base value for that specific view control to be "enabled" or disabled (as it would on any generic view type). So for Windows, it grays it out by happenstance, but for the others it does nothing. That leads me to think that it's not a "bug" in a "regression" sense, but a "concept that wasn't fully implemented"

@beeradmoore
Copy link
Contributor Author

beeradmoore commented Jan 9, 2024

I don't think changing selection mode is a workaround for me (may be for others). My use case is to have a list on the left and you select an item and then hit edit. Section on the right then lets you edit an objects details while the collection view on the left shows what is currently selected and prevents user selecting something else.

The linked Android issue has a workaround from someone to disable the entire pages Content. That did not work for me, so the issue may be slightly different to that one or that disabling the entire page works but only for Android.

For my fix I am going to subclass it, add a fake property for FakeIsEnabled and use that to toggle opacity and InputTransparent and never touch IsEnabled.

When I get into work I'm going to test it ListView has the same problem or not.

So for Windows, it grays it out by happenstance, but for the others it does nothing.

On macOS (screenshots soon) it dims the content so it looks disabled but you can still click another row. That's why my first thought was "odd, I'll make InputTransparent toggle as well so it looks dimmed and also doesn't work" which is when I came across the other bug that it isn't allowing input after setting InputTransparent back again

EDIT: Thinking about this more and going to look at iOS UICollectionView there isn't really any IsEnabled property. It has been a long time since I have done native that I hadn't even thought of it. I agree fully that IsEnabled is a styling of MAUI(+XF) which was never fully implemented. There wasn't a lot of stink about it so I guess a lot of people aren't doing that. UIButton has an isEnabled but that comes from UIControl and it does not appear UICollectionView comes from UIControl so it would make sense it also does not have it.

@beeradmoore beeradmoore changed the title CollectionView IsEnabled does not appear to work CollectionView (and ListView) IsEnabled does not appear to work Jan 9, 2024
@beeradmoore
Copy link
Contributor Author

beeradmoore commented Jan 9, 2024

Updated the code in the repo to show ListView as well as the IsEnabled=true state of both collection types. (Also side note that is interesting but completely unrelated, on macOS the ListViews ItemTemplates DataTemplate does not need a ViewCell, on Windows it will crash unless there is a ViewCell)

macOS

Screen Recording 2024-01-10 at 9 39 54 am

CollectionView has some sort of enabled state change, ListView does not even though it is using the same cell style (I thought it would as I would have thought Label is getting an IsEnabled state change).
Both ListView and CollectionView remain fully intractable when IsEnabled=false.

Windows

Recording 2024-01-10 094419

CollectionView works exactly as expected. ListView does the same as macOS.

iOS (simulator)

Simulator Screen Recording - iPhone 15 - 2024-01-10 at 09 48 04

Both work the same as macOS (not super surprising considering macOS is MacCatalyst)

Android (emulator)

Screen Recording 2024-01-10 at 9 55 17 am

CollectionView IsEnabled=false looks disabled but still accepts input.
ListView IsEnabled=false does not look disabled but does not accept input.

@beeradmoore
Copy link
Contributor Author

If anyone does come across this issue this is my workaround I settled on this, (I'll edit this comment if I find more issues with this and another workaround)

public class ModifiedCollectionView : CollectionView
{
    // Only need to do this hack for macOS+iOS+Android as this works as expected on Windows.
#if !WINDOWS
	protected override void OnPropertyChanged([CallerMemberName] string? propertyName = null)
	{
		base.OnPropertyChanged(propertyName);

		if (propertyName == IsEnabledProperty.PropertyName)
		{
			if (IsEnabled)
			{
				InputTransparent = false;
				Opacity = 1.0;
			}
			else
			{
				InputTransparent = true;
				Opacity = 0.5;
			}
		}
	}
#endif
}

although if you want to keep using CollectionView class you can instead use this effect

internal class CollectionViewIsEnabledHackRoutingEffect : RoutingEffect
{
}

#if WINDOWS
internal class CollectionViewIsEnabledHackPlatformEffect : PlatformEffect
{
    protected override void OnAttached()
    {

    }

    protected override void OnDetached()
    {

    }
}
#else
internal class CollectionViewIsEnabledHackPlatformEffect : PlatformEffect
{
	protected override void OnAttached()
	{
		Element.PropertyChanged += CollectionView_PropertyChanged;
	}

	protected override void OnDetached()
	{
		Element.PropertyChanged -= CollectionView_PropertyChanged;
	}

	private void CollectionView_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
	{
		if (sender is CollectionView collectionView)
		{
			if (e.PropertyName == CollectionView.IsEnabledProperty.PropertyName)
			{
				if (collectionView.IsEnabled)
				{
					collectionView.InputTransparent = false;
					collectionView.Opacity = 1.0;
				}
				else
				{
					collectionView.InputTransparent = true;
					collectionView.Opacity = 0.5;
				}
			}
		}
	}
}
#endif

@PanzerHabba
Copy link

This is still an issue in version 8.0.90 on android with commands and MVVM. When I set IsEnabled="false" on a element in CollectionView, the item`s Opacity and InputTransparent changes as expected. But the command is still triggered if i tap the element. Resulting in "SelectedItems" being mutated.

My assumption was that if a element is disabled, nothing would happen if I tap that element. Am I wrong ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 platform/iOS 🍎 platform/macOS 🍏 macOS / Mac Catalyst t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants