mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(bottom-navigation-android): add tabstripitem css support (#7458)
* wip: add background color placeholders for tabstripitem * feat: add css for tabstripitem for bottom navigation android * chore: update example * fix: revert native default index * clean up tabcontentitem * update setTabBarItemTextTransform * textTransform inherited css property now * fix(android-bottom-navigation): fragment detach logic * chore: fix tests * fix(android-bottom-navigation): fragment lifecycle logic * fix: revert text-transform inherited css property
This commit is contained in:
committed by
Manol Donev
parent
6e1e0e843a
commit
fab9c90007
@@ -205,6 +205,10 @@ public class BottomNavigationBar extends LinearLayout {
|
||||
textView.setVisibility(GONE);
|
||||
}
|
||||
|
||||
if (tabItem.backgroundColor != 0) {
|
||||
ll.setBackgroundColor(tabItem.backgroundColor);
|
||||
}
|
||||
|
||||
ll.setMinimumHeight((int) (BOTTOM_NAV_HEIGHT * density));
|
||||
|
||||
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
|
||||
@@ -212,7 +216,11 @@ public class BottomNavigationBar extends LinearLayout {
|
||||
lp.weight = 1;
|
||||
}
|
||||
|
||||
public void onSelectedPositionChange(int position) {
|
||||
public void onTap(int position) {
|
||||
// to be overridden in JS
|
||||
}
|
||||
|
||||
public void onSelectedPositionChange(int position, int prevPosition) {
|
||||
// to be overridden in JS
|
||||
}
|
||||
|
||||
@@ -239,13 +247,17 @@ public class BottomNavigationBar extends LinearLayout {
|
||||
int tabTextColor = mTabStrip.getTabTextColor();
|
||||
mTabStrip.setTabTextColor(Color.argb(100, Color.red(tabTextColor), Color.green(tabTextColor), Color.blue(tabTextColor)));
|
||||
mTabStrip.setSelectedTabTextColor(Color.argb(255, Color.red(tabTextColor), Color.green(tabTextColor), Color.blue(tabTextColor)));
|
||||
mTabStrip.setSelectedPosition(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSelectedPosition(int position) {
|
||||
int prevPosition = mTabStrip.getSelectedPosition();
|
||||
if (prevPosition == position) {
|
||||
return;
|
||||
}
|
||||
|
||||
mTabStrip.setSelectedPosition(position);
|
||||
onSelectedPositionChange(position);
|
||||
onSelectedPositionChange(position, prevPosition);
|
||||
}
|
||||
|
||||
public void setContentDescription(int i, String desc) {
|
||||
@@ -257,6 +269,7 @@ public class BottomNavigationBar extends LinearLayout {
|
||||
public void onClick(View v) {
|
||||
for (int i = 0; i < mTabStrip.getChildCount(); i++) {
|
||||
if (v == mTabStrip.getChildAt(i)) {
|
||||
onTap(i);
|
||||
setSelectedPosition(i);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -6,4 +6,5 @@ public class TabItemSpec {
|
||||
public String title;
|
||||
public int iconId;
|
||||
public Drawable iconDrawable;
|
||||
public int backgroundColor;
|
||||
}
|
||||
@@ -159,6 +159,10 @@ class TabStrip extends LinearLayout {
|
||||
updateTabsTextColor();
|
||||
}
|
||||
|
||||
int getSelectedPosition(){
|
||||
return mSelectedPosition;
|
||||
}
|
||||
|
||||
void setSelectedPosition(int position) {
|
||||
mSelectedPosition = position;
|
||||
invalidate();
|
||||
@@ -174,7 +178,7 @@ class TabStrip extends LinearLayout {
|
||||
: mDefaultTabColorizer;
|
||||
|
||||
// Thick colored underline below the current selection
|
||||
if (childCount > 0) {
|
||||
if (childCount > 0 && mSelectedPosition < childCount) {
|
||||
View selectedTitle = getChildAt(mSelectedPosition);
|
||||
int left = selectedTitle.getLeft();
|
||||
int right = selectedTitle.getRight();
|
||||
|
||||
Reference in New Issue
Block a user