Add SwipeSensitivity property to SfTabView (Android)#395
Open
Transis-Felipe wants to merge 1 commit into
Open
Conversation
Author
|
@PaulAndersonS Can you review ? |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new SwipeSensitivity bindable property on SfTabView to make Android tab-swipe triggering less/more sensitive by configuring the swipe distance threshold (defaulting to the previous hard-coded behavior).
Changes:
- Added
SfTabView.SwipeSensitivity/SwipeSensitivityPropertywith a default of5.0(backward compatible) and a new internalDefaultSwipeSensitivityconstant. - Updated Android
SfHorizontalContentswipe threshold computation to useSfTabView.SwipeSensitivity(falling back to the default constant).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| maui/src/TabView/Control/SfTabView.cs | Adds the new public bindable property and default constant. |
| maui/src/TabView/Control/HorizontalContent/SfHorizontalContent.Android.cs | Replaces the hard-coded swipe threshold with the configurable property-based calculation. |
| typeof(double), | ||
| typeof(SfTabView), | ||
| DefaultSwipeSensitivity, | ||
| validateValue: (_, value) => (double)value > 0); |
| /// switch is triggered (less sensitive). Lower values make the control | ||
| /// react to shorter swipes (more sensitive). | ||
| /// </remarks> | ||
| public static readonly BindableProperty SwipeSensitivityProperty = |
Comment on lines
+3174
to
+3176
| #region Swipe Sensitivity | ||
|
|
||
| /// <summary> |
Collaborator
There was a problem hiding this comment.
Need to update the PR based on the code
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #393
Summary
Adds a new
SwipeSensitivitybindable property toSfTabViewthat lets developers controlhow far the user must swipe horizontally before a tab switch is triggered on Android.
The old behaviour (hard-coded threshold of
5 × display density) is preserved as the defaultvalue, so this is a non-breaking change.
Problem
The
_swipeThresholdinSfHorizontalContent.Android.cswas computed from a hard-codedmultiplier of
5:This made the control noticeably more sensitive than the native MAUI
TabbedPage, causingusers to accidentally switch tabs while scrolling vertically through list content hosted
inside a tab.
Solution
1.
SfTabView.SwipeSensitivity.cs(new partial class file)A new
BindablePropertyis added as a partial class ofSfTabView:An
internal const double DefaultSwipeSensitivity = 5.0is also exposed so the Androidfile can reference it without hard-coding the number again.
2.
SfHorizontalContent.Android.cs(modified)The hard-coded multiplier is replaced with a read of the new property:
Public API Change
SfTabView.SwipeSensitivityPropertystatic readonly BindablePropertySfTabView.SwipeSensitivitydouble(read/write)5.0XAML usage
C# usage
Behaviour by value
SwipeSensitivity25(default)1520TabbedPagefeelPlatforms affected
Only Android (
SfHorizontalContent.Android.cs). The property is defined on thecross-platform
SfTabViewclass so it is bindable from XAML/C# on all platforms, butswipe interception on iOS/Windows/macOS is handled by the platform's native gesture
recognisers and is not affected.
Checklist
BindablePropertyvalidates that the value is positiveEnable*/ numeric properties in the controlDefaultSwipeSensitivityconstant used in both files to avoid magic numbers