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

Support large bottomTab icons #6855

Merged
merged 2 commits into from
Dec 23, 2020
Merged
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
3 changes: 2 additions & 1 deletion lib/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,8 @@ dependencies {
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'com.google.android.material:material:1.2.0-alpha03'

implementation 'com.github.wix-playground:ahbottomnavigation:3.2.0'
implementation 'com.github.wix-playground:ahbottomnavigation:3.3.0'
// implementation project(':AHBottomNavigation')
implementation 'com.github.wix-playground:reflow-animator:1.0.6'
implementation 'com.github.clans:fab:1.6.4'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static BottomTabOptions parse(Context context, TypefaceLoader typefaceMan
options.textColor = ColorParser.parse(context, json, "textColor");
options.selectedTextColor = ColorParser.parse(context, json, "selectedTextColor");
options.icon = IconParser.parse(json, "icon");
options.iconWidth = NumberParser.parse(json, "iconWidth");
options.iconHeight = NumberParser.parse(json, "iconHeight");
options.selectedIcon = IconParser.parse(json, "selectedIcon");
options.iconColor = ColorParser.parse(context, json, "iconColor");
options.selectedIconColor = ColorParser.parse(context, json, "selectedIconColor");
Expand All @@ -50,6 +52,8 @@ public static BottomTabOptions parse(Context context, TypefaceLoader typefaceMan
public Colour textColor = new NullColor();
public Colour selectedTextColor = new NullColor();
public Text icon = new NullText();
public Number iconWidth = new NullNumber();
public Number iconHeight = new NullNumber();
public Text selectedIcon = new NullText();
public Colour iconColor = new NullColor();
public Colour selectedIconColor = new NullColor();
Expand All @@ -69,6 +73,8 @@ void mergeWith(final BottomTabOptions other) {
if (other.textColor.hasValue()) textColor = other.textColor;
if (other.selectedTextColor.hasValue()) selectedTextColor = other.selectedTextColor;
if (other.icon.hasValue()) icon = other.icon;
if (other.iconWidth.hasValue()) iconWidth = other.iconWidth;
if (other.iconHeight.hasValue()) iconHeight = other.iconHeight;
if (other.selectedIcon.hasValue()) selectedIcon = other.selectedIcon;
if (other.iconColor.hasValue()) iconColor = other.iconColor;
if (other.selectedIconColor.hasValue()) selectedIconColor = other.selectedIconColor;
Expand All @@ -88,6 +94,8 @@ void mergeWithDefault(final BottomTabOptions defaultOptions) {
if (!textColor.hasValue()) textColor = defaultOptions.textColor;
if (!selectedTextColor.hasValue()) selectedTextColor = defaultOptions.selectedTextColor;
if (!icon.hasValue()) icon = defaultOptions.icon;
if (!iconWidth.hasValue()) iconWidth = defaultOptions.iconWidth;
if (!iconHeight.hasValue()) iconHeight = defaultOptions.iconHeight;
if (!selectedIcon.hasValue()) selectedIcon = defaultOptions.selectedIcon;
if (!iconColor.hasValue()) iconColor = defaultOptions.iconColor;
if (!selectedIconColor.hasValue()) selectedIconColor = defaultOptions.selectedIconColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public static BottomTabsOptions parse(Context context, JSONObject json) {
options.drawBehind = BoolParser.parse(json, "drawBehind");
options.preferLargeIcons = BoolParser.parse(json, "preferLargeIcons");
options.animate = BoolParser.parse(json,"animate");
options.animateTabSelection = BoolParser.parse(json, "animateTabSelection");
options.elevation = FractionParser.parse(json, "elevation");
options.testId = TextParser.parse(json, "testID");
options.titleDisplayMode = TitleDisplayMode.fromString(json.optString("titleDisplayMode"));
Expand All @@ -48,6 +49,7 @@ public static BottomTabsOptions parse(Context context, JSONObject json) {
public Bool visible = new NullBool();
public Bool drawBehind = new NullBool();
public Bool animate = new NullBool();
public Bool animateTabSelection = new NullBool();
public Bool preferLargeIcons = new NullBool();
public Number currentTabIndex = new NullNumber();
public Fraction elevation = new NullFraction();
Expand All @@ -63,6 +65,7 @@ void mergeWith(final BottomTabsOptions other) {
if (other.visible.hasValue()) visible = other.visible;
if (other.drawBehind.hasValue()) drawBehind = other.drawBehind;
if (other.animate.hasValue()) animate = other.animate;
if (other.animateTabSelection.hasValue()) animateTabSelection = other.animateTabSelection;
if (other.preferLargeIcons.hasValue()) preferLargeIcons = other.preferLargeIcons;
if (other.elevation.hasValue()) elevation = other.elevation;
if (other.backgroundColor.hasValue()) backgroundColor = other.backgroundColor;
Expand All @@ -78,6 +81,7 @@ void mergeWithDefault(final BottomTabsOptions defaultOptions) {
if (!visible.hasValue()) visible = defaultOptions.visible;
if (!drawBehind.hasValue()) drawBehind = defaultOptions.drawBehind;
if (!animate.hasValue()) animate = defaultOptions.animate;
if (!animateTabSelection.hasValue()) animateTabSelection = defaultOptions.animateTabSelection;
if (!preferLargeIcons.hasValue()) preferLargeIcons = defaultOptions.preferLargeIcons;
if (!elevation.hasValue()) elevation = defaultOptions.elevation;
if (!backgroundColor.hasValue()) backgroundColor = defaultOptions.backgroundColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public void applyOptions() {
bottomTabs.perform(bottomTabs -> {
for (int i = 0; i < tabs.size(); i++) {
BottomTabOptions tab = tabs.get(i).resolveCurrentOptions(defaultOptions).bottomTabOptions;
bottomTabs.setIconWidth(i, tab.iconWidth.get(null));
bottomTabs.setIconHeight(i, tab.iconHeight.get(null));
bottomTabs.setTitleTypeface(i, tab.font.getTypeface(typefaceLoader, Typeface.DEFAULT));
if (tab.selectedIconColor.canApplyValue()) bottomTabs.setIconActiveColor(i, tab.selectedIconColor.get(null));
if (tab.iconColor.canApplyValue()) bottomTabs.setIconInactiveColor(i, tab.iconColor.get(null));
Expand All @@ -81,6 +83,8 @@ public void mergeChildOptions(Options options, ViewController child) {
int index = bottomTabFinder.findByControllerId(child.getId());
if (index >= 0) {
BottomTabOptions tab = options.bottomTabOptions;
if (tab.iconWidth.hasValue()) bottomTabs.setIconWidth(index, tab.iconWidth.get(null));
if (tab.iconHeight.hasValue()) bottomTabs.setIconHeight(index, tab.iconHeight.get(null));
if (tab.font.hasValue()) bottomTabs.setTitleTypeface(index, tab.font.getTypeface(typefaceLoader, Typeface.DEFAULT));
if (canMerge(tab.selectedIconColor)) bottomTabs.setIconActiveColor(index, tab.selectedIconColor.get());
if (canMerge(tab.iconColor)) bottomTabs.setIconInactiveColor(index, tab.iconColor.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ private void mergeBottomTabsOptions(Options options, ViewController view) {
if (bottomTabsOptions.backgroundColor.hasValue()) {
bottomTabs.setBackgroundColor(bottomTabsOptions.backgroundColor.get());
}
if (bottomTabsOptions.animateTabSelection.hasValue()) {
bottomTabs.setAnimateTabSelection(bottomTabsOptions.animateTabSelection.get());
}
if (bottomTabsOptions.currentTabIndex.hasValue()) {
int tabIndex = bottomTabsOptions.currentTabIndex.get();
if (tabIndex >= 0) tabSelector.selectTab(tabIndex);
Expand Down Expand Up @@ -122,6 +125,7 @@ private void applyBottomTabsOptions(Options options) {
bottomTabs.setPreferLargeIcons(options.bottomTabsOptions.preferLargeIcons.get(false));
bottomTabs.setTitleState(bottomTabsOptions.titleDisplayMode.get(getDefaultTitleState()));
bottomTabs.setBackgroundColor(bottomTabsOptions.backgroundColor.get(Color.WHITE));
bottomTabs.setAnimateTabSelection(bottomTabsOptions.animateTabSelection.get(true));
if (bottomTabsOptions.currentTabIndex.hasValue()) {
int tabIndex = bottomTabsOptions.currentTabIndex.get();
if (tabIndex >= 0) {
Expand Down
17 changes: 16 additions & 1 deletion lib/src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,12 @@ export interface OptionsBottomTabs {
* Enable animations when toggling visibility
*/
animate?: boolean;
/**
* Controls wether tab selection is animated or not
* #### (android specific)
* @default true
*/
animateTabSelection?: boolean;
/**
* Use large icons when possible, even when three tabs without titles are displayed
* #### (android specific)
Expand Down Expand Up @@ -840,6 +846,16 @@ export interface OptionsBottomTab {
* Set the icon tint
*/
iconColor?: Color;
/**
* Set the icon width
* #### (Android specific)
*/
iconWidth?: number;
/**
* Set the icon height
* #### (Android specific)
*/
iconHeight?: number;
/**
* Set the text color
*/
Expand Down Expand Up @@ -872,7 +888,6 @@ export interface OptionsBottomTab {
fontSize?: number;
/**
* Set the insets of the icon
* #### (iOS specific)
*/
iconInsets?: Insets;
/**
Expand Down
2 changes: 2 additions & 0 deletions playground/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ applyNativeModulesSettingsGradle(settings)
include ':app'
include ':react-native-navigation'
project(':react-native-navigation').projectDir = new File(rootProject.projectDir, '../../lib/android/app/')
//include ':AHBottomNavigation'
//project(':AHBottomNavigation').projectDir = new File(rootProject.projectDir, '../../../ahbottomnavigation/ahbottomnavigation/')
Binary file added playground/img/plus@2x.android.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added playground/img/plus@2x.ios.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 19 additions & 3 deletions website/docs/api/options-bottomTab.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,25 @@ const options = {

## `icon`

| Type | Required | Platform |
| ------------------------------------------ | -------- | -------- |
| [ImageResource](options-imageResource.mdx) | No | Both |

## `iconWidth`

The width (in dp) of the icon.

| Type | Required | Platform |
| ------ | -------- | -------- |
| [ImageResource](options-imageResource.mdx) | No | Both |
| number | No | Android |

## `iconHeight`

The height (in dp) of the icon.

| Type | Required | Platform |
| ------ | -------- | -------- |
| number | No | Android |

## `iconColor`

Expand All @@ -84,8 +100,8 @@ const options = {

## `selectedIcon`

| Type | Required | Platform |
| ------ | -------- | -------- |
| Type | Required | Platform |
| ------------------------------------------ | -------- | -------- |
| [ImageResource](options-imageResource.mdx) | No | Both |

## `selectedIconColor`
Expand Down
8 changes: 8 additions & 0 deletions website/docs/api/options-bottomTabs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ Controls whether toggling visibility states will be animated.
| ------- | -------- | -------- |
| boolean | No | Both |

## `animateTabSelection`

Controls wether tab selection is animated or not

| Type | Required | Platform |
| ------- | -------- | -------- |
| boolean | No | Android |

## `backgroundColor`

Change the background color.
Expand Down