Procházet zdrojové kódy

Support selectedIcon options on Android

Guy Carmeli před 5 roky
rodič
revize
45e8389b2b

+ 1
- 1
lib/android/app/build.gradle Zobrazit soubor

@@ -97,7 +97,7 @@ dependencies {
97 97
     implementation 'androidx.annotation:annotation:1.1.0'
98 98
     implementation 'com.google.android.material:material:1.1.0-alpha08'
99 99
 
100
-    implementation 'com.github.wix-playground:ahbottomnavigation:3.0.2'
100
+    implementation 'com.github.wix-playground:ahbottomnavigation:3.0.5'
101 101
     implementation 'com.github.wix-playground:reflow-animator:1.0.4'
102 102
     implementation 'com.github.clans:fab:1.6.4'
103 103
 

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/BottomTabOptions.java Zobrazit soubor

@@ -30,6 +30,7 @@ public class BottomTabOptions {
30 30
         options.textColor = ColorParser.parse(json, "textColor");
31 31
         options.selectedTextColor = ColorParser.parse(json, "selectedTextColor");
32 32
         if (json.has("icon")) options.icon = TextParser.parse(json.optJSONObject("icon"), "uri");
33
+        if (json.has("selectedIcon")) options.selectedIcon = TextParser.parse(json.optJSONObject("selectedIcon"), "uri");
33 34
         options.iconColor = ColorParser.parse(json, "iconColor");
34 35
         options.selectedIconColor = ColorParser.parse(json, "selectedIconColor");
35 36
         options.badge = TextParser.parse(json, "badge");
@@ -47,6 +48,7 @@ public class BottomTabOptions {
47 48
     public Colour textColor = new NullColor();
48 49
     public Colour selectedTextColor = new NullColor();
49 50
     public Text icon = new NullText();
51
+    public Text selectedIcon = new NullText();
50 52
     public Colour iconColor = new NullColor();
51 53
     public Colour selectedIconColor = new NullColor();
52 54
     public Text testId = new NullText();
@@ -64,6 +66,7 @@ public class BottomTabOptions {
64 66
         if (other.textColor.hasValue()) textColor = other.textColor;
65 67
         if (other.selectedTextColor.hasValue()) selectedTextColor = other.selectedTextColor;
66 68
         if (other.icon.hasValue()) icon = other.icon;
69
+        if (other.selectedIcon.hasValue()) selectedIcon = other.selectedIcon;
67 70
         if (other.iconColor.hasValue()) iconColor = other.iconColor;
68 71
         if (other.selectedIconColor.hasValue()) selectedIconColor = other.selectedIconColor;
69 72
         if (other.badge.hasValue()) badge = other.badge;
@@ -81,6 +84,7 @@ public class BottomTabOptions {
81 84
         if (!textColor.hasValue()) textColor = defaultOptions.textColor;
82 85
         if (!selectedTextColor.hasValue()) selectedTextColor = defaultOptions.selectedTextColor;
83 86
         if (!icon.hasValue()) icon = defaultOptions.icon;
87
+        if (!selectedIcon.hasValue()) selectedIcon = defaultOptions.selectedIcon;
84 88
         if (!iconColor.hasValue()) iconColor = defaultOptions.iconColor;
85 89
         if (!selectedIconColor.hasValue()) selectedIconColor = defaultOptions.selectedIconColor;
86 90
         if (!badge.hasValue()) badge = defaultOptions.badge;

+ 6
- 0
lib/android/app/src/main/java/com/reactnativenavigation/presentation/BottomTabPresenter.java Zobrazit soubor

@@ -89,6 +89,12 @@ public class BottomTabPresenter {
89 89
                         bottomTabs.setIcon(index, drawable);
90 90
                     }
91 91
                 });
92
+                if (tab.selectedIcon.hasValue()) imageLoader.loadIcon(context, tab.selectedIcon.get(), new ImageLoadingListenerAdapter() {
93
+                    @Override
94
+                    public void onComplete(@NonNull Drawable drawable) {
95
+                        bottomTabs.setSelectedIcon(index, drawable);
96
+                    }
97
+                });
92 98
                 if (tab.testId.hasValue()) bottomTabs.setTag(index, tab.testId.get());
93 99
                 if (shouldApplyDot(tab)) mergeDotIndicator(index, tab.dotIndicator); else mergeBadge(index, tab);
94 100
             }

+ 6
- 4
lib/android/app/src/main/java/com/reactnativenavigation/utils/ImageLoader.java Zobrazit soubor

@@ -7,8 +7,6 @@ import android.graphics.drawable.BitmapDrawable;
7 7
 import android.graphics.drawable.Drawable;
8 8
 import android.net.Uri;
9 9
 import android.os.StrictMode;
10
-import androidx.annotation.NonNull;
11
-import androidx.annotation.Nullable;
12 10
 
13 11
 import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
14 12
 import com.reactnativenavigation.NavigationApplication;
@@ -20,6 +18,9 @@ import java.net.URL;
20 18
 import java.util.ArrayList;
21 19
 import java.util.List;
22 20
 
21
+import androidx.annotation.NonNull;
22
+import androidx.annotation.Nullable;
23
+
23 24
 public class ImageLoader {
24 25
 
25 26
     public interface ImagesLoadingListener {
@@ -33,7 +34,8 @@ public class ImageLoader {
33 34
     private static final String FILE_SCHEME = "file";
34 35
 
35 36
     @Nullable
36
-    public Drawable loadIcon(Context context, String uri) {
37
+    public Drawable loadIcon(Context context, @Nullable String uri) {
38
+        if (uri == null) return null;
37 39
         try {
38 40
             return getDrawable(context, uri);
39 41
         } catch (IOException e) {
@@ -64,7 +66,7 @@ public class ImageLoader {
64 66
     }
65 67
 
66 68
     @NonNull
67
-    private Drawable getDrawable(Context context, String source) throws IOException {
69
+    private Drawable getDrawable(Context context, @NonNull String source) throws IOException {
68 70
         Drawable drawable;
69 71
         if (isLocalFile(Uri.parse(source))) {
70 72
             drawable = loadFile(source);

+ 1
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java Zobrazit soubor

@@ -159,6 +159,7 @@ public class BottomTabsController extends ParentController<BottomTabsLayout> imp
159 159
             return new AHBottomNavigationItem(
160 160
                     options.text.get(""),
161 161
                     imageLoader.loadIcon(getActivity(), options.icon.get()),
162
+                    imageLoader.loadIcon(getActivity(), options.selectedIcon.get(null)),
162 163
                     options.testId.get("")
163 164
             );
164 165
         });

+ 9
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/BottomTabs.java Zobrazit soubor

@@ -75,7 +75,15 @@ public class BottomTabs extends AHBottomNavigation {
75 75
     public void setIcon(int index, Drawable icon) {
76 76
         AHBottomNavigationItem item = getItem(index);
77 77
         if (!item.getDrawable(getContext()).equals(icon)) {
78
-            item.setDrawable(icon);
78
+            item.setIcon(icon);
79
+            refresh();
80
+        }
81
+    }
82
+
83
+    public void setSelectedIcon(int index, Drawable icon) {
84
+        AHBottomNavigationItem item = getItem(index);
85
+        if (!item.getDrawable(getContext()).equals(icon)) {
86
+            item.setSelectedIcon(icon);
79 87
             refresh();
80 88
         }
81 89
     }

binární
playground/img/layouts@2x.android.png Zobrazit soubor


binární
playground/img/layouts@2x.ios.png Zobrazit soubor


binární
playground/img/layouts_selected@2x.android.png Zobrazit soubor


binární
playground/img/layouts_selected@2x.ios.png Zobrazit soubor


binární
playground/img/options@2x.android.png Zobrazit soubor


binární
playground/img/options@2x.ios.png Zobrazit soubor


binární
playground/img/options_selected@2x.android.png Zobrazit soubor


binární
playground/img/options_selected@2x.ios.png Zobrazit soubor


+ 2
- 1
playground/src/app.js Zobrazit soubor

@@ -49,7 +49,7 @@ function start() {
49 49
                   bottomTab: {
50 50
                     text: 'Layouts',
51 51
                     icon: require('../img/layouts.png'),
52
-                    fontSize: 10,
52
+                    selectedIcon: require('../img/layouts_selected.png'),
53 53
                     testID: testIDs.LAYOUTS_TAB
54 54
                   }
55 55
                 }
@@ -73,6 +73,7 @@ function start() {
73 73
                   bottomTab: {
74 74
                     text: 'Options',
75 75
                     icon: require('../img/options.png'),
76
+                    selectedIcon: require('../img/options_selected.png'),
76 77
                     testID: testIDs.OPTIONS_TAB
77 78
                   }
78 79
                 }