Skip to content

Commit

Permalink
Merge branch '8_0_X' into TIMOB-26580_80X
Browse files Browse the repository at this point in the history
  • Loading branch information
lokeshchdhry committed Jan 9, 2019
2 parents 5817410 + e2bc70e commit 020a518
Show file tree
Hide file tree
Showing 9 changed files with 636 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,6 @@ protected void fillIntent(Activity activity, Intent intent)
intent.putExtra(TiC.PROPERTY_WINDOW_PIXEL_FORMAT,
TiConvert.toInt(getProperty(TiC.PROPERTY_WINDOW_PIXEL_FORMAT), PixelFormat.UNKNOWN));
}
if (hasProperty(TiC.PROPERTY_EXTEND_SAFE_AREA)) {
boolean value = TiConvert.toBoolean(getProperty(TiC.PROPERTY_EXTEND_SAFE_AREA), false);
intent.putExtra(TiC.PROPERTY_EXTEND_SAFE_AREA, value);
}

// Set the splitActionBar property
if (hasProperty(TiC.PROPERTY_SPLIT_ACTIONBAR)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.appcelerator.titanium.proxy.ActivityProxy;
import org.appcelerator.titanium.util.TiColorHelper;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.view.TiInsetsProvider;
import org.appcelerator.titanium.view.TiUIView;

import java.util.ArrayList;
Expand Down Expand Up @@ -97,6 +98,7 @@ public abstract class TiUIAbstractTabGroup extends TiUIView
protected int colorPrimaryInt;
protected PagerAdapter tabGroupPagerAdapter;
protected ViewPager tabGroupViewPager;
protected TiInsetsProvider insetsProvider = new TiInsetsProvider();
// endregion

// region private fields
Expand Down Expand Up @@ -147,6 +149,10 @@ public void onRestoreInstanceState(Parcelable state)
this.tabGroupViewPager.setId(android.R.id.tabcontent);
this.tabGroupViewPager.setAdapter(this.tabGroupPagerAdapter);

// Add the tab group's custom insets provider to the activity.
// This provides the tab bar as an inset so that it can be excluded from the activity's safe-area.
activity.addCustomInsetsProvider(this.insetsProvider);

addViews(activity);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/**
* Appcelerator Titanium Mobile
* Copyright (c) 2018-Present by Axway, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
package ti.modules.titanium.ui.widget.tabgroup;

import android.graphics.drawable.Drawable;
import android.graphics.Rect;
import android.support.design.internal.BottomNavigationItemView;
import android.support.design.internal.BottomNavigationMenuView;
import android.support.design.widget.BottomNavigationView;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewParent;

import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiBaseActivity;
Expand Down Expand Up @@ -48,28 +56,60 @@ public void addViews(TiBaseActivity activity)
activity.getPackageName());
this.mBottomNavigationHeightValue = activity.getResources().getDimensionPixelSize(resourceID);

this.mBottomNavigationView = new BottomNavigationView(activity);
// Create the bottom tab navigation view.
this.mBottomNavigationView = new BottomNavigationView(activity) {
@Override
protected boolean fitSystemWindows(Rect insets)
{
// Remove top inset when bottom tab bar is to be extended beneath system insets.
// This prevents Google from blindly padding top of tab bar based on this inset.
if ((insets != null) && getFitsSystemWindows()) {
insets = new Rect(insets);
insets.top = 0;
}
super.fitSystemWindows(insets);
return false;
}

@Override
protected void onLayout(boolean hasChanged, int left, int top, int right, int bottom)
{
// Update bottom inset based on tab bar's height and position in window.
super.onLayout(hasChanged, left, top, right, bottom);
insetsProvider.setBottomBasedOn(this);
}
};
this.mBottomNavigationView.setFitsSystemWindows(true);

// Set the colorPrimary as backgroundColor by default if do not have the backgroundColor set.
if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_TABS_BACKGROUND_COLOR)) {
this.mBottomNavigationView.setBackgroundColor(
TiColorHelper.parseColor(proxy.getProperty(TiC.PROPERTY_TABS_BACKGROUND_COLOR).toString()));
} else {
this.mBottomNavigationView.setBackgroundColor(this.colorPrimaryInt);
}
// Set the LayoutParams for the ViewPager.
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
params.optionBottom = new TiDimension(mBottomNavigationHeightValue, TiDimension.TYPE_BOTTOM);

// Set the LayoutParams for the BottomNavigationView.
TiCompositeLayout.LayoutParams bottomNavigationParams = new TiCompositeLayout.LayoutParams();
bottomNavigationParams.autoFillsWidth = true;
bottomNavigationParams.optionBottom = new TiDimension(0, TiDimension.TYPE_BOTTOM);
// 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.
TiCompositeLayout compositeLayout = (TiCompositeLayout) activity.getLayout();
{
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
params.autoFillsHeight = true;
if (compositeLayout.getFitsSystemWindows()) {
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);
compositeLayout.addView(this.mBottomNavigationView, params);
}

// Add the views to their container.
((TiCompositeLayout) activity.getLayout()).addView(this.tabGroupViewPager, params);
((TiCompositeLayout) activity.getLayout()).addView(mBottomNavigationView, bottomNavigationParams);
// Set teh ViewPager as a native view.
// Set the ViewPager as a native view.
setNativeView(this.tabGroupViewPager);
}

Expand All @@ -81,16 +121,23 @@ public void addViews(TiBaseActivity activity)
public void disableTabNavigation(boolean disable)
{
super.disableTabNavigation(disable);
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
if (disable) {
params.optionBottom = new TiDimension(0, TiDimension.TYPE_BOTTOM);
mBottomNavigationView.setVisibility(View.GONE);
} else {
params.optionBottom = new TiDimension(mBottomNavigationHeightValue, TiDimension.TYPE_BOTTOM);
mBottomNavigationView.setVisibility(View.VISIBLE);

// Resize the view pager (the tab's content) to compensate for shown/hidden tab bar.
// Not applicable if Titanium "extendSafeArea" is true, because tab bar overlaps content in this case.
ViewParent viewParent = this.tabGroupViewPager.getParent();
if ((viewParent instanceof View) && ((View) viewParent).getFitsSystemWindows()) {
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
params.optionBottom = new TiDimension(disable ? 0 : mBottomNavigationHeightValue, TiDimension.TYPE_BOTTOM);
this.tabGroupViewPager.setLayoutParams(params);
}
this.tabGroupViewPager.setLayoutParams(params);

// Show/hide the tab bar.
this.mBottomNavigationView.setVisibility(disable ? View.GONE : View.VISIBLE);
this.mBottomNavigationView.requestLayout();

// Update top inset. (Will remove bottom inset if tab bar is "gone".)
this.insetsProvider.setBottomBasedOn(this.mBottomNavigationView);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package ti.modules.titanium.ui.widget.tabgroup;

import android.graphics.drawable.Drawable;
import android.graphics.Rect;
import android.support.design.widget.TabLayout;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -18,6 +19,7 @@
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.util.TiColorHelper;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiCompositeLayout;
Expand Down Expand Up @@ -54,37 +56,86 @@ public TiUITabLayoutTabGroup(TabGroupProxy proxy, TiBaseActivity activity)
public void disableTabNavigation(boolean disable)
{
super.disableTabNavigation(disable);
if (disable) {
this.mTabLayout.setVisibility(View.GONE);
} else {
this.mTabLayout.setVisibility(View.VISIBLE);
}

// Show/hide the tab bar.
this.mTabLayout.setVisibility(disable ? View.GONE : View.VISIBLE);
this.mTabLayout.requestLayout();

// Update top inset. (Will remove top inset if tab bar is "gone".)
this.insetsProvider.setTopBasedOn(this.mTabLayout);
}

@Override
public void addViews(TiBaseActivity activity)
{
this.mTabLayout = new TabLayout(activity);
// Create the top tab layout view.
this.mTabLayout = new TabLayout(activity) {
@Override
protected boolean fitSystemWindows(Rect insets)
{
// Remove bottom inset when top tab bar is to be extended beneath system insets.
// This prevents Google from blindly padding bottom of tab bar based on this inset.
if ((insets != null) && getFitsSystemWindows()) {
insets = new Rect(insets);
insets.bottom = 0;
}
super.fitSystemWindows(insets);
return false;
}

@Override
protected void onLayout(boolean hasChanged, int left, int top, int right, int bottom)
{
// Update top inset based on tab bar's height and position in window.
super.onLayout(hasChanged, left, top, right, bottom);
insetsProvider.setTopBasedOn(this);
}
};
this.mTabLayout.setFitsSystemWindows(true);

// Set the colorPrimary as backgroundColor by default if do not have the backgroundColor set.
if (proxy.hasPropertyAndNotNull(TiC.PROPERTY_TABS_BACKGROUND_COLOR)) {
this.mTabLayout.setBackgroundColor(
TiColorHelper.parseColor(proxy.getProperty(TiC.PROPERTY_TABS_BACKGROUND_COLOR).toString()));
} else {
this.mTabLayout.setBackgroundColor(this.colorPrimaryInt);
}

// Set the OnTabSelected listener.
this.mTabLayout.addOnTabSelectedListener(this);
// Set the LayoutParams for the TabLayout instance.
TiCompositeLayout.LayoutParams tabLayoutLP = new TiCompositeLayout.LayoutParams();
tabLayoutLP.autoFillsWidth = true;
this.mTabLayout.setLayoutParams(tabLayoutLP);
// Set the LayoutParams for the ViewPager instance.
((TiCompositeLayout) activity.getLayout()).setLayoutArrangement(TiC.LAYOUT_VERTICAL);
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
// Add the views to their container.
((ViewGroup) activity.getLayout()).addView(this.mTabLayout);
((ViewGroup) activity.getLayout()).addView(this.tabGroupViewPager, params);

// 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 top tab bar should overlap/overlay the view pager content.
TiCompositeLayout compositeLayout = (TiCompositeLayout) activity.getLayout();
if (compositeLayout.getFitsSystemWindows()) {
compositeLayout.setLayoutArrangement(TiC.LAYOUT_VERTICAL);
{
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
compositeLayout.addView(this.mTabLayout, params);
}
{
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
params.autoFillsHeight = true;
compositeLayout.addView(this.tabGroupViewPager, params);
}
} else {
{
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
params.autoFillsHeight = true;
compositeLayout.addView(this.tabGroupViewPager, params);
}
{
TiCompositeLayout.LayoutParams params = new TiCompositeLayout.LayoutParams();
params.autoFillsWidth = true;
params.optionTop = new TiDimension(0, TiDimension.TYPE_TOP);
compositeLayout.addView(this.mTabLayout, params);
}
}

// Set the ViewPager as a native view.
setNativeView(this.tabGroupViewPager);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.appcelerator.titanium.view.TiActivitySafeAreaMonitor;
import org.appcelerator.titanium.view.TiCompositeLayout;
import org.appcelerator.titanium.view.TiCompositeLayout.LayoutArrangement;
import org.appcelerator.titanium.view.TiInsetsProvider;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
Expand Down Expand Up @@ -1808,4 +1809,32 @@ public Rect getSafeAreaRect()
}
return this.safeAreaMonitor.getSafeAreaRect();
}

/**
* Adds an object used to provide custom insets to be excluded from the safe-area returned
* by this activity's getSafeAreaRect() method.
* <p>
* For example, Titanium's TabGroup will use this method to add its tab bar as a custom inset.
* <p>
* The provider's insets are expected to be relative to this activity's root decor view.
* @param provider Object used to provide custom insets. If given null, then this method will no-op.
*/
public void addCustomInsetsProvider(TiInsetsProvider provider)
{
if (this.safeAreaMonitor != null) {
this.safeAreaMonitor.addInsetsProvider(provider);
}
}

/**
* Removes the provider added via the addCustomInsetsProvider() method by reference.
* Once removed, the provider's insets will no longer apply to this activity's safe-area.
* @param provider The insets provider to be removed by reference. Can be null.
*/
public void removeCustomInsetsProvider(TiInsetsProvider provider)
{
if (this.safeAreaMonitor != null) {
this.safeAreaMonitor.removeInsetsProvider(provider);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,12 @@ protected void fillIntent(Activity activity, Intent intent)
intent.putExtra(TiC.PROPERTY_WINDOW_SOFT_INPUT_MODE,
TiConvert.toInt(getProperty(TiC.PROPERTY_WINDOW_SOFT_INPUT_MODE), -1));
}

if (hasProperty(TiC.PROPERTY_EXTEND_SAFE_AREA)) {
boolean value = TiConvert.toBoolean(getProperty(TiC.PROPERTY_EXTEND_SAFE_AREA), false);
intent.putExtra(TiC.PROPERTY_EXTEND_SAFE_AREA, value);
}

if (hasProperty(TiC.PROPERTY_EXIT_ON_CLOSE)) {
intent.putExtra(TiC.INTENT_PROPERTY_FINISH_ROOT,
TiConvert.toBoolean(getProperty(TiC.PROPERTY_EXIT_ON_CLOSE), false));
Expand Down

0 comments on commit 020a518

Please sign in to comment.