소스 검색

Add fab.iconColor option

Closes #3664
Guy Carmeli 6 년 전
부모
커밋
13de5cab70

+ 8
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/FabOptions.java 파일 보기

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

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/presentation/FabPresenter.java 파일 보기

255
             fab.setColorRipple(options.rippleColor.get());
255
             fab.setColorRipple(options.rippleColor.get());
256
         }
256
         }
257
         if (options.icon.hasValue()) {
257
         if (options.icon.hasValue()) {
258
-            fab.applyIcon(options.icon.get());
258
+            fab.applyIcon(options.icon.get(), options.iconColor);
259
         }
259
         }
260
         if (options.size.hasValue()) {
260
         if (options.size.hasValue()) {
261
             fab.setButtonSize("mini".equals(options.size.get()) ? SIZE_MINI : SIZE_NORMAL);
261
             fab.setButtonSize("mini".equals(options.size.get()) ? SIZE_MINI : SIZE_NORMAL);
285
             fab.setColorRipple(options.rippleColor.get());
285
             fab.setColorRipple(options.rippleColor.get());
286
         }
286
         }
287
         if (options.icon.hasValue()) {
287
         if (options.icon.hasValue()) {
288
-            fab.applyIcon(options.icon.get());
288
+            fab.applyIcon(options.icon.get(), options.iconColor);
289
         }
289
         }
290
         if (options.size.hasValue()) {
290
         if (options.size.hasValue()) {
291
             fab.setButtonSize("mini".equals(options.size.get()) ? SIZE_MINI : SIZE_NORMAL);
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 파일 보기

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.graphics.PorterDuff;
5
+import android.graphics.PorterDuffColorFilter;
4
 import android.graphics.drawable.Drawable;
6
 import android.graphics.drawable.Drawable;
5
 import android.support.annotation.NonNull;
7
 import android.support.annotation.NonNull;
6
 
8
 
8
 import com.reactnativenavigation.anim.FabAnimator;
10
 import com.reactnativenavigation.anim.FabAnimator;
9
 import com.reactnativenavigation.anim.FabCollapseBehaviour;
11
 import com.reactnativenavigation.anim.FabCollapseBehaviour;
10
 import com.reactnativenavigation.interfaces.ScrollEventListener;
12
 import com.reactnativenavigation.interfaces.ScrollEventListener;
13
+import com.reactnativenavigation.parse.params.Colour;
11
 import com.reactnativenavigation.utils.ImageLoader;
14
 import com.reactnativenavigation.utils.ImageLoader;
12
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
15
 import com.reactnativenavigation.utils.ImageLoadingListenerAdapter;
13
 
16
 
26
         this.id = id;
29
         this.id = id;
27
     }
30
     }
28
 
31
 
29
-    public void applyIcon(String icon) {
32
+    public void applyIcon(String icon, Colour color) {
30
         new ImageLoader().loadIcons(getContext(), Collections.singletonList(icon), new ImageLoadingListenerAdapter() {
33
         new ImageLoader().loadIcons(getContext(), Collections.singletonList(icon), new ImageLoadingListenerAdapter() {
31
             @Override
34
             @Override
32
             public void onComplete(@NonNull List<Drawable> drawables) {
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
                 setImageDrawable(drawables.get(0));
37
                 setImageDrawable(drawables.get(0));
34
             }
38
             }
35
 
39
 

+ 16
- 0
lib/src/interfaces/Options.ts 파일 보기

380
   elevation?: AndroidDensityNumber;
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
 export interface OptionsBottomTabs {
398
 export interface OptionsBottomTabs {
384
   /**
399
   /**
385
    * Show or hide the bottom tabs
400
    * Show or hide the bottom tabs
713
    * Configure the top bar
728
    * Configure the top bar
714
    */
729
    */
715
   topBar?: OptionsTopBar;
730
   topBar?: OptionsTopBar;
731
+  fab?: OptionsFab;
716
   /**
732
   /**
717
    * Configure the bottom tabs
733
    * Configure the bottom tabs
718
    */
734
    */