roubachof / Sharpnado.Tabs

Pure MAUI and Xamarin.Forms Tabs, including fixed tabs, scrollable tabs, bottom tabs, badge, segmented control, custom tabs, button tabs, bendable tabs...
MIT License
460 stars 58 forks source link

[MAUI] Auto-scroll selected tab into view #81

Open maxchu92 opened 1 year ago

maxchu92 commented 1 year ago

Is your feature request related to a problem? Please describe. Selected tab is hidden from the display in a scrollable tab, when SelectedIndex is changed.

Describe the solution you'd like When changing the SelectedIndex value, the TabHostView should auto scroll and center (if applicable) the selected tab into display.

Describe alternatives you've considered Adding an API to manually scroll the tab into view. Example:

//Code to execute
    await TabHostView.ScrollToAsync(3, ScrollToPosition.Center, true);
public async Task ScrollToAsync(double x, double y, bool isAnimated){
    //scroll to position
    await _scrollView.ScrollToAsync(x, y, isAnimated);
}

public async Task ScrollToAsync(int selectedIndex, ScrollToPosition position, bool isAnimated){
    var selectedTab = this.Children().FirstOrDefault(x = true); //Look for selectedTab
    await _scrollView.ScrollToAsync(selectedTab, position, isAnimated);
}

Additional context Example:

Current Behavior:

Scroll the selected tab into view:

Scroll the selected tab into view, and adjust to center (If enough space is available):

AntonUA86 commented 7 months ago

Does anyone know how to implement this now ?