fix(core-android): Tabs selected item color gets applied to wrong Tabs or not applied at all#9040
Conversation
rigor789
left a comment
There was a problem hiding this comment.
Not sure if intentional but packages/core/platforms/android/widgets-release.aar has been removed, I believe it just needs to be rebuilt with the native changes.
| // } | ||
| this._viewPager.setCurrentItem(value, this.animationEnabled); | ||
| if (this._viewPager.getCurrentItem() != value) { | ||
| this._viewPager.setCurrentItem(value); |
There was a problem hiding this comment.
Shouldn't this pass the animationEnabled boolean?
There was a problem hiding this comment.
@rigor789 This is handled in ui-mobile-base android class:
https://github.com/DimitrisRK/NativeScript/blob/tabs-selected/packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/TabViewPager.java#L58
Note: This java code is not an addition of mine. animationEnabled check had always been inside overridden method but it had an extra swipeEnabled check which was breaking proper functionality for all cases, so I removed 1 of 2 conditions.
Sorry, just noticed first comment. It's not removed, just looks like this because it's modified (few lines were left unused, so they got removed). |
PR Checklist
What is the current behavior?
There are couple of issues regarding Tabs navigation UX for some time now.
isAnimationEnabledis not working for Tabs with swipeEnabled set to false.What is the new behavior?
This PR ensures colors are properly changed in all cases and animation to be configurable in all cases.
In terms of performance, this method won't try to update colors when not needed.
Additionally, it prevents the pointless calls of
setCurrentItemevery timeselectedIndexPropertychanges.Until now, the following performance issue had been occuring:
setCurrentItemcalls a native method which by its turn callssetPrimaryItemmethod.setPrimaryItemis overridden inside Tabs UI component and changesselectedIndexproperty.Upon change,
selectedIndexproperty will callsetCurrentItemagain (called usingsetNativesymbol)Luckily, since
setCurrentItemtried to set the same index there was no recursion but still executed tasks that shouldn't.I'm positive this is a very good solution to get rid of some
TabStripUX bugs.People are desperate with Tab components and that may give a small relief for Android platform at least.
There are lots of Tabs examples in UI app where this can be tested, but I also made sure to add selected/unselected colors to swipe-disabled-page and tabs-position-page examples.
Hope you consider this as a good alternative.
Fixes/Closes #8543 #8551 #8552 #8712