maui
maui copied to clipboard
Add the ability to disable swiping on SwipeView but keep the content enabled
Description
When a swipeview contains some buttons or other gesture controls, disabling the swipe will also disable those controls.
Steps to Reproduce
- Create a new Maui App.
- Replace the button with the following code
<SwipeView
IsEnabled="False">
<SwipeView.LeftItems>
<SwipeItem Text="Left" />
</SwipeView.LeftItems>
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked" HorizontalOptions="Fill"/>
</SwipeView>
Expected result: We can't swipe, but we can click the button. Actual Result: We cannot press the button
Notes:
- This COULD be intended behaviour; if you replace the SwipeView with a Grid that is disabled, you will get the same result. If this is the case, then a feature to just disable swiping, or maybe even certain sides would be ideal.
Link to public reproduction project repository
No response
Version with bug
8.0.3
Is this a regression from previous behavior?
Yes, this used to work in Xamarin.Forms
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android
Affected platform versions
No response
Did you find any workaround?
I have not found a good work-a-round. I did try using InputTransparent instead, and that makes the button enabled, but not clickable.
If you're using a collectionview, you can use a datatemplate selector to pick a view with or without the swipeview. Make sure there are no swipe items also works, but I haven't tested if that is feasible during runtime.
Relevant log output
No response
I did manage to test the following work-a-round: adding items during runtime via triggers will achieve the desired effect of disabling the swipe. An example below:
<SwipeView>
<SwipeView.Triggers>
<DataTrigger TargetType="SwipeView" Binding="{Binding IsItemEditable}" Value="True">
<Setter Property="RightItems">
<Setter.Value>
<SwipeItems Mode="Reveal">
<SwipeItem
Text="Edit"
Command="{Binding EditNameCommand}" />
<SwipeItem
Text="Remove"
Command="{Binding RemoveNameCommand}" />
</SwipeItems>
</Setter.Value>
</Setter>
</DataTrigger>
</SwipeView.Triggers>
<Grid ...
(etc...)
Rather unwieldy, but does work. Don't know what happens if you constantly change though.
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
Verified this on VS 17.10.0 Preview 1.0(8.0.6). Repro on Windows 11, Android 14.0-API34, iOS 17.2 and MacCatalyst with below Project: 20142.zip
I am experiencing the same issue. Is there a good workaround?
See previous comment: https://github.com/dotnet/maui/issues/20142#issuecomment-1910336144
Set
IsEnabledon the swipe view item and not the swipe view itself.
Unfortunately, that does not disable swiping, it just disables those individual swipe items. It would be good to have something like a "IsRightSwipeGestureEnabled" or/and "IsLeftSwipeGestureEnabled" property.
you can set isvisible to false on the swipe item
you can set
isvisibleto false on the swipe item
I can confirm that setting all SwipeItemView's "isVisible" to false work-a-round works on iOS and Android.
It works, however it logs an excpetion:
System.InvalidOperationException: PlatformView cannot be null here
at Microsoft.Maui.Handlers.ElementHandler2[[Microsoft.Maui.ISwipeItemMenuItem, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Android.Views.View, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].get_PlatformView() in /_/src/Core/src/Handlers/Element/ElementHandlerOfT.cs:line 21 at Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.Microsoft.Maui.Handlers.ISwipeItemMenuItemHandler.get_PlatformView() in /_/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.cs:line 54 at Microsoft.Maui.Handlers.SwipeItemMenuItemHandler.SwipeItemMenuItemImageSourcePartSetter.SetImageSource(Drawable platformImage) in /_/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.Android.cs:line 150 at Microsoft.Maui.Platform.ImageSourcePartExtensions.UpdateSourceAsync(IImageSourcePart image, View destinationContext, IImageSourceServiceProvider services, Action1 setImage, CancellationToken cancellationToken) in //src/Core/src/Platform/Android/ImageSourcePartExtensions.cs:line 73
at Microsoft.Maui.Platform.ImageSourcePartLoader.UpdateImageSourceAsync() in //src/Core/src/Platform/ImageSourcePartLoader.cs:line 75
at Microsoft.Maui.TaskExtensions.FireAndForget(Task task, Action`1 errorCallback) in /_/src/Core/src/TaskExtensions.cs:line 36