Skip to content

Add SwipeSensitivity property to SfTabView (Android)#395

Open
Transis-Felipe wants to merge 1 commit into
syncfusion:mainfrom
Transis-Felipe:main
Open

Add SwipeSensitivity property to SfTabView (Android)#395
Transis-Felipe wants to merge 1 commit into
syncfusion:mainfrom
Transis-Felipe:main

Conversation

@Transis-Felipe

Copy link
Copy Markdown

Closes #393


Summary

Adds a new SwipeSensitivity bindable property to SfTabView that lets developers control
how 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 default
value, so this is a non-breaking change.


Problem

The _swipeThreshold in SfHorizontalContent.Android.cs was computed from a hard-coded
multiplier of 5:

double _swipeThreshold => 5 * _density;

This made the control noticeably more sensitive than the native MAUI TabbedPage, causing
users 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 BindableProperty is added as a partial class of SfTabView:

public static readonly BindableProperty SwipeSensitivityProperty =
    BindableProperty.Create(
        nameof(SwipeSensitivity),
        typeof(double),
        typeof(SfTabView),
        defaultValue: 5.0,             // backward-compatible default
        validateValue: (_, v) => (double)v > 0);

public double SwipeSensitivity
{
    get => (double)GetValue(SwipeSensitivityProperty);
    set => SetValue(SwipeSensitivityProperty, value);
}

An internal const double DefaultSwipeSensitivity = 5.0 is also exposed so the Android
file 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:

// Before
double _swipeThreshold => 5 * _density;

// After
double _swipeThreshold =>
    (_tabView?.SwipeSensitivity ?? SfTabView.DefaultSwipeSensitivity) * _density;

Public API Change

Member Kind Default
SfTabView.SwipeSensitivityProperty static readonly BindableProperty
SfTabView.SwipeSensitivity double (read/write) 5.0

XAML usage

<!-- Reduce sensitivity: user must swipe ≥15 dp before tab switches -->
<toolkit:SfTabView SwipeSensitivity="15">
    <toolkit:SfTabItem Header="Consulta">
        <views:ConsultaCliente />
    </toolkit:SfTabItem>
    <toolkit:SfTabItem Header="Histórico">
        <views:HistoricoCliente />
    </toolkit:SfTabItem>
</toolkit:SfTabView>

C# usage

var tabView = new SfTabView
{
    SwipeSensitivity = 15   // much less likely to trigger accidentally
};

Behaviour by value

SwipeSensitivity Pixel threshold (mdpi=1×) Effect
2 2 px Very sensitive – short swipes switch tabs
5 (default) 5 px Original behaviour – no change for existing apps
15 15 px Recommended when tabs host vertically scrollable lists
20 20 px Near-native MAUI TabbedPage feel

Platforms affected

Only Android (SfHorizontalContent.Android.cs). The property is defined on the
cross-platform SfTabView class so it is bindable from XAML/C# on all platforms, but
swipe interception on iOS/Windows/macOS is handled by the platform's native gesture
recognisers and is not affected.


Checklist

  • No breaking change (default value preserves existing behaviour)
  • BindableProperty validates that the value is positive
  • XML doc comments on the new property and constant
  • Consistent naming with existing Enable* / numeric properties in the control
  • DefaultSwipeSensitivity constant used in both files to avoid magic numbers

@Transis-Felipe

Copy link
Copy Markdown
Author

@PaulAndersonS Can you review ?

Copilot AI left a comment

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.

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 / SwipeSensitivityProperty with a default of 5.0 (backward compatible) and a new internal DefaultSwipeSensitivity constant.
  • Updated Android SfHorizontalContent swipe threshold computation to use SfTabView.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>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Need to update the PR based on the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] SfTabView Sensitivity

3 participants