Skip to content

Improve pull-to-refresh usability in RefreshContainer - #18617

Merged
MrJul merged 5 commits into
AvaloniaUI:masterfrom
gentledepp:feature/15529_pull2refresh
Jun 22, 2026
Merged

Improve pull-to-refresh usability in RefreshContainer#18617
MrJul merged 5 commits into
AvaloniaUI:masterfrom
gentledepp:feature/15529_pull2refresh

Conversation

@gentledepp

@gentledepp gentledepp commented Apr 9, 2025

Copy link
Copy Markdown
Contributor

What does the pull request do?

Pull to refresh is non-optimal in its current implementation:

  1. you need to select the first item in a list to start a pull2refresh.
  2. It is not supported on desktop devices and cannot optionally be added without rewriting a bunch of internal code.

What is the current behavior?

#15529 goes into great detail.
#17496 is the original pull request - but it seems to be abandoned.

So I:

What is the updated/expected behavior with this PR?

Pull to refresh works seemlessly for mobile and (optionally) also for desktop devices

How was the solution implemented (if it's not obvious)?

see #17496 for more details.

Checklist

I will consider submitting a PR to the documentation, if the desktop support property is accepted and the name is fixed.

Breaking changes

Obsoletions / Deprecations

Fixed issues

Fixes #15529

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0055974-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@cla-avalonia

cla-avalonia commented Apr 9, 2025

Copy link
Copy Markdown
Collaborator
  • All contributors have signed the CLA.


protected override void PointerPressed(PointerPressedEventArgs e)
{
if (Target != null && Target is Visual visual) //&& (e.Pointer.Type == PointerType.Touch || e.Pointer.Type == PointerType.Pen))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean it works with a mouse? Or is this just for testing? I personally always found it weird some of the gesture recognisers are touch only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just a draft - please ignore - I needed the nuget package.
Its the pull2refresh PR including support for desktop apps (so yes, pull to refresh works on windows too)

@thevortexcloud thevortexcloud Apr 14, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like a significant improvement over the existing pull gesture recogniser then, which is impossible to test with without a touch screen.

@gentledepp

Copy link
Copy Markdown
Contributor Author

@alexander.marek,

Please read the following Contributor License Agreement (CLA). If you agree with the CLA, please reply with the following:

@cla-avalonia agree

Contributor License Agreement
1 out of 2 committers have signed the CLA.

alexander.marek doesn't seem to be a GitHub user. Please add the emails used in your commits to your Github account accordingly.

@cla-avalonia agree

@gentledepp
gentledepp force-pushed the feature/15529_pull2refresh branch 2 times, most recently from 909d4f1 to 1243d1b Compare April 14, 2025 12:32
@gentledepp

Copy link
Copy Markdown
Contributor Author

This is actually mainly the code of #17496, with one addition:

Added a styled property "IsEnabledOnDesktop" that allows to optionally enable the pulltorefresh gesture on Desktop applications as well.

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0056035-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@gentledepp gentledepp mentioned this pull request Apr 14, 2025
@gentledepp
gentledepp marked this pull request as ready for review April 14, 2025 13:23
@emmauss

emmauss commented Apr 22, 2025

Copy link
Copy Markdown
Contributor

Could you make your pr description more descriptive? Even if it's based on #17496 , it should still follow contribution guidelines.

@gentledepp
gentledepp force-pushed the feature/15529_pull2refresh branch from 1243d1b to c98aedf Compare May 21, 2025 07:35
@gentledepp

gentledepp commented May 21, 2025

Copy link
Copy Markdown
Contributor Author

@emmauss

Essentially, I

The third feature is important. It allows for

  • easier testing of pull2refresh (mac and windows)
  • opt in pull2refresh for customers, that are confused why "this works on my phone but not my computer" (yes, they exist...)

IsEnabledOnDesktop is a styled property
So it is disabled by default, but can easily be enabled using a global style.

Note that the propertyname is not of my concern.
I understand that you have API design meetings and will most likely change it. You've got my blessings to do so (although you do not need them ;-))

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0056624-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@emmauss

emmauss commented May 21, 2025

Copy link
Copy Markdown
Contributor

@emmauss

Essentially, I

* cherry-picked all changes from [Improve Refresh-Container usability #17496](https://github.com/AvaloniaUI/Avalonia/pull/17496)

* incorporated your feedback (the changes you requested in [Improve Refresh-Container usability #17496](https://github.com/AvaloniaUI/Avalonia/pull/17496))

* added the possibility, to also enable pull2refresh on desktops (mouse-controlled devices)

The third feature is important. It allows for

* easier testing of pull2refresh (mac and windows)

* opt in pull2refresh for customers, that are confused why "this works on my phone but not my computer" (yes, they exist...)

IsEnabledOnDesktop is a styled property So it is disabled by default, but can easily be enabled using a global style.

Note that the propertyname is not of my concern. I understand that you have API design meetings and will most likely change it. You've got my blessings to do so (although you do not need them ;-))

It would be best if you put this in the PR description and follow the section guides.

@MrJul MrJul added feature api-needs-review The PR adds new public APIs that should be reviewed. labels May 31, 2025
@MrJul

MrJul commented Jun 8, 2025

Copy link
Copy Markdown
Member

Public API for review:

 namespace Avalonia.Input.GestureRecognizers
 {
     public class ScrollGestureRecognizer : GestureRecognizer
     {
+        public static readonly DirectProperty<ScrollGestureRecognizer, Vector?> OffsetProperty;
+        public static readonly DirectProperty<ScrollGestureRecognizer, Size?> ExtentProperty;
+        public static readonly DirectProperty<ScrollGestureRecognizer, Size?> ViewportProperty;
+        public Size? Extent { get; private set; }
+        public Size? Offset { get; private set; }
+        public Size? Viewport { get; private set; }
     }
 }
 
 namespace Avalonia.Controls
 {
     public class RefreshContainer : ContentControl
     {
+        public static readonly StyledProperty<bool> IsEnabledOnDesktopProperty;
+        public bool IsEnabledOnDesktop { get; set; }
     }
 }

@thevortexcloud

thevortexcloud commented Jun 8, 2025

Copy link
Copy Markdown
Contributor

I personally think it needs a better name than IsEnabledOnDesktop. Since that implies it wont work at all on a desktop. Which from my understanding is not true, it just enables mouse controls. Perhaps a better name would be SupportAllPointerDevices or UseAllPointerDevices?

Alternatively, allowing customisation of the whitelist for what devices it accepts would also be better and more flexible. The current flag is kind of an all or touch only approach.

@rubiomiguel06

Copy link
Copy Markdown

Thanks for the great development. Releasing this PR will finally fix my gesture orchestrating issues in android! Hopefully it happens soon

@MrJul

MrJul commented Jun 18, 2025

Copy link
Copy Markdown
Member

Notes from the API review:

Remove the properties added to ScrollGestureRecognizer

Exposing Extent, Offset and Viewport shouldn't be necessary. We don't want to add every possible scroll info property as part of the public API of the gesture recognizer.

Instead, the ScrollGestureRecognizer should listen to property change notifications from its parent presenter, which is accessible through the existing Target property.

Rename IsEnabledOnDesktop to IsMouseEnabled

The property isn't really related to desktop: it simply enables the mouse to be recognized, even on mobile platforms.

@MrJul MrJul added api-needs-changes The new public APIs need some changes. and removed api-needs-review The PR adds new public APIs that should be reviewed. labels Jun 18, 2025
@gentledepp
gentledepp force-pushed the feature/15529_pull2refresh branch from c98aedf to 341f7e0 Compare June 27, 2025 09:39
@gentledepp

Copy link
Copy Markdown
Contributor Author

Notes from the API review:

Remove the properties added to ScrollGestureRecognizer

Exposing Extent, Offset and Viewport shouldn't be necessary. We don't want to add every possible scroll info property as part of the public API of the gesture recognizer.

Instead, the ScrollGestureRecognizer should listen to property change notifications from its parent presenter, which is accessible through the existing Target property.

Rename IsEnabledOnDesktop to IsMouseEnabled

The property isn't really related to desktop: it simply enables the mouse to be recognized, even on mobile platforms.

Could you please give me a hint on how to do this?

Because IScrollable and ScrollViewer are actually defined in Avalonia.Controls which I do not have a reference to.

So simply deleting those properties and "using those of the Target" is not possible:
image

The Renaming has been done ;-)

@MrJul

MrJul commented Aug 1, 2025

Copy link
Copy Markdown
Member

Because IScrollable and ScrollViewer are actually defined in Avalonia.Controls which I do not have a reference to.

Sorry for the late reply, you're completely right.

I'm not sure why ScrollGestureRecognizer is in the Base assembly when it's only used in Controls but that ship has sailed.

@MrJul MrJul mentioned this pull request Aug 1, 2025
6 tasks
@MrJul MrJul changed the title Feature/15529 pull2refresh Improve pull-to-refresh usability in RefreshContainer Aug 1, 2025
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0057964-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.0.999-cibuild0058042-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul MrJul added api-approved The new public APIs have been approved. and removed api-needs-changes The new public APIs need some changes. labels Aug 11, 2025
Comment thread src/Avalonia.Controls/PullToRefresh/ScrollablePullGestureRecognizer.cs Outdated
Comment thread src/Avalonia.Controls/PullToRefresh/ScrollablePullGestureRecognizer.cs Outdated
@gentledepp
gentledepp force-pushed the feature/15529_pull2refresh branch 2 times, most recently from 3b6eb1a to 98844d6 Compare May 8, 2026 07:03
@gentledepp

Copy link
Copy Markdown
Contributor Author

I reworked the recognizer - at some points the pull to refresh gesture had no more effect.
Also added test.

@gentledepp
gentledepp force-pushed the feature/15529_pull2refresh branch from 98844d6 to c8ecdfe Compare May 8, 2026 08:54
Added gesture-recognizer for scroll-viewer to improve usability
Added possibility to enable pulltorefresh on desktop too
@gentledepp
gentledepp force-pushed the feature/15529_pull2refresh branch from c8ecdfe to 6e66a0d Compare May 8, 2026 09:17
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0065280-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@gentledepp
gentledepp requested a review from MrJul May 12, 2026 12:24
@maxkatz6
maxkatz6 requested a review from emmauss June 14, 2026 07:51
@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066439-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@avaloniaui-bot

Copy link
Copy Markdown

You can test this PR using the following package version. 12.1.999-cibuild0066720-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@MrJul

MrJul commented Jun 22, 2026

Copy link
Copy Markdown
Member

Note: I've updated the tests to avoid reflection.

@MrJul MrJul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-tested, LGTM!

@MrJul
MrJul enabled auto-merge June 22, 2026 13:15
@MrJul
MrJul added this pull request to the merge queue Jun 22, 2026
Merged via the queue into AvaloniaUI:master with commit 129d959 Jun 22, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-approved The new public APIs have been approved. feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RefreshContainer is not intuitive to use as a user (not developer)

8 participants