CommunityToolkit / Maui

The .NET MAUI Community Toolkit is a community-created library that contains .NET MAUI Extensions, Advanced UI/UX Controls, and Behaviors to help make your life as a .NET MAUI developer easier
https://learn.microsoft.com/dotnet/communitytoolkit/maui
MIT License
2.29k stars 404 forks source link

[Proposal] TouchEffect #86

Closed brminnick closed 8 months ago

brminnick commented 3 years ago

TouchEffect

Summary

Adds additional touch events to any VisualElement

Detailed Design

TouchEffect.shared.cs

public class TouchEffect : RoutingEffect
{
  public event EventHandler<TouchStatusChangedEventArgs> StatusChanged;
  public event EventHandler<TouchStateChangedEventArgs> StateChanged;
  public event EventHandler<TouchInteractionStatusChangedEventArgs> InteractionStatusChanged;
  public event EventHandler<HoverStatusChangedEventArgs> HoverStatusChanged;
  public event EventHandler<HoverStateChangedEventArgs> HoverStateChanged;
  public event EventHandler<TouchCompletedEventArgs> Completed;
  public event EventHandler<LongPressCompletedEventArgs> LongPressCompleted;

  public static readonly BindableProperty IsAvailableProperty;
  public static readonly BindableProperty ShouldMakeChildrenInputTransparentProperty;
  public static readonly BindableProperty CommandProperty;
  public static readonly BindableProperty LongPressCommandProperty;
  public static readonly BindableProperty CommandParameterProperty;
  public static readonly BindableProperty LongPressCommandParameterProperty;
  public static readonly BindableProperty LongPressDurationProperty;
  public static readonly BindableProperty StatusProperty;
  public static readonly BindableProperty StateProperty;
  public static readonly BindableProperty InteractionStatusProperty;
  public static readonly BindableProperty HoverStatusProperty;
  public static readonly BindableProperty HoverStateProperty;
  public static readonly BindableProperty NormalBackgroundColorProperty;
  public static readonly BindableProperty HoveredBackgroundColorProperty;
  public static readonly BindableProperty PressedBackgroundColorProperty;
  public static readonly BindableProperty NormalOpacityProperty;
  public static readonly BindableProperty HoveredOpacityProperty;
  public static readonly BindableProperty PressedOpacityProperty;
  public static readonly BindableProperty NormalScaleProperty;
  public static readonly BindableProperty HoveredScaleProperty;
  public static readonly BindableProperty PressedScaleProperty;
  public static readonly BindableProperty NormalTranslationXProperty;
  public static readonly BindableProperty HoveredTranslationXProperty;
  public static readonly BindableProperty PressedTranslationXProperty;
  public static readonly BindableProperty NormalTranslationYProperty;
  public static readonly BindableProperty HoveredTranslationYProperty;
  public static readonly BindableProperty PressedTranslationYProperty;
  public static readonly BindableProperty NormalRotationProperty;
  public static readonly BindableProperty HoveredRotationProperty;
  public static readonly BindableProperty PressedRotationProperty;
  public static readonly BindableProperty NormalRotationXProperty;
  public static readonly BindableProperty HoveredRotationXProperty;
  public static readonly BindableProperty PressedRotationXProperty;
  public static readonly BindableProperty NormalRotationYProperty;
  public static readonly BindableProperty HoveredRotationYProperty;
  public static readonly BindableProperty PressedRotationYProperty;
  public static readonly BindableProperty AnimationDurationProperty;
  public static readonly BindableProperty AnimationEasingProperty;
  public static readonly BindableProperty PressedAnimationDurationProperty;
  public static readonly BindableProperty PressedAnimationEasingProperty;
  public static readonly BindableProperty NormalAnimationDurationProperty;
  public static readonly BindableProperty NormalAnimationEasingProperty;
  public static readonly BindableProperty HoveredAnimationEasingProperty;
  public static readonly BindableProperty PulseCountProperty;
  public static readonly BindableProperty IsToggledProperty;
  public static readonly BindableProperty DisallowTouchThresholdProperty;
  public static readonly BindableProperty NativeAnimationProperty;
  public static readonly BindableProperty NativeAnimationColorProperty;
  public static readonly BindableProperty NativeAnimationRadiusProperty;
  public static readonly BindableProperty NativeAnimationShadowRadiusProperty;
  public static readonly BindableProperty NormalBackgroundImageSourceProperty;
  public static readonly BindableProperty HoveredBackgroundImageSourceProperty;
  public static readonly BindableProperty PressedBackgroundImageSourceProperty;
  public static readonly BindableProperty BackgroundImageAspectProperty;
  public static readonly BindableProperty NormalBackgroundImageAspectProperty;
  public static readonly BindableProperty HoveredBackgroundImageAspectProperty;
  public static readonly BindableProperty PressedBackgroundImageAspectProperty;
  public static readonly BindableProperty ShouldSetImageOnAnimationEndProperty;
}

Usage Syntax

<Button TouchEffect.PressedScale="3">
</Button>

C# Usage

var button = new Button();
TouchEffect.SetPressedScale(button, 3);
mmendoza-apa commented 2 years ago

Any updates on this?

Really looking forward to use the LongPress behavior!

pictos commented 2 years ago

Hey, @mmendoza-apa this is planned to land on v1.1.0

naweed commented 2 years ago

Hi @pictos , when is 1.1.0 targetted for release?

pictos commented 2 years ago

@naweed we don't have a date to share

JohnHDev commented 2 years ago

@pictos can I confirm if/when this is done it will be a Behaviour, not an effect, right? We have started investigating what is needed to migrate to .NET Maui and we have dependencies that we either want to remove or migrate as well. We have a long press effect we don't want to migrate (unless we have to), we would rather go down the supported route with the replacement for TouchEffect.

bijington commented 2 years ago

@JohnHDev yes that is correct. Much like the IconTintColor and SelectAllTextBehavior implementations we will be moving from the old Effects API over to using Behaviors.

I don't know if @pictos but if not would you fancy the challenge of adding this in?

beeradmoore commented 2 years ago

Was just looking at planning ahead for my XF -> MAUI app migration which is planned for much further in the future. I use NativeAnimation a lot, I find it gives some nice polish. I don't think I can help contribute but I like seeing that the proposal is up at least.

EDIT: Just saw I can use it in MAUI today with Xamarin.CommunityToolkit.MauiCompat :)

smardine commented 2 years ago

Hello, is there any news about this? I can't find it in current version 1.2 Hope it will be implement soon 🤞

mantasdaskev commented 2 years ago

Hello, is there any news about this? I can't find it in current version 1.2 Hope it will be implement soon 🤞

Hello, I am wondering about that too. I have few controls that depends on it and after migrating to MAUI I had to comment it out and release is now suspended.

pictos commented 2 years ago

Hey people, don't have a Date for you right now, but I'll jump on this one right after I finish the status bar implementation (should have a PR during this week). If the port goes well we can have this soonsh

smardine commented 2 years ago

Hey people, don't have a Date for you right now, but I'll jump on this one right after I finish the status bar implementation (should have a PR during this week). If the port goes well we can have this soonsh

🤞😇

KSemenenko commented 2 years ago

Here is the most important point, in the experience of XF, that the ListView and CollectionView gestures did not allow to process all the other gestures.

And of course multiple gesture handlers are also needed

LennoxP90 commented 2 years ago

looking forward to not having to continue using XCT MAUI Compat

jonakirke94 commented 2 years ago

Looking foward to this as well!

In the meanwhile I'm wondering if anyone has gotten to Maui Compat version to work with TouchEffect?

I've opened an issue in the XamarinCommunityToolkit repo here but haven't found a solution yet :)

LennoxP90 commented 2 years ago

Is there an ETA on this?

KieranMaclagan commented 2 years ago

Really looking forward to this, especially for the long press.

KSemenenko commented 2 years ago

@pictos @brminnick is there any design decision about using behavior or effect? I found old pr https://github.com/xamarin/Xamarin.Forms/pull/9740/ for it.

Maybe we can make decision about it and I can start implementation?

pictos commented 2 years ago

@KSemenenko this is in WIP mode, I'm working this. Thanks

tranb3r commented 1 year ago

Is there any progress for the long press support?

fredericoregateiro commented 1 year ago

Looks like long press take long time to implement 😄

sottnik commented 1 year ago

I don't understand. Is it a technical challenge or simply not interesting enough to be implemented?

bijington commented 1 year ago

I don't understand. Is it a technical challenge or simply not interesting enough to be implemented?

We all dedicate our own free time to do this stuff so most likely nobody has found enough of that time to dedicate to this. If it is important to the community and your projects then please do consider contributing the implementation

Hooterr commented 1 year ago

I've got to say, I don't understand this approach at all. Something as crucial as TouchEffect and all other essential bits and pieces are not a part of MAUI itself but rather are "outsourced" to this community toolkit where they lay almost untouched for, in this case 1,5 yrs. At the same time, MAUI repo is swarmed with bugs that also lay untouched for many months or years. What is actually going on here? Is the MAUI team purposely understaffed? Does Microsoft care at all about this project? They sure seem to want to take credit for it, just like they did take credit for MediaElement on Twitter and had to delete the original tweet.

To be honest, I don't understand the move to MAUI either. We had so much stuff implemented in Xamarin.Forms. Most of the bugs were either found a workaround for or fixed. But this... is just a total step or maybe even two steps backwards...

As you can imagine we don't use MAUI for fun but almost exclusively for work. And when we have to spend time fixing bugs in the framework or implementing missing features it's harder and harder to convince the management to stick to this framework. All the advantages of .NET and MAUI are canceled out by its poor quality and missing features. If the plan is for MAUI to eventually get good then by that time there will be hardly any people left that use it which would be a great shame.

naweed commented 1 year ago

That's exactly the reason why I moved away from Maui.

Kalyxt commented 1 year ago

If you are building bigger app not just few screen fun homemade product, you have to have controls and features from 3rd party suppliers like syncfusion, grial etc. It was like that in Xamarin forms times and its like that now too. Although you keep away from them as much as possible and use them only in must situations and if there appears option to replace it by open source alternative from community toolkit or other contributors, you try to switch it. Eventually you will be not dependant on paid 3rd party, but as long as you choose XF or MAUI you have to count with this.

VladislavAntonyuk commented 1 year ago

@Hooterr instead of writing such long comments you could already implement TouchEffect for at least one platform. As @bijington mentioned, we spend our free time delivering new features and bugfixes for this library. The main word in the name of this library is Community.

Hooterr commented 1 year ago

@VladislavAntonyuk that's right. So how can we expect our employers to allow us to spend paid company time to fix things in a Community project? Then the obvious answer is for us to use something else that doesn't need "fixing" from the start. Last time I checked MAUI is not a community project but a Microsoft product. The decision to move essential features to a Community project is questionable, to say the least.

Honestly, in what universe is MAUI a competitive offer if the first thing you need to do with it is to fix numerous bugs and implement pretty basic features? Time spent doing that easily cancels out any benefits of using it and the frustration is just not worth it anymore.

I mean no disrespect to people for whom this is a passion project, but for the majority of us it's just a job.

Gonna agree with @naweed here. It's probably time to move on.

bijington commented 1 year ago

Your company has likely made money from using this free toolkit so justifying providing some effort to help fix things really shouldn't be a debate.

fredericoregateiro commented 1 year ago

For me, I don't contribute more because I lack knowledge on the different platforms.

The work done in this project is spectacular, but sometimes it seems that the MAUI team doesn't develop some features waiting for the community to do it dotnet/maui#8675

In my opinion this would be a feature that should be on the MAUI platform, since day 1, and should not be in an external community project.

bijington commented 1 year ago

For me, I don't contribute more because I lack knowledge on the different platforms.

We are always happy to assist wherever we can in learning about the other platforms. In truth we really appreciate any contributions even if they are only partial.

The work done in this project is spectacular, but sometimes it seems that the MAUI team doesn't develop some features waiting for the community to do it dotnet/maui#8675

Thank you. In truth with the MAUI team, they are massively understaffed which is sadly their burden but not their fault. This toolkit is aimed at both lifting some of that burden and also in the hope that features can be shipped quicker. Being part of .NET now means stricter rules around adding new features to the framework. You might point out that this specific feature hasn't shipped quickly, there were some learnings that we as a team had to make in order to understand how to move away from the old Effects APIs given they have been deprecated and of course only being able to dedicate so much time to this toolkit.

In my opinion this would be a feature that should be on the MAUI platform, since day 1, and should not be in an external community project.

I am sure we could all agree more could be in the framework but given they are limited in numbers I think the team do a fantastic job with what they have.

jfversluis commented 1 year ago

As much as I appreciate a good discussion, doing that in here isn't really helping keeping this proposal on track. Let's please get back to discussing the actual feature here. Thank you!

mirceamuresanse commented 1 year ago

@pictos can I confirm if/when this is done it will be a Behaviour, not an effect, right? We have started investigating what is needed to migrate to .NET Maui and we have dependencies that we either want to remove or migrate as well. We have a long press effect we don't want to migrate (unless we have to), we would rather go down the supported route with the replacement for TouchEffect.

May I ask what do you mean by "we would rather go down the supported route with the replacement for TouchEffect"? Is there an alternative for the TouchEffect in Maui?

pictos commented 1 year ago

@mirceamuresanse, in short terms, we're changing effects to be behaviors, since there will not be further improvements in that area in .net maui. AFAIK, there's no solution for that on the main framework yet... This is WIP mode here

KSemenenko commented 1 year ago

Maybe we can do just gesture recognized? I did it for xamarin some time ago, and do we we relay need that effect? I totally get all concerns about this functionality, but probably all of us must wait for some architectural solution.

BernhardPollerspoeck commented 1 year ago

about 1.5 yeasr later this pretty important feature is still open... 
i found a post here from Wenyang. with a partial solution.. https://learn.microsoft.com/en-us/answers/questions/900859/long-press-in-net-maui

issnt this at least the start of what is required? if so, where is the issue its not in yet? is there any way to assist here? please post clear instructions what you require from the 'community'.

bijington commented 1 year ago

about 1.5 yeasr later this pretty important feature is still open... 

i found a post here from Wenyang. with a partial solution.. https://learn.microsoft.com/en-us/answers/questions/900859/long-press-in-net-maui

issnt this at least the start of what is required?

I can't comment with too much knowledge but it certainly looks like a good starting point

if so, where is the issue its not in yet?

I suspect this was initially held up by the fact that effects were announced to become obsolete so there were learnings to be done on how to overcome that. Then as with everything else time is usually the issue. If you are willing to take this on then that would be great!

is there any way to assist here?

We would welcome the implementation if you are willing

please post clear instructions what you require from the 'community'.

We have a contributing guide here which covers what is required https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md and for the general implementation this issue covers the API surface that we were aiming to bring from the Xamarin Community Toolkit, as you can see it is pretty big.

JkPersson commented 1 year ago

Any news on this one? When can we expect it?

kphillpotts commented 1 year ago

I am doing some work on this today - Expect to have a decent test branch next week if you are keen to test

JkPersson commented 1 year ago

Thanks - looking forward to seeing it.

albilaga commented 1 year ago

Is this still ongoing? I saw #1063 looks like abandoned?

jfversluis commented 1 year ago

This is still being worked on, thanks!

albilaga commented 1 year ago

Do you have any draft PR @jfversluis ? Want to check how is it going because in my implementation (based on #1063), some element can’t be clicked

christianrr commented 1 year ago

@jfversluis Some sort of roadmap would be great indeed, because I think native touch feedback is crucial for perceived responsiveness and state-of-the-art Apps.

We used TouchEffect.NativeAnimation heavily in our Xamarin.Forms applications and we need to know when this feature will be released for Maui in order to be able to estimate when we could release apps with Maui in the back.

kkppstudios commented 1 year ago

@jfversluis Some sort of roadmap would be great indeed, because I think native touch feedback is crucial for perceived responsiveness and state-of-the-art Apps.

We used TouchEffect.NativeAnimation heavily in our Xamarin.Forms applications and we need to know when this feature will be released for Maui in order to be able to estimate when we could release apps with Maui in the back.

+1

jfversluis commented 1 year ago

I understand, it would be great to have that. However it's important to remember that this project is ran by people in their spare time. Sometimes we have more time, sometimes we have less time. Because of that, it's pretty hard to give any kind of estimate.

If it is vital or even critical to your project feel free to lend a hand, that way you will have full control over when you can use it in your project and seeing the engagement over this feature, you'll be making a lot of other people happy as well!

christianrr commented 1 year ago

@jfversluis I'll try my best. I've added an implementation for iOS (ported from XCT). I also fixed some bugs in the Android behavior.

For me, native feedback now works on both platforms.

1326

kphillpotts commented 1 year ago

Nice work with the pull request @christianrr - don't forget to agree to that Contributor License Agreement to progress

kkohler2 commented 1 year ago

When will this be implemented? I currently cannot update a Maui app with same functionality as Xamarin.Forms due to lack of this functionality.

kkppstudios commented 1 year ago

When will this be implemented? I currently cannot update a Maui app with same functionality as Xamarin.Forms due to lack of this functionality.

Same here

r-work commented 1 year ago

There was this pull request that was merged three weeks ago. @kphillpotts Is there an ETA for when this may be available?