Browse Source

Add Support for all common color formats on Android (#497)

closes #454
Guy Carmeli 8 years ago
parent
commit
7074da20a0

+ 9
- 1
android/app/src/main/java/com/reactnativenavigation/bridge/BundleConverter.java View File

19
                     bundle.putBoolean(key, map.getBoolean(key));
19
                     bundle.putBoolean(key, map.getBoolean(key));
20
                     break;
20
                     break;
21
                 case Number:
21
                 case Number:
22
-                    bundle.putDouble(key, map.getDouble(key));
22
+                    putNumber(bundle, map, key);
23
                     break;
23
                     break;
24
                 case String:
24
                 case String:
25
                     bundle.putString(key, map.getString(key));
25
                     bundle.putString(key, map.getString(key));
37
         return bundle;
37
         return bundle;
38
     }
38
     }
39
 
39
 
40
+    private static void putNumber(Bundle bundle, ReadableMap map, String key) {
41
+        try {
42
+            bundle.putInt(key, map.getInt(key));
43
+        } catch (Exception e) {
44
+            bundle.putDouble(key, map.getDouble(key));
45
+        }
46
+    }
47
+
40
     public static Bundle toBundle(ReadableArray array) {
48
     public static Bundle toBundle(ReadableArray array) {
41
         Bundle bundle = new Bundle();
49
         Bundle bundle = new Bundle();
42
         for (int i = 0; i < array.size(); i++) {
50
         for (int i = 0; i < array.size(); i++) {

+ 3
- 5
android/app/src/main/java/com/reactnativenavigation/params/StyleParams.java View File

1
 package com.reactnativenavigation.params;
1
 package com.reactnativenavigation.params;
2
 
2
 
3
+import android.os.Bundle;
3
 import android.support.annotation.ColorInt;
4
 import android.support.annotation.ColorInt;
4
 
5
 
5
 public class StyleParams {
6
 public class StyleParams {
27
             return color;
28
             return color;
28
         }
29
         }
29
 
30
 
30
-        public static Color parse(String str) {
31
-            if (str == null) {
32
-                return new Color();
33
-            }
34
-            return new Color(android.graphics.Color.parseColor(str));
31
+        public static Color parse(Bundle bundle, String key) {
32
+            return bundle.containsKey(key) ? new Color(bundle.getInt(key)) : new Color();
35
         }
33
         }
36
     }
34
     }
37
 
35
 

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

22
         ContextualMenuButtonParams result = new ContextualMenuButtonParams();
22
         ContextualMenuButtonParams result = new ContextualMenuButtonParams();
23
         result.icon = ImageLoader.loadImage(button.getString("icon"));
23
         result.icon = ImageLoader.loadImage(button.getString("icon"));
24
         result.showAsAction = parseShowAsAction(button.getString("showAsAction"));
24
         result.showAsAction = parseShowAsAction(button.getString("showAsAction"));
25
-        result.color = StyleParams.Color.parse(button.getString("color"));
25
+        result.color = StyleParams.Color.parse(button, "color");
26
         result.label = button.getString("label");
26
         result.label = button.getString("label");
27
         result.index = (int) button.getDouble("index");
27
         result.index = (int) button.getDouble("index");
28
         return result;
28
         return result;

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

12
         fabActionParams.id = params.getString("id");
12
         fabActionParams.id = params.getString("id");
13
         fabActionParams.navigatorEventId = navigatorEventId;
13
         fabActionParams.navigatorEventId = navigatorEventId;
14
         fabActionParams.icon = ImageLoader.loadImage(params.getString("icon"));
14
         fabActionParams.icon = ImageLoader.loadImage(params.getString("icon"));
15
-        fabActionParams.backgroundColor = StyleParams.Color.parse(params.getString("backgroundColor"));
15
+        fabActionParams.backgroundColor = StyleParams.Color.parse(params, "backgroundColor");
16
         return fabActionParams;
16
         return fabActionParams;
17
     }
17
     }
18
 }
18
 }

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

38
     }
38
     }
39
 
39
 
40
     protected StyleParams.Color getColor(Bundle bundle, String key, StyleParams.Color defaultColor) {
40
     protected StyleParams.Color getColor(Bundle bundle, String key, StyleParams.Color defaultColor) {
41
-        StyleParams.Color color = StyleParams.Color.parse(bundle.getString(key));
41
+        StyleParams.Color color = StyleParams.Color.parse(bundle, key);
42
         return color.hasColor() || defaultColor == null ? color : defaultColor;
42
         return color.hasColor() || defaultColor == null ? color : defaultColor;
43
     }
43
     }
44
 }
44
 }

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

193
     }
193
     }
194
 
194
 
195
     private StyleParams.Color getColor(String key, StyleParams.Color defaultColor) {
195
     private StyleParams.Color getColor(String key, StyleParams.Color defaultColor) {
196
-        StyleParams.Color color = StyleParams.Color.parse(params.getString(key));
196
+        StyleParams.Color color = StyleParams.Color.parse(params, key);
197
         if (color.hasColor()) {
197
         if (color.hasColor()) {
198
             return color;
198
             return color;
199
         } else {
199
         } else {

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java View File

1
 package com.reactnativenavigation.views;
1
 package com.reactnativenavigation.views;
2
 
2
 
3
 import android.content.Context;
3
 import android.content.Context;
4
-import android.util.Log;
5
 import android.view.View;
4
 import android.view.View;
6
 
5
 
7
 import com.facebook.react.ReactRootView;
6
 import com.facebook.react.ReactRootView;
52
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
51
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
53
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
52
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
54
         int measuredHeight = viewMeasurer.getMeasuredHeight(heightMeasureSpec);
53
         int measuredHeight = viewMeasurer.getMeasuredHeight(heightMeasureSpec);
55
-        Log.i("Guy", "measuredHeight: " + measuredHeight + " " + getClass().getSimpleName());
56
         setMeasuredDimension(viewMeasurer.getMeasuredWidth(widthMeasureSpec),
54
         setMeasuredDimension(viewMeasurer.getMeasuredWidth(widthMeasureSpec),
57
                 measuredHeight);
55
                 measuredHeight);
58
     }
56
     }

+ 20
- 20
src/deprecated/platformSpecificDeprecated.android.js View File

116
   }
116
   }
117
 
117
 
118
   let ret = {
118
   let ret = {
119
-    statusBarColor: originalStyleObject.statusBarColor,
120
-    topBarColor: originalStyleObject.navBarBackgroundColor,
119
+    statusBarColor: processColor(originalStyleObject.statusBarColor),
120
+    topBarColor: processColor(originalStyleObject.navBarBackgroundColor),
121
     topBarTransparent: originalStyleObject.navBarTransparent,
121
     topBarTransparent: originalStyleObject.navBarTransparent,
122
     topBarTranslucent: originalStyleObject.navBarTranslucent,
122
     topBarTranslucent: originalStyleObject.navBarTranslucent,
123
     collapsingToolBarImage: originalStyleObject.collapsingToolBarImage,
123
     collapsingToolBarImage: originalStyleObject.collapsingToolBarImage,
124
-    collapsingToolBarCollapsedColor: originalStyleObject.collapsingToolBarCollapsedColor,
124
+    collapsingToolBarCollapsedColor: processColor(originalStyleObject.collapsingToolBarCollapsedColor),
125
     titleBarHidden: originalStyleObject.navBarHidden,
125
     titleBarHidden: originalStyleObject.navBarHidden,
126
     titleBarHideOnScroll: originalStyleObject.navBarHideOnScroll,
126
     titleBarHideOnScroll: originalStyleObject.navBarHideOnScroll,
127
-    titleBarTitleColor: originalStyleObject.navBarTextColor,
128
-    titleBarSubtitleColor: originalStyleObject.navBarTextSubtitleColor,
129
-    titleBarButtonColor: originalStyleObject.navBarButtonColor,
130
-    titleBarDisabledButtonColor: originalStyleObject.titleBarDisabledButtonColor,
127
+    titleBarTitleColor: processColor(originalStyleObject.navBarTextColor),
128
+    titleBarSubtitleColor: processColor(originalStyleObject.navBarTextSubtitleColor),
129
+    titleBarButtonColor: processColor(originalStyleObject.navBarButtonColor),
130
+    titleBarDisabledButtonColor: processColor(originalStyleObject.titleBarDisabledButtonColor),
131
     backButtonHidden: originalStyleObject.backButtonHidden,
131
     backButtonHidden: originalStyleObject.backButtonHidden,
132
     topTabsHidden: originalStyleObject.topTabsHidden,
132
     topTabsHidden: originalStyleObject.topTabsHidden,
133
-    contextualMenuStatusBarColor: originalStyleObject.contextualMenuStatusBarColor,
134
-    contextualMenuBackgroundColor: originalStyleObject.contextualMenuBackgroundColor,
135
-    contextualMenuButtonsColor: originalStyleObject.contextualMenuButtonsColor,
133
+    contextualMenuStatusBarColor: processColor(originalStyleObject.contextualMenuStatusBarColor),
134
+    contextualMenuBackgroundColor: processColor(originalStyleObject.contextualMenuBackgroundColor),
135
+    contextualMenuButtonsColor: processColor(originalStyleObject.contextualMenuButtonsColor),
136
 
136
 
137
     drawBelowTopBar: !originalStyleObject.drawUnderNavBar,
137
     drawBelowTopBar: !originalStyleObject.drawUnderNavBar,
138
 
138
 
139
-    topTabTextColor: originalStyleObject.topTabTextColor,
140
-    selectedTopTabTextColor: originalStyleObject.selectedTopTabTextColor,
139
+    topTabTextColor: processColor(originalStyleObject.topTabTextColor),
140
+    selectedTopTabTextColor: processColor(originalStyleObject.selectedTopTabTextColor),
141
     selectedTopTabIndicatorHeight: originalStyleObject.selectedTopTabIndicatorHeight,
141
     selectedTopTabIndicatorHeight: originalStyleObject.selectedTopTabIndicatorHeight,
142
-    selectedTopTabIndicatorColor: originalStyleObject.selectedTopTabIndicatorColor,
142
+    selectedTopTabIndicatorColor: processColor(originalStyleObject.selectedTopTabIndicatorColor),
143
 
143
 
144
-    screenBackgroundColor: originalStyleObject.screenBackgroundColor,
144
+    screenBackgroundColor: processColor(originalStyleObject.screenBackgroundColor),
145
 
145
 
146
     drawScreenAboveBottomTabs: !originalStyleObject.drawUnderTabBar,
146
     drawScreenAboveBottomTabs: !originalStyleObject.drawUnderTabBar,
147
 
147
 
148
-    bottomTabsColor: originalStyleObject.tabBarBackgroundColor,
149
-    bottomTabsButtonColor: originalStyleObject.tabBarButtonColor,
150
-    bottomTabsSelectedButtonColor: originalStyleObject.tabBarSelectedButtonColor,
148
+    bottomTabsColor: processColor(originalStyleObject.tabBarBackgroundColor),
149
+    bottomTabsButtonColor: processColor(originalStyleObject.tabBarButtonColor),
150
+    bottomTabsSelectedButtonColor: processColor(originalStyleObject.tabBarSelectedButtonColor),
151
     bottomTabsHidden: originalStyleObject.tabBarHidden,
151
     bottomTabsHidden: originalStyleObject.tabBarHidden,
152
     bottomTabsHiddenOnScroll: originalStyleObject.bottomTabsHiddenOnScroll,
152
     bottomTabsHiddenOnScroll: originalStyleObject.bottomTabsHiddenOnScroll,
153
     forceTitlesDisplay: originalStyleObject.forceTitlesDisplay,
153
     forceTitlesDisplay: originalStyleObject.forceTitlesDisplay,
154
-    bottomTabBadgeTextColor: originalStyleObject.bottomTabBadgeTextColor,
155
-    bottomTabBadgeBackgroundColor: originalStyleObject.bottomTabBadgeBackgroundColor,
154
+    bottomTabBadgeTextColor: processColor(originalStyleObject.bottomTabBadgeTextColor),
155
+    bottomTabBadgeBackgroundColor: processColor(originalStyleObject.bottomTabBadgeBackgroundColor),
156
 
156
 
157
-    navigationBarColor: originalStyleObject.navigationBarColor
157
+    navigationBarColor: processColor(originalStyleObject.navigationBarColor)
158
   }
158
   }
159
 
159
 
160
   if (originalStyleObject.collapsingToolBarImage) {
160
   if (originalStyleObject.collapsingToolBarImage) {