Skip to content

Commit

Permalink
Add fab.iconColor option
Browse files Browse the repository at this point in the history
Closes #3664
  • Loading branch information
guyca committed Dec 23, 2018
1 parent d2ae142 commit 13de5ca
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static FabOptions parse(JSONObject json) {
if (json.has("icon")) {
options.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
}
options.iconColor = ColorParser.parse(json, "iconColor");
if (json.has("actions")) {
JSONArray fabsArray = json.optJSONArray("actions");
for (int i = 0; i < fabsArray.length(); i++) {
Expand All @@ -49,6 +50,7 @@ public static FabOptions parse(JSONObject json) {
public Colour clickColor = new NullColor();
public Colour rippleColor = new NullColor();
public Text icon = new NullText();
public Colour iconColor = new NullColor();
public Bool visible = new NullBool();
public ArrayList<FabOptions> actionsArray = new ArrayList<>();
public Text alignHorizontally = new NullText();
Expand All @@ -75,6 +77,9 @@ void mergeWith(final FabOptions other) {
if (other.icon.hasValue()) {
icon = other.icon;
}
if (other.iconColor.hasValue()) {
iconColor = other.iconColor;
}
if (other.actionsArray.size() > 0) {
actionsArray = other.actionsArray;
}
Expand Down Expand Up @@ -111,6 +116,9 @@ void mergeWithDefault(FabOptions defaultOptions) {
if (!icon.hasValue()) {
icon = defaultOptions.icon;
}
if (!iconColor.hasValue()) {
iconColor = defaultOptions.iconColor;
}
if (actionsArray.size() == 0) {
actionsArray = defaultOptions.actionsArray;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private void applyFabOptions(Fab fab, FabOptions options) {
fab.setColorRipple(options.rippleColor.get());
}
if (options.icon.hasValue()) {
fab.applyIcon(options.icon.get());
fab.applyIcon(options.icon.get(), options.iconColor);
}
if (options.size.hasValue()) {
fab.setButtonSize("mini".equals(options.size.get()) ? SIZE_MINI : SIZE_NORMAL);
Expand Down Expand Up @@ -285,7 +285,7 @@ private void mergeFabOptions(Fab fab, FabOptions options) {
fab.setColorRipple(options.rippleColor.get());
}
if (options.icon.hasValue()) {
fab.applyIcon(options.icon.get());
fab.applyIcon(options.icon.get(), options.iconColor);
}
if (options.size.hasValue()) {
fab.setButtonSize("mini".equals(options.size.get()) ? SIZE_MINI : SIZE_NORMAL);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package com.reactnativenavigation.views;

import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;

import com.github.clans.fab.FloatingActionButton;
import com.reactnativenavigation.anim.FabAnimator;
import com.reactnativenavigation.anim.FabCollapseBehaviour;
import com.reactnativenavigation.interfaces.ScrollEventListener;
import com.reactnativenavigation.parse.params.Colour;
import com.reactnativenavigation.utils.ImageLoader;
import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;

Expand All @@ -26,10 +29,11 @@ public Fab(Context context, String id) {
this.id = id;
}

public void applyIcon(String icon) {
public void applyIcon(String icon, Colour color) {
new ImageLoader().loadIcons(getContext(), Collections.singletonList(icon), new ImageLoadingListenerAdapter() {
@Override
public void onComplete(@NonNull List<Drawable> drawables) {
if (color.hasValue()) drawables.get(0).setColorFilter(new PorterDuffColorFilter(color.get(), PorterDuff.Mode.SRC_IN));
setImageDrawable(drawables.get(0));
}

Expand Down
16 changes: 16 additions & 0 deletions lib/src/interfaces/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,21 @@ export interface OptionsTopBar {
elevation?: AndroidDensityNumber;
}

export interface OptionsFab {
id: string;
backgroundColor?: Color;
clickColor?: Color;
rippleColor?: Color;
visible?: boolean;
icon?: ImageRequireSource;
iconColor?: Color;
alignHorizontally?: 'left' | 'right';
alignVertically?: 'top' | 'bottom';
hideOnScroll?: boolean;
size?: number;
actions?: OptionsFab[];
}

export interface OptionsBottomTabs {
/**
* Show or hide the bottom tabs
Expand Down Expand Up @@ -713,6 +728,7 @@ export interface Options {
* Configure the top bar
*/
topBar?: OptionsTopBar;
fab?: OptionsFab;
/**
* Configure the bottom tabs
*/
Expand Down

0 comments on commit 13de5ca

Please sign in to comment.