File tree 3 files changed +18
-0
lines changed
packages/core-tabs/platforms/android/java/com/nativescript/material/core
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) {
184
184
185
185
}
186
186
187
+ public void scrollToTab (int tabIndex ) {
188
+ scrollToTab (tabIndex , 0 );
189
+ }
190
+
187
191
/**
188
192
* Updates the UI of an item at specified index
189
193
*/
Original file line number Diff line number Diff line change @@ -86,6 +86,19 @@ export class Tabs extends TabNavigation<TabsBar> {
86
86
87
87
protected override setTabBarItems ( tabItems : com . nativescript . material . core . TabItemSpec [ ] ) {
88
88
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 ) ;
89
102
}
90
103
91
104
protected override selectTabBar ( oldIndex : number , newIndex : number ) {
Original file line number Diff line number Diff line change @@ -40,6 +40,7 @@ declare namespace com {
40
40
41
41
setViewPager ( viewPager : androidx . viewpager2 . widget . ViewPager2 ) : void ;
42
42
setItems ( items : Array < TabItemSpec > ) : void ;
43
+ scrollToTab ( tabIndex : Int ) ;
43
44
updateItemAt ( position : number , itemSpec : TabItemSpec ) : void ;
44
45
45
46
setSelectedPosition ( position : number ) : void ;
You can’t perform that action at this time.
0 commit comments