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

Add the ability to disable swiping on SwipeView but keep the content enabled #20142

Open
asi-evin opened this issue Jan 24, 2024 · 9 comments
Open
Labels
area-controls-swipeview SwipeView migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 platform/iOS 🍎 proposal/open s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@asi-evin
Copy link

asi-evin commented Jan 24, 2024

Description

When a swipeview contains some buttons or other gesture controls, disabling the swipe will also disable those controls.

Steps to Reproduce

  1. Create a new Maui App.
  2. 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

@asi-evin asi-evin added the t/bug Something isn't working label Jan 24, 2024
@samhouts samhouts added migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor labels Jan 25, 2024
@asi-evin
Copy link
Author

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.

@PureWeen PureWeen changed the title Disabling a SwipeView disables the underlying items Add the ability to disable swiping on SwipeView but keep the content enabled Jan 26, 2024
@PureWeen PureWeen added this to the Backlog milestone Jan 26, 2024
@ghost
Copy link

ghost commented Jan 26, 2024

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.

@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Mar 7, 2024
@XamlTest
Copy link

XamlTest commented Mar 7, 2024

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

@Eilon Eilon added area-controls-swipeview SwipeView and removed legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor labels May 11, 2024
@abdullahraiyyan
Copy link

I am experiencing the same issue. Is there a good workaround?

@asi-evin
Copy link
Author

See previous comment: #20142 (comment)

@asi-evin
Copy link
Author

Set IsEnabled on 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.

@Taofeek-Allison
Copy link

you can set isvisible to false on the swipe item

@asi-evin
Copy link
Author

you can set isvisible to false on the swipe item

I can confirm that setting all SwipeItemView's "isVisible" to false work-a-round works on iOS and Android.

@Jon2G
Copy link
Contributor

Jon2G commented Jun 26, 2024

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

@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-swipeview SwipeView migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/android 🤖 platform/iOS 🍎 proposal/open s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants