-
Notifications
You must be signed in to change notification settings - Fork 110
Expose RippleEffect.RaiseRipple and RaiseRippleAbsoluteCoord function #453
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d34f28
Add control name for FloatingButton /template/ RippleEffect
appleneko2001 39a1d82
Refactor RippleEffect and expose RaiseRipple
appleneko2001 2d0d5dc
Move attached property "IsClicked" as a demo into AutomationAssist
appleneko2001 e75fbb5
apply some changes for PR#453
appleneko2001 543f079
apply some changes for PR#453 (second-patch)
appleneko2001 541cfb4
apply Interlocked (RippleEffect) according to the PR#453 comments
appleneko2001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using System.Reactive; | ||
| using Avalonia; | ||
| using Avalonia.Controls; | ||
| using Avalonia.Interactivity; | ||
| using Avalonia.VisualTree; | ||
| using Material.Ripple; | ||
| using Material.Styles.Assists; | ||
|
|
||
| namespace Material.Avalonia.Demo.Assists; | ||
|
|
||
| public static class AutomationAssist { | ||
| #region Initiator (used for observe control changes) | ||
|
|
||
| // This placeholder is used for anti-optimising to keep it persisted, also triggering static constructor | ||
| internal static void Placeholder() { | ||
| Console.WriteLine("Automation assist is initiate..."); | ||
| } | ||
|
|
||
| static AutomationAssist() { | ||
| Button.ClickEvent.Raised | ||
| .Subscribe(new AnonymousObserver<(object, RoutedEventArgs)>(OnButtonClickedPrivate)); | ||
| } | ||
|
|
||
| #endregion | ||
|
|
||
| // Used for memorise which hyperlink button clicked (or just say, visited) | ||
| // this property can be attached to any buttons for use | ||
| // we have confirmed that this property doesn't need to integrate to the theming library | ||
| // but it can be used as an example | ||
| #region AttachedProperty : IsClicked | ||
|
|
||
| public static readonly AvaloniaProperty<bool?> IsClickedProperty = | ||
| AvaloniaProperty.RegisterAttached<Button, bool?>("IsClicked", typeof(ButtonAssist)); | ||
|
|
||
| public static void SetIsClicked(AvaloniaObject element, bool? value) => | ||
| element.SetValue(IsClickedProperty, value); | ||
|
|
||
| public static bool? GetIsClicked(AvaloniaObject element) => | ||
| element.GetValue<bool?>(IsClickedProperty); | ||
|
|
||
|
|
||
| private static void OnButtonClickedPrivate((object, RoutedEventArgs) args) { | ||
| if (args.Item1 is not Button button) | ||
| return; | ||
|
|
||
| UpdateIsClickedPropertyPrivate(button); | ||
| RaiseRipplePrivate(button); | ||
| } | ||
|
|
||
| internal static void RaiseRipplePrivate(Control c) { | ||
| // Try to find first RippleEffect control with name PART_Ripple | ||
| var visual = c | ||
| .GetVisualDescendants() | ||
| .FirstOrDefault(a => a is RippleEffect && a.Name == "PART_Ripple"); | ||
|
|
||
| // if such control not exist or mouse is over on it | ||
| if (visual is not RippleEffect effect || effect.IsPointerOver) | ||
| return; | ||
|
|
||
| effect.RaiseRipple(); | ||
| } | ||
|
|
||
| private static void UpdateIsClickedPropertyPrivate(Button button) { | ||
| var value = GetIsClicked(button); | ||
|
|
||
| // null means not required for handling | ||
| if (!value.HasValue && button is not HyperlinkButton) | ||
| return; | ||
|
|
||
| value = false; | ||
|
|
||
| // if IsClickedProperty is false, put it to true | ||
| if (!value.Value) | ||
| SetIsClicked(button, true); | ||
|
|
||
| if (button is not HyperlinkButton hyperlink) | ||
| return; | ||
|
|
||
| // change Hyperlink button is visited state | ||
| hyperlink.IsVisited = true; | ||
| } | ||
|
|
||
| #endregion | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.