Browse Source

Update left button navigatorEventId when changing TopTabs (#1269)

Guy Carmeli 7 years ago
parent
commit
8165ab9808

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/screens/Screen.java View File

79
         }
79
         }
80
         if (ViewPagerScreenChangedEvent.TYPE.equals(event.getType()) && isShown() ) {
80
         if (ViewPagerScreenChangedEvent.TYPE.equals(event.getType()) && isShown() ) {
81
             topBar.dismissContextualMenu();
81
             topBar.dismissContextualMenu();
82
+            topBar.onViewPagerScreenChanged(getScreenParams());
82
         }
83
         }
83
     }
84
     }
84
 
85
 
134
         topBar.addTitleBarAndSetButtons(screenParams.rightButtons,
135
         topBar.addTitleBarAndSetButtons(screenParams.rightButtons,
135
                 screenParams.leftButton,
136
                 screenParams.leftButton,
136
                 leftButtonOnClickListener,
137
                 leftButtonOnClickListener,
137
-                screenParams.getNavigatorEventId(),
138
+                getNavigatorEventId(),
138
                 screenParams.overrideBackPressInJs);
139
                 screenParams.overrideBackPressInJs);
139
     }
140
     }
140
 
141
 

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java View File

326
     public void setScreenTitleBarLeftButton(String screenInstanceId, final String navigatorEventId, final TitleBarLeftButtonParams titleBarLeftButtonParams) {
326
     public void setScreenTitleBarLeftButton(String screenInstanceId, final String navigatorEventId, final TitleBarLeftButtonParams titleBarLeftButtonParams) {
327
         performOnScreen(screenInstanceId, new Task<Screen>() {
327
         performOnScreen(screenInstanceId, new Task<Screen>() {
328
             @Override
328
             @Override
329
-            public void run(Screen param) {
330
-                param.setTitleBarLeftButton(navigatorEventId, leftButtonOnClickListener, titleBarLeftButtonParams);
329
+            public void run(Screen screen) {
330
+                screen.setTitleBarLeftButton(navigatorEventId, leftButtonOnClickListener, titleBarLeftButtonParams);
331
             }
331
             }
332
         });
332
         });
333
     }
333
     }

+ 14
- 4
android/app/src/main/java/com/reactnativenavigation/screens/ViewPagerScreen.java View File

9
 import com.reactnativenavigation.params.FabParams;
9
 import com.reactnativenavigation.params.FabParams;
10
 import com.reactnativenavigation.params.PageParams;
10
 import com.reactnativenavigation.params.PageParams;
11
 import com.reactnativenavigation.params.ScreenParams;
11
 import com.reactnativenavigation.params.ScreenParams;
12
+import com.reactnativenavigation.params.TitleBarLeftButtonParams;
12
 import com.reactnativenavigation.views.ContentView;
13
 import com.reactnativenavigation.views.ContentView;
13
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
14
 import com.reactnativenavigation.views.LeftButtonOnClickListener;
14
 import com.reactnativenavigation.views.TopTabs;
15
 import com.reactnativenavigation.views.TopTabs;
30
 
31
 
31
     @Override
32
     @Override
32
     public BaseScreenParams getScreenParams() {
33
     public BaseScreenParams getScreenParams() {
33
-        return screenParams.topTabParams.get(viewPager.getCurrentItem());
34
+        return screenParams.topTabParams.get(getCurrentItem());
35
+    }
36
+
37
+    @Override
38
+    public void setTitleBarLeftButton(String navigatorEventId, LeftButtonOnClickListener backButtonListener, TitleBarLeftButtonParams titleBarLeftButtonParams) {
39
+        super.setTitleBarLeftButton(getNavigatorEventId(), backButtonListener, titleBarLeftButtonParams);
34
     }
40
     }
35
 
41
 
36
     @Override
42
     @Override
41
 
47
 
42
     @Override
48
     @Override
43
     public ContentView getContentView() {
49
     public ContentView getContentView() {
44
-        return contentViews.get(viewPager.getCurrentItem());
50
+        return contentViews.get(getCurrentItem());
45
     }
51
     }
46
 
52
 
47
     @Override
53
     @Override
120
 
126
 
121
     @Override
127
     @Override
122
     public String getScreenInstanceId() {
128
     public String getScreenInstanceId() {
123
-        return screenParams.topTabParams.get(viewPager.getCurrentItem()).navigationParams.screenInstanceId;
129
+        return screenParams.topTabParams.get(getCurrentItem()).navigationParams.screenInstanceId;
124
     }
130
     }
125
 
131
 
126
     @Override
132
     @Override
127
     public String getNavigatorEventId() {
133
     public String getNavigatorEventId() {
128
-        return screenParams.topTabParams.get(viewPager.getCurrentItem()).navigationParams.navigatorEventId;
134
+        return screenParams.topTabParams.get(getCurrentItem()).navigationParams.navigatorEventId;
135
+    }
136
+
137
+    private int getCurrentItem() {
138
+        return viewPager == null ? 0 : viewPager.getCurrentItem();
129
     }
139
     }
130
 
140
 
131
     public void selectTopTabByTabIndex(int index) {
141
     public void selectTopTabByTabIndex(int index) {

+ 5
- 1
android/app/src/main/java/com/reactnativenavigation/views/LeftButton.java View File

20
 
20
 
21
     private TitleBarLeftButtonParams params;
21
     private TitleBarLeftButtonParams params;
22
     private final LeftButtonOnClickListener onClickListener;
22
     private final LeftButtonOnClickListener onClickListener;
23
-    private final String navigatorEventId;
23
+    private String navigatorEventId;
24
     private final boolean overrideBackPressInJs;
24
     private final boolean overrideBackPressInJs;
25
 
25
 
26
     LeftButton(Context context,
26
     LeftButton(Context context,
108
     private void sendClickEvent() {
108
     private void sendClickEvent() {
109
         NavigationApplication.instance.getEventEmitter().sendNavigatorEvent(params.eventId, navigatorEventId);
109
         NavigationApplication.instance.getEventEmitter().sendNavigatorEvent(params.eventId, navigatorEventId);
110
     }
110
     }
111
+
112
+    void updateNavigatorEventId(String navigatorEventId) {
113
+        this.navigatorEventId = navigatorEventId;
114
+    }
111
 }
115
 }

+ 7
- 0
android/app/src/main/java/com/reactnativenavigation/views/TitleBar.java View File

13
 import android.view.animation.AccelerateInterpolator;
13
 import android.view.animation.AccelerateInterpolator;
14
 import android.widget.TextView;
14
 import android.widget.TextView;
15
 
15
 
16
+import com.reactnativenavigation.params.BaseScreenParams;
16
 import com.reactnativenavigation.params.BaseTitleBarButtonParams;
17
 import com.reactnativenavigation.params.BaseTitleBarButtonParams;
17
 import com.reactnativenavigation.params.StyleParams;
18
 import com.reactnativenavigation.params.StyleParams;
18
 import com.reactnativenavigation.params.TitleBarButtonParams;
19
 import com.reactnativenavigation.params.TitleBarButtonParams;
303
     BaseTitleBarButtonParams getButton(int index) {
304
     BaseTitleBarButtonParams getButton(int index) {
304
         return rightButtons.get(rightButtons.size() - index - 1);
305
         return rightButtons.get(rightButtons.size() - index - 1);
305
     }
306
     }
307
+
308
+    public void onViewPagerScreenChanged(BaseScreenParams screenParams) {
309
+        if (hasLeftButton()) {
310
+            leftButton.updateNavigatorEventId(screenParams.getNavigatorEventId());
311
+        }
312
+    }
306
 }
313
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/views/TopBar.java View File

8
 import android.widget.FrameLayout;
8
 import android.widget.FrameLayout;
9
 
9
 
10
 import com.facebook.react.bridge.Callback;
10
 import com.facebook.react.bridge.Callback;
11
+import com.reactnativenavigation.params.BaseScreenParams;
11
 import com.reactnativenavigation.params.ContextualMenuParams;
12
 import com.reactnativenavigation.params.ContextualMenuParams;
12
 import com.reactnativenavigation.params.StyleParams;
13
 import com.reactnativenavigation.params.StyleParams;
13
 import com.reactnativenavigation.params.TitleBarButtonParams;
14
 import com.reactnativenavigation.params.TitleBarButtonParams;
158
     public void destroy() {
159
     public void destroy() {
159
 
160
 
160
     }
161
     }
162
+
163
+    public void onViewPagerScreenChanged(BaseScreenParams screenParams) {
164
+        titleBar.onViewPagerScreenChanged(screenParams);
165
+    }
161
 }
166
 }