소스 검색

Initial setButtons implementation

Guy Carmeli 8 년 전
부모
커밋
3ea4cfa850

+ 8
- 1
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java 파일 보기

@@ -3,8 +3,13 @@ package com.reactnativenavigation.bridge;
3 3
 import com.facebook.react.bridge.ReactApplicationContext;
4 4
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
5 5
 import com.facebook.react.bridge.ReactMethod;
6
+import com.facebook.react.bridge.ReadableArray;
6 7
 import com.facebook.react.bridge.ReadableMap;
7 8
 import com.reactnativenavigation.controllers.NavigationCommandsHandler;
9
+import com.reactnativenavigation.params.TitleBarButtonParams;
10
+import com.reactnativenavigation.params.parsers.TitleBarButtonParamsParser;
11
+
12
+import java.util.List;
8 13
 
9 14
 /**
10 15
  * The basic abstract components we will expose:
@@ -39,7 +44,9 @@ public class NavigationReactModule extends ReactContextBaseJavaModule {
39 44
     }
40 45
 
41 46
     @ReactMethod
42
-    public void setScreenTitleBarButtons(final ReadableMap params) {
47
+    public void setScreenTitleBarButtons(String screenInstanceId, String navigatorEventId, ReadableArray buttons) {
48
+        List<TitleBarButtonParams> titleBarButtons = TitleBarButtonParamsParser.parse(BundleConverter.toBundle(buttons));
49
+        NavigationCommandsHandler.setScreenTitleBarButtons(screenInstanceId, navigatorEventId, titleBarButtons);
43 50
     }
44 51
 
45 52
     @ReactMethod

+ 7
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java 파일 보기

@@ -12,10 +12,13 @@ import com.reactnativenavigation.layouts.Layout;
12 12
 import com.reactnativenavigation.layouts.LayoutFactory;
13 13
 import com.reactnativenavigation.params.ActivityParams;
14 14
 import com.reactnativenavigation.params.ScreenParams;
15
+import com.reactnativenavigation.params.TitleBarButtonParams;
15 16
 import com.reactnativenavigation.react.JsDevReloadHandler;
16 17
 import com.reactnativenavigation.react.NavigationReactInstance;
17 18
 import com.reactnativenavigation.react.RedboxPermission;
18 19
 
20
+import java.util.List;
21
+
19 22
 public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler, NavigationReactInstance.OnJsDevReloadListener {
20 23
 
21 24
     /**
@@ -135,6 +138,10 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
135 138
         layout.setTitleBarTitle(screenInstanceId, title);
136 139
     }
137 140
 
141
+    public void setTitleBarButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
142
+        layout.setTitleBarButtons(screenInstanceId, navigatorEventId, titleBarButtons);
143
+    }
144
+
138 145
     void showModal(ScreenParams screenParams) {
139 146
         modalController.showModal(screenParams);
140 147
     }

+ 18
- 1
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java 파일 보기

@@ -6,9 +6,12 @@ import android.os.Bundle;
6 6
 import com.reactnativenavigation.NavigationApplication;
7 7
 import com.reactnativenavigation.params.ActivityParams;
8 8
 import com.reactnativenavigation.params.ScreenParams;
9
+import com.reactnativenavigation.params.TitleBarButtonParams;
9 10
 import com.reactnativenavigation.params.parsers.ActivityParamsParser;
10 11
 import com.reactnativenavigation.params.parsers.ScreenParamsParser;
11 12
 
13
+import java.util.List;
14
+
12 15
 public class NavigationCommandsHandler {
13 16
 
14 17
     private static final String ACTIVITY_PARAMS_BUNDLE = "ACTIVITY_PARAMS_BUNDLE";
@@ -118,7 +121,6 @@ public class NavigationCommandsHandler {
118 121
         });
119 122
     }
120 123
 
121
-
122 124
     public static void showModal(Bundle params) {
123 125
         final NavigationActivity currentActivity = NavigationActivity.currentActivity;
124 126
         if (currentActivity == null) {
@@ -132,5 +134,20 @@ public class NavigationCommandsHandler {
132 134
             public void run() {
133 135
                 currentActivity.showModal(screenParams);
134 136
             }
137
+        });
138
+    }
139
+
140
+    public static void setScreenTitleBarButtons(final String screenInstanceId, final String navigatorEventId, final List<TitleBarButtonParams> titleBarButtons) {
141
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
142
+        if (currentActivity == null) {
143
+            return;
135 144
         }
145
+
146
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
147
+            @Override
148
+            public void run() {
149
+                currentActivity.setTitleBarButtons(screenInstanceId, navigatorEventId, titleBarButtons);
150
+            }
151
+        });
152
+    }
136 153
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/Layout.java 파일 보기

@@ -1,6 +1,9 @@
1 1
 package com.reactnativenavigation.layouts;
2 2
 
3 3
 import com.reactnativenavigation.params.ScreenParams;
4
+import com.reactnativenavigation.params.TitleBarButtonParams;
5
+
6
+import java.util.List;
4 7
 
5 8
 public interface Layout {
6 9
     boolean onBackPressed();
@@ -20,4 +23,6 @@ public interface Layout {
20 23
     void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated);
21 24
 
22 25
     void setTitleBarTitle(String screenInstanceId, String title);
26
+
27
+    void setTitleBarButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons);
23 28
 }

+ 7
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/Screen.java 파일 보기

@@ -11,11 +11,14 @@ import android.widget.RelativeLayout;
11 11
 import com.reactnativenavigation.animation.VisibilityAnimator;
12 12
 import com.reactnativenavigation.params.ScreenParams;
13 13
 import com.reactnativenavigation.params.ScreenStyleParams;
14
+import com.reactnativenavigation.params.TitleBarButtonParams;
14 15
 import com.reactnativenavigation.utils.SdkSupports;
15 16
 import com.reactnativenavigation.utils.ViewUtils;
16 17
 import com.reactnativenavigation.views.ScrollDirectionListener;
17 18
 import com.reactnativenavigation.views.TopBar;
18 19
 
20
+import java.util.List;
21
+
19 22
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
20 23
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
21 24
 
@@ -119,4 +122,8 @@ public abstract class Screen extends RelativeLayout implements ScrollDirectionLi
119 122
     public void setTitleBarTitle(String title) {
120 123
         topBar.setTitle(title);
121 124
     }
125
+
126
+    public void setTitleBarButtons(String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
127
+        topBar.setTitleBarButtons(navigatorEventId, titleBarButtons);
128
+    }
122 129
 }

+ 9
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenStack.java 파일 보기

@@ -5,7 +5,9 @@ import android.content.Context;
5 5
 import android.widget.FrameLayout;
6 6
 
7 7
 import com.reactnativenavigation.params.ScreenParams;
8
+import com.reactnativenavigation.params.TitleBarButtonParams;
8 9
 
10
+import java.util.List;
9 11
 import java.util.Stack;
10 12
 
11 13
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
@@ -113,6 +115,13 @@ public class ScreenStack extends FrameLayout {
113 115
         }
114 116
     }
115 117
 
118
+    public void setTitleBarButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
119
+        Screen screen = findScreenByScreenInstanceId(screenInstanceId);
120
+        if (screen != null) {
121
+            screen.setTitleBarButtons(navigatorEventId, titleBarButtons);
122
+        }
123
+    }
124
+
116 125
 
117 126
     //    /**
118 127
 //     * Remove the ScreenStack from {@code parent} while preventing all child react views from getting unmounted

+ 8
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java 파일 보기

@@ -4,6 +4,9 @@ import android.content.Context;
4 4
 import android.widget.FrameLayout;
5 5
 
6 6
 import com.reactnativenavigation.params.ScreenParams;
7
+import com.reactnativenavigation.params.TitleBarButtonParams;
8
+
9
+import java.util.List;
7 10
 
8 11
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
9 12
 
@@ -76,4 +79,9 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
76 79
     public void setTitleBarTitle(String screenInstanceId, String title) {
77 80
         stack.setTitleBarTitle(screenInstanceId, title);
78 81
     }
82
+
83
+    @Override
84
+    public void setTitleBarButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
85
+        stack.setTitleBarButtons(screenInstanceId, navigatorEventId, titleBarButtons);
86
+    }
79 87
 }

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java 파일 보기

@@ -36,4 +36,8 @@ public class TopBar extends AppBarLayout {
36 36
         setVisibility(styleParams.topBarHidden ? GONE : VISIBLE);
37 37
         titleBar.setVisibility(styleParams.titleBarHidden ? GONE : VISIBLE);
38 38
     }
39
+
40
+    public void setTitleBarButtons(String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
41
+        titleBar.setButtons(titleBarButtons, navigatorEventId);
42
+    }
39 43
 }

+ 11
- 11
src/deprecated/platformSpecificDeprecated.android.js 파일 보기

@@ -138,17 +138,17 @@ function addTabIcon(tab) {
138 138
 }
139 139
 
140 140
 function navigatorSetButtons(navigator, navigatorEventID, params) {
141
-  //if (params.rightButtons) {
142
-  //  params.rightButtons.forEach(function(button) {
143
-  //    if (button.icon) {
144
-  //      const icon = resolveAssetSource(button.icon);
145
-  //      if (icon) {
146
-  //        button.icon = icon.uri;
147
-  //      }
148
-  //    }
149
-  //  });
150
-  //}
151
-  //RctActivity.setNavigatorButtons(params);
141
+  if (params.rightButtons) {
142
+   params.rightButtons.forEach(function(button) {
143
+     if (button.icon) {
144
+       const icon = resolveAssetSource(button.icon);
145
+       if (icon) {
146
+         button.icon = icon.uri;
147
+       }
148
+     }
149
+   });
150
+  }
151
+  newPlatformSpecific.setScreenTitleBarButtons(navigator.screenInstanceID, navigatorEventID, params.rightButtons);
152 152
 }
153 153
 
154 154
 function navigatorSetTabBadge(navigator, params) {

+ 6
- 1
src/platformSpecific.android.js 파일 보기

@@ -40,6 +40,10 @@ function setScreenTitleBarTitle(screenInstanceID, title) {
40 40
   NativeModules.NavigationReactModule.setScreenTitleBarTitle(screenInstanceID, title);
41 41
 }
42 42
 
43
+function setScreenTitleBarButtons(screenInstanceID, navigatorEventID, buttons) {
44
+  NativeModules.NavigationReactModule.setScreenTitleBarButtons(screenInstanceID, navigatorEventID, buttons);
45
+}
46
+
43 47
 module.exports = {
44 48
   startApp,
45 49
   push,
@@ -47,5 +51,6 @@ module.exports = {
47 51
   popToRoot,
48 52
   newStack,
49 53
   toggleTopBarVisible,
50
-  setScreenTitleBarTitle
54
+  setScreenTitleBarTitle,
55
+  setScreenTitleBarButtons
51 56
 };