Browse Source

Add disabledColor property to TitleBar buttons

Can also be set cross app by using titleBarDisabledButtonColor property in appStyle
Guy Carmeli 8 years ago
parent
commit
db82290c0a

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

19
             return color != null;
19
             return color != null;
20
         }
20
         }
21
 
21
 
22
+        @ColorInt
22
         public int getColor() {
23
         public int getColor() {
23
             if (!hasColor()) {
24
             if (!hasColor()) {
24
                 throw new RuntimeException("Color undefined");
25
                 throw new RuntimeException("Color undefined");
44
     public boolean titleBarHidden;
45
     public boolean titleBarHidden;
45
     public Color titleBarTitleColor;
46
     public Color titleBarTitleColor;
46
     public Color titleBarButtonColor;
47
     public Color titleBarButtonColor;
48
+    public Color titleBarDisabledButtonColor;
47
     public boolean backButtonHidden;
49
     public boolean backButtonHidden;
48
 
50
 
49
     public Color topTabTextColor;
51
     public Color topTabTextColor;

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

21
     public String label;
21
     public String label;
22
     public Drawable icon;
22
     public Drawable icon;
23
     public StyleParams.Color color;
23
     public StyleParams.Color color;
24
+    public StyleParams.Color disabledColor;
24
     public ShowAsAction showAsAction;
25
     public ShowAsAction showAsAction;
25
     public boolean enabled = true;
26
     public boolean enabled = true;
26
 
27
 

+ 8
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/StyleParamsParser.java View File

1
 package com.reactnativenavigation.params.parsers;
1
 package com.reactnativenavigation.params.parsers;
2
 
2
 
3
+import android.graphics.Color;
3
 import android.os.Bundle;
4
 import android.os.Bundle;
4
 import android.support.annotation.NonNull;
5
 import android.support.annotation.NonNull;
5
 import android.support.annotation.Nullable;
6
 import android.support.annotation.Nullable;
26
         result.titleBarHidden = getBoolean("titleBarHidden", getDefaultTopBarHidden());
27
         result.titleBarHidden = getBoolean("titleBarHidden", getDefaultTopBarHidden());
27
         result.titleBarTitleColor = getColor("titleBarTitleColor", getDefaultTitleBarColor());
28
         result.titleBarTitleColor = getColor("titleBarTitleColor", getDefaultTitleBarColor());
28
         result.titleBarButtonColor = getColor("titleBarButtonColor", getTitleBarButtonColor());
29
         result.titleBarButtonColor = getColor("titleBarButtonColor", getTitleBarButtonColor());
30
+        result.titleBarDisabledButtonColor = getColor("titleBarDisabledButtonColor", getTitleBarDisabledButtonColor());
29
         result.backButtonHidden = getBoolean("backButtonHidden", getDefaultBackButtonHidden());
31
         result.backButtonHidden = getBoolean("backButtonHidden", getDefaultBackButtonHidden());
30
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
32
         result.topTabsHidden = getBoolean("topTabsHidden", getDefaultTopTabsHidden());
31
 
33
 
40
 
42
 
41
         result.bottomTabsHidden = getBoolean("bottomTabsHidden", getDefaultBottomTabsHidden());
43
         result.bottomTabsHidden = getBoolean("bottomTabsHidden", getDefaultBottomTabsHidden());
42
         result.drawScreenAboveBottomTabs = !result.bottomTabsHidden &&
44
         result.drawScreenAboveBottomTabs = !result.bottomTabsHidden &&
43
-                params.getBoolean("drawScreenAboveBottomTabs", getDefaultDrawScreenAboveBottomTabs());
45
+                                           params.getBoolean("drawScreenAboveBottomTabs", getDefaultDrawScreenAboveBottomTabs());
44
         result.bottomTabsHiddenOnScroll =
46
         result.bottomTabsHiddenOnScroll =
45
                 getBoolean("bottomTabsHiddenOnScroll", getDefaultBottomTabsHiddenOnScroll());
47
                 getBoolean("bottomTabsHiddenOnScroll", getDefaultBottomTabsHiddenOnScroll());
46
         result.bottomTabsColor = getColor("bottomTabsColor", getDefaultBottomTabsColor());
48
         result.bottomTabsColor = getColor("bottomTabsColor", getDefaultBottomTabsColor());
128
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.titleBarButtonColor;
130
         return AppStyle.appStyle == null ? new StyleParams.Color() : AppStyle.appStyle.titleBarButtonColor;
129
     }
131
     }
130
 
132
 
133
+    @Nullable
134
+    private StyleParams.Color getTitleBarDisabledButtonColor() {
135
+        return AppStyle.appStyle == null ? new StyleParams.Color(Color.LTGRAY) : AppStyle.appStyle.titleBarDisabledButtonColor;
136
+    }
137
+
131
     private boolean getDefaultTopBarHidden() {
138
     private boolean getDefaultTopBarHidden() {
132
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarHidden;
139
         return AppStyle.appStyle != null && AppStyle.appStyle.titleBarHidden;
133
     }
140
     }

+ 4
- 3
android/app/src/main/java/com/reactnativenavigation/params/parsers/TitleBarButtonParamsParser.java View File

26
         if (hasKey(bundle,"icon")) {
26
         if (hasKey(bundle,"icon")) {
27
             result.icon = ImageLoader.loadImage(bundle.getString("icon"));
27
             result.icon = ImageLoader.loadImage(bundle.getString("icon"));
28
         }
28
         }
29
-        result.color = getColor(bundle, AppStyle.appStyle.titleBarButtonColor);
29
+        result.color = getColor(bundle, "color", AppStyle.appStyle.titleBarButtonColor);
30
+        result.disabledColor = getColor(bundle, "disabledColor", AppStyle.appStyle.titleBarDisabledButtonColor);
30
         result.showAsAction = parseShowAsAction(bundle.getString("showAsAction"));
31
         result.showAsAction = parseShowAsAction(bundle.getString("showAsAction"));
31
         result.enabled = bundle.getBoolean("enabled", true);
32
         result.enabled = bundle.getBoolean("enabled", true);
32
         result.eventId = bundle.getString("id");
33
         result.eventId = bundle.getString("id");
33
         return result;
34
         return result;
34
     }
35
     }
35
 
36
 
36
-    private StyleParams.Color getColor(Bundle bundle, StyleParams.Color defaultColor) {
37
-        StyleParams.Color color = StyleParams.Color.parse(bundle.getString("color"));
37
+    private StyleParams.Color getColor(Bundle bundle, String key, StyleParams.Color defaultColor) {
38
+        StyleParams.Color color = StyleParams.Color.parse(bundle.getString(key));
38
         return color.hasColor() || defaultColor == null ? color : defaultColor;
39
         return color.hasColor() || defaultColor == null ? color : defaultColor;
39
     }
40
     }
40
 
41
 

+ 4
- 2
android/app/src/main/java/com/reactnativenavigation/utils/ViewUtils.java View File

1
 package com.reactnativenavigation.utils;
1
 package com.reactnativenavigation.utils;
2
 
2
 
3
 import android.content.Context;
3
 import android.content.Context;
4
-import android.graphics.Color;
5
 import android.graphics.PorterDuff;
4
 import android.graphics.PorterDuff;
6
 import android.graphics.PorterDuffColorFilter;
5
 import android.graphics.PorterDuffColorFilter;
7
 import android.graphics.drawable.Drawable;
6
 import android.graphics.drawable.Drawable;
12
 import android.view.WindowManager;
11
 import android.view.WindowManager;
13
 
12
 
14
 import com.reactnativenavigation.NavigationApplication;
13
 import com.reactnativenavigation.NavigationApplication;
14
+import com.reactnativenavigation.params.AppStyle;
15
 
15
 
16
 import java.util.concurrent.atomic.AtomicInteger;
16
 import java.util.concurrent.atomic.AtomicInteger;
17
 
17
 
33
     }
33
     }
34
 
34
 
35
     public static void tintDrawable(Drawable drawable, int tint, boolean enabled) {
35
     public static void tintDrawable(Drawable drawable, int tint, boolean enabled) {
36
-        drawable.setColorFilter(new PorterDuffColorFilter(enabled ? tint : Color.LTGRAY, PorterDuff.Mode.SRC_IN));
36
+        drawable.setColorFilter(new PorterDuffColorFilter(enabled ? tint :
37
+                AppStyle.appStyle.titleBarDisabledButtonColor.getColor(),
38
+                PorterDuff.Mode.SRC_IN));
37
     }
39
     }
38
 
40
 
39
     public static float convertDpToPixel(float dp) {
41
     public static float convertDpToPixel(float dp) {