Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: improve BottomNavigation (experimental feature) #14126

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,9 @@ public class AndroidModule extends KrollModule
@Kroll.constant
public static final int FLAG_UPDATE_CURRENT = PendingIntent.FLAG_UPDATE_CURRENT;

@Kroll.constant
public static final int STATUS_BAR_LIGHT = 8192;

@Kroll.constant
public static final int RESULT_OK = Activity.RESULT_OK;
@Kroll.constant
Expand Down
18 changes: 18 additions & 0 deletions android/modules/ui/res/layout/titanium_ui_bottom_navigation.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/bottomNavBar_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottomNavBar" />

<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />

</RelativeLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
*/
package ti.modules.titanium.ui;

import static ti.modules.titanium.android.AndroidModule.STATUS_BAR_LIGHT;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
Expand All @@ -29,6 +33,7 @@
import org.appcelerator.titanium.TiRootActivity;
import org.appcelerator.titanium.proxy.ActivityProxy;
import org.appcelerator.titanium.proxy.TiWindowProxy;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiRHelper;
import org.appcelerator.titanium.util.TiUIHelper;
Expand All @@ -39,6 +44,7 @@

import ti.modules.titanium.ui.android.AndroidModule;
import ti.modules.titanium.ui.widget.tabgroup.TiUIAbstractTabGroup;
import ti.modules.titanium.ui.widget.tabgroup.TiUIBottomNavigation;
import ti.modules.titanium.ui.widget.tabgroup.TiUIBottomNavigationTabGroup;
import ti.modules.titanium.ui.widget.tabgroup.TiUITabLayoutTabGroup;

Expand All @@ -49,7 +55,8 @@
TiC.PROPERTY_SWIPEABLE,
TiC.PROPERTY_AUTO_TAB_TITLE,
TiC.PROPERTY_EXIT_ON_CLOSE,
TiC.PROPERTY_SMOOTH_SCROLL_ON_TAB_CLICK
TiC.PROPERTY_SMOOTH_SCROLL_ON_TAB_CLICK,
TiC.PROPERTY_INDICATOR_COLOR
})
public class TabGroupProxy extends TiWindowProxy implements TiActivityWindow
{
Expand Down Expand Up @@ -323,6 +330,21 @@ protected void handleOpen(KrollDict options)
if (topActivity == null || topActivity.isFinishing()) {
return;
}

// set theme for XML layout
if (hasProperty(TiC.PROPERTY_STYLE)
&& ((Integer) getProperty(TiC.PROPERTY_STYLE)) == AndroidModule.TABS_STYLE_BOTTOM_NAVIGATION
&& getProperty(TiC.PROPERTY_THEME) != null) {
try {
String themeName = getProperty(TiC.PROPERTY_THEME).toString();
int theme = TiRHelper.getResource("style."
+ themeName.replaceAll("[^A-Za-z0-9_]", "_"));
topActivity.setTheme(theme);
topActivity.getApplicationContext().setTheme(theme);
} catch (Exception e) {
}
}

Intent intent = new Intent(topActivity, TiActivity.class);
fillIntent(topActivity, intent);

Expand Down Expand Up @@ -367,7 +389,11 @@ public void windowCreated(TiBaseActivity activity, Bundle savedInstanceState)
((TiUITabLayoutTabGroup) view).setTabMode((Integer) getProperty(TiC.PROPERTY_TAB_MODE));
}
} else {
view = new TiUIBottomNavigationTabGroup(this, activity);
if (TiConvert.toBoolean(getProperty("experimental"), false)) {
view = new TiUIBottomNavigation(this, activity);
} else {
view = new TiUIBottomNavigationTabGroup(this, activity);
}
}
// If we have set a title before the creation of the native view, set it now.
if (this.tabGroupTitle != null) {
Expand Down Expand Up @@ -405,6 +431,22 @@ public void windowCreated(TiBaseActivity activity, Bundle savedInstanceState)

// Need to handle the cached activity proxy properties in the JS side.
callPropertySync(PROPERTY_POST_TAB_GROUP_CREATED, null);

if (getActivity() != null) {
if (hasPropertyAndNotNull(TiC.PROPERTY_FLAGS)) {
if (TiConvert.toInt(getProperty(TiC.PROPERTY_FLAGS)) == STATUS_BAR_LIGHT
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
getActivity().getWindow().getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}
if (hasPropertyAndNotNull(TiC.PROPERTY_STATUS_BAR_COLOR)) {
int colorInt = TiColorHelper.parseColor(
TiConvert.toString(getProperty(TiC.PROPERTY_STATUS_BAR_COLOR)),
TiApplication.getAppRootOrCurrentActivity());
getActivity().getWindow().setStatusBarColor(colorInt);
}
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

package ti.modules.titanium.ui;

import static ti.modules.titanium.android.AndroidModule.STATUS_BAR_LIGHT;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.text.Spannable;
Expand Down Expand Up @@ -328,6 +331,13 @@ public void windowCreated(TiBaseActivity activity, Bundle savedInstanceState)
win.setStatusBarColor(colorInt);
}

if (hasProperty(TiC.PROPERTY_WINDOW_FLAGS)) {
if ((TiConvert.toInt(getProperty(TiC.PROPERTY_WINDOW_FLAGS)) & STATUS_BAR_LIGHT) != 0
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
win.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
}
}

// Handle titleAttributes property.
if (hasProperty(TiC.PROPERTY_TITLE_ATTRIBUTES)) {
KrollDict innerAttributes = getProperties().getKrollDict(TiC.PROPERTY_TITLE_ATTRIBUTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.appcelerator.titanium.proxy.TiWindowProxy;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiIconDrawable;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiInsetsProvider;
import org.appcelerator.titanium.view.TiUIView;
Expand Down Expand Up @@ -115,6 +116,13 @@ public abstract class TiUIAbstractTabGroup extends TiUIView
*/
public abstract void updateTabBackgroundDrawable(int index);

/**
* Material 3 active indicator color
hansemannn marked this conversation as resolved.
Show resolved Hide resolved
*
* @param color color
*/
public abstract void updateActiveIndicatorColor(int color);

/**
* Update the tab's title to the proper text.
*
Expand Down Expand Up @@ -454,7 +462,7 @@ public void onPageScrollStateChanged(int i)
// Set action bar color.
if (proxy != null) {
final ActionBar actionBar = ((AppCompatActivity) proxy.getActivity()).getSupportActionBar();
if (actionBar != null) {
if (actionBar != null && !this.tabs.isEmpty()) {
final TiWindowProxy windowProxy = ((TabProxy) this.tabs.get(tabIndex).getProxy()).getWindow();
final KrollDict windowProperties = windowProxy.getProperties();
final KrollDict properties = getProxy().getProperties();
Expand Down Expand Up @@ -495,6 +503,9 @@ public void processProperties(KrollDict d)
} else {
setBackgroundColor(getDefaultBackgroundColor());
}
if (d.containsKeyAndNotNull(TiC.PROPERTY_INDICATOR_COLOR)) {
updateActiveIndicatorColor(TiConvert.toColor(d, TiC.PROPERTY_INDICATOR_COLOR, proxy.getActivity()));
}
super.processProperties(d);
}

Expand All @@ -516,6 +527,8 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP
for (TiUITab tabView : tabs) {
updateTabBackgroundDrawable(tabs.indexOf(tabView));
}
} else if (key.equals(TiC.PROPERTY_INDICATOR_COLOR)) {
updateActiveIndicatorColor(TiColorHelper.parseColor(newValue.toString(), proxy.getActivity()));
} else {
super.propertyChanged(key, oldValue, newValue, proxy);
}
Expand Down Expand Up @@ -552,7 +565,12 @@ public Drawable updateIconTint(TiViewProxy tabProxy, Drawable drawable, boolean
}

// Clone existing drawable so color filter applies correctly.
drawable = drawable.getConstantState().newDrawable();
if (drawable.getConstantState() == null && drawable.getClass() == TiIconDrawable.class) {
// TiIconDrawable
drawable = drawable.mutate();
} else {
drawable = drawable.getConstantState().newDrawable();
}

final KrollDict tabProperties = tabProxy.getProperties();
final KrollDict properties = getProxy().getProperties();
Expand Down
Loading
Loading