Kaynağa Gözat

Add fab.iconColor option

Closes #3664
Guy Carmeli 5 yıl önce
ebeveyn
işleme
13de5cab70

+ 8
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/FabOptions.java Dosyayı Görüntüle

@@ -30,6 +30,7 @@ public class FabOptions {
30 30
         if (json.has("icon")) {
31 31
             options.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
32 32
         }
33
+        options.iconColor = ColorParser.parse(json, "iconColor");
33 34
         if (json.has("actions")) {
34 35
             JSONArray fabsArray = json.optJSONArray("actions");
35 36
             for (int i = 0; i < fabsArray.length(); i++) {
@@ -49,6 +50,7 @@ public class FabOptions {
49 50
     public Colour clickColor = new NullColor();
50 51
     public Colour rippleColor = new NullColor();
51 52
     public Text icon = new NullText();
53
+    public Colour iconColor = new NullColor();
52 54
     public Bool visible = new NullBool();
53 55
     public ArrayList<FabOptions> actionsArray = new ArrayList<>();
54 56
     public Text alignHorizontally = new NullText();
@@ -75,6 +77,9 @@ public class FabOptions {
75 77
         if (other.icon.hasValue()) {
76 78
             icon = other.icon;
77 79
         }
80
+        if (other.iconColor.hasValue()) {
81
+            iconColor = other.iconColor;
82
+        }
78 83
         if (other.actionsArray.size() > 0) {
79 84
             actionsArray = other.actionsArray;
80 85
         }
@@ -111,6 +116,9 @@ public class FabOptions {
111 116
         if (!icon.hasValue()) {
112 117
             icon = defaultOptions.icon;
113 118
         }
119
+        if (!iconColor.hasValue()) {
120
+            iconColor = defaultOptions.iconColor;
121
+        }
114 122
         if (actionsArray.size() == 0) {
115 123
             actionsArray = defaultOptions.actionsArray;
116 124
         }

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/presentation/FabPresenter.java Dosyayı Görüntüle

@@ -255,7 +255,7 @@ public class FabPresenter {
255 255
             fab.setColorRipple(options.rippleColor.get());
256 256
         }
257 257
         if (options.icon.hasValue()) {
258
-            fab.applyIcon(options.icon.get());
258
+            fab.applyIcon(options.icon.get(), options.iconColor);
259 259
         }
260 260
         if (options.size.hasValue()) {
261 261
             fab.setButtonSize("mini".equals(options.size.get()) ? SIZE_MINI : SIZE_NORMAL);
@@ -285,7 +285,7 @@ public class FabPresenter {
285 285
             fab.setColorRipple(options.rippleColor.get());
286 286
         }
287 287
         if (options.icon.hasValue()) {
288
-            fab.applyIcon(options.icon.get());
288
+            fab.applyIcon(options.icon.get(), options.iconColor);
289 289
         }
290 290
         if (options.size.hasValue()) {
291 291
             fab.setButtonSize("mini".equals(options.size.get()) ? SIZE_MINI : SIZE_NORMAL);

+ 5
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/Fab.java Dosyayı Görüntüle

@@ -1,6 +1,8 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3 3
 import android.content.Context;
4
+import android.graphics.PorterDuff;
5
+import android.graphics.PorterDuffColorFilter;
4 6
 import android.graphics.drawable.Drawable;
5 7
 import android.support.annotation.NonNull;
6 8
 
@@ -8,6 +10,7 @@ import com.github.clans.fab.FloatingActionButton;
8 10
 import com.reactnativenavigation.anim.FabAnimator;
9 11
 import com.reactnativenavigation.anim.FabCollapseBehaviour;
10 12
 import com.reactnativenavigation.interfaces.ScrollEventListener;
13
+import com.reactnativenavigation.parse.params.Colour;
11 14
 import com.reactnativenavigation.utils.ImageLoader;
12 15
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
13 16
 
@@ -26,10 +29,11 @@ public class Fab extends FloatingActionButton implements FabAnimator {
26 29
         this.id = id;
27 30
     }
28 31
 
29
-    public void applyIcon(String icon) {
32
+    public void applyIcon(String icon, Colour color) {
30 33
         new ImageLoader().loadIcons(getContext(), Collections.singletonList(icon), new ImageLoadingListenerAdapter() {
31 34
             @Override
32 35
             public void onComplete(@NonNull List<Drawable> drawables) {
36
+                if (color.hasValue()) drawables.get(0).setColorFilter(new PorterDuffColorFilter(color.get(), PorterDuff.Mode.SRC_IN));
33 37
                 setImageDrawable(drawables.get(0));
34 38
             }
35 39
 

+ 16
- 0
lib/src/interfaces/Options.ts Dosyayı Görüntüle

@@ -380,6 +380,21 @@ export interface OptionsTopBar {
380 380
   elevation?: AndroidDensityNumber;
381 381
 }
382 382
 
383
+export interface OptionsFab {
384
+  id: string;
385
+  backgroundColor?: Color;
386
+  clickColor?: Color;
387
+  rippleColor?: Color;
388
+  visible?: boolean;
389
+  icon?: ImageRequireSource;
390
+  iconColor?: Color;
391
+  alignHorizontally?: 'left' | 'right';
392
+  alignVertically?: 'top' | 'bottom';
393
+  hideOnScroll?: boolean;
394
+  size?: number;
395
+  actions?: OptionsFab[];
396
+}
397
+
383 398
 export interface OptionsBottomTabs {
384 399
   /**
385 400
    * Show or hide the bottom tabs
@@ -713,6 +728,7 @@ export interface Options {
713 728
    * Configure the top bar
714 729
    */
715 730
   topBar?: OptionsTopBar;
731
+  fab?: OptionsFab;
716 732
   /**
717 733
    * Configure the bottom tabs
718 734
    */