File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed
packages/core-tabs/platforms/android/java/com/nativescript/material/core Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,10 @@ public void setItems(TabItemSpec[] items) {
184184
185185 }
186186
187+ public void scrollToTab (int tabIndex ) {
188+ scrollToTab (tabIndex , 0 );
189+ }
190+
187191 /**
188192 * Updates the UI of an item at specified index
189193 */
Original file line number Diff line number Diff line change @@ -86,6 +86,19 @@ export class Tabs extends TabNavigation<TabsBar> {
8686
8787 protected override setTabBarItems ( tabItems : com . nativescript . material . core . TabItemSpec [ ] ) {
8888 this . mTabsBar . setItems ( tabItems ) ;
89+ // The setTimeout below is necessary to ensure the scrollToTab is executed only after
90+ // all tabs are recreated. The tabs' recreation is triggered by the setItems call above.
91+ //
92+ // The setTimeout is necessary to fix an Android issue:
93+ // Android Issue: Active Tab item not displaying after nav back
94+ // Reproduce steps:
95+ // 1. On app with multiple (overflown) tab items, Switch to the last tab item
96+ // 2. Navigate to a new page
97+ // 3. Nav back to the page with Tabs
98+ // 4. Notice the active last tab item is not showing. The tab strip is showing the most left / initial tab items instead.
99+ setTimeout ( ( ) => {
100+ this . mTabsBar . scrollToTab ( this . selectedIndex ) ;
101+ } , 0 ) ;
89102 }
90103
91104 protected override selectTabBar ( oldIndex : number , newIndex : number ) {
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ declare namespace com {
4040
4141 setViewPager ( viewPager : androidx . viewpager2 . widget . ViewPager2 ) : void ;
4242 setItems ( items : Array < TabItemSpec > ) : void ;
43+ scrollToTab ( tabIndex : Int ) ;
4344 updateItemAt ( position : number , itemSpec : TabItemSpec ) : void ;
4445
4546 setSelectedPosition ( position : number ) : void ;
You can’t perform that action at this time.
0 commit comments