-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Remove public constructors for KeyEventArgs, PointerEventArgs and friends #8860
Remove public constructors for KeyEventArgs, PointerEventArgs and friends #8860
Conversation
Should we also remove public ctors from Raw...EventArgs from Avalonia.Input.Raw namespace? |
…from-avalonia.base
We support platform backends being written by a 3rd party, but without any binary compatibility guarantees. So everything required to write such backend should be available |
You can test this PR using the following package version. |
I could still create my own event args derived from EventArgs, right? |
Ah yes now I see it's removed for specific events which is unlikely you create on your own. |
…from-avalonia.base
You can test this PR using the following package version. |
…from-avalonia.base
You can test this PR using the following package version. |
@Takoooooo @kekekeks @danwalmsley Why was this done? As far as I can tell there isn't much risk exposing these classes unless there are known changes coming up. It however is causing issues for control-library authors: amwx/FluentAvalonia#241 (comment). @maxkatz6 Also mentioned it here but that also doesn't make sense to me since constructors like this will likely never change in the future. I can foresee some custom controls on my end that won't benefit from this PR. It's going to require creating new event args instead of re-using what is already in the framework. I'm really struggling to understand why this PR was done. |
Aside from the reasoning of this PR, we should make API flexible enough, so users won't need to simulate behavior by passing a fake input argument. I am specifically saying about TextBox.Redo/Undo which make all sense to be public methods. |
Just created a new feature request for enhancing However, in my other cases:
Last time I checked WPF still has these as public classes - WinUI doesn't though. At the very least, can these classes gain a default protected constructor (or make them protected internal) and make the properties protected set so at least they can be sub-classed to get around this (sort of)? |
I also am not 100% sure why this change was made. @Takoooooo or @kekekeks could you explain in more detail why it's not a good idea to create instances of these classes manually. The only reason I can think of is that on certain platforms pointer capture is carried out automatically by the OS on pointer press, and raising a fake event won't have this behavior, is this true? There may be other reasons. |
It's mostly to limit the public API surface so we could add features and improve the perf later. We've already had a problem with public constructors when we were adding pointer histroy API. In general I don't think that triggering fake events is a good idea, we should provide a better API for cases where it's currently required. |
Pointer capture also plays some role but not with PointerEntered event, I think. |
In my application the majority of input controls are not created until they get focused (the content is drawn directly), for example TextBox. In order to allow the created control to handle the PointerPressed event (like text inputs), I capture that event and need to resend to have the same experience:
So currently, this is still working, with sending the already handled, captured event again (feels strange though). Q: Is it save to resend captured PointerEventArgs? |
…uctors-from-eventargs-from-avalonia.base" This reverts commit a26d515, reversing changes made to 4670536. # Conflicts: # src/Avalonia.Base/Input/KeyEventArgs.cs # src/Avalonia.Base/Input/PointerDeltaEventArgs.cs # src/Avalonia.Base/Input/PointerEventArgs.cs # src/Avalonia.Base/Input/PointerWheelEventArgs.cs # src/Avalonia.Base/Input/TextInputEventArgs.cs
…uctors-from-eventargs-from-avalonia.base" This reverts commit a26d515, reversing changes made to 4670536. # Conflicts: # src/Avalonia.Base/Input/KeyEventArgs.cs # src/Avalonia.Base/Input/PointerDeltaEventArgs.cs # src/Avalonia.Base/Input/PointerEventArgs.cs # src/Avalonia.Base/Input/PointerWheelEventArgs.cs # src/Avalonia.Base/Input/TextInputEventArgs.cs
…uctors-from-eventargs-from-avalonia.base" This reverts commit a26d515, reversing changes made to 4670536. # Conflicts: # src/Avalonia.Base/Input/KeyEventArgs.cs # src/Avalonia.Base/Input/PointerDeltaEventArgs.cs # src/Avalonia.Base/Input/PointerEventArgs.cs # src/Avalonia.Base/Input/PointerWheelEventArgs.cs # src/Avalonia.Base/Input/TextInputEventArgs.cs
Revert #8860 (removal of public constructors)
Fixed issues
Part of #6666