Просмотр исходного кода

Send accept and cancel LeftButton events

Guy Carmeli 8 лет назад
Родитель
Сommit
a2740d2a14

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactEventEmitter.java Просмотреть файл

@@ -9,6 +9,7 @@ public class NavigationReactEventEmitter {
9 9
 
10 10
     private static final String KEY_EVENT_ID = "id";
11 11
     private static final String KEY_EVENT_TYPE = "type";
12
+    private static final String KEY_NAVIGATOR_EVENT_ID = "navigatorEventID";
12 13
     private static final String EVENT_TYPE = "NavBarButtonPress";
13 14
     private RCTDeviceEventEmitter eventEmitter;
14 15
 
@@ -20,7 +21,7 @@ public class NavigationReactEventEmitter {
20 21
         WritableMap params = Arguments.createMap();
21 22
         params.putString(KEY_EVENT_TYPE, EVENT_TYPE);
22 23
         params.putString(KEY_EVENT_ID, eventId);
23
-        params.putString("navigatorEventID", navigatorEventId);
24
+        params.putString(KEY_NAVIGATOR_EVENT_ID, navigatorEventId);
24 25
         eventEmitter.emit(navigatorEventId, params);
25 26
     }
26 27
 }

+ 20
- 5
android/app/src/main/java/com/reactnativenavigation/views/LeftButton.java Просмотреть файл

@@ -5,6 +5,7 @@ import android.graphics.Color;
5 5
 import android.view.View;
6 6
 
7 7
 import com.balysv.materialmenu.MaterialMenuDrawable;
8
+import com.reactnativenavigation.NavigationApplication;
8 9
 import com.reactnativenavigation.params.TitleBarButtonParams;
9 10
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
10 11
 
@@ -32,22 +33,36 @@ public class LeftButton extends MaterialMenuDrawable implements View.OnClickList
32 33
         setInitialState();
33 34
     }
34 35
 
35
-    private void setInitialState() {
36
-        if (params != null) {
37
-            setIconState(params.iconState);
38
-        } else {
39
-            setVisible(false);
36
+    public void setIconState(TitleBarLeftButtonParams params) {
37
+        this.params = params;
38
+        if (params.color.hasColor()) {
39
+            setColor(params.color.getColor());
40 40
         }
41
+        animateIconState(params.iconState);
41 42
     }
42 43
 
43 44
     @Override
44 45
     public void onClick(View v) {
45 46
         if (isBackButton()) {
46 47
             titleBarBackButtonListener.onTitleBarBackPress();
48
+        } else {
49
+            sendClickEvent();
50
+        }
51
+    }
52
+
53
+    private void setInitialState() {
54
+        if (params != null) {
55
+            setIconState(params.iconState);
56
+        } else {
57
+            setVisible(false);
47 58
         }
48 59
     }
49 60
 
50 61
     private boolean isBackButton() {
51 62
         return getIconState() == IconState.ARROW;
52 63
     }
64
+
65
+    private void sendClickEvent() {
66
+        NavigationApplication.instance.sendEvent(params.eventId, navigatorEventId);
67
+    }
53 68
 }

+ 1
- 1
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java Просмотреть файл

@@ -48,7 +48,7 @@ public class TitleBar extends Toolbar {
48 48
         if (leftButton == null) {
49 49
             createAndSetLeftButton(leftButtonParams, titleBarBackButtonListener, navigatorEventId);
50 50
         } else {
51
-            leftButton.animateIconState(leftButtonParams.iconState);
51
+            leftButton.setIconState(leftButtonParams);
52 52
         }
53 53
     }
54 54