Преглед на файлове

Send fab press events and collapse fab on action click

Guy Carmeli преди 8 години
родител
ревизия
4b756ce0b1

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/params/FabActionParams.java Целия файл

@@ -4,6 +4,7 @@ import android.graphics.drawable.Drawable;
4 4
 
5 5
 public class FabActionParams {
6 6
     public String id;
7
+    public String navigatorEventId;
7 8
     public Drawable icon;
8 9
     public StyleParams.Color backgroundColor;
9 10
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/params/FabParams.java Целия файл

@@ -9,5 +9,10 @@ public class FabParams {
9 9
     public Drawable expendedIcon;
10 10
     public StyleParams.Color backgroundColor;
11 11
     public String id;
12
+    public String navigatorEventId;
12 13
     public List<FabActionParams> actions;
14
+
15
+    public boolean hasExpendedState() {
16
+        return actions != null && actions.size() > 0;
17
+    }
13 18
 }

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/params/parsers/ButtonParser.java Целия файл

@@ -35,10 +35,10 @@ public class ButtonParser extends Parser {
35 35
         return leftButton;
36 36
     }
37 37
 
38
-    public static FabParams parseFab(Bundle params) {
38
+    public static FabParams parseFab(Bundle params, String navigatorEventId) {
39 39
         FabParams fabParams = null;
40 40
         if (hasKey(params, KEY_FAB)) {
41
-            fabParams = new FabParamsParser().parse(params.getBundle(KEY_FAB));
41
+            fabParams = new FabParamsParser().parse(params.getBundle(KEY_FAB), navigatorEventId);
42 42
         }
43 43
         return fabParams;
44 44
     }

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/FabActionParamsParser.java Целия файл

@@ -7,9 +7,10 @@ import com.reactnativenavigation.params.StyleParams;
7 7
 import com.reactnativenavigation.react.ImageLoader;
8 8
 
9 9
 public class FabActionParamsParser extends Parser {
10
-    public FabActionParams parse(Bundle params) {
10
+    public FabActionParams parse(Bundle params, String navigatorEventId) {
11 11
         FabActionParams fabActionParams = new FabActionParams();
12 12
         fabActionParams.id = params.getString("id");
13
+        fabActionParams.navigatorEventId = navigatorEventId;
13 14
         fabActionParams.icon = ImageLoader.loadImage(params.getString("icon"));
14 15
         fabActionParams.backgroundColor = StyleParams.Color.parse(params.getString("backgroundColor"));
15 16
         return fabActionParams;

+ 3
- 3
android/app/src/main/java/com/reactnativenavigation/params/parsers/FabParamsParser.java Целия файл

@@ -8,9 +8,10 @@ import com.reactnativenavigation.params.StyleParams;
8 8
 import com.reactnativenavigation.react.ImageLoader;
9 9
 
10 10
 public class FabParamsParser extends Parser {
11
-    public FabParams parse(Bundle params) {
11
+    public FabParams parse(Bundle params, final String navigatorEventId) {
12 12
         FabParams fabParams = new FabParams();
13 13
         fabParams.id = params.getString("id");
14
+        fabParams.navigatorEventId = navigatorEventId;
14 15
         fabParams.backgroundColor = getColor(params, "backgroundColor", new StyleParams.Color());
15 16
 
16 17
         if (hasKey(params, "collapsedIcon")) {
@@ -23,11 +24,10 @@ public class FabParamsParser extends Parser {
23 24
             fabParams.actions = parseBundle(params.getBundle("actions"), new ParseStrategy<FabActionParams>() {
24 25
                 @Override
25 26
                 public FabActionParams parse(Bundle params) {
26
-                    return new FabActionParamsParser().parse(params);
27
+                    return new FabActionParamsParser().parse(params, navigatorEventId);
27 28
                 }
28 29
             });
29 30
         }
30
-
31 31
         return fabParams;
32 32
     }
33 33
 }

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/ScreenParamsParser.java Целия файл

@@ -41,7 +41,7 @@ public class ScreenParamsParser extends Parser {
41 41
             result.fragmentCreatorPassProps = params.getBundle(FRAGMENT_CREATOR_PASS_PROPS);
42 42
         }
43 43
 
44
-        result.fabParams = ButtonParser.parseFab(params);
44
+        result.fabParams = ButtonParser.parseFab(params, result.navigationParams.navigatorEventId);
45 45
 
46 46
         result.tabLabel = getTabLabel(params);
47 47
         result.tabIcon = getTabIcon(params);

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/params/parsers/TopTabParamsParser.java Целия файл

@@ -31,7 +31,7 @@ public class TopTabParamsParser extends Parser {
31 31
         result.navigationParams = new NavigationParams(params.getBundle(NAVIGATION_PARAMS));
32 32
         result.leftButton = ButtonParser.parseLeftButton(params);
33 33
         result.rightButtons = ButtonParser.parseRightButton(params);
34
-        result.fabParams = ButtonParser.parseFab(params);
34
+        result.fabParams = ButtonParser.parseFab(params, result.navigationParams.navigatorEventId);
35 35
         return result;
36 36
     }
37 37
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/views/FloatingActionButtonAnimator.java Целия файл

@@ -44,6 +44,11 @@ public class FloatingActionButtonAnimator {
44 44
                 .start();
45 45
     }
46 46
 
47
+    public void collapse() {
48
+        hideExpended();
49
+        showCollapsed();
50
+    }
51
+
47 52
     void hideCollapsed() {
48 53
         animateFab(collapsedFab, 0, 90);
49 54
     }

+ 22
- 6
android/app/src/main/java/com/reactnativenavigation/views/FloatingActionButtonCoordinator.java Целия файл

@@ -12,6 +12,7 @@ import android.support.design.widget.FloatingActionButton;
12 12
 import android.view.Gravity;
13 13
 import android.view.View;
14 14
 
15
+import com.reactnativenavigation.NavigationApplication;
15 16
 import com.reactnativenavigation.params.FabActionParams;
16 17
 import com.reactnativenavigation.params.FabParams;
17 18
 import com.reactnativenavigation.utils.ViewUtils;
@@ -87,9 +88,13 @@ public class FloatingActionButtonCoordinator {
87 88
         collapsedFab.setOnClickListener(new View.OnClickListener() {
88 89
             @Override
89 90
             public void onClick(View v) {
90
-                fabAnimator.hideCollapsed();
91
-                fabAnimator.showExpended();
92
-                showActions();
91
+                if (params.hasExpendedState()) {
92
+                    fabAnimator.hideCollapsed();
93
+                    fabAnimator.showExpended();
94
+                    showActions();
95
+                } else {
96
+                    NavigationApplication.instance.sendNavigatorEvent(params.id, params.navigatorEventId);
97
+                }
93 98
             }
94 99
         });
95 100
     }
@@ -102,8 +107,7 @@ public class FloatingActionButtonCoordinator {
102 107
         expendedFab.setOnClickListener(new View.OnClickListener() {
103 108
             @Override
104 109
             public void onClick(View v) {
105
-                fabAnimator.hideExpended();
106
-                fabAnimator.showCollapsed();
110
+                fabAnimator.collapse();
107 111
             }
108 112
         });
109 113
     }
@@ -142,9 +146,16 @@ public class FloatingActionButtonCoordinator {
142 146
     }
143 147
 
144 148
     private FloatingActionButton createAction(int index) {
145
-        FabActionParams actionParams = params.actions.get(index);
149
+        final FabActionParams actionParams = params.actions.get(index);
146 150
         FloatingActionButton action = createFab(actionParams.icon);
147 151
         action.setLayoutParams(createActionLayoutParams(index));
152
+        action.setOnClickListener(new View.OnClickListener() {
153
+            @Override
154
+            public void onClick(View v) {
155
+                NavigationApplication.instance.sendNavigatorEvent(actionParams.id, actionParams.navigatorEventId);
156
+                fabAnimator.collapse();
157
+            }
158
+        });
148 159
         if (actionParams.backgroundColor.hasColor()) {
149 160
             action.setBackgroundTintList(ColorStateList.valueOf(actionParams.backgroundColor.getColor()));
150 161
         }
@@ -182,9 +193,14 @@ public class FloatingActionButtonCoordinator {
182 193
             float fraction = calculateTransitionFraction(dependentValue);
183 194
             child.setY(calculateY(parent, fraction));
184 195
             child.setAlpha(calculateAlpha(fraction));
196
+            setVisibility(child);
185 197
             return true;
186 198
         }
187 199
 
200
+        private void setVisibility(FloatingActionButton child) {
201
+            child.setVisibility(child.getAlpha() == 0 ? View.GONE : View.VISIBLE);
202
+        }
203
+
188 204
         private float calculateAlpha(float fraction) {
189 205
             return 1 * fraction;
190 206
         }