Skip to content

Commit

Permalink
feat(android): floating bottom navigtion
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga authored and ewanharris committed Aug 13, 2021
1 parent 5fdf4ff commit af619dc
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 14 deletions.
5 changes: 5 additions & 0 deletions android/modules/ui/res/drawable/titanium_rounded_corners.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:radius="17dp" />
</shape>
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
*/
package ti.modules.titanium.ui.widget.tabgroup;

import java.util.ArrayList;

import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;

import android.annotation.SuppressLint;
import android.content.res.ColorStateList;
import android.graphics.Rect;
Expand All @@ -25,6 +14,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewParent;

import androidx.annotation.ColorInt;
import androidx.core.graphics.ColorUtils;

Expand All @@ -34,6 +24,18 @@
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.bottomnavigation.LabelVisibilityMode;

import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiBaseActivity;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.TiDimension;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.R;

import java.util.ArrayList;

import ti.modules.titanium.ui.TabGroupProxy;
import ti.modules.titanium.ui.TabProxy;

Expand Down Expand Up @@ -80,6 +82,11 @@ public void addViews(TiBaseActivity activity)
activity.getPackageName());
this.mBottomNavigationHeightValue = activity.getResources().getDimensionPixelSize(resourceID);

int paddingLeft = proxy.getProperties().optInt(TiC.PROPERTY_PADDING_LEFT, 0);
int paddingRight = proxy.getProperties().optInt(TiC.PROPERTY_PADDING_RIGHT, 0);
int paddingBottom = proxy.getProperties().optInt(TiC.PROPERTY_PADDING_BOTTOM, 0);
boolean isFloating = (paddingLeft != 0 || paddingRight != 0 || paddingBottom != 0);

// Create the bottom tab navigation view.
this.mBottomNavigationView = new BottomNavigationView(activity) {
@Override
Expand All @@ -101,12 +108,15 @@ protected void onLayout(boolean hasChanged, int left, int top, int right, int bo
// Update bottom inset based on tab bar's height and position in window.
super.onLayout(hasChanged, left, top, right, bottom);
insetsProvider.setBottomBasedOn(this);
if (isFloating) {
setBackgroundResource(R.drawable.titanium_rounded_corners);
setElevation(8);
}
}
};
this.mBottomNavigationView.setFitsSystemWindows(true);
this.mBottomNavigationView.setItemRippleColor(
TiUIAbstractTabGroup.createRippleColorStateListFrom(getColorPrimary()));

// Add tab bar and view pager to the root Titanium view.
// Note: If getFitsSystemWindows() returns false, then Titanium window's "extendSafeArea" is set true.
// This means the bottom tab bar should overlap/overlay the view pager content.
Expand All @@ -115,15 +125,22 @@ protected void onLayout(boolean hasChanged, int left, int top, int right, int bo
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
params.autoFillsHeight = true;
if (compositeLayout.getFitsSystemWindows()) {

if (compositeLayout.getFitsSystemWindows() && !isFloating) {
params.optionBottom = new TiDimension(mBottomNavigationHeightValue, TiDimension.TYPE_BOTTOM);
}
compositeLayout.addView(this.tabGroupViewPager, params);
}
{
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
params.optionBottom = new TiDimension(0, TiDimension.TYPE_BOTTOM);
if (isFloating) {
params.optionLeft = new TiDimension(paddingLeft, TiDimension.TYPE_LEFT);
params.optionRight = new TiDimension(paddingRight, TiDimension.TYPE_RIGHT);
params.optionBottom = new TiDimension(paddingBottom, TiDimension.TYPE_BOTTOM);
} else {
params.optionBottom = new TiDimension(0, TiDimension.TYPE_BOTTOM);
}
compositeLayout.addView(this.mBottomNavigationView, params);
}

Expand Down
36 changes: 36 additions & 0 deletions apidoc/Titanium/UI/TabGroup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,34 @@ properties:
A value of `transparent` results in a semi-opaque black bar style.
type: [String, Titanium.UI.Color]
platforms: [iphone, ipad, android, macos]

- name: paddingLeft
summary: Left padding of bottom navigation
description: |
When using [TABS_STYLE_BOTTOM_NAVIGATION](Titanium.UI.Android.TABS_STYLE_BOTTOM_NAVIGATION) you can set the padding to have
a floating bottom navigation
since: "10.1.0"
type: Number
platforms: [android]

- name: paddingRight
summary: Right padding of bottom navigation
description: |
When using [TABS_STYLE_BOTTOM_NAVIGATION](Titanium.UI.Android.TABS_STYLE_BOTTOM_NAVIGATION) you can set the padding to have
a floating bottom navigation
since: "10.1.0"
type: Number
platforms: [android]

- name: paddingBottom
summary: Bottom padding of bottom navigation
description: |
When using [TABS_STYLE_BOTTOM_NAVIGATION](Titanium.UI.Android.TABS_STYLE_BOTTOM_NAVIGATION) you can set the padding to have
a floating bottom navigation
since: "10.1.0"
type: Number
platforms: [android]

- name: translucent
summary: Boolean value indicating if the nav bar (typically for the **More** tab), is translucent.
platforms: [iphone, ipad, macos]
Expand Down Expand Up @@ -459,6 +486,15 @@ properties:
the TabGroup with a list of Tabs in a controller at the bottom of the screen. The recommended usage of this
style is for items count between three and five: (https://material.io/design/components/bottom-navigation.html#usage)
In Android it is limited to supporting a maximum number of five tabs.
You can use paddingLeft, paddingRight, paddingBottom to create a floating bottom navigation. If you want to change the
radius or background color you'll need to create `/app/platform/android/res/drawable/titanium_rounded_corners.xml` and set it to
```xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FFFFFF" />
<corners android:radius="7dp" />
</shape>
```
availability: creation
constants: Titanium.UI.Android.TABS_STYLE_*
Expand Down

0 comments on commit af619dc

Please sign in to comment.