Browse Source

Supporting tinting FAB icons

Guy Carmeli 6 years ago
parent
commit
5f9f00fd23

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/FabActionParams.java View File

7
     public String navigatorEventId;
7
     public String navigatorEventId;
8
     public Drawable icon;
8
     public Drawable icon;
9
     public StyleParams.Color backgroundColor;
9
     public StyleParams.Color backgroundColor;
10
+    public StyleParams.Color iconColor;
10
 }
11
 }

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/params/FabParams.java View File

8
     public Drawable collapsedIcon;
8
     public Drawable collapsedIcon;
9
     public Drawable expendedIcon;
9
     public Drawable expendedIcon;
10
     public StyleParams.Color backgroundColor;
10
     public StyleParams.Color backgroundColor;
11
+    public StyleParams.Color collapsedIconColor;
12
+    public StyleParams.Color expendedIconColor;
11
     public String collapsedId;
13
     public String collapsedId;
12
     public String expendedId;
14
     public String expendedId;
13
     public String navigatorEventId;
15
     public String navigatorEventId;

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

5
 import com.reactnativenavigation.params.FabActionParams;
5
 import com.reactnativenavigation.params.FabActionParams;
6
 import com.reactnativenavigation.params.StyleParams;
6
 import com.reactnativenavigation.params.StyleParams;
7
 import com.reactnativenavigation.react.ImageLoader;
7
 import com.reactnativenavigation.react.ImageLoader;
8
+import com.reactnativenavigation.utils.ViewUtils;
8
 
9
 
9
 public class FabActionParamsParser extends Parser {
10
 public class FabActionParamsParser extends Parser {
10
     public FabActionParams parse(Bundle params, String navigatorEventId) {
11
     public FabActionParams parse(Bundle params, String navigatorEventId) {
13
         fabActionParams.navigatorEventId = navigatorEventId;
14
         fabActionParams.navigatorEventId = navigatorEventId;
14
         fabActionParams.icon = ImageLoader.loadImage(params.getString("icon"));
15
         fabActionParams.icon = ImageLoader.loadImage(params.getString("icon"));
15
         fabActionParams.backgroundColor = StyleParams.Color.parse(params, "backgroundColor");
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
         return fabActionParams;
21
         return fabActionParams;
17
     }
22
     }
18
 }
23
 }

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

1
 package com.reactnativenavigation.params.parsers;
1
 package com.reactnativenavigation.params.parsers;
2
 
2
 
3
+import android.graphics.drawable.Drawable;
3
 import android.os.Bundle;
4
 import android.os.Bundle;
4
 
5
 
5
 import com.reactnativenavigation.params.FabActionParams;
6
 import com.reactnativenavigation.params.FabActionParams;
6
 import com.reactnativenavigation.params.FabParams;
7
 import com.reactnativenavigation.params.FabParams;
7
 import com.reactnativenavigation.params.StyleParams;
8
 import com.reactnativenavigation.params.StyleParams;
8
 import com.reactnativenavigation.react.ImageLoader;
9
 import com.reactnativenavigation.react.ImageLoader;
10
+import com.reactnativenavigation.utils.ViewUtils;
9
 
11
 
10
 public class FabParamsParser extends Parser {
12
 public class FabParamsParser extends Parser {
11
     public FabParams parse(Bundle params, final String navigatorEventId, String screenInstanceId) {
13
     public FabParams parse(Bundle params, final String navigatorEventId, String screenInstanceId) {
12
         FabParams fabParams = new FabParams();
14
         FabParams fabParams = new FabParams();
13
         fabParams.collapsedId = params.getString("collapsedId");
15
         fabParams.collapsedId = params.getString("collapsedId");
14
         fabParams.expendedId = params.getString("expendedId");
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
         fabParams.navigatorEventId = navigatorEventId;
19
         fabParams.navigatorEventId = navigatorEventId;
16
         fabParams.screenInstanceId = screenInstanceId;
20
         fabParams.screenInstanceId = screenInstanceId;
17
         fabParams.backgroundColor = getColor(params, "backgroundColor", new StyleParams.Color());
21
         fabParams.backgroundColor = getColor(params, "backgroundColor", new StyleParams.Color());
18
 
22
 
19
         if (hasKey(params, "collapsedIcon")) {
23
         if (hasKey(params, "collapsedIcon")) {
20
             fabParams.collapsedIcon = ImageLoader.loadImage(params.getString("collapsedIcon"));
24
             fabParams.collapsedIcon = ImageLoader.loadImage(params.getString("collapsedIcon"));
25
+            tintIcon(fabParams.collapsedIcon, fabParams.collapsedIconColor);
21
         }
26
         }
22
         if (hasKey(params, "expendedIcon")) {
27
         if (hasKey(params, "expendedIcon")) {
23
             fabParams.expendedIcon = ImageLoader.loadImage(params.getString("expendedIcon"));
28
             fabParams.expendedIcon = ImageLoader.loadImage(params.getString("expendedIcon"));
29
+            tintIcon(fabParams.expendedIcon, fabParams.expendedIconColor);
24
         }
30
         }
25
         if (hasKey(params, "actions")) {
31
         if (hasKey(params, "actions")) {
26
             fabParams.actions = parseBundle(params.getBundle("actions"), new ParseStrategy<FabActionParams>() {
32
             fabParams.actions = parseBundle(params.getBundle("actions"), new ParseStrategy<FabActionParams>() {
32
         }
38
         }
33
         return fabParams;
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 View File

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

+ 9
- 0
src/deprecated/platformSpecificDeprecated.android.js View File

590
   if (fab.backgroundColor) {
590
   if (fab.backgroundColor) {
591
     fab.backgroundColor = processColor(fab.backgroundColor);
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
   if (fab.actions) {
600
   if (fab.actions) {
595
     _.forEach(fab.actions, (action) => {
601
     _.forEach(fab.actions, (action) => {
597
       if (action.backgroundColor) {
603
       if (action.backgroundColor) {
598
         action.backgroundColor = processColor(action.backgroundColor)
604
         action.backgroundColor = processColor(action.backgroundColor)
599
       }
605
       }
606
+      if (action.iconColor) {
607
+        action.iconColor = processColor(action.iconColor)
608
+      }
600
       return action;
609
       return action;
601
     });
610
     });
602
   }
611
   }