Explorar el Código

Supporting tinting FAB icons

Guy Carmeli hace 6 años
padre
commit
5f9f00fd23

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/FabActionParams.java Ver fichero

@@ -7,4 +7,5 @@ public class FabActionParams {
7 7
     public String navigatorEventId;
8 8
     public Drawable icon;
9 9
     public StyleParams.Color backgroundColor;
10
+    public StyleParams.Color iconColor;
10 11
 }

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/params/FabParams.java Ver fichero

@@ -8,6 +8,8 @@ public class FabParams {
8 8
     public Drawable collapsedIcon;
9 9
     public Drawable expendedIcon;
10 10
     public StyleParams.Color backgroundColor;
11
+    public StyleParams.Color collapsedIconColor;
12
+    public StyleParams.Color expendedIconColor;
11 13
     public String collapsedId;
12 14
     public String expendedId;
13 15
     public String navigatorEventId;

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/FabActionParamsParser.java Ver fichero

@@ -5,6 +5,7 @@ import android.os.Bundle;
5 5
 import com.reactnativenavigation.params.FabActionParams;
6 6
 import com.reactnativenavigation.params.StyleParams;
7 7
 import com.reactnativenavigation.react.ImageLoader;
8
+import com.reactnativenavigation.utils.ViewUtils;
8 9
 
9 10
 public class FabActionParamsParser extends Parser {
10 11
     public FabActionParams parse(Bundle params, String navigatorEventId) {
@@ -13,6 +14,10 @@ public class FabActionParamsParser extends Parser {
13 14
         fabActionParams.navigatorEventId = navigatorEventId;
14 15
         fabActionParams.icon = ImageLoader.loadImage(params.getString("icon"));
15 16
         fabActionParams.backgroundColor = StyleParams.Color.parse(params, "backgroundColor");
17
+        fabActionParams.iconColor = StyleParams.Color.parse(params, "iconColor");
18
+        if (fabActionParams.iconColor.hasColor()) {
19
+            ViewUtils.tintDrawable(fabActionParams.icon, fabActionParams.iconColor.getColor(), true);
20
+        }
16 21
         return fabActionParams;
17 22
     }
18 23
 }

+ 12
- 0
android/app/src/main/java/com/reactnativenavigation/params/parsers/FabParamsParser.java Ver fichero

@@ -1,26 +1,32 @@
1 1
 package com.reactnativenavigation.params.parsers;
2 2
 
3
+import android.graphics.drawable.Drawable;
3 4
 import android.os.Bundle;
4 5
 
5 6
 import com.reactnativenavigation.params.FabActionParams;
6 7
 import com.reactnativenavigation.params.FabParams;
7 8
 import com.reactnativenavigation.params.StyleParams;
8 9
 import com.reactnativenavigation.react.ImageLoader;
10
+import com.reactnativenavigation.utils.ViewUtils;
9 11
 
10 12
 public class FabParamsParser extends Parser {
11 13
     public FabParams parse(Bundle params, final String navigatorEventId, String screenInstanceId) {
12 14
         FabParams fabParams = new FabParams();
13 15
         fabParams.collapsedId = params.getString("collapsedId");
14 16
         fabParams.expendedId = params.getString("expendedId");
17
+        fabParams.collapsedIconColor = getColor(params, "collapsedIconColor", new StyleParams.Color());
18
+        fabParams.expendedIconColor = getColor(params, "expendedIconColor", new StyleParams.Color());
15 19
         fabParams.navigatorEventId = navigatorEventId;
16 20
         fabParams.screenInstanceId = screenInstanceId;
17 21
         fabParams.backgroundColor = getColor(params, "backgroundColor", new StyleParams.Color());
18 22
 
19 23
         if (hasKey(params, "collapsedIcon")) {
20 24
             fabParams.collapsedIcon = ImageLoader.loadImage(params.getString("collapsedIcon"));
25
+            tintIcon(fabParams.collapsedIcon, fabParams.collapsedIconColor);
21 26
         }
22 27
         if (hasKey(params, "expendedIcon")) {
23 28
             fabParams.expendedIcon = ImageLoader.loadImage(params.getString("expendedIcon"));
29
+            tintIcon(fabParams.expendedIcon, fabParams.expendedIconColor);
24 30
         }
25 31
         if (hasKey(params, "actions")) {
26 32
             fabParams.actions = parseBundle(params.getBundle("actions"), new ParseStrategy<FabActionParams>() {
@@ -32,4 +38,10 @@ public class FabParamsParser extends Parser {
32 38
         }
33 39
         return fabParams;
34 40
     }
41
+
42
+    private void tintIcon(Drawable icon, StyleParams.Color color) {
43
+        if (color.hasColor()) {
44
+            ViewUtils.tintDrawable(icon, color.getColor(), true);
45
+        }
46
+    }
35 47
 }

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/views/FloatingActionButtonCoordinator.java Ver fichero

@@ -10,7 +10,6 @@ import android.support.annotation.NonNull;
10 10
 import android.support.annotation.Nullable;
11 11
 import android.support.design.widget.CoordinatorLayout;
12 12
 import android.support.design.widget.FloatingActionButton;
13
-import android.util.Log;
14 13
 import android.view.Gravity;
15 14
 import android.view.View;
16 15
 
@@ -42,7 +41,6 @@ class FloatingActionButtonCoordinator {
42 41
     }
43 42
 
44 43
     public void add(final FabParams params) {
45
-        Log.i(TAG, "add() called with: params = [" + params + "]");
46 44
         if (hasFab()) {
47 45
             remove(new Runnable() {
48 46
                 @Override

+ 9
- 0
src/deprecated/platformSpecificDeprecated.android.js Ver fichero

@@ -590,6 +590,12 @@ function getFab(screen) {
590 590
   if (fab.backgroundColor) {
591 591
     fab.backgroundColor = processColor(fab.backgroundColor);
592 592
   }
593
+  if (fab.collapsedIconColor) {
594
+    fab.collapsedIconColor = processColor(fab.collapsedIconColor);
595
+  }
596
+  if (fab.expendedIconColor) {
597
+    fab.expendedIconColor = processColor(fab.expendedIconColor);
598
+  }
593 599
 
594 600
   if (fab.actions) {
595 601
     _.forEach(fab.actions, (action) => {
@@ -597,6 +603,9 @@ function getFab(screen) {
597 603
       if (action.backgroundColor) {
598 604
         action.backgroundColor = processColor(action.backgroundColor)
599 605
       }
606
+      if (action.iconColor) {
607
+        action.iconColor = processColor(action.iconColor)
608
+      }
600 609
       return action;
601 610
     });
602 611
   }