Issue with TouchBehavior Background Color Remaining After Navigation in .NET MAUI (iOS 18)
Description
I'm using a contentview with TouchBehavior from the .NET MAUI Community Toolkit, and I have the following code to change the background color and scale when the contentview is pressed:
<ContentView.Behaviors>
<toolkit:TouchBehavior
DefaultAnimationDuration="100"
DefaultAnimationEasing="{x:Static Easing.CubicInOut}"
PressedOpacity="0.6"
Command="{Binding Command, Source={x:Reference RowIconLabelElement}, Mode=TwoWay}"
PressedBackgroundColor="{StaticResource neutralGrayLighter}"
PressedScale="1.05"
/>
</ContentView.Behaviors>
The behavior works as expected when the button is pressed, and it navigates to another page. However, when I navigate back to the page, the background color sometimes stays as neutralGrayLighter.This issue happens intermittently, about 6 out of 10 navigations. Additionally, I started experiencing this problem after upgrading to iOS 18. Before the update, everything worked correctly.
Steps to Reproduce
1)Create a ContentView:
Use a ContentView with the TouchBehavior from the .NET MAUI Community Toolkit. Ensure the TouchBehavior changes the background color and scale when the content is pressed. Add a command to navigate to another page upon pressing. Implement the Behavior:
2)Navigate to Another Page:
Use the Command to navigate to a different page(Push Modal Page) in the application. Navigate Back:
After pressing the contentview, navigate back to the page with the ContentView. Observe the Background Behavior:
Repeat the navigation process multiple times (e.g., 10 times) to observe if the background color intermittently remains set to neutralGrayLighter. iOS 18 Specific Issue:
Ensure that you are testing on iOS 18.
Link to public reproduction project repository
No response
Version with bug
8.0.91 SR9.1
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
8.0.40 SR5
Affected platforms
iOS
Affected platform versions
iOS 18
Did you find any workaround?
No response
Relevant log output
No response
reproduction app : https://github.com/alpayclsr1/TouchBehaviourReproductionApp.git. @PureWeen
https://github.com/user-attachments/assets/226e8106-18f6-4a18-9328-04934f763e81
Hi @sheiksyedm
Could you please clarify why this issue was marked as "completed"? If it has indeed been resolved, could you also let me know in which version the fix was applied?
Hi @sheiksyedm
Could you please clarify why this issue was marked as "completed"? If it has indeed been resolved, could you also let me know in which version the fix was applied?
@alpayclsr1 Sorry, it was closed by mistake, I've reopened it.
@alpayclsr1 Upon further validation of this issue in the .NET MAUI SDK, it was observed in the MauiCommunityToolkit source. The issue occurs when TouchBehavior's PressedBackgroundColor is applied to a .NET MAUI visual element's BackgroundColor property via animations. These animations, along with the visual element's BackgroundColor, are not cleared after page navigation on MauiCommunityToolkit source. As a result, the BackgroundColor persists on the previous page during navigation. I recommend reporting this issue to the MauiCommunityToolkit repository for further investigation and resolution
This indeed seems like a .NET MAUI Community Toolkit bug. Please report it there. Thanks!